Skip to content

Commit d94dc69

Browse files
committed
Merge bitcoin/bitcoin#23501: test: various feature_nulldummy.py improvements
f1ed304 test: refactor: simplify `block_submit` in feature_nulldummy.py (Sebastian Falbesoner) 5ba9f1f test: refactor: rename NULLDUMMY-invalidation helper (Sebastian Falbesoner) e1d4a12 test: simplify and document NULLDUMMY-invalidation helper (Sebastian Falbesoner) Pull request description: This PR improves the functional test `feature_nulldummy.py` by simplifying the helpers `trueDummy` (renamed to `invalidate_nulldummy_tx`) and `block_submit`. Details can be found in the commit messages. ACKs for top commit: laanwj: Code review ACK f1ed304 Tree-SHA512: ad227b31936f53c5dbded823643bced296d86f40b90f2c144a9857db3d00544f9ad5bbce4c7e84b6ece25e78e95c19aafb1d8fb31e610dcd5cbf3da63190de85
2 parents 398fd63 + f1ed304 commit d94dc69

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

test/functional/feature_nulldummy.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
create_transaction,
2323
)
2424
from test_framework.messages import CTransaction
25-
from test_framework.script import CScript
25+
from test_framework.script import (
26+
OP_0,
27+
OP_TRUE,
28+
)
2629
from test_framework.test_framework import BitcoinTestFramework
2730
from test_framework.util import (
2831
assert_equal,
@@ -32,16 +35,11 @@
3235
NULLDUMMY_ERROR = "non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)"
3336

3437

35-
def trueDummy(tx):
36-
scriptSig = CScript(tx.vin[0].scriptSig)
37-
newscript = []
38-
for i in scriptSig:
39-
if len(newscript) == 0:
40-
assert len(i) == 0
41-
newscript.append(b'\x51')
42-
else:
43-
newscript.append(i)
44-
tx.vin[0].scriptSig = CScript(newscript)
38+
def invalidate_nulldummy_tx(tx):
39+
"""Transform a NULLDUMMY compliant tx (i.e. scriptSig starts with OP_0)
40+
to be non-NULLDUMMY compliant by replacing the dummy with OP_TRUE"""
41+
assert_equal(tx.vin[0].scriptSig[0], OP_0)
42+
tx.vin[0].scriptSig = bytes([OP_TRUE]) + tx.vin[0].scriptSig[1:]
4543
tx.rehash()
4644

4745

@@ -94,7 +92,7 @@ def run_test(self):
9492

9593
self.log.info("Test 2: Non-NULLDUMMY base multisig transaction should not be accepted to mempool before activation")
9694
test2tx = create_transaction(self.nodes[0], txid2, self.ms_address, amount=47)
97-
trueDummy(test2tx)
95+
invalidate_nulldummy_tx(test2tx)
9896
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, test2tx.serialize_with_witness().hex(), 0)
9997

10098
self.log.info(f"Test 3: Non-NULLDUMMY base transactions should be accepted in a block before activation [{COINBASE_MATURITY + 4}]")
@@ -103,7 +101,7 @@ def run_test(self):
103101
self.log.info("Test 4: Non-NULLDUMMY base multisig transaction is invalid after activation")
104102
test4tx = create_transaction(self.nodes[0], test2tx.hash, self.address, amount=46)
105103
test6txs = [CTransaction(test4tx)]
106-
trueDummy(test4tx)
104+
invalidate_nulldummy_tx(test4tx)
107105
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, test4tx.serialize_with_witness().hex(), 0)
108106
self.block_submit(self.nodes[0], [test4tx], accept=False)
109107

@@ -123,11 +121,7 @@ def block_submit(self, node, txs, *, with_witness=False, accept):
123121
tmpl = node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
124122
assert_equal(tmpl['previousblockhash'], self.lastblockhash)
125123
assert_equal(tmpl['height'], self.lastblockheight + 1)
126-
block = create_block(tmpl=tmpl, ntime=self.lastblocktime + 1)
127-
for tx in txs:
128-
tx.rehash()
129-
block.vtx.append(tx)
130-
block.hashMerkleRoot = block.calc_merkle_root()
124+
block = create_block(tmpl=tmpl, ntime=self.lastblocktime + 1, txlist=txs)
131125
if with_witness:
132126
add_witness_commitment(block)
133127
block.solve()

0 commit comments

Comments
 (0)