5555P2WPKH = 0
5656P2WSH = 1
5757
58+
5859def getutxo (txid ):
5960 utxo = {}
6061 utxo ["vout" ] = 0
6162 utxo ["txid" ] = txid
6263 return utxo
6364
65+
6466def find_spendable_utxo (node , min_value ):
6567 for utxo in node .listunspent (query_options = {'minimumAmount' : min_value }):
6668 if utxo ['spendable' ]:
6769 return utxo
6870
6971 raise AssertionError (f"Unspent output equal or higher than { min_value } not found" )
7072
71- txs_mined = {} # txindex from txid to blockhash
73+
74+ txs_mined = {} # txindex from txid to blockhash
75+
7276
7377class SegWitTest (BitcoinTestFramework ):
7478 def set_test_params (self ):
@@ -135,8 +139,8 @@ def run_test(self):
135139
136140 balance_presetup = self .nodes [0 ].getbalance ()
137141 self .pubkey = []
138- p2sh_ids = [] # p2sh_ids[NODE][TYPE] is an array of txids that spend to P2WPKH (TYPE=0) or P2WSH (TYPE=1) scripts to an address for NODE embedded in p2sh
139- wit_ids = [] # wit_ids[NODE][TYPE] is an array of txids that spend to P2WPKH (TYPE=0) or P2WSH (TYPE=1) scripts to an address for NODE via bare witness
142+ p2sh_ids = [] # p2sh_ids[NODE][TYPE] is an array of txids that spend to P2WPKH (TYPE=0) or P2WSH (TYPE=1) scripts to an address for NODE embedded in p2sh
143+ wit_ids = [] # wit_ids[NODE][TYPE] is an array of txids that spend to P2WPKH (TYPE=0) or P2WSH (TYPE=1) scripts to an address for NODE via bare witness
140144 for i in range (3 ):
141145 newaddress = self .nodes [i ].getnewaddress ()
142146 self .pubkey .append (self .nodes [i ].getaddressinfo (newaddress )["pubkey" ])
@@ -216,7 +220,7 @@ def run_test(self):
216220 witnesses = coinbase_tx ["decoded" ]["vin" ][0 ]["txinwitness" ]
217221 assert_equal (len (witnesses ), 1 )
218222 assert_is_hex_string (witnesses [0 ])
219- assert_equal (witnesses [0 ], '00' * 32 )
223+ assert_equal (witnesses [0 ], '00' * 32 )
220224
221225 self .log .info ("Verify witness txs without witness data are invalid after the fork" )
222226 self .fail_accept (self .nodes [2 ], 'non-mandatory-script-verify-flag (Witness program hash mismatch)' , wit_ids [NODE_2 ][P2WPKH ][2 ], sign = False )
@@ -357,7 +361,7 @@ def run_test(self):
357361
358362 for i in compressed_spendable_address :
359363 v = self .nodes [0 ].getaddressinfo (i )
360- if ( v ['isscript' ]) :
364+ if v ['isscript' ]:
361365 [bare , p2sh , p2wsh , p2sh_p2wsh ] = self .p2sh_address_to_script (v )
362366 # p2sh multisig with compressed keys should always be spendable
363367 spendable_anytime .extend ([p2sh ])
@@ -376,7 +380,7 @@ def run_test(self):
376380
377381 for i in uncompressed_spendable_address :
378382 v = self .nodes [0 ].getaddressinfo (i )
379- if ( v ['isscript' ]) :
383+ if v ['isscript' ]:
380384 [bare , p2sh , p2wsh , p2sh_p2wsh ] = self .p2sh_address_to_script (v )
381385 # p2sh multisig with uncompressed keys should always be spendable
382386 spendable_anytime .extend ([p2sh ])
@@ -395,7 +399,7 @@ def run_test(self):
395399
396400 for i in compressed_solvable_address :
397401 v = self .nodes [0 ].getaddressinfo (i )
398- if ( v ['isscript' ]) :
402+ if v ['isscript' ]:
399403 # Multisig without private is not seen after addmultisigaddress, but seen after importaddress
400404 [bare , p2sh , p2wsh , p2sh_p2wsh ] = self .p2sh_address_to_script (v )
401405 solvable_after_importaddress .extend ([bare , p2sh , p2wsh , p2sh_p2wsh ])
@@ -408,7 +412,7 @@ def run_test(self):
408412
409413 for i in uncompressed_solvable_address :
410414 v = self .nodes [0 ].getaddressinfo (i )
411- if ( v ['isscript' ]) :
415+ if v ['isscript' ]:
412416 [bare , p2sh , p2wsh , p2sh_p2wsh ] = self .p2sh_address_to_script (v )
413417 # Base uncompressed multisig without private is not seen after addmultisigaddress, but seen after importaddress
414418 solvable_after_importaddress .extend ([bare , p2sh ])
@@ -447,7 +451,7 @@ def run_test(self):
447451 importlist = []
448452 for i in compressed_spendable_address + uncompressed_spendable_address + compressed_solvable_address + uncompressed_solvable_address :
449453 v = self .nodes [0 ].getaddressinfo (i )
450- if ( v ['isscript' ]) :
454+ if v ['isscript' ]:
451455 bare = bytes .fromhex (v ['hex' ])
452456 importlist .append (bare .hex ())
453457 importlist .append (script_to_p2wsh_script (bare ).hex ())
@@ -510,7 +514,7 @@ def run_test(self):
510514
511515 for i in compressed_spendable_address :
512516 v = self .nodes [0 ].getaddressinfo (i )
513- if ( v ['isscript' ]) :
517+ if v ['isscript' ]:
514518 [bare , p2sh , p2wsh , p2sh_p2wsh ] = self .p2sh_address_to_script (v )
515519 premature_witaddress .append (script_to_p2sh (p2wsh ))
516520 else :
@@ -520,7 +524,7 @@ def run_test(self):
520524
521525 for i in uncompressed_spendable_address + uncompressed_solvable_address :
522526 v = self .nodes [0 ].getaddressinfo (i )
523- if ( v ['isscript' ]) :
527+ if v ['isscript' ]:
524528 [bare , p2sh , p2wsh , p2sh_p2wsh ] = self .p2sh_address_to_script (v )
525529 # P2WSH and P2SH(P2WSH) multisig with uncompressed keys are never seen
526530 unseen_anytime .extend ([p2wsh , p2sh_p2wsh ])
@@ -531,7 +535,7 @@ def run_test(self):
531535
532536 for i in compressed_solvable_address :
533537 v = self .nodes [0 ].getaddressinfo (i )
534- if ( v ['isscript' ]) :
538+ if v ['isscript' ]:
535539 [bare , p2sh , p2wsh , p2sh_p2wsh ] = self .p2sh_address_to_script (v )
536540 premature_witaddress .append (script_to_p2sh (p2wsh ))
537541 else :
@@ -598,13 +602,13 @@ def mine_and_test_listunspent(self, script_list, ismine):
598602 watchcount = 0
599603 spendcount = 0
600604 for i in self .nodes [0 ].listunspent ():
601- if ( i ['txid' ] == txid ) :
605+ if i ['txid' ] == txid :
602606 watchcount += 1
603607 if i ['spendable' ]:
604608 spendcount += 1
605- if ( ismine == 2 ) :
609+ if ismine == 2 :
606610 assert_equal (spendcount , len (script_list ))
607- elif ( ismine == 1 ) :
611+ elif ismine == 1 :
608612 assert_equal (watchcount , len (script_list ))
609613 assert_equal (spendcount , 0 )
610614 else :
@@ -616,7 +620,7 @@ def p2sh_address_to_script(self, v):
616620 p2sh = CScript (bytes .fromhex (v ['scriptPubKey' ]))
617621 p2wsh = script_to_p2wsh_script (bare )
618622 p2sh_p2wsh = script_to_p2sh_script (p2wsh )
619- return ( [bare , p2sh , p2wsh , p2sh_p2wsh ])
623+ return [bare , p2sh , p2wsh , p2sh_p2wsh ]
620624
621625 def p2pkh_address_to_script (self , v ):
622626 pubkey = bytes .fromhex (v ['pubkey' ])
0 commit comments