From e4e5605ef8a6c3fd71ffec4710f3e5d737e2309b Mon Sep 17 00:00:00 2001 From: merge-script Date: Wed, 31 Jul 2024 12:01:33 +0100 Subject: [PATCH] Merge bitcoin/bitcoin#30552: test: fix constructor of msg_tx ec5e294e4b830766dcc4a80add0613d3705c1794 test: fix constructor of msg_tx (Martin Zumsande) Pull request description: In python, if the default value is a mutable object (here: a class) it is shared over all instances, so that one instance being changed would affect others to be changed as well. This was the source of #30543, and possibly various other intermittent bugs in the functional tests, see https://github.com/bitcoin/bitcoin/issues/29621#issuecomment-1999298224. Fixes #30543 Fixes #29621 Fixes #25128 ACKs for top commit: sipa: utACK ec5e294e4b830766dcc4a80add0613d3705c1794. I believe some linters even warn about doing this. maflcko: ACK ec5e294e4b830766dcc4a80add0613d3705c1794 vasild: ACK ec5e294e4b830766dcc4a80add0613d3705c1794 :heart: theStack: ACK ec5e294e4b830766dcc4a80add0613d3705c1794 Tree-SHA512: a6204fb1a326de3f9aa965f345fd658f6a4dcf78731db25cc905ff6eb8d4eeb65d14cc316305eebd89387aec8748c57c3a4f4ca62408f8e5ee53f535b88b1411 --- test/functional/test_framework/messages.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index e96af7412a..945f9713ce 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -1724,8 +1724,11 @@ class msg_tx: __slots__ = ("tx",) msgtype = b"tx" - def __init__(self, tx=CTransaction()): - self.tx = tx + def __init__(self, tx=None): + if tx is None: + self.tx = CTransaction() + else: + self.tx = tx def deserialize(self, f): self.tx.deserialize(f)