aboutsummaryrefslogtreecommitdiff
path: root/test/functional/wallet_descriptor.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/wallet_descriptor.py')
-rwxr-xr-xtest/functional/wallet_descriptor.py70
1 files changed, 65 insertions, 5 deletions
diff --git a/test/functional/wallet_descriptor.py b/test/functional/wallet_descriptor.py
index 1de41a5f96..1e032bdd6c 100755
--- a/test/functional/wallet_descriptor.py
+++ b/test/functional/wallet_descriptor.py
@@ -23,11 +23,14 @@ class WalletDescriptorTest(BitcoinTestFramework):
self.skip_if_no_sqlite()
def run_test(self):
- # Make a legacy wallet and check it is BDB
- self.nodes[0].createwallet(wallet_name="legacy1", descriptors=False)
- wallet_info = self.nodes[0].getwalletinfo()
- assert_equal(wallet_info['format'], 'bdb')
- self.nodes[0].unloadwallet("legacy1")
+ if self.is_bdb_compiled():
+ # Make a legacy wallet and check it is BDB
+ self.nodes[0].createwallet(wallet_name="legacy1", descriptors=False)
+ wallet_info = self.nodes[0].getwalletinfo()
+ assert_equal(wallet_info['format'], 'bdb')
+ self.nodes[0].unloadwallet("legacy1")
+ else:
+ self.log.warning("Skipping BDB test")
# Make a descriptor wallet
self.log.info("Making a descriptor wallet")
@@ -148,5 +151,62 @@ class WalletDescriptorTest(BitcoinTestFramework):
nopriv_rpc = self.nodes[0].get_wallet_rpc('desc_no_priv')
assert_raises_rpc_error(-4, 'This wallet has no available keys', nopriv_rpc.getnewaddress)
+ self.log.info("Test descriptor exports")
+ self.nodes[0].createwallet(wallet_name='desc_export', descriptors=True)
+ exp_rpc = self.nodes[0].get_wallet_rpc('desc_export')
+ self.nodes[0].createwallet(wallet_name='desc_import', disable_private_keys=True, descriptors=True)
+ imp_rpc = self.nodes[0].get_wallet_rpc('desc_import')
+
+ addr_types = [('legacy', False, 'pkh(', '44\'/1\'/0\'', -13),
+ ('p2sh-segwit', False, 'sh(wpkh(', '49\'/1\'/0\'', -14),
+ ('bech32', False, 'wpkh(', '84\'/1\'/0\'', -13),
+ ('legacy', True, 'pkh(', '44\'/1\'/0\'', -13),
+ ('p2sh-segwit', True, 'sh(wpkh(', '49\'/1\'/0\'', -14),
+ ('bech32', True, 'wpkh(', '84\'/1\'/0\'', -13)]
+
+ for addr_type, internal, desc_prefix, deriv_path, int_idx in addr_types:
+ int_str = 'internal' if internal else 'external'
+
+ self.log.info("Testing descriptor address type for {} {}".format(addr_type, int_str))
+ if internal:
+ addr = exp_rpc.getrawchangeaddress(address_type=addr_type)
+ else:
+ addr = exp_rpc.getnewaddress(address_type=addr_type)
+ desc = exp_rpc.getaddressinfo(addr)['parent_desc']
+ assert_equal(desc_prefix, desc[0:len(desc_prefix)])
+ idx = desc.index('/') + 1
+ assert_equal(deriv_path, desc[idx:idx + 9])
+ if internal:
+ assert_equal('1', desc[int_idx])
+ else:
+ assert_equal('0', desc[int_idx])
+
+ self.log.info("Testing the same descriptor is returned for address type {} {}".format(addr_type, int_str))
+ for i in range(0, 10):
+ if internal:
+ addr = exp_rpc.getrawchangeaddress(address_type=addr_type)
+ else:
+ addr = exp_rpc.getnewaddress(address_type=addr_type)
+ test_desc = exp_rpc.getaddressinfo(addr)['parent_desc']
+ assert_equal(desc, test_desc)
+
+ self.log.info("Testing import of exported {} descriptor".format(addr_type))
+ imp_rpc.importdescriptors([{
+ 'desc': desc,
+ 'active': True,
+ 'next_index': 11,
+ 'timestamp': 'now',
+ 'internal': internal
+ }])
+
+ for i in range(0, 10):
+ if internal:
+ exp_addr = exp_rpc.getrawchangeaddress(address_type=addr_type)
+ imp_addr = imp_rpc.getrawchangeaddress(address_type=addr_type)
+ else:
+ exp_addr = exp_rpc.getnewaddress(address_type=addr_type)
+ imp_addr = imp_rpc.getnewaddress(address_type=addr_type)
+ assert_equal(exp_addr, imp_addr)
+
if __name__ == '__main__':
WalletDescriptorTest().main ()