mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
e197f976e1
* Merge #16509: test: Adapt test framework for chains other than "regtest" faf36838bdba7393960fce6ad0c56dc1f93f5870 test: Avoid hardcoding the chain name in combine_logs (MarcoFalke) fa8a1d7ba30040f8c74f93fc41a61276c255a6a6 test: Adapt test framework for chains other than "regtest" (MarcoFalke) 68f546635d5de2ccfedadeabc7bc79e12e5eca6a test: Fix “local variable 'e' is assigned to but never used” (Ben Woosley) Pull request description: This is required for various work in progress: * testchains #8994 * signet #16411 * some of my locally written tests While it will be unused in the master branch as of now, it will make all of those pull requests shorter. Thus review for non-regtest tests can focus on the actual changes and not some test framework changes. ACKs for top commit: jonatack: ACK faf36838bdba7393960fce6ad0c56dc1f93f5870, ran tests and reviewed the code. Tree-SHA512: 35add66c12cab68f2fac8f7c7d47c604d3f24eae9336ff78f83e2c92b3dc08a25e7f4217199bac5393dd3fb72f945bba9c001d6fbb8efd298c88858075fcb3d6 * Add devnet support for tests * test: make sure devnet can connect to each other and start * Partial merge bitcoin/bitcoin#16681: Tests: Use self.chain instead of 'regtest' in almost all current tests, revert one TODO while at it Co-authored-by: MarcoFalke <falke.marco@gmail.com> Co-authored-by: Jorge Timón <jtimon@jtimon.cc>
71 lines
2.7 KiB
Python
Executable File
71 lines
2.7 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 os
|
|
import shutil
|
|
import sys
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import (
|
|
assert_equal,
|
|
connect_nodes_bi,
|
|
)
|
|
|
|
|
|
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']]
|
|
self.stderr = sys.stdout
|
|
|
|
def run_test(self):
|
|
wallet_path = os.path.join(self.nodes[1].datadir, self.chain, "wallets", "wallet.dat")
|
|
wallet_backup_path = os.path.join(self.nodes[1].datadir, "wallet.bak")
|
|
self.nodes[0].generate(101)
|
|
|
|
self.log.info("Make backup of wallet")
|
|
self.stop_node(1)
|
|
shutil.copyfile(wallet_path, wallet_backup_path)
|
|
self.start_node(1, self.extra_args[1])
|
|
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)
|
|
self.sync_blocks()
|
|
|
|
self.log.info("Restart node with wallet backup")
|
|
self.stop_node(1)
|
|
shutil.copyfile(wallet_backup_path, wallet_path)
|
|
self.start_node(1, self.extra_args[1])
|
|
connect_nodes_bi(self.nodes, 0, 1)
|
|
self.sync_all()
|
|
|
|
self.log.info("Verify keypool is restored and balance is correct")
|
|
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].getaddressinfo(self.nodes[1].getnewaddress())['hdkeypath'], "m/44'/1'/0'/0/110")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
KeypoolRestoreTest().main()
|