From 5b02e3314bd998b23fc9301b7c967ebe30b86cb1 Mon Sep 17 00:00:00 2001 From: ishaanam Date: Thu, 4 Aug 2022 11:20:43 -0400 Subject: [PATCH] test: add test for `descriptorprocesspsbt` RPC --- test/functional/rpc_psbt.py | 56 +++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py index 37de098111d6cf..7359a7643b1d2c 100755 --- a/test/functional/rpc_psbt.py +++ b/test/functional/rpc_psbt.py @@ -38,7 +38,10 @@ find_vout_for_address, random_bytes, ) -from test_framework.wallet_util import bytes_to_wif +from test_framework.wallet_util import ( + bytes_to_wif, + get_generate_key, +) import json import os @@ -50,8 +53,8 @@ class PSBTTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 3 self.extra_args = [ - ["-walletrbf=1", "-addresstype=bech32", "-changetype=bech32"], #TODO: Remove address type restrictions once taproot has psbt extensions - ["-walletrbf=0", "-changetype=legacy"], + ["-walletrbf=1", "-addresstype=bech32", "-changetype=bech32", "-txindex"], #TODO: Remove address type restrictions once taproot has psbt extensions + ["-walletrbf=0", "-changetype=legacy", "-txindex"], [] ] self.supports_cli = False @@ -578,6 +581,53 @@ def test_psbt_input_keys(psbt_input, keys): break assert shuffled + self.log.info("Test descriptorprocesspsbt updates and signs a psbt with descriptors") + key_info = get_generate_key() + key1 = key_info[0] + wpkh_addr = key_info[5] + descriptor1 = descsum_create(f"wpkh({key1})") + + a_key_info = get_generate_key() + b_key_info = get_generate_key() + c_key_info = get_generate_key() + a_key = a_key_info[0] + a_pubkey = a_key_info[1] + b_key = b_key_info[0] + b_pubkey = b_key_info[1] + c_pubkey = c_key_info[1] + + descriptor_a = descsum_create(f"wsh(multi(2,{a_key},{b_pubkey},{c_pubkey}))") + descriptor_b = descsum_create(f"wsh(multi(2,{a_pubkey},{b_key},{c_pubkey}))") + wsh_addr = self.nodes[0].deriveaddresses(descriptor_a)[0] + + txid1 = self.nodes[0].sendtoaddress(wpkh_addr, 1) + vout1 = find_output(self.nodes[0], txid1, 1) + txid3 = self.nodes[0].sendtoaddress(wsh_addr, 1) + vout3 = find_output(self.nodes[0], txid3, 1) + self.sync_all() + + psbt = self.nodes[1].createpsbt([{"txid":txid1, "vout":vout1},{"txid":txid2, "vout":vout2},{"txid":txid3, "vout":vout3}], {self.nodes[0].getnewaddress():12.999}) + decoded = self.nodes[1].decodepsbt(psbt) + test_psbt_input_keys(decoded['inputs'][0], []) + test_psbt_input_keys(decoded['inputs'][1], []) + test_psbt_input_keys(decoded['inputs'][2], []) + + psbt = self.nodes[1].descriptorprocesspsbt(psbt, [descriptor_a])["psbt"] + decoded = self.nodes[1].decodepsbt(psbt) + test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'non_witness_utxo']) + test_psbt_input_keys(decoded['inputs'][1], ['non_witness_utxo']) + test_psbt_input_keys(decoded['inputs'][2], ['witness_utxo', 'non_witness_utxo', 'bip32_derivs', 'witness_script', 'partial_signatures']) + + psbt = self.nodes[2].descriptorprocesspsbt(psbt=psbt, descriptors=[descriptor1, descriptor_b], sighashtype="ALL", bip32derivs=False, finalize=False)["psbt"] + decoded = self.nodes[1].decodepsbt(psbt) + test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'non_witness_utxo', 'partial_signatures']) + test_psbt_input_keys(decoded['inputs'][1], ['non_witness_utxo']) + test_psbt_input_keys(decoded['inputs'][2], ['witness_utxo', 'non_witness_utxo', 'bip32_derivs', 'witness_script', 'partial_signatures']) + + psbt = self.nodes[1].walletprocesspsbt(psbt)["psbt"] + rawtx = self.nodes[1].finalizepsbt(psbt)["hex"] + self.nodes[1].sendrawtransaction(rawtx) + # Newly created PSBT needs UTXOs and updating addr = self.nodes[1].getnewaddress("", "p2sh-segwit") txid = self.nodes[0].sendtoaddress(addr, 7)