0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-08 10:31:50 -05:00

tests: Test importing of multipath descriptors

Test that both importmulti and importdescriptors behave as expected when
importing a multipath descriptor.
This commit is contained in:
Ava Chow 2024-08-07 16:29:21 -04:00
parent f97d5c137d
commit 0019f61fc5
2 changed files with 89 additions and 0 deletions

View file

@ -16,6 +16,7 @@ variants.
and test the values returned."""
import concurrent.futures
import time
from test_framework.authproxy import JSONRPCException
from test_framework.blocktools import COINBASE_MATURITY
@ -708,5 +709,56 @@ class ImportDescriptorsTest(BitcoinTestFramework):
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()

View file

@ -896,6 +896,43 @@ class ImportMultiTest(BitcoinTestFramework):
)
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()