@@ -301,6 +301,53 @@ def test_sighash_mismatch(self):
301
301
302
302
wallet .unloadwallet ()
303
303
304
+ def test_sighash_adding (self ):
305
+ self .log .info ("Test adding of sighash type field" )
306
+ self .nodes [0 ].createwallet ("sighash_adding" )
307
+ wallet = self .nodes [0 ].get_wallet_rpc ("sighash_adding" )
308
+ def_wallet = self .nodes [0 ].get_wallet_rpc (self .default_wallet_name )
309
+
310
+ outputs = [{wallet .getnewaddress (address_type = "bech32" ): 1 }]
311
+ outputs .append ({wallet .getnewaddress (address_type = "bech32m" ): 1 })
312
+ descs = wallet .listdescriptors (True )["descriptors" ]
313
+ def_wallet .send (outputs )
314
+ self .generate (self .nodes [0 ], 6 )
315
+ utxos = wallet .listunspent ()
316
+
317
+ # Make a PSBT
318
+ psbt = wallet .walletcreatefundedpsbt (utxos , [{def_wallet .getnewaddress (): 0.5 }])["psbt" ]
319
+
320
+ # Process the PSBT with the wallet
321
+ wallet_psbt = wallet .walletprocesspsbt (psbt = psbt , sighashtype = "ALL|ANYONECANPAY" , finalize = False )["psbt" ]
322
+
323
+ # Separately process the PSBT with descriptors
324
+ desc_psbt = self .nodes [0 ].descriptorprocesspsbt (psbt = psbt , descriptors = descs , sighashtype = "ALL|ANYONECANPAY" , finalize = False )["psbt" ]
325
+
326
+ for psbt in [wallet_psbt , desc_psbt ]:
327
+ # Check that the PSBT has a sighash field on all inputs
328
+ dec_psbt = self .nodes [0 ].decodepsbt (psbt )
329
+ for input in dec_psbt ["inputs" ]:
330
+ assert_equal (input ["sighash" ], "ALL|ANYONECANPAY" )
331
+
332
+ # Make sure we can still finalize the transaction
333
+ fin_res = self .nodes [0 ].finalizepsbt (psbt )
334
+ assert_equal (fin_res ["complete" ], True )
335
+ fin_hex = fin_res ["hex" ]
336
+ assert_equal (self .nodes [0 ].testmempoolaccept ([fin_hex ])[0 ]["allowed" ], True )
337
+
338
+ # Change the sighash field to a different value and make sure we can no longer finalize
339
+ mod_psbt = PSBT .from_base64 (psbt )
340
+ mod_psbt .i [0 ].map [PSBT_IN_SIGHASH_TYPE ] = (SIGHASH_ALL ).to_bytes (4 , byteorder = "little" )
341
+ mod_psbt .i [1 ].map [PSBT_IN_SIGHASH_TYPE ] = (SIGHASH_ALL ).to_bytes (4 , byteorder = "little" )
342
+ psbt = mod_psbt .to_base64 ()
343
+ fin_res = self .nodes [0 ].finalizepsbt (psbt )
344
+ assert_equal (fin_res ["complete" ], False )
345
+
346
+ self .nodes [0 ].sendrawtransaction (fin_hex )
347
+ self .generate (self .nodes [0 ], 1 )
348
+
349
+ wallet .unloadwallet ()
350
+
304
351
def assert_change_type (self , psbtx , expected_type ):
305
352
"""Assert that the given PSBT has a change output with the given type."""
306
353
@@ -1139,6 +1186,7 @@ def test_psbt_input_keys(psbt_input, keys):
1139
1186
assert_raises_rpc_error (- 8 , "'all' is not a valid sighash parameter." , self .nodes [2 ].descriptorprocesspsbt , psbt , [descriptor ], sighashtype = "all" )
1140
1187
1141
1188
self .test_sighash_mismatch ()
1189
+ self .test_sighash_adding ()
1142
1190
1143
1191
if __name__ == '__main__' :
1144
1192
PSBTTest (__file__ ).main ()
0 commit comments