diff --git a/test/functional/combine_logs.py b/test/functional/combine_logs.py --- a/test/functional/combine_logs.py +++ b/test/functional/combine_logs.py @@ -6,6 +6,7 @@ import argparse from collections import defaultdict, namedtuple +import glob import heapq import itertools import os @@ -54,9 +55,21 @@ Delegates to generator function get_log_events() to provide individual log events for each of the input log files.""" + # Find out what the folder is called that holds the debug.log file + chain = glob.glob("{}/node0/*/debug.log".format(tmp_dir)) + if chain: + # pick the first one if more than one chain was found (should never + # happen) + chain = chain[0] + # extract the chain name + chain = re.search(r'node0/(.+?)/debug\.log$', chain).group(1) + else: + # fallback to regtest (should only happen when none exists) + chain = 'regtest' + files = [("test", "{}/test_framework.log".format(tmp_dir))] for i in itertools.count(): - logfile = "{}/node{}/regtest/debug.log".format(tmp_dir, i) + logfile = "{}/node{}/{}/debug.log".format(tmp_dir, i, chain) if not os.path.isfile(logfile): break files.append(("node{}".format(i), logfile)) diff --git a/test/functional/feature_blocksdir.py b/test/functional/feature_blocksdir.py --- a/test/functional/feature_blocksdir.py +++ b/test/functional/feature_blocksdir.py @@ -19,10 +19,10 @@ def run_test(self): self.stop_node(0) assert os.path.isdir(os.path.join( - self.nodes[0].datadir, "regtest", "blocks")) + self.nodes[0].datadir, self.chain, "blocks")) assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "blocks")) shutil.rmtree(self.nodes[0].datadir) - initialize_datadir(self.options.tmpdir, 0) + initialize_datadir(self.options.tmpdir, 0, self.chain) self.log.info("Starting with nonexistent blocksdir ...") blocksdir_path = os.path.join(self.options.tmpdir, 'blocksdir') self.nodes[0].assert_start_raises_init_error( @@ -34,9 +34,9 @@ self.nodes[0].generatetoaddress( 10, self.nodes[0].get_deterministic_priv_key().address) assert os.path.isfile(os.path.join( - blocksdir_path, "regtest", "blocks", "blk00000.dat")) + blocksdir_path, self.chain, "blocks", "blk00000.dat")) assert os.path.isdir(os.path.join( - self.nodes[0].datadir, "regtest", "blocks", "index")) + self.nodes[0].datadir, self.chain, "blocks", "index")) if __name__ == '__main__': diff --git a/test/functional/interface_bitcoin_cli.py b/test/functional/interface_bitcoin_cli.py --- a/test/functional/interface_bitcoin_cli.py +++ b/test/functional/interface_bitcoin_cli.py @@ -39,7 +39,7 @@ rpc_response = self.nodes[0].getblockchaininfo() assert_equal(cli_response, rpc_response) - user, password = get_auth_cookie(self.nodes[0].datadir) + user, password = get_auth_cookie(self.nodes[0].datadir, self.chain) self.log.info("Test -stdinrpcpass option") assert_equal(0, self.nodes[0].cli( diff --git a/test/functional/rpc_bind.py b/test/functional/rpc_bind.py --- a/test/functional/rpc_bind.py +++ b/test/functional/rpc_bind.py @@ -67,7 +67,7 @@ self.nodes[0].host = None self.start_nodes([node_args]) # connect to node through non-loopback interface - url = rpc_url(self.nodes[0].datadir, rpchost, rpcport) + url = rpc_url(self.nodes[0].datadir, self.chain, rpchost, rpcport) node = get_rpc_proxy(url, 0, coveragedir=self.options.coveragedir) node.getnetworkinfo() self.stop_nodes() diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -75,6 +75,7 @@ def __init__(self): """Sets test framework defaults. Do not override this method. Instead, override the set_test_params() method""" + self.chain = 'regtest' self.setup_clean_chain = False self.nodes = [] self.network_thread = None @@ -280,7 +281,7 @@ # scripts. def add_nodes(self, num_nodes, extra_args=None, - *, rpchost=None, binary=None): + *, host=None, binary=None): """Instantiate TestNode objects. Should only be called once after the nodes have been specified in @@ -300,7 +301,8 @@ self.nodes.append(TestNode( i, get_datadir_path(self.options.tmpdir, i), - host=rpchost, + chain=self.chain, + host=host, rpc_port=rpc_port(i), p2p_port=p2p_port(i), timewait=self.rpc_timeout, @@ -455,10 +457,12 @@ # Create cache directories, run bitcoinds: for i in range(MAX_NODES): - datadir = initialize_datadir(self.options.cachedir, i) + datadir = initialize_datadir( + self.options.cachedir, i, self.chain) self.nodes.append(TestNode( i, get_datadir_path(self.options.cachedir, i), + chain=self.chain, extra_conf=["bind=127.0.0.1"], extra_args=[], host=None, @@ -516,7 +520,7 @@ def cache_path(n, *paths): return os.path.join(get_datadir_path( - self.options.cachedir, n), "regtest", *paths) + self.options.cachedir, n), self.chain, *paths) for i in range(MAX_NODES): # Remove empty wallets dir @@ -530,7 +534,7 @@ to_dir = get_datadir_path(self.options.tmpdir, i) shutil.copytree(from_dir, to_dir) # Overwrite port/rpcport in bitcoin.conf - initialize_datadir(self.options.tmpdir, i) + initialize_datadir(self.options.tmpdir, i, self.chain) def _initialize_chain_clean(self): """Initialize empty blockchain for use by the test. @@ -538,7 +542,7 @@ Create an empty blockchain and num_nodes wallets. Useful if a test case wants complete control over initialization.""" for i in range(self.num_nodes): - initialize_datadir(self.options.tmpdir, i) + initialize_datadir(self.options.tmpdir, i, self.chain) def skip_if_no_py3_zmq(self): """Attempt to import the zmq package and skip the test if the import fails.""" diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -57,13 +57,14 @@ To make things easier for the test writer, any unrecognised messages will be dispatched to the RPC connection.""" - def __init__(self, i, datadir, *, host, rpc_port, p2p_port, timewait, bitcoind, - bitcoin_cli, mocktime, coverage_dir, extra_conf=None, extra_args=None, use_cli=False, emulator=None): + def __init__(self, i, datadir, *, chain, host, rpc_port, p2p_port, timewait, bitcoind, bitcoin_cli, + mocktime, coverage_dir, extra_conf=None, extra_args=None, use_cli=False, emulator=None): self.index = i self.datadir = datadir self.bitcoinconf = os.path.join(self.datadir, "bitcoin.conf") self.stdout_dir = os.path.join(self.datadir, "stdout") self.stderr_dir = os.path.join(self.datadir, "stderr") + self.chain = chain self.host = host self.rpc_port = rpc_port self.p2p_port = p2p_port @@ -208,7 +209,7 @@ # Delete any existing cookie file -- if such a file exists (eg due to # unclean shutdown), it will get overwritten anyway by bitcoind, and # potentially interfere with our attempt to authenticate - delete_cookie_file(self.datadir) + delete_cookie_file(self.datadir, self.chain) # add environment variable LIBC_FATAL_STDERR_=1 so that libc errors are # written to stderr and not the terminal @@ -237,8 +238,15 @@ raise FailedToStartError(self._node_msg( 'bitcoind exited with status {} during initialization'.format(self.process.returncode))) try: - rpc = get_rpc_proxy(rpc_url(self.datadir, self.host, self.rpc_port), - self.index, timeout=self.rpc_timeout, coveragedir=self.coverage_dir) + rpc = get_rpc_proxy( + rpc_url( + self.datadir, + self.chain, + self.host, + self.rpc_port), + self.index, + timeout=self.rpc_timeout, + coveragedir=self.coverage_dir) rpc.getblockcount() # If the call to getblockcount() succeeds then the RPC # connection is up @@ -322,7 +330,7 @@ if unexpected_msgs is None: unexpected_msgs = [] time_end = time.time() + timeout - debug_log = os.path.join(self.datadir, 'regtest', 'debug.log') + debug_log = os.path.join(self.datadir, self.chain, 'debug.log') with open(debug_log, encoding='utf-8') as dl: dl.seek(0, 2) prev_size = dl.tell() diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -320,8 +320,8 @@ (MAX_NODES * PortSeed.n) % (PORT_RANGE - 1 - MAX_NODES) -def rpc_url(datadir, host, port): - rpc_u, rpc_p = get_auth_cookie(datadir) +def rpc_url(datadir, chain, host, port): + rpc_u, rpc_p = get_auth_cookie(datadir, chain) if host is None: host = '127.0.0.1' return "http://{}:{}@{}:{}".format(rpc_u, rpc_p, host, int(port)) @@ -330,13 +330,13 @@ ################ -def initialize_datadir(dirname, n): +def initialize_datadir(dirname, n, chain): datadir = get_datadir_path(dirname, n) if not os.path.isdir(datadir): os.makedirs(datadir) with open(os.path.join(datadir, "bitcoin.conf"), 'w', encoding='utf8') as f: - f.write("regtest=1\n") - f.write("[regtest]\n") + f.write("{}=1\n".format(chain)) + f.write("[{}]\n".format(chain)) f.write("port=" + str(p2p_port(n)) + "\n") f.write("rpcport=" + str(rpc_port(n)) + "\n") f.write("server=1\n") @@ -359,7 +359,7 @@ f.write(option + "\n") -def get_auth_cookie(datadir): +def get_auth_cookie(datadir, chain): user = None password = None if os.path.isfile(os.path.join(datadir, "bitcoin.conf")): @@ -372,7 +372,7 @@ assert password is None # Ensure that there is only one rpcpassword line password = line.split("=")[1].strip("\n") try: - with open(os.path.join(datadir, "regtest", ".cookie"), 'r', encoding="ascii") as f: + with open(os.path.join(datadir, chain, ".cookie"), 'r', encoding="ascii") as f: userpass = f.read() split_userpass = userpass.split(':') user = split_userpass[0] @@ -385,10 +385,10 @@ # If a cookie file exists in the given datadir, delete it. -def delete_cookie_file(datadir): - if os.path.isfile(os.path.join(datadir, "regtest", ".cookie")): +def delete_cookie_file(datadir, chain): + if os.path.isfile(os.path.join(datadir, chain, ".cookie")): logger.debug("Deleting leftover cookie file") - os.remove(os.path.join(datadir, "regtest", ".cookie")) + os.remove(os.path.join(datadir, chain, ".cookie")) def set_node_times(nodes, t):