Skip to content

Commit b8eb0df

Browse files
author
MarcoFalke
committed
Merge #13928: qa: blocktools enforce named args for amount
cf9ed30 qa: blocktools enforce named args for amount (MarcoFalke) Pull request description: Since #13669 changed some signatures, I think it might be worthwhile to enforce named args for primitive types such as amounts. Tree-SHA512: 2733e7b6a20590b54bd54e81a09e3f5e2fadf4390bed594916b70729bcf485b048266012c1203369e0968032a2c6a2719107ac17ee925d8939af3df916eab1a6
2 parents a9c56b6 + cf9ed30 commit b8eb0df

File tree

8 files changed

+37
-41
lines changed

8 files changed

+37
-41
lines changed

test/functional/feature_cltv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def run_test(self):
6565
self.log.info("Test that an invalid-according-to-CLTV transaction can still appear in a block")
6666

6767
spendtx = create_transaction(self.nodes[0], self.coinbase_txids[0],
68-
self.nodeaddress, 1.0)
68+
self.nodeaddress, amount=1.0)
6969
cltv_invalidate(spendtx)
7070
spendtx.rehash()
7171

@@ -100,7 +100,7 @@ def run_test(self):
100100
block.nVersion = 4
101101

102102
spendtx = create_transaction(self.nodes[0], self.coinbase_txids[1],
103-
self.nodeaddress, 1.0)
103+
self.nodeaddress, amount=1.0)
104104
cltv_invalidate(spendtx)
105105
spendtx.rehash()
106106

test/functional/feature_csv_activation.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,22 @@ def sign_transaction(node, unsignedtx):
9494
return tx
9595

9696
def create_bip112special(node, input, txversion, address):
97-
tx = create_transaction(node, input, address, Decimal("49.98"))
97+
tx = create_transaction(node, input, address, amount=Decimal("49.98"))
9898
tx.nVersion = txversion
9999
signtx = sign_transaction(node, tx)
100100
signtx.vin[0].scriptSig = CScript([-1, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(signtx.vin[0].scriptSig)))
101101
return signtx
102102

103103
def send_generic_input_tx(node, coinbases, address):
104-
amount = Decimal("49.99")
105-
return node.sendrawtransaction(ToHex(sign_transaction(node, create_transaction(node, node.getblock(coinbases.pop())['tx'][0], address, amount))))
104+
return node.sendrawtransaction(ToHex(sign_transaction(node, create_transaction(node, node.getblock(coinbases.pop())['tx'][0], address, amount=Decimal("49.99")))))
106105

107106
def create_bip68txs(node, bip68inputs, txversion, address, locktime_delta=0):
108107
"""Returns a list of bip68 transactions with different bits set."""
109108
txs = []
110109
assert(len(bip68inputs) >= 16)
111110
for i, (sdf, srhb, stf, srlb) in enumerate(product(*[[True, False]] * 4)):
112111
locktime = relative_locktime(sdf, srhb, stf, srlb)
113-
tx = create_transaction(node, bip68inputs[i], address, Decimal("49.98"))
112+
tx = create_transaction(node, bip68inputs[i], address, amount=Decimal("49.98"))
114113
tx.nVersion = txversion
115114
tx.vin[0].nSequence = locktime + locktime_delta
116115
tx = sign_transaction(node, tx)
@@ -125,7 +124,7 @@ def create_bip112txs(node, bip112inputs, varyOP_CSV, txversion, address, locktim
125124
assert(len(bip112inputs) >= 16)
126125
for i, (sdf, srhb, stf, srlb) in enumerate(product(*[[True, False]] * 4)):
127126
locktime = relative_locktime(sdf, srhb, stf, srlb)
128-
tx = create_transaction(node, bip112inputs[i], address, Decimal("49.98"))
127+
tx = create_transaction(node, bip112inputs[i], address, amount=Decimal("49.98"))
129128
if (varyOP_CSV): # if varying OP_CSV, nSequence is fixed
130129
tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME + locktime_delta
131130
else: # vary nSequence instead, OP_CSV is fixed
@@ -269,10 +268,10 @@ def run_test(self):
269268

270269
# Test both version 1 and version 2 transactions for all tests
271270
# BIP113 test transaction will be modified before each use to put in appropriate block time
272-
bip113tx_v1 = create_transaction(self.nodes[0], bip113input, self.nodeaddress, Decimal("49.98"))
271+
bip113tx_v1 = create_transaction(self.nodes[0], bip113input, self.nodeaddress, amount=Decimal("49.98"))
273272
bip113tx_v1.vin[0].nSequence = 0xFFFFFFFE
274273
bip113tx_v1.nVersion = 1
275-
bip113tx_v2 = create_transaction(self.nodes[0], bip113input, self.nodeaddress, Decimal("49.98"))
274+
bip113tx_v2 = create_transaction(self.nodes[0], bip113input, self.nodeaddress, amount=Decimal("49.98"))
276275
bip113tx_v2.vin[0].nSequence = 0xFFFFFFFE
277276
bip113tx_v2.nVersion = 2
278277

test/functional/feature_dersig.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def run_test(self):
5454
self.log.info("Test that a transaction with non-DER signature can still appear in a block")
5555

5656
spendtx = create_transaction(self.nodes[0], self.coinbase_txids[0],
57-
self.nodeaddress, 1.0)
57+
self.nodeaddress, amount=1.0)
5858
unDERify(spendtx)
5959
spendtx.rehash()
6060

@@ -91,7 +91,7 @@ def run_test(self):
9191
block.nVersion = 3
9292

9393
spendtx = create_transaction(self.nodes[0], self.coinbase_txids[1],
94-
self.nodeaddress, 1.0)
94+
self.nodeaddress, amount=1.0)
9595
unDERify(spendtx)
9696
spendtx.rehash()
9797

@@ -127,8 +127,7 @@ def run_test(self):
127127
assert b'Non-canonical DER signature' in self.nodes[0].p2p.last_message["reject"].reason
128128

129129
self.log.info("Test that a version 3 block with a DERSIG-compliant transaction is accepted")
130-
block.vtx[1] = create_transaction(self.nodes[0],
131-
self.coinbase_txids[1], self.nodeaddress, 1.0)
130+
block.vtx[1] = create_transaction(self.nodes[0], self.coinbase_txids[1], self.nodeaddress, amount=1.0)
132131
block.hashMerkleRoot = block.calc_merkle_root()
133132
block.rehash()
134133
block.solve()

test/functional/feature_nulldummy.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,31 @@ def run_test(self):
6060
self.lastblocktime = int(time.time()) + 429
6161

6262
self.log.info("Test 1: NULLDUMMY compliant base transactions should be accepted to mempool and mined before activation [430]")
63-
test1txs = [create_transaction(self.nodes[0], coinbase_txid[0], self.ms_address, 49)]
63+
test1txs = [create_transaction(self.nodes[0], coinbase_txid[0], self.ms_address, amount=49)]
6464
txid1 = self.nodes[0].sendrawtransaction(bytes_to_hex_str(test1txs[0].serialize_with_witness()), True)
65-
test1txs.append(create_transaction(self.nodes[0], txid1, self.ms_address, 48))
65+
test1txs.append(create_transaction(self.nodes[0], txid1, self.ms_address, amount=48))
6666
txid2 = self.nodes[0].sendrawtransaction(bytes_to_hex_str(test1txs[1].serialize_with_witness()), True)
67-
test1txs.append(create_transaction(self.nodes[0], coinbase_txid[1], self.wit_ms_address, 49))
67+
test1txs.append(create_transaction(self.nodes[0], coinbase_txid[1], self.wit_ms_address, amount=49))
6868
txid3 = self.nodes[0].sendrawtransaction(bytes_to_hex_str(test1txs[2].serialize_with_witness()), True)
6969
self.block_submit(self.nodes[0], test1txs, False, True)
7070

7171
self.log.info("Test 2: Non-NULLDUMMY base multisig transaction should not be accepted to mempool before activation")
72-
test2tx = create_transaction(self.nodes[0], txid2, self.ms_address, 47)
72+
test2tx = create_transaction(self.nodes[0], txid2, self.ms_address, amount=47)
7373
trueDummy(test2tx)
7474
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, bytes_to_hex_str(test2tx.serialize_with_witness()), True)
7575

7676
self.log.info("Test 3: Non-NULLDUMMY base transactions should be accepted in a block before activation [431]")
7777
self.block_submit(self.nodes[0], [test2tx], False, True)
7878

7979
self.log.info("Test 4: Non-NULLDUMMY base multisig transaction is invalid after activation")
80-
test4tx = create_transaction(self.nodes[0], test2tx.hash, self.address, 46)
80+
test4tx = create_transaction(self.nodes[0], test2tx.hash, self.address, amount=46)
8181
test6txs=[CTransaction(test4tx)]
8282
trueDummy(test4tx)
8383
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, bytes_to_hex_str(test4tx.serialize_with_witness()), True)
8484
self.block_submit(self.nodes[0], [test4tx])
8585

8686
self.log.info("Test 5: Non-NULLDUMMY P2WSH multisig transaction invalid after activation")
87-
test5tx = create_transaction(self.nodes[0], txid3, self.wit_address, 48)
87+
test5tx = create_transaction(self.nodes[0], txid3, self.wit_address, amount=48)
8888
test6txs.append(CTransaction(test5tx))
8989
test5tx.wit.vtxinwit[0].scriptWitness.stack[0] = b'\x01'
9090
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, bytes_to_hex_str(test5tx.serialize_with_witness()), True)

test/functional/mempool_reorg.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ def run_test(self):
3939
# and make sure the mempool code behaves correctly.
4040
b = [ self.nodes[0].getblockhash(n) for n in range(101, 105) ]
4141
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
42-
spend_101_raw = create_raw_transaction(self.nodes[0], coinbase_txids[1], node1_address, 49.99)
43-
spend_102_raw = create_raw_transaction(self.nodes[0], coinbase_txids[2], node0_address, 49.99)
44-
spend_103_raw = create_raw_transaction(self.nodes[0], coinbase_txids[3], node0_address, 49.99)
42+
spend_101_raw = create_raw_transaction(self.nodes[0], coinbase_txids[1], node1_address, amount=49.99)
43+
spend_102_raw = create_raw_transaction(self.nodes[0], coinbase_txids[2], node0_address, amount=49.99)
44+
spend_103_raw = create_raw_transaction(self.nodes[0], coinbase_txids[3], node0_address, amount=49.99)
4545

4646
# Create a transaction which is time-locked to two blocks in the future
4747
timelock_tx = self.nodes[0].createrawtransaction([{"txid": coinbase_txids[0], "vout": 0}], {node0_address: 49.99})
@@ -57,11 +57,11 @@ def run_test(self):
5757
spend_103_id = self.nodes[0].sendrawtransaction(spend_103_raw)
5858
self.nodes[0].generate(1)
5959
# Time-locked transaction is still too immature to spend
60-
assert_raises_rpc_error(-26,'non-final', self.nodes[0].sendrawtransaction, timelock_tx)
60+
assert_raises_rpc_error(-26, 'non-final', self.nodes[0].sendrawtransaction, timelock_tx)
6161

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

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

test/functional/mempool_resurrect.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ def run_test(self):
2525
# Mine a new block
2626
# ... make sure all the transactions are confirmed again.
2727

28-
b = [ self.nodes[0].getblockhash(n) for n in range(1, 4) ]
29-
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
30-
spends1_raw = [ create_raw_transaction(self.nodes[0], txid, node0_address, 49.99) for txid in coinbase_txids ]
31-
spends1_id = [ self.nodes[0].sendrawtransaction(tx) for tx in spends1_raw ]
28+
b = [self.nodes[0].getblockhash(n) for n in range(1, 4)]
29+
coinbase_txids = [self.nodes[0].getblock(h)['tx'][0] for h in b]
30+
spends1_raw = [create_raw_transaction(self.nodes[0], txid, node0_address, amount=49.99) for txid in coinbase_txids]
31+
spends1_id = [self.nodes[0].sendrawtransaction(tx) for tx in spends1_raw]
3232

3333
blocks = []
3434
blocks.extend(self.nodes[0].generate(1))
3535

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

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

test/functional/mempool_spend_coinbase.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ def run_test(self):
2929
# Coinbase at height chain_height-100+1 ok in mempool, should
3030
# get mined. Coinbase at height chain_height-100+2 is
3131
# is too immature to spend.
32-
b = [ self.nodes[0].getblockhash(n) for n in range(101, 103) ]
33-
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
34-
spends_raw = [ create_raw_transaction(self.nodes[0], txid, node0_address, 49.99) for txid in coinbase_txids ]
32+
b = [self.nodes[0].getblockhash(n) for n in range(101, 103)]
33+
coinbase_txids = [self.nodes[0].getblock(h)['tx'][0] for h in b]
34+
spends_raw = [create_raw_transaction(self.nodes[0], txid, node0_address, amount=49.99) for txid in coinbase_txids]
3535

3636
spend_101_id = self.nodes[0].sendrawtransaction(spends_raw[0])
3737

test/functional/test_framework/blocktools.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def create_coinbase(height, pubkey=None):
118118
coinbase.calc_sha256()
119119
return coinbase
120120

121-
def create_tx_with_script(prevtx, n, script_sig=b"", amount=1, script_pub_key=CScript()):
121+
def create_tx_with_script(prevtx, n, script_sig=b"", *, amount, script_pub_key=CScript()):
122122
"""Return one-input, one-output transaction object
123123
spending the prevtx's n-th output with the given amount.
124124
@@ -131,26 +131,24 @@ def create_tx_with_script(prevtx, n, script_sig=b"", amount=1, script_pub_key=CS
131131
tx.calc_sha256()
132132
return tx
133133

134-
def create_transaction(node, txid, to_address, amount):
134+
def create_transaction(node, txid, to_address, *, amount):
135135
""" Return signed transaction spending the first output of the
136136
input txid. Note that the node must be able to sign for the
137137
output that is being spent, and the node must not be running
138138
multiple wallets.
139139
"""
140-
raw_tx = create_raw_transaction(node, txid, to_address, amount)
140+
raw_tx = create_raw_transaction(node, txid, to_address, amount=amount)
141141
tx = CTransaction()
142142
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx)))
143143
return tx
144144

145-
def create_raw_transaction(node, txid, to_address, amount):
145+
def create_raw_transaction(node, txid, to_address, *, amount):
146146
""" Return raw signed transaction spending the first output of the
147147
input txid. Note that the node must be able to sign for the
148148
output that is being spent, and the node must not be running
149149
multiple wallets.
150150
"""
151-
inputs = [{"txid": txid, "vout": 0}]
152-
outputs = {to_address: amount}
153-
rawtx = node.createrawtransaction(inputs, outputs)
151+
rawtx = node.createrawtransaction(inputs=[{"txid": txid, "vout": 0}], outputs={to_address: amount})
154152
signresult = node.signrawtransactionwithwallet(rawtx)
155153
assert_equal(signresult["complete"], True)
156154
return signresult['hex']

0 commit comments

Comments
 (0)