Explicitly start nodes with -usehd=1 in wallet-dump.py

We currently have usehd defaulted to 0, so we need to explicitly start it
with usehd=1 in wallet-dump.py.

This requires setting up a new data dirs cache for hd as the wallets won't
be compatible otherwise. At the same time we need the initial state of
the wallet to test the dump functionality.

Also use redirect_stderr=True to fix failure when run from pull-tester
This commit is contained in:
Alexander Block 2018-01-31 10:40:27 +01:00
parent a92b7b2ede
commit 9c5032c540
2 changed files with 16 additions and 7 deletions

View File

@ -240,7 +240,7 @@ def wait_for_bitcoind_start(process, url, i):
raise # unknown JSON RPC exception
time.sleep(0.25)
def initialize_chain(test_dir, num_nodes, cachedir):
def initialize_chain(test_dir, num_nodes, cachedir, extra_args=None):
"""
Create a cache of a 200-block-long chain (with wallet) for MAX_NODES
Afterward, create num_nodes copies from the cache
@ -266,6 +266,8 @@ def initialize_chain(test_dir, num_nodes, cachedir):
args = [ os.getenv("DASHD", "dashd"), "-server", "-keypool=1", "-datadir="+datadir, "-discover=0" ]
if i > 0:
args.append("-connect=127.0.0.1:"+str(p2p_port(0)))
if extra_args is not None:
args += extra_args
bitcoind_processes[i] = subprocess.Popen(args)
if os.getenv("PYTHON_DEBUG", ""):
print("initialize_chain: dashd started, waiting for RPC to come up")

View File

@ -4,7 +4,7 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (start_nodes, start_node, assert_equal, bitcoind_processes)
from test_framework.util import *
def read_dump(file_name, addrs, hd_master_addr_old):
@ -57,15 +57,21 @@ class WalletDumpTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.setup_clean_chain = False
self.redirect_stderr = True
self.num_nodes = 1
self.extra_args = [["-keypool=90"]]
self.extra_args = [["-keypool=90", "-usehd=1"]]
def setup_chain(self):
# TODO remove this when usehd=1 becomes the default
# use our own cache and -usehd=1 as extra arg as the default cache is run with -usehd=0
initialize_chain(self.options.tmpdir, self.num_nodes, self.options.cachedir + "/hd", ["-usehd=1"])
def setup_network(self, split=False):
# Use 1 minute timeout because the initial getnewaddress RPC can take
# longer than the default 30 seconds due to an expensive
# CWallet::TopUpKeyPool call, and the encryptwallet RPC made later in
# the test often takes even longer.
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, self.extra_args, timewait=60)
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, self.extra_args, timewait=60, redirect_stderr=True)
def run_test (self):
tmpdir = self.options.tmpdir
@ -87,7 +93,7 @@ class WalletDumpTest(BitcoinTestFramework):
read_dump(tmpdir + "/node0/wallet.unencrypted.dump", addrs, None)
assert_equal(found_addr, test_addr_count) # all keys must be in the dump
assert_equal(found_addr_chg, 50) # 50 blocks where mined
assert_equal(found_addr_rsv, 90 + 1) # keypool size (TODO: fix off-by-one)
assert_equal(found_addr_rsv, 180) # keypool size (external+internal)
#encrypt wallet, restart, unlock and dump
self.nodes[0].encryptwallet('test')
@ -101,8 +107,9 @@ class WalletDumpTest(BitcoinTestFramework):
found_addr, found_addr_chg, found_addr_rsv, hd_master_addr_enc = \
read_dump(tmpdir + "/node0/wallet.encrypted.dump", addrs, hd_master_addr_unenc)
assert_equal(found_addr, test_addr_count)
assert_equal(found_addr_chg, 90 + 1 + 50) # old reserve keys are marked as change now
assert_equal(found_addr_rsv, 90 + 1) # keypool size (TODO: fix off-by-one)
# TODO clarify if we want the behavior that is tested below in Dash (only when HD seed was generated and not user-provided)
# assert_equal(found_addr_chg, 180 + 50) # old reserve keys are marked as change now
assert_equal(found_addr_rsv, 180) # keypool size (TODO: fix off-by-one)
if __name__ == '__main__':
WalletDumpTest().main ()