Skip to content

Commit b80de4c

Browse files
committed
test: Test signing psbts without explicitly having scripts
1 parent a73b568 commit b80de4c

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

test/functional/rpc_psbt.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from itertools import product
1010

1111
from test_framework.descriptors import descsum_create
12-
from test_framework.key import ECKey
12+
from test_framework.key import ECKey, H_POINT
1313
from test_framework.messages import (
1414
ser_compact_size,
1515
WITNESS_SCALE_FACTOR,
@@ -723,5 +723,46 @@ def test_psbt_input_keys(psbt_input, keys):
723723
)
724724
assert_equal(psbt2["fee"], psbt3["fee"])
725725

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+
726767
if __name__ == '__main__':
727768
PSBTTest().main()

test/functional/test_framework/key.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515

1616
from .util import modinv
1717

18+
# Point with no known discrete log.
19+
H_POINT = "50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0"
20+
21+
1822
def TaggedHash(tag, data):
1923
ss = hashlib.sha256(tag.encode('utf-8')).digest()
2024
ss += ss

test/functional/wallet_taproot.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from decimal import Decimal
1010
from test_framework.address import output_key_to_p2tr
11+
from test_framework.key import H_POINT
1112
from test_framework.test_framework import BitcoinTestFramework
1213
from test_framework.util import assert_equal
1314
from test_framework.descriptors import descsum_create
@@ -157,9 +158,6 @@
157158
CHANGE_XPRV = "tprv8ZgxMBicQKsPcyDrWwiecVnTtFmfRwbfFqEfR4ZGWvq5aTTwLBWmAm5zrbMcYtb9gQNFfhRfqhhrBG37U3nhmXxEgeEPBJGHAPrHCrAd1WX"
158159
CHANGE_XPUB = "tpubD6NzVbkrYhZ4WSFeQbPF1uSaTHHbbGnZq8qShabZwCdUQwihxaLMMFhs2kidGF2qrRKiQVqw8VoyuTHj1bZqmMXMeciaU1gBjWA1sim2zUB"
159160

160-
# Point with no known discrete log.
161-
H_POINT = "50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0"
162-
163161

164162
def key(hex_key):
165163
"""Construct an x-only pubkey from its hex representation."""

0 commit comments

Comments
 (0)