@@ -47,7 +47,40 @@ def setup_network(self):
47
47
self .connect_nodes (0 , 2 )
48
48
self .connect_nodes (0 , 3 )
49
49
50
+ def lock_outputs_type (self , wallet , outputtype ):
51
+ """
52
+ Only allow UTXOs of the given type
53
+ """
54
+ if outputtype in ["legacy" , "p2pkh" , "pkh" ]:
55
+ prefixes = ["pkh(" , "sh(multi(" ]
56
+ elif outputtype in ["p2sh-segwit" , "sh_wpkh" ]:
57
+ prefixes = ["sh(wpkh(" , "sh(wsh(" ]
58
+ elif outputtype in ["bech32" , "wpkh" ]:
59
+ prefixes = ["wpkh(" , "wsh(" ]
60
+ else :
61
+ assert False , f"Unknown output type { outputtype } "
62
+
63
+ to_lock = []
64
+ for utxo in wallet .listunspent ():
65
+ if "desc" in utxo :
66
+ for prefix in prefixes :
67
+ if utxo ["desc" ].startswith (prefix ):
68
+ to_lock .append ({"txid" : utxo ["txid" ], "vout" : utxo ["vout" ]})
69
+ wallet .lockunspent (False , to_lock )
70
+
71
+ def unlock_utxos (self , wallet ):
72
+ """
73
+ Unlock all UTXOs except the watchonly one
74
+ """
75
+ to_keep = []
76
+ if self .watchonly_txid is not None and self .watchonly_vout is not None :
77
+ to_keep .append ({"txid" : self .watchonly_txid , "vout" : self .watchonly_vout })
78
+ wallet .lockunspent (True )
79
+ wallet .lockunspent (False , to_keep )
80
+
50
81
def run_test (self ):
82
+ self .watchonly_txid = None
83
+ self .watchonly_vout = None
51
84
self .log .info ("Connect nodes, set fees, generate blocks, and sync" )
52
85
self .min_relay_tx_fee = self .nodes [0 ].getnetworkinfo ()['relayfee' ]
53
86
# This test is not meant to test fee estimation and we'd like
@@ -373,6 +406,7 @@ def test_invalid_input(self):
373
406
def test_fee_p2pkh (self ):
374
407
"""Compare fee of a standard pubkeyhash transaction."""
375
408
self .log .info ("Test fundrawtxn p2pkh fee" )
409
+ self .lock_outputs_type (self .nodes [0 ], "p2pkh" )
376
410
inputs = []
377
411
outputs = {self .nodes [1 ].getnewaddress ():1.1 }
378
412
rawtx = self .nodes [0 ].createrawtransaction (inputs , outputs )
@@ -386,9 +420,12 @@ def test_fee_p2pkh(self):
386
420
feeDelta = Decimal (fundedTx ['fee' ]) - Decimal (signedFee )
387
421
assert feeDelta >= 0 and feeDelta <= self .fee_tolerance
388
422
423
+ self .unlock_utxos (self .nodes [0 ])
424
+
389
425
def test_fee_p2pkh_multi_out (self ):
390
426
"""Compare fee of a standard pubkeyhash transaction with multiple outputs."""
391
427
self .log .info ("Test fundrawtxn p2pkh fee with multiple outputs" )
428
+ self .lock_outputs_type (self .nodes [0 ], "p2pkh" )
392
429
inputs = []
393
430
outputs = {
394
431
self .nodes [1 ].getnewaddress ():1.1 ,
@@ -409,8 +446,11 @@ def test_fee_p2pkh_multi_out(self):
409
446
feeDelta = Decimal (fundedTx ['fee' ]) - Decimal (signedFee )
410
447
assert feeDelta >= 0 and feeDelta <= self .fee_tolerance
411
448
449
+ self .unlock_utxos (self .nodes [0 ])
450
+
412
451
def test_fee_p2sh (self ):
413
452
"""Compare fee of a 2-of-2 multisig p2sh transaction."""
453
+ self .lock_outputs_type (self .nodes [0 ], "p2pkh" )
414
454
# Create 2-of-2 addr.
415
455
addr1 = self .nodes [1 ].getnewaddress ()
416
456
addr2 = self .nodes [1 ].getnewaddress ()
@@ -433,9 +473,12 @@ def test_fee_p2sh(self):
433
473
feeDelta = Decimal (fundedTx ['fee' ]) - Decimal (signedFee )
434
474
assert feeDelta >= 0 and feeDelta <= self .fee_tolerance
435
475
476
+ self .unlock_utxos (self .nodes [0 ])
477
+
436
478
def test_fee_4of5 (self ):
437
479
"""Compare fee of a standard pubkeyhash transaction."""
438
480
self .log .info ("Test fundrawtxn fee with 4-of-5 addresses" )
481
+ self .lock_outputs_type (self .nodes [0 ], "p2pkh" )
439
482
440
483
# Create 4-of-5 addr.
441
484
addr1 = self .nodes [1 ].getnewaddress ()
@@ -474,6 +517,8 @@ def test_fee_4of5(self):
474
517
feeDelta = Decimal (fundedTx ['fee' ]) - Decimal (signedFee )
475
518
assert feeDelta >= 0 and feeDelta <= self .fee_tolerance
476
519
520
+ self .unlock_utxos (self .nodes [0 ])
521
+
477
522
def test_spend_2of2 (self ):
478
523
"""Spend a 2-of-2 multisig transaction over fundraw."""
479
524
self .log .info ("Test fundpsbt spending 2-of-2 multisig" )
0 commit comments