24
24
from test_framework .messages import CTransaction
25
25
from test_framework .script import CScript
26
26
from test_framework .test_framework import BitcoinTestFramework
27
- from test_framework .util import assert_equal , assert_raises_rpc_error
27
+ from test_framework .util import (
28
+ assert_equal ,
29
+ assert_raises_rpc_error ,
30
+ )
28
31
29
32
NULLDUMMY_ERROR = "non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)"
30
33
@@ -86,36 +89,36 @@ def run_test(self):
86
89
txid2 = self .nodes [0 ].sendrawtransaction (test1txs [1 ].serialize_with_witness ().hex (), 0 )
87
90
test1txs .append (create_transaction (self .nodes [0 ], coinbase_txid [1 ], self .wit_ms_address , amount = 49 ))
88
91
txid3 = self .nodes [0 ].sendrawtransaction (test1txs [2 ].serialize_with_witness ().hex (), 0 )
89
- self .block_submit (self .nodes [0 ], test1txs , False , True )
92
+ self .block_submit (self .nodes [0 ], test1txs , accept = True )
90
93
91
94
self .log .info ("Test 2: Non-NULLDUMMY base multisig transaction should not be accepted to mempool before activation" )
92
95
test2tx = create_transaction (self .nodes [0 ], txid2 , self .ms_address , amount = 47 )
93
96
trueDummy (test2tx )
94
97
assert_raises_rpc_error (- 26 , NULLDUMMY_ERROR , self .nodes [0 ].sendrawtransaction , test2tx .serialize_with_witness ().hex (), 0 )
95
98
96
99
self .log .info (f"Test 3: Non-NULLDUMMY base transactions should be accepted in a block before activation [{ COINBASE_MATURITY + 4 } ]" )
97
- self .block_submit (self .nodes [0 ], [test2tx ], False , True )
100
+ self .block_submit (self .nodes [0 ], [test2tx ], accept = True )
98
101
99
102
self .log .info ("Test 4: Non-NULLDUMMY base multisig transaction is invalid after activation" )
100
103
test4tx = create_transaction (self .nodes [0 ], test2tx .hash , self .address , amount = 46 )
101
104
test6txs = [CTransaction (test4tx )]
102
105
trueDummy (test4tx )
103
106
assert_raises_rpc_error (- 26 , NULLDUMMY_ERROR , self .nodes [0 ].sendrawtransaction , test4tx .serialize_with_witness ().hex (), 0 )
104
- self .block_submit (self .nodes [0 ], [test4tx ])
107
+ self .block_submit (self .nodes [0 ], [test4tx ], accept = False )
105
108
106
109
self .log .info ("Test 5: Non-NULLDUMMY P2WSH multisig transaction invalid after activation" )
107
110
test5tx = create_transaction (self .nodes [0 ], txid3 , self .wit_address , amount = 48 )
108
111
test6txs .append (CTransaction (test5tx ))
109
112
test5tx .wit .vtxinwit [0 ].scriptWitness .stack [0 ] = b'\x01 '
110
113
assert_raises_rpc_error (- 26 , NULLDUMMY_ERROR , self .nodes [0 ].sendrawtransaction , test5tx .serialize_with_witness ().hex (), 0 )
111
- self .block_submit (self .nodes [0 ], [test5tx ], True )
114
+ self .block_submit (self .nodes [0 ], [test5tx ], with_witness = True , accept = False )
112
115
113
116
self .log .info (f"Test 6: NULLDUMMY compliant base/witness transactions should be accepted to mempool and in block after activation [{ COINBASE_MATURITY + 5 } ]" )
114
117
for i in test6txs :
115
118
self .nodes [0 ].sendrawtransaction (i .serialize_with_witness ().hex (), 0 )
116
- self .block_submit (self .nodes [0 ], test6txs , True , True )
119
+ self .block_submit (self .nodes [0 ], test6txs , with_witness = True , accept = True )
117
120
118
- def block_submit (self , node , txs , witness = False , accept = False ):
121
+ def block_submit (self , node , txs , * , with_witness = False , accept ):
119
122
tmpl = node .getblocktemplate (NORMAL_GBT_REQUEST_PARAMS )
120
123
assert_equal (tmpl ['previousblockhash' ], self .lastblockhash )
121
124
assert_equal (tmpl ['height' ], self .lastblockheight + 1 )
@@ -124,11 +127,12 @@ def block_submit(self, node, txs, witness=False, accept=False):
124
127
tx .rehash ()
125
128
block .vtx .append (tx )
126
129
block .hashMerkleRoot = block .calc_merkle_root ()
127
- witness and add_witness_commitment (block )
130
+ if with_witness :
131
+ add_witness_commitment (block )
128
132
block .rehash ()
129
133
block .solve ()
130
134
assert_equal (None if accept else 'block-validation-failed' , node .submitblock (block .serialize ().hex ()))
131
- if ( accept ) :
135
+ if accept :
132
136
assert_equal (node .getbestblockhash (), block .hash )
133
137
self .lastblockhash = block .hash
134
138
self .lastblocktime += 1
0 commit comments