Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_hd.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2016-2019 The Bitcoin Core developers | # Copyright (c) 2016-2019 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test Hierarchical Deterministic wallet function.""" | """Test Hierarchical Deterministic wallet function.""" | ||||
import os | import os | ||||
import shutil | import shutil | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
connect_nodes_bi, | connect_nodes, | ||||
assert_raises_rpc_error | assert_raises_rpc_error | ||||
) | ) | ||||
class WalletHDTest(BitcoinTestFramework): | class WalletHDTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Assert that derivation is deterministic | # Assert that derivation is deterministic | ||||
hd_add_2 = None | hd_add_2 = None | ||||
for i in range(NUM_HD_ADDS): | for i in range(NUM_HD_ADDS): | ||||
hd_add_2 = self.nodes[1].getnewaddress() | hd_add_2 = self.nodes[1].getnewaddress() | ||||
hd_info_2 = self.nodes[1].getaddressinfo(hd_add_2) | hd_info_2 = self.nodes[1].getaddressinfo(hd_add_2) | ||||
assert_equal(hd_info_2["hdkeypath"], "m/0'/0'/" + str(i) + "'") | assert_equal(hd_info_2["hdkeypath"], "m/0'/0'/" + str(i) + "'") | ||||
assert_equal(hd_info_2["hdseedid"], masterkeyid) | assert_equal(hd_info_2["hdseedid"], masterkeyid) | ||||
assert_equal(hd_add, hd_add_2) | assert_equal(hd_add, hd_add_2) | ||||
connect_nodes_bi(self.nodes[0], self.nodes[1]) | connect_nodes(self.nodes[0], self.nodes[1]) | ||||
self.sync_all() | self.sync_all() | ||||
# Needs rescan | # Needs rescan | ||||
self.stop_node(1) | self.stop_node(1) | ||||
self.start_node(1, extra_args=self.extra_args[1] + ['-rescan']) | self.start_node(1, extra_args=self.extra_args[1] + ['-rescan']) | ||||
assert_equal(self.nodes[1].getbalance(), NUM_HD_ADDS + 1) | assert_equal(self.nodes[1].getbalance(), NUM_HD_ADDS + 1) | ||||
# Try a RPC based rescan | # Try a RPC based rescan | ||||
self.stop_node(1) | self.stop_node(1) | ||||
shutil.rmtree(os.path.join(self.nodes[1].datadir, "regtest", "blocks")) | shutil.rmtree(os.path.join(self.nodes[1].datadir, "regtest", "blocks")) | ||||
shutil.rmtree(os.path.join( | shutil.rmtree(os.path.join( | ||||
self.nodes[1].datadir, "regtest", "chainstate")) | self.nodes[1].datadir, "regtest", "chainstate")) | ||||
shutil.copyfile(os.path.join(self.nodes[1].datadir, "hd.bak"), os.path.join( | shutil.copyfile(os.path.join(self.nodes[1].datadir, "hd.bak"), os.path.join( | ||||
self.nodes[1].datadir, "regtest", "wallets", "wallet.dat")) | self.nodes[1].datadir, "regtest", "wallets", "wallet.dat")) | ||||
self.start_node(1, extra_args=self.extra_args[1]) | self.start_node(1, extra_args=self.extra_args[1]) | ||||
connect_nodes_bi(self.nodes[0], self.nodes[1]) | connect_nodes(self.nodes[0], self.nodes[1]) | ||||
self.sync_all() | self.sync_all() | ||||
# Wallet automatically scans blocks older than key on startup | # Wallet automatically scans blocks older than key on startup | ||||
assert_equal(self.nodes[1].getbalance(), NUM_HD_ADDS + 1) | assert_equal(self.nodes[1].getbalance(), NUM_HD_ADDS + 1) | ||||
out = self.nodes[1].rescanblockchain(0, 1) | out = self.nodes[1].rescanblockchain(0, 1) | ||||
assert_equal(out['start_height'], 0) | assert_equal(out['start_height'], 0) | ||||
assert_equal(out['stop_height'], 1) | assert_equal(out['stop_height'], 1) | ||||
out = self.nodes[1].rescanblockchain(2, 4) | out = self.nodes[1].rescanblockchain(2, 4) | ||||
assert_equal(out['start_height'], 2) | assert_equal(out['start_height'], 2) | ||||
▲ Show 20 Lines • Show All 73 Lines • Show Last 20 Lines |