diff --git a/test/functional/mempool_reorg.py b/test/functional/mempool_reorg.py --- a/test/functional/mempool_reorg.py +++ b/test/functional/mempool_reorg.py @@ -9,7 +9,8 @@ """ from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, assert_raises_rpc_error, create_tx +from test_framework.blocktools import create_raw_transaction +from test_framework.util import assert_equal, assert_raises_rpc_error # Create one-input, one-output, no-fee transaction: @@ -41,11 +42,11 @@ # and make sure the mempool code behaves correctly. b = [self.nodes[0].getblockhash(n) for n in range(101, 105)] coinbase_txids = [self.nodes[0].getblock(h)['tx'][0] for h in b] - spend_101_raw = create_tx( + spend_101_raw = create_raw_transaction( self.nodes[0], coinbase_txids[1], node1_address, 49.99) - spend_102_raw = create_tx( + spend_102_raw = create_raw_transaction( self.nodes[0], coinbase_txids[2], node0_address, 49.99) - spend_103_raw = create_tx( + spend_103_raw = create_raw_transaction( self.nodes[0], coinbase_txids[3], node0_address, 49.99) # Create a transaction which is time-locked to two blocks in the future @@ -70,9 +71,9 @@ self.nodes[0].sendrawtransaction, timelock_tx) # Create 102_1 and 103_1: - spend_102_1_raw = create_tx( + spend_102_1_raw = create_raw_transaction( self.nodes[0], spend_102_id, node1_address, 49.98) - spend_103_1_raw = create_tx( + spend_103_1_raw = create_raw_transaction( self.nodes[0], spend_103_id, node1_address, 49.98) # Broadcast and mine 103_1: diff --git a/test/functional/mempool_resurrect.py b/test/functional/mempool_resurrect.py --- a/test/functional/mempool_resurrect.py +++ b/test/functional/mempool_resurrect.py @@ -5,7 +5,8 @@ """Test resurrection of mined transactions when the blockchain is re-organized.""" from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, create_tx +from test_framework.blocktools import create_raw_transaction +from test_framework.util import assert_equal # Create one-input, one-output, no-fee transaction: @@ -29,7 +30,7 @@ b = [self.nodes[0].getblockhash(n) for n in range(1, 4)] coinbase_txids = [self.nodes[0].getblock(h)['tx'][0] for h in b] - spends1_raw = [create_tx(self.nodes[0], txid, node0_address, 49.99) + spends1_raw = [create_raw_transaction(self.nodes[0], txid, node0_address, 49.99) for txid in coinbase_txids] spends1_id = [self.nodes[0].sendrawtransaction(tx) for tx in spends1_raw] @@ -37,7 +38,7 @@ blocks = [] blocks.extend(self.nodes[0].generate(1)) - spends2_raw = [create_tx(self.nodes[0], txid, node0_address, 49.98) + spends2_raw = [create_raw_transaction(self.nodes[0], txid, node0_address, 49.98) for txid in spends1_id] spends2_id = [self.nodes[0].sendrawtransaction(tx) for tx in spends2_raw] diff --git a/test/functional/mempool_spend_coinbase.py b/test/functional/mempool_spend_coinbase.py --- a/test/functional/mempool_spend_coinbase.py +++ b/test/functional/mempool_spend_coinbase.py @@ -13,7 +13,9 @@ """ from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, assert_raises_rpc_error, create_tx +from test_framework.blocktools import create_raw_transaction +from test_framework.util import assert_equal, assert_raises_rpc_error + # Create one-input, one-output, no-fee transaction: @@ -32,7 +34,7 @@ # is too immature to spend. b = [self.nodes[0].getblockhash(n) for n in range(101, 103)] coinbase_txids = [self.nodes[0].getblock(h)['tx'][0] for h in b] - spends_raw = [create_tx(self.nodes[0], txid, node0_address, 49.99) + spends_raw = [create_raw_transaction(self.nodes[0], txid, node0_address, 49.99) for txid in coinbase_txids] spend_101_id = self.nodes[0].sendrawtransaction(spends_raw[0]) diff --git a/test/functional/test_framework/blocktools.py b/test/functional/test_framework/blocktools.py --- a/test/functional/test_framework/blocktools.py +++ b/test/functional/test_framework/blocktools.py @@ -25,7 +25,7 @@ ser_string, ) from .txtools import pad_tx -from .util import satoshi_round +from .util import assert_equal, satoshi_round # Create a block (with regtest difficulty) @@ -106,6 +106,20 @@ return tx +def create_raw_transaction(node, txid, to_address, amount): + """ Return raw signed transaction spending the first output of the + input txid. Note that the node must be able to sign for the + output that is being spent, and the node must not be running + multiple wallets. + """ + inputs = [{"txid": txid, "vout": 0}] + outputs = {to_address: amount} + rawtx = node.createrawtransaction(inputs, outputs) + signresult = node.signrawtransactionwithwallet(rawtx) + assert_equal(signresult["complete"], True) + return signresult['hex'] + + def get_legacy_sigopcount_block(block, fAccurate=True): count = 0 for tx in block.vtx: diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -555,15 +555,6 @@ txouts = txouts + script_pubkey return txouts - -def create_tx(node, coinbase, to_address, amount): - inputs = [{"txid": coinbase, "vout": 0}] - outputs = {to_address: amount} - rawtx = node.createrawtransaction(inputs, outputs) - signresult = node.signrawtransactionwithwallet(rawtx) - assert_equal(signresult["complete"], True) - return signresult["hex"] - # Create a spend of each passed-in utxo, splicing in "txouts" to each raw # transaction to make it large. See gen_return_txouts() above.