Browse Source

[tests] Avoid passing around member variables in test_framework

Github-Pull: #11121
Rebased-From: 6cf094a022
0.15
John Newbery 7 years ago committed by MarcoFalke
parent
commit
bb5e7cb308
  1. 2
      test/functional/assumevalid.py
  2. 2
      test/functional/dbcrash.py
  3. 2
      test/functional/import-rescan.py
  4. 2
      test/functional/proxy_test.py
  5. 2
      test/functional/pruning.py
  6. 2
      test/functional/rpcbind_test.py
  7. 2
      test/functional/smartfees.py
  8. 50
      test/functional/test_framework/test_framework.py
  9. 2
      test/functional/wallet-dump.py
  10. 2
      test/functional/wallet.py
  11. 2
      test/functional/zmq_test.py

2
test/functional/assumevalid.py

@ -60,7 +60,7 @@ class AssumeValidTest(BitcoinTestFramework):
self.num_nodes = 3 self.num_nodes = 3
def setup_network(self): def setup_network(self):
self.add_nodes(3, self.options.tmpdir) self.add_nodes(3)
# Start node0. We don't start the other nodes yet since # Start node0. We don't start the other nodes yet since
# we need to pre-mine a block with an invalid transaction # we need to pre-mine a block with an invalid transaction
# signature so we can pass in the block hash as assumevalid. # signature so we can pass in the block hash as assumevalid.

2
test/functional/dbcrash.py

@ -65,7 +65,7 @@ class ChainstateWriteCrashTest(BitcoinTestFramework):
def setup_network(self): def setup_network(self):
# Need a bit of extra time for the nodes to start up for this test # Need a bit of extra time for the nodes to start up for this test
self.add_nodes(self.num_nodes, self.options.tmpdir, self.extra_args, timewait=90) self.add_nodes(self.num_nodes, timewait=90)
self.start_nodes() self.start_nodes()
# Leave them unconnected, we'll use submitblock directly in this test # Leave them unconnected, we'll use submitblock directly in this test

2
test/functional/import-rescan.py

@ -121,7 +121,7 @@ class ImportRescanTest(BitcoinTestFramework):
if import_node.prune: if import_node.prune:
extra_args[i] += ["-prune=1"] extra_args[i] += ["-prune=1"]
self.add_nodes(self.num_nodes, self.options.tmpdir, extra_args) self.add_nodes(self.num_nodes, extra_args)
self.start_nodes() self.start_nodes()
for i in range(1, self.num_nodes): for i in range(1, self.num_nodes):
connect_nodes(self.nodes[i], 0) connect_nodes(self.nodes[i], 0)

2
test/functional/proxy_test.py

@ -89,7 +89,7 @@ class ProxyTest(BitcoinTestFramework):
] ]
if self.have_ipv6: if self.have_ipv6:
args[3] = ['-listen', '-proxy=[%s]:%i' % (self.conf3.addr),'-proxyrandomize=0', '-noonion'] args[3] = ['-listen', '-proxy=[%s]:%i' % (self.conf3.addr),'-proxyrandomize=0', '-noonion']
self.add_nodes(self.num_nodes, self.options.tmpdir, extra_args=args) self.add_nodes(self.num_nodes, extra_args=args)
self.start_nodes() self.start_nodes()
def node_test(self, node, proxies, auth, test_onion=True): def node_test(self, node, proxies, auth, test_onion=True):

2
test/functional/pruning.py

@ -57,7 +57,7 @@ class PruneTest(BitcoinTestFramework):
sync_blocks(self.nodes[0:5]) sync_blocks(self.nodes[0:5])
def setup_nodes(self): def setup_nodes(self):
self.add_nodes(self.num_nodes, self.options.tmpdir, self.extra_args, timewait=900) self.add_nodes(self.num_nodes, self.extra_args, timewait=900)
self.start_nodes() self.start_nodes()
def create_big_chain(self): def create_big_chain(self):

2
test/functional/rpcbind_test.py

@ -20,7 +20,7 @@ class RPCBindTest(BitcoinTestFramework):
self.num_nodes = 1 self.num_nodes = 1
def setup_network(self): def setup_network(self):
self.add_nodes(self.num_nodes, self.options.tmpdir, None) self.add_nodes(self.num_nodes, None)
def run_bind_test(self, allow_ips, connect_to, addresses, expected): def run_bind_test(self, allow_ips, connect_to, addresses, expected):
''' '''

2
test/functional/smartfees.py

@ -153,7 +153,7 @@ class EstimateFeeTest(BitcoinTestFramework):
But first we need to use one node to create a lot of outputs But first we need to use one node to create a lot of outputs
which we will use to generate our transactions. which we will use to generate our transactions.
""" """
self.add_nodes(3, self.options.tmpdir, extra_args=[["-maxorphantx=1000", "-whitelist=127.0.0.1"], self.add_nodes(3, extra_args=[["-maxorphantx=1000", "-whitelist=127.0.0.1"],
["-blockmaxsize=17000", "-maxorphantx=1000"], ["-blockmaxsize=17000", "-maxorphantx=1000"],
["-blockmaxsize=8000", "-maxorphantx=1000"]]) ["-blockmaxsize=8000", "-maxorphantx=1000"]])
# Use node0 to mine blocks for input splitting # Use node0 to mine blocks for input splitting

50
test/functional/test_framework/test_framework.py

@ -73,9 +73,9 @@ class BitcoinTestFramework(object):
def setup_chain(self): def setup_chain(self):
self.log.info("Initializing test directory " + self.options.tmpdir) self.log.info("Initializing test directory " + self.options.tmpdir)
if self.setup_clean_chain: if self.setup_clean_chain:
self._initialize_chain_clean(self.options.tmpdir, self.num_nodes) self._initialize_chain_clean()
else: else:
self._initialize_chain(self.options.tmpdir, self.num_nodes, self.options.cachedir) self._initialize_chain()
def setup_network(self): def setup_network(self):
self.setup_nodes() self.setup_nodes()
@ -91,7 +91,7 @@ class BitcoinTestFramework(object):
extra_args = None extra_args = None
if hasattr(self, "extra_args"): if hasattr(self, "extra_args"):
extra_args = self.extra_args extra_args = self.extra_args
self.add_nodes(self.num_nodes, self.options.tmpdir, extra_args) self.add_nodes(self.num_nodes, extra_args)
self.start_nodes() self.start_nodes()
def run_test(self): def run_test(self):
@ -205,7 +205,7 @@ class BitcoinTestFramework(object):
# Public helper methods. These can be accessed by the subclass test scripts. # Public helper methods. These can be accessed by the subclass test scripts.
def add_nodes(self, num_nodes, dirname, extra_args=None, rpchost=None, timewait=None, binary=None): def add_nodes(self, num_nodes, extra_args=None, rpchost=None, timewait=None, binary=None):
"""Instantiate TestNode objects""" """Instantiate TestNode objects"""
if extra_args is None: if extra_args is None:
@ -215,7 +215,7 @@ class BitcoinTestFramework(object):
assert_equal(len(extra_args), num_nodes) assert_equal(len(extra_args), num_nodes)
assert_equal(len(binary), num_nodes) assert_equal(len(binary), num_nodes)
for i in range(num_nodes): for i in range(num_nodes):
self.nodes.append(TestNode(i, dirname, extra_args[i], rpchost, timewait=timewait, binary=binary[i], stderr=None, mocktime=self.mocktime, coverage_dir=self.options.coveragedir)) self.nodes.append(TestNode(i, self.options.tmpdir, extra_args[i], rpchost, timewait=timewait, binary=binary[i], stderr=None, mocktime=self.mocktime, coverage_dir=self.options.coveragedir))
def start_node(self, i, extra_args=None, stderr=None): def start_node(self, i, extra_args=None, stderr=None):
"""Start a bitcoind""" """Start a bitcoind"""
@ -357,16 +357,16 @@ class BitcoinTestFramework(object):
rpc_handler.setLevel(logging.DEBUG) rpc_handler.setLevel(logging.DEBUG)
rpc_logger.addHandler(rpc_handler) rpc_logger.addHandler(rpc_handler)
def _initialize_chain(self, test_dir, num_nodes, cachedir): def _initialize_chain(self):
"""Initialize a pre-mined blockchain for use by the test. """Initialize a pre-mined blockchain for use by the test.
Create a cache of a 200-block-long chain (with wallet) for MAX_NODES Create a cache of a 200-block-long chain (with wallet) for MAX_NODES
Afterward, create num_nodes copies from the cache.""" Afterward, create num_nodes copies from the cache."""
assert num_nodes <= MAX_NODES assert self.num_nodes <= MAX_NODES
create_cache = False create_cache = False
for i in range(MAX_NODES): for i in range(MAX_NODES):
if not os.path.isdir(os.path.join(cachedir, 'node' + str(i))): if not os.path.isdir(os.path.join(self.options.cachedir, 'node' + str(i))):
create_cache = True create_cache = True
break break
@ -375,16 +375,16 @@ class BitcoinTestFramework(object):
# find and delete old cache directories if any exist # find and delete old cache directories if any exist
for i in range(MAX_NODES): for i in range(MAX_NODES):
if os.path.isdir(os.path.join(cachedir, "node" + str(i))): if os.path.isdir(os.path.join(self.options.cachedir, "node" + str(i))):
shutil.rmtree(os.path.join(cachedir, "node" + str(i))) shutil.rmtree(os.path.join(self.options.cachedir, "node" + str(i)))
# Create cache directories, run bitcoinds: # Create cache directories, run bitcoinds:
for i in range(MAX_NODES): for i in range(MAX_NODES):
datadir = initialize_datadir(cachedir, i) datadir = initialize_datadir(self.options.cachedir, i)
args = [os.getenv("BITCOIND", "bitcoind"), "-server", "-keypool=1", "-datadir=" + datadir, "-discover=0"] args = [os.getenv("BITCOIND", "bitcoind"), "-server", "-keypool=1", "-datadir=" + datadir, "-discover=0"]
if i > 0: if i > 0:
args.append("-connect=127.0.0.1:" + str(p2p_port(0))) args.append("-connect=127.0.0.1:" + str(p2p_port(0)))
self.nodes.append(TestNode(i, cachedir, extra_args=[], rpchost=None, timewait=None, binary=None, stderr=None, mocktime=self.mocktime, coverage_dir=None)) self.nodes.append(TestNode(i, self.options.cachedir, extra_args=[], rpchost=None, timewait=None, binary=None, stderr=None, mocktime=self.mocktime, coverage_dir=None))
self.nodes[i].args = args self.nodes[i].args = args
self.start_node(i) self.start_node(i)
@ -415,24 +415,24 @@ class BitcoinTestFramework(object):
self.nodes = [] self.nodes = []
self.disable_mocktime() self.disable_mocktime()
for i in range(MAX_NODES): for i in range(MAX_NODES):
os.remove(log_filename(cachedir, i, "debug.log")) os.remove(log_filename(self.options.cachedir, i, "debug.log"))
os.remove(log_filename(cachedir, i, "db.log")) os.remove(log_filename(self.options.cachedir, i, "db.log"))
os.remove(log_filename(cachedir, i, "peers.dat")) os.remove(log_filename(self.options.cachedir, i, "peers.dat"))
os.remove(log_filename(cachedir, i, "fee_estimates.dat")) os.remove(log_filename(self.options.cachedir, i, "fee_estimates.dat"))
for i in range(num_nodes): for i in range(self.num_nodes):
from_dir = os.path.join(cachedir, "node" + str(i)) from_dir = os.path.join(self.options.cachedir, "node" + str(i))
to_dir = os.path.join(test_dir, "node" + str(i)) to_dir = os.path.join(self.options.tmpdir, "node" + str(i))
shutil.copytree(from_dir, to_dir) shutil.copytree(from_dir, to_dir)
initialize_datadir(test_dir, i) # Overwrite port/rpcport in bitcoin.conf initialize_datadir(self.options.tmpdir, i) # Overwrite port/rpcport in bitcoin.conf
def _initialize_chain_clean(self, test_dir, num_nodes): def _initialize_chain_clean(self):
"""Initialize empty blockchain for use by the test. """Initialize empty blockchain for use by the test.
Create an empty blockchain and num_nodes wallets. Create an empty blockchain and num_nodes wallets.
Useful if a test case wants complete control over initialization.""" Useful if a test case wants complete control over initialization."""
for i in range(num_nodes): for i in range(self.num_nodes):
initialize_datadir(test_dir, i) initialize_datadir(self.options.tmpdir, i)
class ComparisonTestFramework(BitcoinTestFramework): class ComparisonTestFramework(BitcoinTestFramework):
"""Test framework for doing p2p comparison testing """Test framework for doing p2p comparison testing
@ -459,7 +459,7 @@ class ComparisonTestFramework(BitcoinTestFramework):
extra_args = [['-whitelist=127.0.0.1']] * self.num_nodes extra_args = [['-whitelist=127.0.0.1']] * self.num_nodes
if hasattr(self, "extra_args"): if hasattr(self, "extra_args"):
extra_args = self.extra_args extra_args = self.extra_args
self.add_nodes(self.num_nodes, self.options.tmpdir, extra_args, self.add_nodes(self.num_nodes, extra_args,
binary=[self.options.testbinary] + binary=[self.options.testbinary] +
[self.options.refbinary] * (self.num_nodes - 1)) [self.options.refbinary] * (self.num_nodes - 1))
self.start_nodes() self.start_nodes()

2
test/functional/wallet-dump.py

@ -68,7 +68,7 @@ class WalletDumpTest(BitcoinTestFramework):
# longer than the default 30 seconds due to an expensive # longer than the default 30 seconds due to an expensive
# CWallet::TopUpKeyPool call, and the encryptwallet RPC made later in # CWallet::TopUpKeyPool call, and the encryptwallet RPC made later in
# the test often takes even longer. # the test often takes even longer.
self.add_nodes(self.num_nodes, self.options.tmpdir, self.extra_args, timewait=60) self.add_nodes(self.num_nodes, self.extra_args, timewait=60)
self.start_nodes() self.start_nodes()
def run_test (self): def run_test (self):

2
test/functional/wallet.py

@ -21,7 +21,7 @@ class WalletTest(BitcoinTestFramework):
self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)] self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)]
def setup_network(self): def setup_network(self):
self.add_nodes(4, self.options.tmpdir, self.extra_args) self.add_nodes(4, self.extra_args)
self.start_node(0) self.start_node(0)
self.start_node(1) self.start_node(1)
self.start_node(2) self.start_node(2)

2
test/functional/zmq_test.py

@ -42,7 +42,7 @@ class ZMQTest (BitcoinTestFramework):
ip_address = "tcp://127.0.0.1:28332" ip_address = "tcp://127.0.0.1:28332"
self.zmqSubSocket.connect(ip_address) self.zmqSubSocket.connect(ip_address)
self.extra_args = [['-zmqpubhashtx=%s' % ip_address, '-zmqpubhashblock=%s' % ip_address], []] self.extra_args = [['-zmqpubhashtx=%s' % ip_address, '-zmqpubhashblock=%s' % ip_address], []]
self.add_nodes(self.num_nodes, self.options.tmpdir, self.extra_args) self.add_nodes(self.num_nodes, self.extra_args)
self.start_nodes() self.start_nodes()
def run_test(self): def run_test(self):

Loading…
Cancel
Save