Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_hd.py
Show All 21 Lines | class WalletHDTest(BitcoinTestFramework): | ||||
def run_test(self): | def run_test(self): | ||||
tmpdir = self.options.tmpdir | tmpdir = self.options.tmpdir | ||||
# Make sure can't switch off usehd after wallet creation | # Make sure can't switch off usehd after wallet creation | ||||
self.stop_node(1) | self.stop_node(1) | ||||
self.assert_start_raises_init_error( | self.assert_start_raises_init_error( | ||||
1, ['-usehd=0'], 'already existing HD wallet') | 1, ['-usehd=0'], 'already existing HD wallet') | ||||
self.start_node(1) | self.start_node(1) | ||||
connect_nodes_bi(self.nodes, 0, 1) | connect_nodes_bi(self.nodes[0], self.nodes[1]) | ||||
# Make sure we use hd, keep masterkeyid | # Make sure we use hd, keep masterkeyid | ||||
masterkeyid = self.nodes[1].getwalletinfo()['hdmasterkeyid'] | masterkeyid = self.nodes[1].getwalletinfo()['hdmasterkeyid'] | ||||
assert_equal(len(masterkeyid), 40) | assert_equal(len(masterkeyid), 40) | ||||
# create an internal key | # create an internal key | ||||
change_addr = self.nodes[1].getrawchangeaddress() | change_addr = self.nodes[1].getrawchangeaddress() | ||||
change_addrV = self.nodes[1].validateaddress(change_addr) | change_addrV = self.nodes[1].validateaddress(change_addr) | ||||
▲ Show 20 Lines • Show All 45 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 _ in range(num_hd_adds): | for _ 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].validateaddress(hd_add_2) | hd_info_2 = self.nodes[1].validateaddress(hd_add_2) | ||||
assert_equal(hd_info_2["hdkeypath"], "m/0'/0'/" + str(_) + "'") | assert_equal(hd_info_2["hdkeypath"], "m/0'/0'/" + str(_) + "'") | ||||
assert_equal(hd_info_2["hdmasterkeyid"], masterkeyid) | assert_equal(hd_info_2["hdmasterkeyid"], masterkeyid) | ||||
assert_equal(hd_add, hd_add_2) | assert_equal(hd_add, hd_add_2) | ||||
connect_nodes_bi(self.nodes, 0, 1) | connect_nodes_bi(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(tmpdir, "node1/regtest/blocks")) | shutil.rmtree(os.path.join(tmpdir, "node1/regtest/blocks")) | ||||
shutil.rmtree(os.path.join(tmpdir, "node1/regtest/chainstate")) | shutil.rmtree(os.path.join(tmpdir, "node1/regtest/chainstate")) | ||||
shutil.copyfile(os.path.join(tmpdir, "hd.bak"), | shutil.copyfile(os.path.join(tmpdir, "hd.bak"), | ||||
os.path.join(tmpdir, "node1/regtest/wallet.dat")) | os.path.join(tmpdir, "node1/regtest/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, 1) | connect_nodes_bi(self.nodes[0], self.nodes[1]) | ||||
self.sync_all() | self.sync_all() | ||||
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) | ||||
assert_equal(out['stop_height'], 4) | assert_equal(out['stop_height'], 4) | ||||
out = self.nodes[1].rescanblockchain(3) | out = self.nodes[1].rescanblockchain(3) | ||||
Show All 22 Lines |