Skip to content

Commit

Permalink
tests: Test importing of multipath descriptors
Browse files Browse the repository at this point in the history
Test that both importmulti and importdescriptors behave as expected when
importing a multipath descriptor.
  • Loading branch information
achow101 committed Oct 9, 2023
1 parent 7ead6fc commit ad7dc92
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/functional/wallet_importdescriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
and test the values returned."""

import concurrent.futures
import time

from test_framework.authproxy import JSONRPCException
from test_framework.blocktools import COINBASE_MATURITY
Expand Down Expand Up @@ -712,5 +713,56 @@ def run_test(self):

assert_equal(temp_wallet.getbalance(), encrypted_wallet.getbalance())

self.log.info("Multipath descriptors")
self.nodes[1].createwallet(wallet_name="multipath", descriptors=True, blank=True)
w_multipath = self.nodes[1].get_wallet_rpc("multipath")
self.nodes[1].createwallet(wallet_name="multipath_split", descriptors=True, blank=True)
w_multisplit = self.nodes[1].get_wallet_rpc("multipath_split")
timestamp = int(time.time())

self.test_importdesc({"desc": descsum_create(f"wpkh({xpriv}/<10;20>/0/*)"),
"active": True,
"range": 10,
"timestamp": "now",
"label": "some label"},
success=False,
error_code=-8,
error_message="Multipath descriptors should not have a label",
wallet=w_multipath)
self.test_importdesc({"desc": descsum_create(f"wpkh({xpriv}/<10;20>/0/*)"),
"active": True,
"range": 10,
"timestamp": timestamp,
"internal": True},
success=False,
error_code=-5,
error_message="Cannot have multipath descriptor while also specifying \'internal\'",
wallet=w_multipath)

self.test_importdesc({"desc": descsum_create(f"wpkh({xpriv}/<10;20>/0/*)"),
"active": True,
"range": 10,
"timestamp": timestamp},
success=True,
wallet=w_multipath)

self.test_importdesc({"desc": descsum_create(f"wpkh({xpriv}/10/0/*)"),
"active": True,
"range": 10,
"timestamp": timestamp},
success=True,
wallet=w_multisplit)
self.test_importdesc({"desc": descsum_create(f"wpkh({xpriv}/20/0/*)"),
"active": True,
"range": 10,
"internal": True,
"timestamp": timestamp},
success=True,
wallet=w_multisplit)
for _ in range(0, 10):
assert_equal(w_multipath.getnewaddress(address_type="bech32"), w_multisplit.getnewaddress(address_type="bech32"))
assert_equal(w_multipath.getrawchangeaddress(address_type="bech32"), w_multisplit.getrawchangeaddress(address_type="bech32"))
assert_equal(sorted(w_multipath.listdescriptors()["descriptors"], key=lambda x: x["desc"]), sorted(w_multisplit.listdescriptors()["descriptors"], key=lambda x: x["desc"]))

if __name__ == '__main__':
ImportDescriptorsTest().main()
37 changes: 37 additions & 0 deletions test/functional/wallet_importmulti.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,43 @@ def run_test(self):
)
assert result[0]['success']

self.log.info("Multipath descriptors")
self.nodes[1].createwallet(wallet_name="multipath", blank=True, disable_private_keys=True)
w_multipath = self.nodes[1].get_wallet_rpc("multipath")
self.nodes[1].createwallet(wallet_name="multipath_split", blank=True, disable_private_keys=True)
w_multisplit = self.nodes[1].get_wallet_rpc("multipath_split")

res = w_multipath.importmulti([{"desc": descsum_create(f"wpkh({xpub}/<10;20>/0/*)"),
"keypool": True,
"range": 10,
"timestamp": "now",
"internal": True}])
assert_equal(res[0]["success"], False)
assert_equal(res[0]["error"]["code"], -5)
assert_equal(res[0]["error"]["message"], "Cannot have multipath descriptor while also specifying 'internal'")

res = w_multipath.importmulti([{"desc": descsum_create(f"wpkh({xpub}/<10;20>/0/*)"),
"keypool": True,
"range": 10,
"timestamp": "now"}])
assert_equal(res[0]["success"], True)

res = w_multisplit.importmulti([{"desc": descsum_create(f"wpkh({xpub}/10/0/*)"),
"keypool": True,
"range": 10,
"timestamp": "now"}])
assert_equal(res[0]["success"], True)
res = w_multisplit.importmulti([{"desc": descsum_create(f"wpkh({xpub}/20/0/*)"),
"keypool": True,
"range": 10,
"internal": True,
"timestamp": timestamp}])
assert_equal(res[0]["success"], True)

for _ in range(0, 9):
assert_equal(w_multipath.getnewaddress(address_type="bech32"), w_multisplit.getnewaddress(address_type="bech32"))
assert_equal(w_multipath.getrawchangeaddress(address_type="bech32"), w_multisplit.getrawchangeaddress(address_type="bech32"))


if __name__ == '__main__':
ImportMultiTest().main()

0 comments on commit ad7dc92

Please sign in to comment.