Remove manual byte editing in wallet_tx_clone func test

This commit is contained in:
Gregory Sanders 2019-02-13 09:49:36 -05:00 committed by Steven Roose
parent 0c05901791
commit 52c8601cf4
No known key found for this signature in database
GPG key ID: 7FC91380BB4CE800

View file

@ -6,13 +6,12 @@
import io import io
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.messages import CTransaction from test_framework.messages import CTransaction, COIN
from test_framework.util import ( from test_framework.util import (
assert_equal, assert_equal,
connect_nodes, connect_nodes,
disconnect_nodes, disconnect_nodes,
sync_blocks, sync_blocks,
hex_str_to_bytes,
) )
class TxnMallTest(BitcoinTestFramework): class TxnMallTest(BitcoinTestFramework):
@ -76,13 +75,13 @@ class TxnMallTest(BitcoinTestFramework):
# createrawtransaction randomizes the order of its outputs, so swap them if necessary. # createrawtransaction randomizes the order of its outputs, so swap them if necessary.
clone_tx = CTransaction() clone_tx = CTransaction()
clone_tx.deserialize(io.BytesIO(hex_str_to_bytes(clone_raw))) clone_tx.deserialize(io.BytesIO(bytes.fromhex(clone_raw)))
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): 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):
(clone_tx.vout[0], clone_tx.vout[1]) = (clone_tx.vout[1], clone_tx.vout[0]) (clone_tx.vout[0], clone_tx.vout[1]) = (clone_tx.vout[1], clone_tx.vout[0])
# Use a different signature hash type to sign. This creates an equivalent but malleated clone. # Use a different signature hash type to sign. This creates an equivalent but malleated clone.
# Don't send the clone anywhere yet # Don't send the clone anywhere yet
tx1_clone = self.nodes[0].signrawtransactionwithwallet(clone_raw, None, "ALL|ANYONECANPAY") tx1_clone = self.nodes[0].signrawtransactionwithwallet(clone_tx.serialize().hex(), None, "ALL|ANYONECANPAY")
assert_equal(tx1_clone["complete"], True) assert_equal(tx1_clone["complete"], True)
# Have node0 mine a block, if requested: # Have node0 mine a block, if requested: