55
55
P2WPKH = 0
56
56
P2WSH = 1
57
57
58
+
58
59
def getutxo (txid ):
59
60
utxo = {}
60
61
utxo ["vout" ] = 0
61
62
utxo ["txid" ] = txid
62
63
return utxo
63
64
65
+
64
66
def find_spendable_utxo (node , min_value ):
65
67
for utxo in node .listunspent (query_options = {'minimumAmount' : min_value }):
66
68
if utxo ['spendable' ]:
67
69
return utxo
68
70
69
71
raise AssertionError (f"Unspent output equal or higher than { min_value } not found" )
70
72
71
- txs_mined = {} # txindex from txid to blockhash
73
+
74
+ txs_mined = {} # txindex from txid to blockhash
75
+
72
76
73
77
class SegWitTest (BitcoinTestFramework ):
74
78
def set_test_params (self ):
@@ -135,8 +139,8 @@ def run_test(self):
135
139
136
140
balance_presetup = self .nodes [0 ].getbalance ()
137
141
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
140
144
for i in range (3 ):
141
145
newaddress = self .nodes [i ].getnewaddress ()
142
146
self .pubkey .append (self .nodes [i ].getaddressinfo (newaddress )["pubkey" ])
@@ -216,7 +220,7 @@ def run_test(self):
216
220
witnesses = coinbase_tx ["decoded" ]["vin" ][0 ]["txinwitness" ]
217
221
assert_equal (len (witnesses ), 1 )
218
222
assert_is_hex_string (witnesses [0 ])
219
- assert_equal (witnesses [0 ], '00' * 32 )
223
+ assert_equal (witnesses [0 ], '00' * 32 )
220
224
221
225
self .log .info ("Verify witness txs without witness data are invalid after the fork" )
222
226
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):
357
361
358
362
for i in compressed_spendable_address :
359
363
v = self .nodes [0 ].getaddressinfo (i )
360
- if ( v ['isscript' ]) :
364
+ if v ['isscript' ]:
361
365
[bare , p2sh , p2wsh , p2sh_p2wsh ] = self .p2sh_address_to_script (v )
362
366
# p2sh multisig with compressed keys should always be spendable
363
367
spendable_anytime .extend ([p2sh ])
@@ -376,7 +380,7 @@ def run_test(self):
376
380
377
381
for i in uncompressed_spendable_address :
378
382
v = self .nodes [0 ].getaddressinfo (i )
379
- if ( v ['isscript' ]) :
383
+ if v ['isscript' ]:
380
384
[bare , p2sh , p2wsh , p2sh_p2wsh ] = self .p2sh_address_to_script (v )
381
385
# p2sh multisig with uncompressed keys should always be spendable
382
386
spendable_anytime .extend ([p2sh ])
@@ -395,7 +399,7 @@ def run_test(self):
395
399
396
400
for i in compressed_solvable_address :
397
401
v = self .nodes [0 ].getaddressinfo (i )
398
- if ( v ['isscript' ]) :
402
+ if v ['isscript' ]:
399
403
# Multisig without private is not seen after addmultisigaddress, but seen after importaddress
400
404
[bare , p2sh , p2wsh , p2sh_p2wsh ] = self .p2sh_address_to_script (v )
401
405
solvable_after_importaddress .extend ([bare , p2sh , p2wsh , p2sh_p2wsh ])
@@ -408,7 +412,7 @@ def run_test(self):
408
412
409
413
for i in uncompressed_solvable_address :
410
414
v = self .nodes [0 ].getaddressinfo (i )
411
- if ( v ['isscript' ]) :
415
+ if v ['isscript' ]:
412
416
[bare , p2sh , p2wsh , p2sh_p2wsh ] = self .p2sh_address_to_script (v )
413
417
# Base uncompressed multisig without private is not seen after addmultisigaddress, but seen after importaddress
414
418
solvable_after_importaddress .extend ([bare , p2sh ])
@@ -447,7 +451,7 @@ def run_test(self):
447
451
importlist = []
448
452
for i in compressed_spendable_address + uncompressed_spendable_address + compressed_solvable_address + uncompressed_solvable_address :
449
453
v = self .nodes [0 ].getaddressinfo (i )
450
- if ( v ['isscript' ]) :
454
+ if v ['isscript' ]:
451
455
bare = bytes .fromhex (v ['hex' ])
452
456
importlist .append (bare .hex ())
453
457
importlist .append (script_to_p2wsh_script (bare ).hex ())
@@ -510,7 +514,7 @@ def run_test(self):
510
514
511
515
for i in compressed_spendable_address :
512
516
v = self .nodes [0 ].getaddressinfo (i )
513
- if ( v ['isscript' ]) :
517
+ if v ['isscript' ]:
514
518
[bare , p2sh , p2wsh , p2sh_p2wsh ] = self .p2sh_address_to_script (v )
515
519
premature_witaddress .append (script_to_p2sh (p2wsh ))
516
520
else :
@@ -520,7 +524,7 @@ def run_test(self):
520
524
521
525
for i in uncompressed_spendable_address + uncompressed_solvable_address :
522
526
v = self .nodes [0 ].getaddressinfo (i )
523
- if ( v ['isscript' ]) :
527
+ if v ['isscript' ]:
524
528
[bare , p2sh , p2wsh , p2sh_p2wsh ] = self .p2sh_address_to_script (v )
525
529
# P2WSH and P2SH(P2WSH) multisig with uncompressed keys are never seen
526
530
unseen_anytime .extend ([p2wsh , p2sh_p2wsh ])
@@ -531,7 +535,7 @@ def run_test(self):
531
535
532
536
for i in compressed_solvable_address :
533
537
v = self .nodes [0 ].getaddressinfo (i )
534
- if ( v ['isscript' ]) :
538
+ if v ['isscript' ]:
535
539
[bare , p2sh , p2wsh , p2sh_p2wsh ] = self .p2sh_address_to_script (v )
536
540
premature_witaddress .append (script_to_p2sh (p2wsh ))
537
541
else :
@@ -598,13 +602,13 @@ def mine_and_test_listunspent(self, script_list, ismine):
598
602
watchcount = 0
599
603
spendcount = 0
600
604
for i in self .nodes [0 ].listunspent ():
601
- if ( i ['txid' ] == txid ) :
605
+ if i ['txid' ] == txid :
602
606
watchcount += 1
603
607
if i ['spendable' ]:
604
608
spendcount += 1
605
- if ( ismine == 2 ) :
609
+ if ismine == 2 :
606
610
assert_equal (spendcount , len (script_list ))
607
- elif ( ismine == 1 ) :
611
+ elif ismine == 1 :
608
612
assert_equal (watchcount , len (script_list ))
609
613
assert_equal (spendcount , 0 )
610
614
else :
@@ -616,7 +620,7 @@ def p2sh_address_to_script(self, v):
616
620
p2sh = CScript (bytes .fromhex (v ['scriptPubKey' ]))
617
621
p2wsh = script_to_p2wsh_script (bare )
618
622
p2sh_p2wsh = script_to_p2sh_script (p2wsh )
619
- return ( [bare , p2sh , p2wsh , p2sh_p2wsh ])
623
+ return [bare , p2sh , p2wsh , p2sh_p2wsh ]
620
624
621
625
def p2pkh_address_to_script (self , v ):
622
626
pubkey = bytes .fromhex (v ['pubkey' ])
0 commit comments