test: add test for modififed walletprocesspsbt calls

This test checks that we can successfully process PSBTs and opt out of
finalization.

Previously trying to call `walletprocesspsbt` would attempt to
auto-finalize (as a convenience), and would not permit opt-out of
finalization, instead aborting via `CHECK_NONFATAL`.

Github-Pull: #30357
Rebased-From: 7e36dca657
This commit is contained in:
willcl-ark 2024-06-28 12:45:47 +01:00 committed by fanquake
parent f22b9ca70c
commit 54bb9b0541
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -69,6 +69,28 @@ class PSBTTest(BitcoinTestFramework):
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def test_psbt_incomplete_after_invalid_modification(self):
self.log.info("Check that PSBT is correctly marked as incomplete after invalid modification")
node = self.nodes[2]
wallet = node.get_wallet_rpc(self.default_wallet_name)
address = wallet.getnewaddress()
wallet.sendtoaddress(address=address, amount=1.0)
self.generate(node, nblocks=1, sync_fun=lambda: self.sync_all(self.nodes[:2]))
utxos = wallet.listunspent(addresses=[address])
psbt = wallet.createpsbt([{"txid": utxos[0]["txid"], "vout": utxos[0]["vout"]}], [{wallet.getnewaddress(): 0.9999}])
signed_psbt = wallet.walletprocesspsbt(psbt)["psbt"]
# Modify the raw transaction by changing the output address, so the signature is no longer valid
signed_psbt_obj = PSBT.from_base64(signed_psbt)
substitute_addr = wallet.getnewaddress()
raw = wallet.createrawtransaction([{"txid": utxos[0]["txid"], "vout": utxos[0]["vout"]}], [{substitute_addr: 0.9999}])
signed_psbt_obj.g.map[PSBT_GLOBAL_UNSIGNED_TX] = bytes.fromhex(raw)
# Check that the walletprocesspsbt call succeeds but also recognizes that the transaction is not complete
signed_psbt_incomplete = wallet.walletprocesspsbt(signed_psbt_obj.to_base64(), finalize=False)
assert signed_psbt_incomplete["complete"] is False
def test_utxo_conversion(self):
self.log.info("Check that non-witness UTXOs are removed for segwit v1+ inputs")
mining_node = self.nodes[2]
@ -590,6 +612,7 @@ class PSBTTest(BitcoinTestFramework):
if self.options.descriptors:
self.test_utxo_conversion()
self.test_psbt_incomplete_after_invalid_modification()
self.test_input_confs_control()