Merge #9832: [qa] assert_start_raises_init_error
025dec0
[qa] assert_start_raises_init_error (NicolasDorier)
Tree-SHA512: 0fe3ecbd47625b181aed92f15445ac26993e1a8b9843bbc1088c4adcea774e503b870912a18e13dca3f255c22a9964c1c0ca92c758907538143f316c5272ea4a
This commit is contained in:
commit
48c3429c50
2 changed files with 29 additions and 2 deletions
|
@ -15,6 +15,7 @@ import http.client
|
||||||
import random
|
import random
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import tempfile
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
import errno
|
import errno
|
||||||
|
@ -325,7 +326,7 @@ def _rpchost_to_args(rpchost):
|
||||||
rv += ['-rpcport=' + rpcport]
|
rv += ['-rpcport=' + rpcport]
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=None):
|
def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=None, stderr=None):
|
||||||
"""
|
"""
|
||||||
Start a bitcoind and return RPC connection to it
|
Start a bitcoind and return RPC connection to it
|
||||||
"""
|
"""
|
||||||
|
@ -334,7 +335,7 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=
|
||||||
binary = os.getenv("BITCOIND", "bitcoind")
|
binary = os.getenv("BITCOIND", "bitcoind")
|
||||||
args = [ binary, "-datadir="+datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-mocktime="+str(get_mocktime()) ]
|
args = [ binary, "-datadir="+datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-mocktime="+str(get_mocktime()) ]
|
||||||
if extra_args is not None: args.extend(extra_args)
|
if extra_args is not None: args.extend(extra_args)
|
||||||
bitcoind_processes[i] = subprocess.Popen(args)
|
bitcoind_processes[i] = subprocess.Popen(args, stderr=stderr)
|
||||||
if os.getenv("PYTHON_DEBUG", ""):
|
if os.getenv("PYTHON_DEBUG", ""):
|
||||||
print("start_node: bitcoind started, waiting for RPC to come up")
|
print("start_node: bitcoind started, waiting for RPC to come up")
|
||||||
url = rpc_url(i, rpchost)
|
url = rpc_url(i, rpchost)
|
||||||
|
@ -348,6 +349,25 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=
|
||||||
|
|
||||||
return proxy
|
return proxy
|
||||||
|
|
||||||
|
def assert_start_raises_init_error(i, dirname, extra_args=None, expected_msg=None):
|
||||||
|
with tempfile.SpooledTemporaryFile(max_size=2**16) as log_stderr:
|
||||||
|
try:
|
||||||
|
node = start_node(i, dirname, extra_args, stderr=log_stderr)
|
||||||
|
stop_node(node, i)
|
||||||
|
except Exception as e:
|
||||||
|
assert 'bitcoind exited' in str(e) #node must have shutdown
|
||||||
|
if expected_msg is not None:
|
||||||
|
log_stderr.seek(0)
|
||||||
|
stderr = log_stderr.read().decode('utf-8')
|
||||||
|
if expected_msg not in stderr:
|
||||||
|
raise AssertionError("Expected error \"" + expected_msg + "\" not found in:\n" + stderr)
|
||||||
|
else:
|
||||||
|
if expected_msg is None:
|
||||||
|
assert_msg = "bitcoind should have exited with an error"
|
||||||
|
else:
|
||||||
|
assert_msg = "bitcoind should have exited with expected error " + expected_msg
|
||||||
|
raise AssertionError(assert_msg)
|
||||||
|
|
||||||
def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, timewait=None, binary=None):
|
def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, timewait=None, binary=None):
|
||||||
"""
|
"""
|
||||||
Start multiple bitcoinds, return RPC connections to them
|
Start multiple bitcoinds, return RPC connections to them
|
||||||
|
|
|
@ -10,6 +10,7 @@ from test_framework.util import (
|
||||||
start_node,
|
start_node,
|
||||||
assert_equal,
|
assert_equal,
|
||||||
connect_nodes_bi,
|
connect_nodes_bi,
|
||||||
|
assert_start_raises_init_error
|
||||||
)
|
)
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -31,6 +32,12 @@ class WalletHDTest(BitcoinTestFramework):
|
||||||
def run_test (self):
|
def run_test (self):
|
||||||
tmpdir = self.options.tmpdir
|
tmpdir = self.options.tmpdir
|
||||||
|
|
||||||
|
# Make sure can't switch off usehd after wallet creation
|
||||||
|
self.stop_node(1)
|
||||||
|
assert_start_raises_init_error(1, self.options.tmpdir, ['-usehd=0'], 'already existing HD wallet')
|
||||||
|
self.nodes[1] = start_node(1, self.options.tmpdir, self.node_args[1])
|
||||||
|
connect_nodes_bi(self.nodes, 0, 1)
|
||||||
|
|
||||||
# Make sure we use hd, keep masterkeyid
|
# Make sure we use hd, keep masterkeyid
|
||||||
masterkeyid = self.nodes[1].getwalletinfo()['hdmasterkeyid']
|
masterkeyid = self.nodes[1].getwalletinfo()['hdmasterkeyid']
|
||||||
assert_equal(len(masterkeyid), 40)
|
assert_equal(len(masterkeyid), 40)
|
||||||
|
|
Loading…
Reference in a new issue