17bb230d74
7148b74dc [tests] Functional tests must explicitly set num_nodes (John Newbery) 5448a1471 [tests] don't override __init__() in individual tests (John Newbery) 6cf094a02 [tests] Avoid passing around member variables in test_framework (John Newbery) 36b626867 [tests] TestNode: separate add_node from start_node (John Newbery) be2a2ab6a [tests] fix - use rpc_timeout as rpc timeout (John Newbery) Pull request description: Some additional tidyups after the introduction of TestNode: - commit 1 makes TestNode use the correct rpc timeout. This should have been included in #11077 - commit 2 separates `add_node()` from `start_node()` as originally discussed here: https://github.com/bitcoin/bitcoin/pull/10556#discussion_r121161453 with @kallewoof . The test writer no longer needs to assign to `self.nodes` when starting/stopping nodes. - commit 3 adds a `set_test_params()` method, so individual tests don't need to override `__init__()` and call `super().__init__()` Tree-SHA512: 0adb030623b96675b5c29e2890ce99ccd837ed05f721d0c91b35378c5ac01b6658174aac12f1f77402e1d38b61f39b3c43b4df85c96952565dde1cda05b0db84
79 lines
2.8 KiB
Python
Executable File
79 lines
2.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2017 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 HD Wallet keypool restore function.
|
|
|
|
Two nodes. Node1 is under test. Node0 is providing transactions and generating blocks.
|
|
|
|
- Start node1, shutdown and backup wallet.
|
|
- Generate 110 keys (enough to drain the keypool). Store key 90 (in the initial keypool) and key 110 (beyond the initial keypool). Send funds to key 90 and key 110.
|
|
- Stop node1, clear the datadir, move wallet file back into the datadir and restart node1.
|
|
- connect node1 to node0. Verify that they sync and node1 receives its funds."""
|
|
import shutil
|
|
import sys
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import (
|
|
assert_equal,
|
|
connect_nodes_bi,
|
|
sync_blocks,
|
|
)
|
|
|
|
class KeypoolRestoreTest(BitcoinTestFramework):
|
|
def set_test_params(self):
|
|
self.setup_clean_chain = True
|
|
self.num_nodes = 2
|
|
self.extra_args = [['-usehd=0'], ['-usehd=1', '-keypool=100', '-keypoolmin=20']]
|
|
|
|
def setup_network(self):
|
|
self.setup_nodes(stderr=sys.stdout)
|
|
|
|
def run_test(self):
|
|
self.tmpdir = self.options.tmpdir
|
|
self.nodes[0].generate(101)
|
|
|
|
self.log.info("Make backup of wallet")
|
|
|
|
self.stop_node(1)
|
|
|
|
shutil.copyfile(self.tmpdir + "/node1/regtest/wallet.dat", self.tmpdir + "/wallet.bak")
|
|
self.start_node(1, self.extra_args[1], stderr=sys.stdout)
|
|
connect_nodes_bi(self.nodes, 0, 1)
|
|
|
|
self.log.info("Generate keys for wallet")
|
|
|
|
for _ in range(90):
|
|
addr_oldpool = self.nodes[1].getnewaddress()
|
|
for _ in range(20):
|
|
addr_extpool = self.nodes[1].getnewaddress()
|
|
|
|
self.log.info("Send funds to wallet")
|
|
|
|
self.nodes[0].sendtoaddress(addr_oldpool, 10)
|
|
self.nodes[0].generate(1)
|
|
self.nodes[0].sendtoaddress(addr_extpool, 5)
|
|
self.nodes[0].generate(1)
|
|
sync_blocks(self.nodes)
|
|
|
|
self.log.info("Restart node with wallet backup")
|
|
|
|
self.stop_node(1)
|
|
|
|
shutil.copyfile(self.tmpdir + "/wallet.bak", self.tmpdir + "/node1/regtest/wallet.dat")
|
|
|
|
self.log.info("Verify keypool is restored and balance is correct")
|
|
|
|
self.start_node(1, self.extra_args[1], stderr=sys.stdout)
|
|
connect_nodes_bi(self.nodes, 0, 1)
|
|
self.sync_all()
|
|
|
|
assert_equal(self.nodes[1].getbalance(), 15)
|
|
assert_equal(self.nodes[1].listtransactions()[0]['category'], "receive")
|
|
|
|
# Check that we have marked all keys up to the used keypool key as used
|
|
assert_equal(self.nodes[1].validateaddress(self.nodes[1].getnewaddress())['hdkeypath'], "m/44'/1'/0'/0/111")
|
|
|
|
if __name__ == '__main__':
|
|
KeypoolRestoreTest().main()
|