mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
544d33309a
ceefab5226
fix: feature_backwards compatible works now with as expected if no bdb compiled (Konstantin Akimov)b20f812674
fix: follow-up fixes for functional tests used protx (Konstantin Akimov)655146d5e7
Merge #21302: wallet: createwallet examples for descriptor wallets (W. J. van der Laan)99a8b60393
Merge #21063: wallet, rpc: update listdescriptors response format (fanquake)6ee2c7cc59
Merge #21277: wallet: listdescriptors uses normalized descriptor form (Wladimir J. van der Laan)8bacdbf71f
Merge #19136: wallet: add parent_desc to getaddressinfo (Samuel Dobson)f567de007a
chore: release notes for 5965 with wallet tool improvements (Konstantin Akimov)0daf360edf
chore: add TODO to implement mnemonic for descriptor wallets (Konstantin Akimov)5016294307
chore: move functional test wallet_multiwallet from category "slow 5 minutes" to "fast test" (Konstantin Akimov)ef7ce87c1b
fix: remove workarounds introduced due to missing bitcoin#20267 (bdb is not compiled) (Konstantin Akimov)06b2d85bb4
partial Merge #20267: Disable and fix tests for when BDB is not compiled (Wladimir J. van der Laan) Pull request description: ## Issue being fixed or feature implemented https://github.com/dashpay/dash-issues/issues/59 ## Extra notes This commit `chore: move functional test wallet_multiwallet from category "slow 5 minutes" to "fast test"` is not directly connected to descriptor wallets, but added to this PR due to conflicts with 20267 ## What was done? It steadily improves support of descriptor wallets in Dash core. Done backports and related fixes: - partial bitcoin/bitcoin#20267 - bitcoin/bitcoin#19136 - bitcoin/bitcoin#21277 - bitcoin/bitcoin#21063 - bitcoin/bitcoin#21302 Beside backports and related fixes, this PR includes release notes for previous batch of backports for descriptor wallets support #5965 ## How Has This Been Tested? Run unit functional tests ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone Top commit has no ACKs. Tree-SHA512: f4b2033f8c4fa1d0f72cfc31378909703b3ae8f44748989ff00c3e71311ac80ac37837137133c7e4a166823a941ed7df10efa09c89f5b213f3c8ede7d3d6e8f4
192 lines
9.1 KiB
Python
Executable File
192 lines
9.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2019-2020 The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
"""Test descriptor wallet function."""
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import (
|
|
assert_equal,
|
|
assert_raises_rpc_error
|
|
)
|
|
|
|
|
|
class WalletDescriptorTest(BitcoinTestFramework):
|
|
def set_test_params(self):
|
|
self.setup_clean_chain = True
|
|
self.num_nodes = 1
|
|
self.extra_args = [['-keypool=100']]
|
|
self.wallet_names = []
|
|
|
|
def skip_test_if_missing_module(self):
|
|
self.skip_if_no_wallet()
|
|
self.skip_if_no_sqlite()
|
|
|
|
def run_test(self):
|
|
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")
|
|
self.nodes[0].createwallet(wallet_name="desc1", descriptors=True)
|
|
|
|
# A descriptor wallet should have 100 addresses * 1 type = 100 keys
|
|
self.log.info("Checking wallet info")
|
|
wallet_info = self.nodes[0].getwalletinfo()
|
|
assert_equal(wallet_info['format'], 'sqlite')
|
|
assert_equal(wallet_info['keypoolsize'], 100)
|
|
assert_equal(wallet_info['keypoolsize_hd_internal'], 100)
|
|
assert 'keypoololdest' not in wallet_info
|
|
|
|
# Check that getnewaddress works
|
|
self.log.info("Test that getnewaddress and getrawchangeaddress work")
|
|
addr = self.nodes[0].getnewaddress("")
|
|
addr_info = self.nodes[0].getaddressinfo(addr)
|
|
assert addr_info['desc'].startswith('pkh(')
|
|
assert_equal(addr_info['hdkeypath'], 'm/44\'/1\'/0\'/0/0')
|
|
|
|
# Check that getrawchangeaddress works
|
|
addr = self.nodes[0].getrawchangeaddress()
|
|
addr_info = self.nodes[0].getaddressinfo(addr)
|
|
assert addr_info['desc'].startswith('pkh(')
|
|
assert_equal(addr_info['hdkeypath'], 'm/44\'/1\'/0\'/1/0')
|
|
|
|
# Make a wallet to receive coins at
|
|
self.nodes[0].createwallet(wallet_name="desc2", descriptors=True)
|
|
recv_wrpc = self.nodes[0].get_wallet_rpc("desc2")
|
|
send_wrpc = self.nodes[0].get_wallet_rpc("desc1")
|
|
|
|
# Generate some coins
|
|
send_wrpc.generatetoaddress(101, send_wrpc.getnewaddress())
|
|
|
|
# Make transactions
|
|
self.log.info("Test sending and receiving")
|
|
addr = recv_wrpc.getnewaddress()
|
|
send_wrpc.sendtoaddress(addr, 10)
|
|
|
|
# Make sure things are disabled
|
|
self.log.info("Test disabled RPCs")
|
|
assert_raises_rpc_error(-4, "This type of wallet does not support this command", recv_wrpc.rpc.importprivkey, "cVpF924EspNh8KjYsfhgY96mmxvT6DgdWiTYMtMjuM74hJaU5psW")
|
|
assert_raises_rpc_error(-4, "This type of wallet does not support this command", recv_wrpc.rpc.importpubkey, send_wrpc.getaddressinfo(send_wrpc.getnewaddress()))
|
|
assert_raises_rpc_error(-4, "This type of wallet does not support this command", recv_wrpc.rpc.importaddress, recv_wrpc.getnewaddress())
|
|
assert_raises_rpc_error(-4, "This type of wallet does not support this command", recv_wrpc.rpc.importmulti, [])
|
|
assert_raises_rpc_error(-4, "This type of wallet does not support this command", recv_wrpc.rpc.addmultisigaddress, 1, [recv_wrpc.getnewaddress()])
|
|
assert_raises_rpc_error(-4, "This type of wallet does not support this command", recv_wrpc.rpc.dumpprivkey, recv_wrpc.getnewaddress())
|
|
assert_raises_rpc_error(-4, "This type of wallet does not support this command", recv_wrpc.rpc.dumpwallet, 'wallet.dump')
|
|
assert_raises_rpc_error(-4, "This type of wallet does not support this command", recv_wrpc.rpc.importwallet, 'wallet.dump')
|
|
# TODO: there is not RPC `sethdseed`
|
|
# assert_raises_rpc_error(-4, "This type of wallet does not support this command", recv_wrpc.rpc.sethdseed)
|
|
|
|
self.log.info("Test encryption")
|
|
# Get the master fingerprint before encrypt
|
|
info1 = send_wrpc.getaddressinfo(send_wrpc.getnewaddress())
|
|
|
|
# Encrypt wallet 0
|
|
send_wrpc.encryptwallet('pass')
|
|
send_wrpc.walletpassphrase('pass', 10)
|
|
addr = send_wrpc.getnewaddress()
|
|
info2 = send_wrpc.getaddressinfo(addr)
|
|
assert info1['hdmasterfingerprint'] != info2['hdmasterfingerprint']
|
|
send_wrpc.walletlock()
|
|
assert 'hdmasterfingerprint' in send_wrpc.getaddressinfo(send_wrpc.getnewaddress())
|
|
info3 = send_wrpc.getaddressinfo(addr)
|
|
assert_equal(info2['desc'], info3['desc'])
|
|
|
|
self.log.info("Test that getnewaddress still works after keypool is exhausted in an encrypted wallet")
|
|
for i in range(0, 500):
|
|
send_wrpc.getnewaddress()
|
|
|
|
self.log.info("Test that unlock is needed when deriving only hardened keys in an encrypted wallet")
|
|
send_wrpc.walletpassphrase('pass', 10)
|
|
send_wrpc.importdescriptors([{
|
|
"desc": "pkh(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0h/*h)#y4dfsj7n",
|
|
"timestamp": "now",
|
|
"range": [0,10],
|
|
"active": True
|
|
}])
|
|
send_wrpc.walletlock()
|
|
# Exhaust keypool of 100
|
|
for i in range(0, 100):
|
|
# keypool should be exhaused by bech32 addresses, but in dash case keypool is not exhausted
|
|
send_wrpc.getnewaddress()
|
|
# This should now error
|
|
# this check is disabled, see comment above above
|
|
# assert_raises_rpc_error(-12, "Keypool ran out, please call keypoolrefill first", send_wrpc.getnewaddress, '')
|
|
|
|
self.log.info("Test born encrypted wallets")
|
|
self.nodes[0].createwallet('desc_enc', False, False, 'pass', False, True)
|
|
enc_rpc = self.nodes[0].get_wallet_rpc('desc_enc')
|
|
enc_rpc.getnewaddress() # Makes sure that we can get a new address from a born encrypted wallet
|
|
|
|
self.log.info("Test blank descriptor wallets")
|
|
self.nodes[0].createwallet(wallet_name='desc_blank', blank=True, descriptors=True)
|
|
blank_rpc = self.nodes[0].get_wallet_rpc('desc_blank')
|
|
assert_raises_rpc_error(-4, 'This wallet has no available keys', blank_rpc.getnewaddress)
|
|
|
|
self.log.info("Test descriptor wallet with disabled private keys")
|
|
self.nodes[0].createwallet(wallet_name='desc_no_priv', disable_private_keys=True, descriptors=True)
|
|
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),
|
|
('legacy', True, 'pkh(', '44\'/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()
|
|
else:
|
|
addr = exp_rpc.getnewaddress()
|
|
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()
|
|
else:
|
|
addr = exp_rpc.getnewaddress()
|
|
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()
|
|
imp_addr = imp_rpc.getrawchangeaddress()
|
|
else:
|
|
exp_addr = exp_rpc.getnewaddress()
|
|
imp_addr = imp_rpc.getnewaddress()
|
|
assert_equal(exp_addr, imp_addr)
|
|
|
|
if __name__ == '__main__':
|
|
WalletDescriptorTest().main ()
|