diff --git a/test/functional/abc-cmdline.py b/test/functional/abc-cmdline.py --- a/test/functional/abc-cmdline.py +++ b/test/functional/abc-cmdline.py @@ -12,8 +12,6 @@ import re from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( - start_node, - stop_node, assert_equal, assert_start_raises_init_error ) @@ -48,16 +46,16 @@ self.log.info(" Set to twice the default, i.e. %d bytes" % (2 * LEGACY_MAX_BLOCK_SIZE)) - stop_node(self.nodes[0], 0) - self.nodes[0] = start_node(0, self.options.tmpdir, [ - "-excessiveblocksize=%d" % (2 * LEGACY_MAX_BLOCK_SIZE)]) + self.stop_node(0) + self.nodes[0] = self.start_node(0, self.options.tmpdir, [ + "-excessiveblocksize=%d" % (2 * LEGACY_MAX_BLOCK_SIZE)]) self.check_excessive(2 * LEGACY_MAX_BLOCK_SIZE) # Check for EB correctness in the subver string self.check_subversion("/Bitcoin ABC:.*\(EB2\.0; .*\)/") self.log.info(" Attempt to set below legacy limit of 1MB - try %d bytes" % LEGACY_MAX_BLOCK_SIZE) - stop_node(self.nodes[0], 0) + self.stop_node(0) assert_start_raises_init_error(0, self.options.tmpdir, [ "-excessiveblocksize=%d" % LEGACY_MAX_BLOCK_SIZE], 'Error: Excessive block size must be > 1,000,000 bytes (1MB)') self.log.info(" Attempt to set below blockmaxsize (mining limit)") @@ -66,7 +64,7 @@ # Make sure we leave the test with a node running as this is what thee # framework expects. - self.nodes[0] = start_node(0, self.options.tmpdir, []) + self.nodes[0] = self.start_node(0, self.options.tmpdir, []) def run_test(self): # Run tests on -excessiveblocksize option diff --git a/test/functional/fundrawtransaction.py b/test/functional/fundrawtransaction.py --- a/test/functional/fundrawtransaction.py +++ b/test/functional/fundrawtransaction.py @@ -459,10 +459,10 @@ # # locked wallet test - self.nodes[1].encryptwallet("test") self.stop_node(0) self.stop_node(2) self.stop_node(3) + self.nodes[1].encryptwallet("test") self.nodes.pop(1) self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir) diff --git a/test/functional/high_priority_transaction.py b/test/functional/high_priority_transaction.py --- a/test/functional/high_priority_transaction.py +++ b/test/functional/high_priority_transaction.py @@ -79,9 +79,9 @@ assert_equal(self.nodes[0].getmempoolinfo()['bytes'], mempool_size_pre) # restart with default blockprioritypercentage - stop_nodes(self.nodes) - self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, - [["-limitfreerelay=2"]]) + self.stop_nodes() + self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir, + [["-limitfreerelay=2"]]) # second test step: default reserved prio space in block (100K). # the mempool size is about 25K this means that all txns will be diff --git a/test/functional/mempool-accept-txn.py b/test/functional/mempool-accept-txn.py --- a/test/functional/mempool-accept-txn.py +++ b/test/functional/mempool-accept-txn.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# Copyright (c) 2015-2016 The Bitcoin Core developers # Copyright (c) 2017 The Bitcoin developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -50,9 +49,9 @@ def setup_network(self): self.extra_args = [['-norelaypriority']] - self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, - self.extra_args, - binary=[self.options.testbinary]) + self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir, + self.extra_args, + binary=[self.options.testbinary]) def add_options(self, parser): super().add_options(parser) diff --git a/test/functional/net.py b/test/functional/net.py --- a/test/functional/net.py +++ b/test/functional/net.py @@ -14,7 +14,8 @@ assert_equal, assert_raises_jsonrpc, connect_nodes_bi, - p2p_port) + p2p_port, +) class NetTest(BitcoinTestFramework): diff --git a/test/functional/p2p-mempool.py b/test/functional/p2p-mempool.py --- a/test/functional/p2p-mempool.py +++ b/test/functional/p2p-mempool.py @@ -13,11 +13,8 @@ def __init__(self): super().__init__() self.setup_clean_chain = True - self.num_nodes = 2 - - def setup_network(self): - self.nodes = [start_node(0, self.options.tmpdir, [ - "-peerbloomfilters=0"])] + self.num_nodes = 1 + self.extra_args = [["-peerbloomfilters=0"]] def run_test(self): # connect a mininode diff --git a/test/functional/rpcnamedargs.py b/test/functional/rpcnamedargs.py --- a/test/functional/rpcnamedargs.py +++ b/test/functional/rpcnamedargs.py @@ -12,8 +12,6 @@ assert_raises_jsonrpc, assert_is_hex_string, assert_is_hash_string, - start_nodes, - connect_nodes_bi, ) 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 @@ -33,10 +33,10 @@ p2p_port, rpc_url, set_node_times, - start_node, - start_nodes, - stop_node, - stop_nodes, + _start_node, + _start_nodes, + _stop_node, + _stop_nodes, sync_blocks, sync_mempools, wait_for_bitcoind_start, @@ -105,7 +105,7 @@ extra_args = None if hasattr(self, "extra_args"): extra_args = self.extra_args - self.nodes = start_nodes( + self.nodes = _start_nodes( self.num_nodes, self.options.tmpdir, extra_args) def run_test(self): @@ -232,16 +232,16 @@ # Public helper methods. These can be accessed by the subclass test scripts. def start_node(self, i, dirname, extra_args=None, rpchost=None, timewait=None, binary=None, stderr=None): - return start_node(i, dirname, extra_args, rpchost, timewait, binary, stderr) + return _start_node(i, dirname, extra_args, rpchost, timewait, binary, stderr) def start_nodes(self, num_nodes, dirname, extra_args=None, rpchost=None, timewait=None, binary=None): - return start_nodes(num_nodes, dirname, extra_args, rpchost, timewait, binary) + return _start_nodes(num_nodes, dirname, extra_args, rpchost, timewait, binary) def stop_node(self, num_node): - stop_node(self.nodes[num_node], num_node) + _stop_node(self.nodes[num_node], num_node) def stop_nodes(self): - stop_nodes(self.nodes) + _stop_nodes(self.nodes) def split_network(self): """ 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 @@ -302,10 +302,11 @@ return bitcoind_binary -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. - """ +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 + + This function should only be called from within test_framework, not by individual test scripts.""" + datadir = os.path.join(dirname, "node" + str(i)) if binary is None: binary = locate_bitcoind_binary() @@ -329,8 +330,8 @@ 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) + 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: @@ -347,12 +348,15 @@ raise AssertionError(assert_msg) -def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, timewait=None, binary=None): - """ - Start multiple bitcoinds, return RPC connections to them - """ +def _start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, timewait=None, binary=None): + """Start multiple bitcoinds, return RPC connections to them + + This function should only be called from within test_framework, not by individual test scripts.""" + if extra_args is None: extra_args = [None for _ in range(num_nodes)] + if binary is None: + binary = [None for _ in range(num_nodes)] assert_equal(len(extra_args), num_nodes) if binary is None: binary = [None for _ in range(num_nodes)] @@ -360,11 +364,10 @@ rpcs = [] try: for i in range(num_nodes): - rpcs.append(start_node(i, dirname, extra_args[i], - rpchost, timewait=timewait, - binary=binary[i])) + rpcs.append(_start_node( + i, dirname, extra_args[i], rpchost, timewait=timewait, binary=binary[i])) except: # If one node failed to start, stop the others - stop_nodes(rpcs) + _stop_nodes(rpcs) raise return rpcs @@ -373,7 +376,11 @@ return os.path.join(dirname, "node" + str(n_node), "regtest", logname) -def stop_node(node, i): +def _stop_node(node, i): + """Stop a bitcoind test node + + This function should only be called from within test_framework, not by individual test scripts.""" + logger.debug("Stopping node %d" % i) try: node.stop() @@ -385,9 +392,13 @@ del bitcoind_processes[i] -def stop_nodes(nodes): +def _stop_nodes(nodes): + """Stop multiple bitcoind test nodes + + This function should only be called from within test_framework, not by individual test scripts.""" + for i, node in enumerate(nodes): - stop_node(node, i) + _stop_node(node, i) assert not bitcoind_processes.values() # All connections must be gone now diff --git a/test/functional/zmq_test.py b/test/functional/zmq_test.py --- a/test/functional/zmq_test.py +++ b/test/functional/zmq_test.py @@ -13,7 +13,6 @@ from test_framework.util import ( assert_equal, bytes_to_hex_str, - start_nodes, )