[tests] don't override __init__() in individual tests
[bitcoinplatinum.git] / test / functional / keypool-topup.py
blobb87433a9c522ca919ae9edba7f30518e82c0650a
1 #!/usr/bin/env python3
2 # Copyright (c) 2017 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 """Test HD Wallet keypool restore function.
7 Two nodes. Node1 is under test. Node0 is providing transactions and generating blocks.
9 - Start node1, shutdown and backup wallet.
10 - 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.
11 - Stop node1, clear the datadir, move wallet file back into the datadir and restart node1.
12 - connect node1 to node0. Verify that they sync and node1 receives its funds."""
13 import shutil
15 from test_framework.test_framework import BitcoinTestFramework
16 from test_framework.util import (
17 assert_equal,
18 connect_nodes_bi,
19 sync_blocks,
22 class KeypoolRestoreTest(BitcoinTestFramework):
23 def set_test_params(self):
24 self.setup_clean_chain = True
25 self.num_nodes = 2
26 self.extra_args = [['-usehd=0'], ['-usehd=1', '-keypool=100', '-keypoolmin=20']]
28 def run_test(self):
29 self.tmpdir = self.options.tmpdir
30 self.nodes[0].generate(101)
32 self.log.info("Make backup of wallet")
34 self.stop_node(1)
36 shutil.copyfile(self.tmpdir + "/node1/regtest/wallet.dat", self.tmpdir + "/wallet.bak")
37 self.start_node(1, self.extra_args[1])
38 connect_nodes_bi(self.nodes, 0, 1)
40 self.log.info("Generate keys for wallet")
42 for _ in range(90):
43 addr_oldpool = self.nodes[1].getnewaddress()
44 for _ in range(20):
45 addr_extpool = self.nodes[1].getnewaddress()
47 self.log.info("Send funds to wallet")
49 self.nodes[0].sendtoaddress(addr_oldpool, 10)
50 self.nodes[0].generate(1)
51 self.nodes[0].sendtoaddress(addr_extpool, 5)
52 self.nodes[0].generate(1)
53 sync_blocks(self.nodes)
55 self.log.info("Restart node with wallet backup")
57 self.stop_node(1)
59 shutil.copyfile(self.tmpdir + "/wallet.bak", self.tmpdir + "/node1/regtest/wallet.dat")
61 self.log.info("Verify keypool is restored and balance is correct")
63 self.start_node(1, self.extra_args[1])
64 connect_nodes_bi(self.nodes, 0, 1)
65 self.sync_all()
67 assert_equal(self.nodes[1].getbalance(), 15)
68 assert_equal(self.nodes[1].listtransactions()[0]['category'], "receive")
70 # Check that we have marked all keys up to the used keypool key as used
71 assert_equal(self.nodes[1].validateaddress(self.nodes[1].getnewaddress())['hdkeypath'], "m/0'/0'/110'")
73 if __name__ == '__main__':
74 KeypoolRestoreTest().main()