|
9 | 9 | from itertools import product
|
10 | 10 |
|
11 | 11 | from test_framework.descriptors import descsum_create
|
12 |
| -from test_framework.key import ECKey |
| 12 | +from test_framework.key import ECKey, H_POINT |
13 | 13 | from test_framework.messages import (
|
14 | 14 | ser_compact_size,
|
15 | 15 | WITNESS_SCALE_FACTOR,
|
@@ -723,5 +723,46 @@ def test_psbt_input_keys(psbt_input, keys):
|
723 | 723 | )
|
724 | 724 | assert_equal(psbt2["fee"], psbt3["fee"])
|
725 | 725 |
|
| 726 | + self.log.info("Test signing inputs that the wallet has keys for but is not watching the scripts") |
| 727 | + self.nodes[1].createwallet(wallet_name="scriptwatchonly", disable_private_keys=True) |
| 728 | + watchonly = self.nodes[1].get_wallet_rpc("scriptwatchonly") |
| 729 | + |
| 730 | + eckey = ECKey() |
| 731 | + eckey.generate() |
| 732 | + privkey = bytes_to_wif(eckey.get_bytes()) |
| 733 | + |
| 734 | + desc = descsum_create("wsh(pkh({}))".format(eckey.get_pubkey().get_bytes().hex())) |
| 735 | + if self.options.descriptors: |
| 736 | + res = watchonly.importdescriptors([{"desc": desc, "timestamp": "now"}]) |
| 737 | + else: |
| 738 | + res = watchonly.importmulti([{"desc": desc, "timestamp": "now"}]) |
| 739 | + assert res[0]["success"] |
| 740 | + addr = self.nodes[0].deriveaddresses(desc)[0] |
| 741 | + self.nodes[0].sendtoaddress(addr, 10) |
| 742 | + self.generate(self.nodes[0], 1) |
| 743 | + self.nodes[0].importprivkey(privkey) |
| 744 | + |
| 745 | + psbt = watchonly.sendall([wallet.getnewaddress()])["psbt"] |
| 746 | + psbt = self.nodes[0].walletprocesspsbt(psbt)["psbt"] |
| 747 | + self.nodes[0].sendrawtransaction(self.nodes[0].finalizepsbt(psbt)["hex"]) |
| 748 | + |
| 749 | + # Same test but for taproot |
| 750 | + if self.options.descriptors: |
| 751 | + eckey = ECKey() |
| 752 | + eckey.generate() |
| 753 | + privkey = bytes_to_wif(eckey.get_bytes()) |
| 754 | + |
| 755 | + desc = descsum_create("tr({},pk({}))".format(H_POINT, eckey.get_pubkey().get_bytes().hex())) |
| 756 | + res = watchonly.importdescriptors([{"desc": desc, "timestamp": "now"}]) |
| 757 | + assert res[0]["success"] |
| 758 | + addr = self.nodes[0].deriveaddresses(desc)[0] |
| 759 | + self.nodes[0].sendtoaddress(addr, 10) |
| 760 | + self.generate(self.nodes[0], 1) |
| 761 | + self.nodes[0].importdescriptors([{"desc": descsum_create("tr({})".format(privkey)), "timestamp":"now"}]) |
| 762 | + |
| 763 | + psbt = watchonly.sendall([wallet.getnewaddress()])["psbt"] |
| 764 | + psbt = self.nodes[0].walletprocesspsbt(psbt)["psbt"] |
| 765 | + self.nodes[0].sendrawtransaction(self.nodes[0].finalizepsbt(psbt)["hex"]) |
| 766 | + |
726 | 767 | if __name__ == '__main__':
|
727 | 768 | PSBTTest().main()
|
0 commit comments