Skip to content

Commit a268b67

Browse files
committed
fix clone tx test
1 parent d5b2735 commit a268b67

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

test/functional/wallet_txn_clone.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the wallet accounts properly when there are cloned transactions with malleated scriptsigs."""
66

7+
import io
78
from test_framework.test_framework import BitcoinTestFramework
9+
from test_framework.messages import CTransaction
810
from test_framework.util import (
911
assert_equal,
1012
connect_nodes,
1113
disconnect_nodes,
1214
sync_blocks,
15+
hex_str_to_bytes,
1316
)
1417

1518
class TxnMallTest(BitcoinTestFramework):
@@ -69,15 +72,10 @@ def run_test(self):
6972
clone_raw = self.nodes[0].createrawtransaction(clone_inputs, clone_outputs, clone_locktime)
7073

7174
# createrawtransaction randomizes the order of its outputs, so swap them if necessary.
72-
# output 0 is at version+#inputs+input+sigstub+sequence+#outputs
73-
# 40 BTC serialized is 00286bee00000000
74-
pos0 = 2 * (4 + 1 + 36 + 1 + 4 + 1)
75-
hex40 = "00286bee00000000"
76-
output_len = 16 + 2 + 2 * int("0x" + clone_raw[pos0 + 16:pos0 + 16 + 2], 0)
77-
if (rawtx1["vout"][0]["value"] == 40 and clone_raw[pos0:pos0 + 16] != hex40 or rawtx1["vout"][0]["value"] != 40 and clone_raw[pos0:pos0 + 16] == hex40):
78-
output0 = clone_raw[pos0:pos0 + output_len]
79-
output1 = clone_raw[pos0 + output_len:pos0 + 2 * output_len]
80-
clone_raw = clone_raw[:pos0] + output1 + output0 + clone_raw[pos0 + 2 * output_len:]
75+
clone_tx = CTransaction()
76+
clone_tx.deserialize(io.BytesIO(hex_str_to_bytes(clone_raw)))
77+
if (rawtx1["vout"][0]["value"] == 40 and clone_tx.vout[0].nValue != 40 or rawtx1["vout"][0]["value"] != 40 and clone_tx.vout[0].nValue == 40):
78+
(clone_tx.vout[0], clone_tx.vout[1]) = (clone_tx.vout[1], clone_tx.vout[0])
8179

8280
# Use a different signature hash type to sign. This creates an equivalent but malleated clone.
8381
# Don't send the clone anywhere yet

0 commit comments

Comments
 (0)