Skip to content

Commit

Permalink
test: add test for modififed walletprocesspsbt calls
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
willcl-ark committed Jul 1, 2024
1 parent 26cadb8 commit efa8138
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/functional/rpc_psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ def set_test_params(self):
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(address_type="bech32m")
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(address_type="bech32m")
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]
Expand Down Expand Up @@ -589,6 +611,7 @@ def run_test(self):

if self.options.descriptors:
self.test_utxo_conversion()
self.test_psbt_incomplete_after_invalid_modification()

self.test_input_confs_control()

Expand Down

0 comments on commit efa8138

Please sign in to comment.