Skip to content

Commit 52c8601

Browse files
instagibbsstevenroose
authored andcommitted
Remove manual byte editing in wallet_tx_clone func test
1 parent 0c05901 commit 52c8601

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

test/functional/wallet_txn_clone.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66

77
import io
88
from test_framework.test_framework import BitcoinTestFramework
9-
from test_framework.messages import CTransaction
9+
from test_framework.messages import CTransaction, COIN
1010
from test_framework.util import (
1111
assert_equal,
1212
connect_nodes,
1313
disconnect_nodes,
1414
sync_blocks,
15-
hex_str_to_bytes,
1615
)
1716

1817
class TxnMallTest(BitcoinTestFramework):
@@ -76,13 +75,13 @@ def run_test(self):
7675

7776
# createrawtransaction randomizes the order of its outputs, so swap them if necessary.
7877
clone_tx = CTransaction()
79-
clone_tx.deserialize(io.BytesIO(hex_str_to_bytes(clone_raw)))
80-
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.deserialize(io.BytesIO(bytes.fromhex(clone_raw)))
79+
if (rawtx1["vout"][0]["value"] == 40 and clone_tx.vout[0].nValue != 40*COIN or rawtx1["vout"][0]["value"] != 40 and clone_tx.vout[0].nValue == 40*COIN):
8180
(clone_tx.vout[0], clone_tx.vout[1]) = (clone_tx.vout[1], clone_tx.vout[0])
8281

8382
# Use a different signature hash type to sign. This creates an equivalent but malleated clone.
8483
# Don't send the clone anywhere yet
85-
tx1_clone = self.nodes[0].signrawtransactionwithwallet(clone_raw, None, "ALL|ANYONECANPAY")
84+
tx1_clone = self.nodes[0].signrawtransactionwithwallet(clone_tx.serialize().hex(), None, "ALL|ANYONECANPAY")
8685
assert_equal(tx1_clone["complete"], True)
8786

8887
# Have node0 mine a block, if requested:

0 commit comments

Comments
 (0)