Skip to content

Commit 1576518

Browse files
committed
[Tests] Rename create_tx and move to blocktools.py
1 parent df9f712 commit 1576518

File tree

5 files changed

+24
-16
lines changed

5 files changed

+24
-16
lines changed

test/functional/mempool_reorg.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010

1111
from test_framework.test_framework import BitcoinTestFramework
12+
from test_framework.blocktools import create_raw_transaction
1213
from test_framework.util import *
1314

1415
# Create one-input, one-output, no-fee transaction:
@@ -39,9 +40,9 @@ def run_test(self):
3940
# and make sure the mempool code behaves correctly.
4041
b = [ self.nodes[0].getblockhash(n) for n in range(101, 105) ]
4142
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
42-
spend_101_raw = create_tx(self.nodes[0], coinbase_txids[1], node1_address, 49.99)
43-
spend_102_raw = create_tx(self.nodes[0], coinbase_txids[2], node0_address, 49.99)
44-
spend_103_raw = create_tx(self.nodes[0], coinbase_txids[3], node0_address, 49.99)
43+
spend_101_raw = create_raw_transaction(self.nodes[0], coinbase_txids[1], node1_address, 49.99)
44+
spend_102_raw = create_raw_transaction(self.nodes[0], coinbase_txids[2], node0_address, 49.99)
45+
spend_103_raw = create_raw_transaction(self.nodes[0], coinbase_txids[3], node0_address, 49.99)
4546

4647
# Create a transaction which is time-locked to two blocks in the future
4748
timelock_tx = self.nodes[0].createrawtransaction([{"txid": coinbase_txids[0], "vout": 0}], {node0_address: 49.99})
@@ -60,8 +61,8 @@ def run_test(self):
6061
assert_raises_rpc_error(-26,'non-final', self.nodes[0].sendrawtransaction, timelock_tx)
6162

6263
# Create 102_1 and 103_1:
63-
spend_102_1_raw = create_tx(self.nodes[0], spend_102_id, node1_address, 49.98)
64-
spend_103_1_raw = create_tx(self.nodes[0], spend_103_id, node1_address, 49.98)
64+
spend_102_1_raw = create_raw_transaction(self.nodes[0], spend_102_id, node1_address, 49.98)
65+
spend_103_1_raw = create_raw_transaction(self.nodes[0], spend_103_id, node1_address, 49.98)
6566

6667
# Broadcast and mine 103_1:
6768
spend_103_1_id = self.nodes[0].sendrawtransaction(spend_103_1_raw)

test/functional/mempool_resurrect.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""Test resurrection of mined transactions when the blockchain is re-organized."""
66

77
from test_framework.test_framework import BitcoinTestFramework
8+
from test_framework.blocktools import create_raw_transaction
89
from test_framework.util import *
910

1011
# Create one-input, one-output, no-fee transaction:
@@ -27,13 +28,13 @@ def run_test(self):
2728

2829
b = [ self.nodes[0].getblockhash(n) for n in range(1, 4) ]
2930
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
30-
spends1_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.99) for txid in coinbase_txids ]
31+
spends1_raw = [ create_raw_transaction(self.nodes[0], txid, node0_address, 49.99) for txid in coinbase_txids ]
3132
spends1_id = [ self.nodes[0].sendrawtransaction(tx) for tx in spends1_raw ]
3233

3334
blocks = []
3435
blocks.extend(self.nodes[0].generate(1))
3536

36-
spends2_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.98) for txid in spends1_id ]
37+
spends2_raw = [ create_raw_transaction(self.nodes[0], txid, node0_address, 49.98) for txid in spends1_id ]
3738
spends2_id = [ self.nodes[0].sendrawtransaction(tx) for tx in spends2_raw ]
3839

3940
blocks.extend(self.nodes[0].generate(1))

test/functional/mempool_spend_coinbase.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"""
1414

1515
from test_framework.test_framework import BitcoinTestFramework
16+
from test_framework.blocktools import create_raw_transaction
1617
from test_framework.util import *
1718

1819
# Create one-input, one-output, no-fee transaction:
@@ -31,7 +32,7 @@ def run_test(self):
3132
# is too immature to spend.
3233
b = [ self.nodes[0].getblockhash(n) for n in range(101, 103) ]
3334
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
34-
spends_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.99) for txid in coinbase_txids ]
35+
spends_raw = [ create_raw_transaction(self.nodes[0], txid, node0_address, 49.99) for txid in coinbase_txids ]
3536

3637
spend_101_id = self.nodes[0].sendrawtransaction(spends_raw[0])
3738

test/functional/test_framework/blocktools.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ def create_transaction(prevtx, n, sig, value, script_pub_key=CScript()):
128128
tx.calc_sha256()
129129
return tx
130130

131+
def create_raw_transaction(node, txid, to_address, amount):
132+
""" Return raw signed transaction spending the first output of the
133+
input txid. Note that the node must be able to sign for the
134+
output that is being spent, and the node must not be running
135+
multiple wallets.
136+
"""
137+
inputs = [{"txid": txid, "vout": 0}]
138+
outputs = {to_address: amount}
139+
rawtx = node.createrawtransaction(inputs, outputs)
140+
signresult = node.signrawtransactionwithwallet(rawtx)
141+
assert_equal(signresult["complete"], True)
142+
return signresult['hex']
143+
131144
def get_legacy_sigopcount_block(block, accurate=True):
132145
count = 0
133146
for tx in block.vtx:

test/functional/test_framework/util.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -526,14 +526,6 @@ def gen_return_txouts():
526526
txouts = txouts + script_pubkey
527527
return txouts
528528

529-
def create_tx(node, coinbase, to_address, amount):
530-
inputs = [{"txid": coinbase, "vout": 0}]
531-
outputs = {to_address: amount}
532-
rawtx = node.createrawtransaction(inputs, outputs)
533-
signresult = node.signrawtransactionwithwallet(rawtx)
534-
assert_equal(signresult["complete"], True)
535-
return signresult["hex"]
536-
537529
# Create a spend of each passed-in utxo, splicing in "txouts" to each raw
538530
# transaction to make it large. See gen_return_txouts() above.
539531
def create_lots_of_big_transactions(node, txouts, utxos, num, fee):

0 commit comments

Comments
 (0)