2020 create_transaction ,
2121)
2222from test_framework .messages import CTransaction
23- from test_framework .script import CScript
23+ from test_framework .script import (
24+ OP_0 ,
25+ OP_TRUE ,
26+ )
2427from test_framework .test_framework import BitcoinTestFramework
2528from test_framework .util import (
2629 assert_equal ,
2932
3033NULLDUMMY_ERROR = "non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)"
3134
32- def trueDummy (tx ):
33- scriptSig = CScript (tx .vin [0 ].scriptSig )
34- newscript = []
35- for i in scriptSig :
36- if len (newscript ) == 0 :
37- assert len (i ) == 0
38- newscript .append (b'\x51 ' )
39- else :
40- newscript .append (i )
41- tx .vin [0 ].scriptSig = CScript (newscript )
35+
36+ def invalidate_nulldummy_tx (tx ):
37+ """Transform a NULLDUMMY compliant tx (i.e. scriptSig starts with OP_0)
38+ to be non-NULLDUMMY compliant by replacing the dummy with OP_TRUE"""
39+ assert_equal (tx .vin [0 ].scriptSig [0 ], OP_0 )
40+ tx .vin [0 ].scriptSig = bytes ([OP_TRUE ]) + tx .vin [0 ].scriptSig [1 :]
4241 tx .rehash ()
4342
4443class NULLDUMMYTest (BitcoinTestFramework ):
@@ -86,7 +85,7 @@ def run_test(self):
8685
8786 self .log .info ("Test 2: Non-NULLDUMMY base multisig transaction should not be accepted to mempool before activation" )
8887 test2tx = create_transaction (self .nodes [0 ], txid2 , self .ms_address , amount = 47 )
89- trueDummy (test2tx )
88+ invalidate_nulldummy_tx (test2tx )
9089 assert_raises_rpc_error (- 26 , NULLDUMMY_ERROR , self .nodes [0 ].sendrawtransaction , test2tx .serialize ().hex (), 0 )
9190
9291 self .log .info (f"Test 3: Non-NULLDUMMY base transactions should be accepted in a block before activation [{ COINBASE_MATURITY + 4 } ]" )
@@ -95,7 +94,7 @@ def run_test(self):
9594 self .log .info ("Test 4: Non-NULLDUMMY base multisig transaction is invalid after activation" )
9695 test4tx = create_transaction (self .nodes [0 ], test2tx .hash , self .address , amount = 46 )
9796 test6txs = [CTransaction (test4tx )]
98- trueDummy (test4tx )
97+ invalidate_nulldummy_tx (test4tx )
9998 assert_raises_rpc_error (- 26 , NULLDUMMY_ERROR , self .nodes [0 ].sendrawtransaction , test4tx .serialize ().hex (), 0 )
10099 self .block_submit (self .nodes [0 ], [test4tx ], accept = False )
101100
@@ -110,12 +109,7 @@ def block_submit(self, node, txs, *, accept=False):
110109 tmpl = node .getblocktemplate (NORMAL_GBT_REQUEST_PARAMS )
111110 assert_equal (tmpl ['previousblockhash' ], self .lastblockhash )
112111 assert_equal (tmpl ['height' ], self .lastblockheight + 1 )
113- block = create_block (tmpl = tmpl , ntime = self .lastblocktime + 1 , dip4_activated = dip4_activated )
114- for tx in txs :
115- tx .rehash ()
116- block .vtx .append (tx )
117- block .hashMerkleRoot = block .calc_merkle_root ()
118- block .rehash ()
112+ block = create_block (tmpl = tmpl , ntime = self .lastblocktime + 1 , txlist = txs , dip4_activated = dip4_activated )
119113 block .solve ()
120114 assert_equal (None if accept else NULLDUMMY_ERROR , node .submitblock (block .serialize ().hex ()))
121115 if accept :
0 commit comments