mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 21:12:48 +01:00
2c7b29bac5
c1e5d40
Make debugging test crash easier (MeshCollider)8263f6a
Create walletdir if datadir doesn't exist and fix tests (MeshCollider)9587a9c
Default walletdir is wallets/ if it exists (MeshCollider)d987889
Add release notes for -walletdir and wallets/ dir (MeshCollider)80c5cbc
Add test for -walletdir (MeshCollider)0530ba0
Add -walletdir parameter to specify custom wallet dir (MeshCollider) Pull request description: Closes #11348 Adds a `-walletdir` parameter which specifies a directory to use for wallets, allowing them to be stored separately from the 'main' data directory. Creates a new `wallets/` directory in datadir if this is the first time running, and defaults to using it if it exists. Includes tests and release notes. Things which might need to be considered more: - there is no 'lock' on the wallets directory, which might be needed? - because this uses a new wallets/ directory by default, downgrading to an earlier version won't see the wallets in that directory (not a big deal though, users can just copy them up to the main dir) - jnewbery suggested putting each wallet in its own directory, which is a good idea, but out of scope for this PR IMO. EDIT: this is being done in https://github.com/bitcoin/bitcoin/pull/11687 - doc/files.md needs updating (will do soon) I also considered including a cleanup by removing caching of data directory paths and instead just initialise them once on startup (c.f. #3073), but decided it wasn't super relevant here will just complicate review. Tree-SHA512: c8ac04bfe9a810c32055f2c8b8fa0d535e56125ceb8d96f12447dd3538bf3e5ee992b60b1cd2173bf5f3fa023a9feab12c9963593bf27ed419df929bb413398d
77 lines
2.7 KiB
Python
Executable File
77 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 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']]
|
|
self.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/wallets/wallet.dat", self.tmpdir + "/wallet.bak")
|
|
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)
|
|
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/wallets/wallet.dat")
|
|
|
|
self.log.info("Verify keypool is restored and balance is correct")
|
|
|
|
self.start_node(1, self.extra_args[1])
|
|
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/110")
|
|
|
|
if __name__ == '__main__':
|
|
KeypoolRestoreTest().main()
|