mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
test: Test signing psbts without explicitly having scripts
This commit is contained in:
parent
a73b56888a
commit
b80de4c505
3 changed files with 47 additions and 4 deletions
|
@ -9,7 +9,7 @@ from decimal import Decimal
|
||||||
from itertools import product
|
from itertools import product
|
||||||
|
|
||||||
from test_framework.descriptors import descsum_create
|
from test_framework.descriptors import descsum_create
|
||||||
from test_framework.key import ECKey
|
from test_framework.key import ECKey, H_POINT
|
||||||
from test_framework.messages import (
|
from test_framework.messages import (
|
||||||
ser_compact_size,
|
ser_compact_size,
|
||||||
WITNESS_SCALE_FACTOR,
|
WITNESS_SCALE_FACTOR,
|
||||||
|
@ -723,5 +723,46 @@ class PSBTTest(BitcoinTestFramework):
|
||||||
)
|
)
|
||||||
assert_equal(psbt2["fee"], psbt3["fee"])
|
assert_equal(psbt2["fee"], psbt3["fee"])
|
||||||
|
|
||||||
|
self.log.info("Test signing inputs that the wallet has keys for but is not watching the scripts")
|
||||||
|
self.nodes[1].createwallet(wallet_name="scriptwatchonly", disable_private_keys=True)
|
||||||
|
watchonly = self.nodes[1].get_wallet_rpc("scriptwatchonly")
|
||||||
|
|
||||||
|
eckey = ECKey()
|
||||||
|
eckey.generate()
|
||||||
|
privkey = bytes_to_wif(eckey.get_bytes())
|
||||||
|
|
||||||
|
desc = descsum_create("wsh(pkh({}))".format(eckey.get_pubkey().get_bytes().hex()))
|
||||||
|
if self.options.descriptors:
|
||||||
|
res = watchonly.importdescriptors([{"desc": desc, "timestamp": "now"}])
|
||||||
|
else:
|
||||||
|
res = watchonly.importmulti([{"desc": desc, "timestamp": "now"}])
|
||||||
|
assert res[0]["success"]
|
||||||
|
addr = self.nodes[0].deriveaddresses(desc)[0]
|
||||||
|
self.nodes[0].sendtoaddress(addr, 10)
|
||||||
|
self.generate(self.nodes[0], 1)
|
||||||
|
self.nodes[0].importprivkey(privkey)
|
||||||
|
|
||||||
|
psbt = watchonly.sendall([wallet.getnewaddress()])["psbt"]
|
||||||
|
psbt = self.nodes[0].walletprocesspsbt(psbt)["psbt"]
|
||||||
|
self.nodes[0].sendrawtransaction(self.nodes[0].finalizepsbt(psbt)["hex"])
|
||||||
|
|
||||||
|
# Same test but for taproot
|
||||||
|
if self.options.descriptors:
|
||||||
|
eckey = ECKey()
|
||||||
|
eckey.generate()
|
||||||
|
privkey = bytes_to_wif(eckey.get_bytes())
|
||||||
|
|
||||||
|
desc = descsum_create("tr({},pk({}))".format(H_POINT, eckey.get_pubkey().get_bytes().hex()))
|
||||||
|
res = watchonly.importdescriptors([{"desc": desc, "timestamp": "now"}])
|
||||||
|
assert res[0]["success"]
|
||||||
|
addr = self.nodes[0].deriveaddresses(desc)[0]
|
||||||
|
self.nodes[0].sendtoaddress(addr, 10)
|
||||||
|
self.generate(self.nodes[0], 1)
|
||||||
|
self.nodes[0].importdescriptors([{"desc": descsum_create("tr({})".format(privkey)), "timestamp":"now"}])
|
||||||
|
|
||||||
|
psbt = watchonly.sendall([wallet.getnewaddress()])["psbt"]
|
||||||
|
psbt = self.nodes[0].walletprocesspsbt(psbt)["psbt"]
|
||||||
|
self.nodes[0].sendrawtransaction(self.nodes[0].finalizepsbt(psbt)["hex"])
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
PSBTTest().main()
|
PSBTTest().main()
|
||||||
|
|
|
@ -15,6 +15,10 @@ import unittest
|
||||||
|
|
||||||
from .util import modinv
|
from .util import modinv
|
||||||
|
|
||||||
|
# Point with no known discrete log.
|
||||||
|
H_POINT = "50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0"
|
||||||
|
|
||||||
|
|
||||||
def TaggedHash(tag, data):
|
def TaggedHash(tag, data):
|
||||||
ss = hashlib.sha256(tag.encode('utf-8')).digest()
|
ss = hashlib.sha256(tag.encode('utf-8')).digest()
|
||||||
ss += ss
|
ss += ss
|
||||||
|
|
|
@ -8,6 +8,7 @@ import random
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from test_framework.address import output_key_to_p2tr
|
from test_framework.address import output_key_to_p2tr
|
||||||
|
from test_framework.key import H_POINT
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import assert_equal
|
from test_framework.util import assert_equal
|
||||||
from test_framework.descriptors import descsum_create
|
from test_framework.descriptors import descsum_create
|
||||||
|
@ -157,9 +158,6 @@ KEYS = [
|
||||||
CHANGE_XPRV = "tprv8ZgxMBicQKsPcyDrWwiecVnTtFmfRwbfFqEfR4ZGWvq5aTTwLBWmAm5zrbMcYtb9gQNFfhRfqhhrBG37U3nhmXxEgeEPBJGHAPrHCrAd1WX"
|
CHANGE_XPRV = "tprv8ZgxMBicQKsPcyDrWwiecVnTtFmfRwbfFqEfR4ZGWvq5aTTwLBWmAm5zrbMcYtb9gQNFfhRfqhhrBG37U3nhmXxEgeEPBJGHAPrHCrAd1WX"
|
||||||
CHANGE_XPUB = "tpubD6NzVbkrYhZ4WSFeQbPF1uSaTHHbbGnZq8qShabZwCdUQwihxaLMMFhs2kidGF2qrRKiQVqw8VoyuTHj1bZqmMXMeciaU1gBjWA1sim2zUB"
|
CHANGE_XPUB = "tpubD6NzVbkrYhZ4WSFeQbPF1uSaTHHbbGnZq8qShabZwCdUQwihxaLMMFhs2kidGF2qrRKiQVqw8VoyuTHj1bZqmMXMeciaU1gBjWA1sim2zUB"
|
||||||
|
|
||||||
# Point with no known discrete log.
|
|
||||||
H_POINT = "50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0"
|
|
||||||
|
|
||||||
|
|
||||||
def key(hex_key):
|
def key(hex_key):
|
||||||
"""Construct an x-only pubkey from its hex representation."""
|
"""Construct an x-only pubkey from its hex representation."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue