Skip to content

Commit 7e36dca

Browse files
committed
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`.
1 parent 39cea21 commit 7e36dca

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/functional/rpc_psbt.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@ def set_test_params(self):
6868
def skip_test_if_missing_module(self):
6969
self.skip_if_no_wallet()
7070

71+
def test_psbt_incomplete_after_invalid_modification(self):
72+
self.log.info("Check that PSBT is correctly marked as incomplete after invalid modification")
73+
node = self.nodes[2]
74+
wallet = node.get_wallet_rpc(self.default_wallet_name)
75+
address = wallet.getnewaddress()
76+
wallet.sendtoaddress(address=address, amount=1.0)
77+
self.generate(node, nblocks=1, sync_fun=lambda: self.sync_all(self.nodes[:2]))
78+
79+
utxos = wallet.listunspent(addresses=[address])
80+
psbt = wallet.createpsbt([{"txid": utxos[0]["txid"], "vout": utxos[0]["vout"]}], [{wallet.getnewaddress(): 0.9999}])
81+
signed_psbt = wallet.walletprocesspsbt(psbt)["psbt"]
82+
83+
# Modify the raw transaction by changing the output address, so the signature is no longer valid
84+
signed_psbt_obj = PSBT.from_base64(signed_psbt)
85+
substitute_addr = wallet.getnewaddress()
86+
raw = wallet.createrawtransaction([{"txid": utxos[0]["txid"], "vout": utxos[0]["vout"]}], [{substitute_addr: 0.9999}])
87+
signed_psbt_obj.g.map[PSBT_GLOBAL_UNSIGNED_TX] = bytes.fromhex(raw)
88+
89+
# Check that the walletprocesspsbt call succeeds but also recognizes that the transaction is not complete
90+
signed_psbt_incomplete = wallet.walletprocesspsbt(signed_psbt_obj.to_base64(), finalize=False)
91+
assert signed_psbt_incomplete["complete"] is False
92+
7193
def test_utxo_conversion(self):
7294
self.log.info("Check that non-witness UTXOs are removed for segwit v1+ inputs")
7395
mining_node = self.nodes[2]
@@ -589,6 +611,7 @@ def run_test(self):
589611

590612
if self.options.descriptors:
591613
self.test_utxo_conversion()
614+
self.test_psbt_incomplete_after_invalid_modification()
592615

593616
self.test_input_confs_control()
594617

0 commit comments

Comments
 (0)