Skip to content

Commit 1bce12a

Browse files
committed
test: add test for descriptorprocesspsbt RPC
1 parent fb2a3a7 commit 1bce12a

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

test/functional/rpc_psbt.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@
4242
find_vout_for_address,
4343
random_bytes,
4444
)
45-
from test_framework.wallet_util import bytes_to_wif
45+
from test_framework.wallet_util import (
46+
bytes_to_wif,
47+
get_generate_key
48+
)
4649

4750
import json
4851
import os
@@ -944,6 +947,48 @@ def test_psbt_input_keys(psbt_input, keys):
944947
self.log.info("Test we don't crash when making a 0-value funded transaction at 0 fee without forcing an input selection")
945948
assert_raises_rpc_error(-4, "Transaction requires one destination of non-0 value, a non-0 feerate, or a pre-selected input", self.nodes[0].walletcreatefundedpsbt, [], [{"data": "deadbeef"}], 0, {"fee_rate": "0"})
946949

950+
self.log.info("Test descriptorprocesspsbt updates and signs a psbt with descriptors")
951+
952+
self.generate(self.nodes[2], 1)
953+
954+
# Disable the wallet for node 2 since `descriptorprocesspsbt` does not use the wallet
955+
self.restart_node(2, extra_args=["-disablewallet"])
956+
self.connect_nodes(0, 2)
957+
self.connect_nodes(1, 2)
958+
959+
key_info = get_generate_key()
960+
key = key_info.privkey
961+
address = key_info.p2wpkh_addr
962+
963+
descriptor = descsum_create(f"wpkh({key})")
964+
965+
txid = self.nodes[0].sendtoaddress(address, 1)
966+
self.sync_all()
967+
vout = find_output(self.nodes[0], txid, 1)
968+
969+
psbt = self.nodes[2].createpsbt([{"txid": txid, "vout": vout}], {self.nodes[0].getnewaddress(): 0.99999})
970+
decoded = self.nodes[2].decodepsbt(psbt)
971+
test_psbt_input_keys(decoded['inputs'][0], [])
972+
973+
# Test that even if the wrong descriptor is given, `witness_utxo` and `non_witness_utxo`
974+
# are still added to the psbt
975+
alt_descriptor = descsum_create(f"wpkh({get_generate_key().privkey})")
976+
alt_psbt = self.nodes[2].descriptorprocesspsbt(psbt=psbt, descriptors=[alt_descriptor], sighashtype="ALL")["psbt"]
977+
decoded = self.nodes[2].decodepsbt(alt_psbt)
978+
test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'non_witness_utxo'])
979+
980+
# Test that the psbt is not finalized and does not have bip32_derivs unless specified
981+
psbt = self.nodes[2].descriptorprocesspsbt(psbt=psbt, descriptors=[descriptor], sighashtype="ALL", bip32derivs=True, finalize=False)["psbt"]
982+
decoded = self.nodes[2].decodepsbt(psbt)
983+
test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'non_witness_utxo', 'partial_signatures', 'bip32_derivs'])
984+
985+
psbt = self.nodes[2].descriptorprocesspsbt(psbt=psbt, descriptors=[descriptor], sighashtype="ALL", bip32derivs=False, finalize=True)["psbt"]
986+
decoded = self.nodes[2].decodepsbt(psbt)
987+
test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'non_witness_utxo', 'final_scriptwitness'])
988+
989+
# Broadcast transaction
990+
rawtx = self.nodes[2].finalizepsbt(psbt)["hex"]
991+
self.nodes[2].sendrawtransaction(rawtx)
947992

948993
if __name__ == '__main__':
949994
PSBTTest().main()

0 commit comments

Comments
 (0)