@@ -30,7 +30,7 @@ def set_test_params(self):
30
30
self .num_nodes = 3
31
31
self .extra_args = [
32
32
["-walletrbf=1" ],
33
- ["-walletrbf=0" ],
33
+ ["-walletrbf=0" , "-changetype=legacy" ],
34
34
[]
35
35
]
36
36
self .supports_cli = False
@@ -83,6 +83,14 @@ def test_utxo_conversion(self):
83
83
connect_nodes (self .nodes [0 ], 1 )
84
84
connect_nodes (self .nodes [0 ], 2 )
85
85
86
+ def assert_change_type (self , psbtx , expected_type ):
87
+ """Assert that the given PSBT has a change output with the given type."""
88
+
89
+ # The decodepsbt RPC is stateless and independent of any settings, we can always just call it on the first node
90
+ decoded_psbt = self .nodes [0 ].decodepsbt (psbtx ["psbt" ])
91
+ changepos = psbtx ["changepos" ]
92
+ assert_equal (decoded_psbt ["tx" ]["vout" ][changepos ]["scriptPubKey" ]["type" ], expected_type )
93
+
86
94
def run_test (self ):
87
95
# Create and fund a raw tx for sending 10 BTC
88
96
psbtx1 = self .nodes [0 ].walletcreatefundedpsbt ([], {self .nodes [2 ].getnewaddress ():10 })['psbt' ]
@@ -301,6 +309,17 @@ def run_test(self):
301
309
# when attempting BnB coin selection
302
310
self .nodes [0 ].walletcreatefundedpsbt ([], [{self .nodes [2 ].getnewaddress ():unspent ["amount" ]+ 1 }], block_height + 2 , {"changeAddress" :self .nodes [1 ].getnewaddress ()}, False )
303
311
312
+ # Make sure the wallet's change type is respected by default
313
+ small_output = {self .nodes [0 ].getnewaddress ():0.1 }
314
+ psbtx_native = self .nodes [0 ].walletcreatefundedpsbt ([], [small_output ])
315
+ self .assert_change_type (psbtx_native , "witness_v0_keyhash" )
316
+ psbtx_legacy = self .nodes [1 ].walletcreatefundedpsbt ([], [small_output ])
317
+ self .assert_change_type (psbtx_legacy , "pubkeyhash" )
318
+
319
+ # Make sure the change type of the wallet can also be overwritten
320
+ psbtx_np2wkh = self .nodes [1 ].walletcreatefundedpsbt ([], [small_output ], 0 , {"change_type" :"p2sh-segwit" })
321
+ self .assert_change_type (psbtx_np2wkh , "scripthash" )
322
+
304
323
# Regression test for 14473 (mishandling of already-signed witness transaction):
305
324
psbtx_info = self .nodes [0 ].walletcreatefundedpsbt ([{"txid" :unspent ["txid" ], "vout" :unspent ["vout" ]}], [{self .nodes [2 ].getnewaddress ():unspent ["amount" ]+ 1 }], 0 , {"add_inputs" : True })
306
325
complete_psbt = self .nodes [0 ].walletprocesspsbt (psbtx_info ["psbt" ])
0 commit comments