Skip to content

Commit 6cf094a

Browse files
committed
[tests] Avoid passing around member variables in test_framework
1 parent 36b6268 commit 6cf094a

File tree

11 files changed

+37
-37
lines changed

11 files changed

+37
-37
lines changed

test/functional/assumevalid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __init__(self):
6060
self.num_nodes = 3
6161

6262
def setup_network(self):
63-
self.add_nodes(3, self.options.tmpdir)
63+
self.add_nodes(3)
6464
# Start node0. We don't start the other nodes yet since
6565
# we need to pre-mine a block with an invalid transaction
6666
# signature so we can pass in the block hash as assumevalid.

test/functional/dbcrash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(self):
6565

6666
def setup_network(self):
6767
# Need a bit of extra time for the nodes to start up for this test
68-
self.add_nodes(self.num_nodes, self.options.tmpdir, self.extra_args, timewait=90)
68+
self.add_nodes(self.num_nodes, timewait=90)
6969
self.start_nodes()
7070
# Leave them unconnected, we'll use submitblock directly in this test
7171

test/functional/import-rescan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def setup_network(self):
121121
if import_node.prune:
122122
extra_args[i] += ["-prune=1"]
123123

124-
self.add_nodes(self.num_nodes, self.options.tmpdir, extra_args)
124+
self.add_nodes(self.num_nodes, extra_args)
125125
self.start_nodes()
126126
for i in range(1, self.num_nodes):
127127
connect_nodes(self.nodes[i], 0)

test/functional/proxy_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def setup_nodes(self):
8989
]
9090
if self.have_ipv6:
9191
args[3] = ['-listen', '-proxy=[%s]:%i' % (self.conf3.addr),'-proxyrandomize=0', '-noonion']
92-
self.add_nodes(self.num_nodes, self.options.tmpdir, extra_args=args)
92+
self.add_nodes(self.num_nodes, extra_args=args)
9393
self.start_nodes()
9494

9595
def node_test(self, node, proxies, auth, test_onion=True):

test/functional/pruning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def setup_network(self):
5757
sync_blocks(self.nodes[0:5])
5858

5959
def setup_nodes(self):
60-
self.add_nodes(self.num_nodes, self.options.tmpdir, self.extra_args, timewait=900)
60+
self.add_nodes(self.num_nodes, self.extra_args, timewait=900)
6161
self.start_nodes()
6262

6363
def create_big_chain(self):

test/functional/rpcbind_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self):
2020
self.num_nodes = 1
2121

2222
def setup_network(self):
23-
self.add_nodes(self.num_nodes, self.options.tmpdir, None)
23+
self.add_nodes(self.num_nodes, None)
2424

2525
def run_bind_test(self, allow_ips, connect_to, addresses, expected):
2626
'''

test/functional/smartfees.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ def setup_network(self):
153153
But first we need to use one node to create a lot of outputs
154154
which we will use to generate our transactions.
155155
"""
156-
self.add_nodes(3, self.options.tmpdir, extra_args=[["-maxorphantx=1000", "-whitelist=127.0.0.1"],
157-
["-blockmaxsize=17000", "-maxorphantx=1000"],
158-
["-blockmaxsize=8000", "-maxorphantx=1000"]])
156+
self.add_nodes(3, extra_args=[["-maxorphantx=1000", "-whitelist=127.0.0.1"],
157+
["-blockmaxsize=17000", "-maxorphantx=1000"],
158+
["-blockmaxsize=8000", "-maxorphantx=1000"]])
159159
# Use node0 to mine blocks for input splitting
160160
# Node1 mines small blocks but that are bigger than the expected transaction rate.
161161
# NOTE: the CreateNewBlock code starts counting block size at 1,000 bytes,

test/functional/test_framework/test_framework.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ def add_options(self, parser):
7373
def setup_chain(self):
7474
self.log.info("Initializing test directory " + self.options.tmpdir)
7575
if self.setup_clean_chain:
76-
self._initialize_chain_clean(self.options.tmpdir, self.num_nodes)
76+
self._initialize_chain_clean()
7777
else:
78-
self._initialize_chain(self.options.tmpdir, self.num_nodes, self.options.cachedir)
78+
self._initialize_chain()
7979

8080
def setup_network(self):
8181
self.setup_nodes()
@@ -91,7 +91,7 @@ def setup_nodes(self):
9191
extra_args = None
9292
if hasattr(self, "extra_args"):
9393
extra_args = self.extra_args
94-
self.add_nodes(self.num_nodes, self.options.tmpdir, extra_args)
94+
self.add_nodes(self.num_nodes, extra_args)
9595
self.start_nodes()
9696

9797
def run_test(self):
@@ -205,7 +205,7 @@ def main(self):
205205

206206
# Public helper methods. These can be accessed by the subclass test scripts.
207207

208-
def add_nodes(self, num_nodes, dirname, extra_args=None, rpchost=None, timewait=None, binary=None):
208+
def add_nodes(self, num_nodes, extra_args=None, rpchost=None, timewait=None, binary=None):
209209
"""Instantiate TestNode objects"""
210210

211211
if extra_args is None:
@@ -215,7 +215,7 @@ def add_nodes(self, num_nodes, dirname, extra_args=None, rpchost=None, timewait=
215215
assert_equal(len(extra_args), num_nodes)
216216
assert_equal(len(binary), num_nodes)
217217
for i in range(num_nodes):
218-
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))
218+
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))
219219

220220
def start_node(self, i, extra_args=None, stderr=None):
221221
"""Start a bitcoind"""
@@ -357,16 +357,16 @@ def _start_logging(self):
357357
rpc_handler.setLevel(logging.DEBUG)
358358
rpc_logger.addHandler(rpc_handler)
359359

360-
def _initialize_chain(self, test_dir, num_nodes, cachedir):
360+
def _initialize_chain(self):
361361
"""Initialize a pre-mined blockchain for use by the test.
362362
363363
Create a cache of a 200-block-long chain (with wallet) for MAX_NODES
364364
Afterward, create num_nodes copies from the cache."""
365365

366-
assert num_nodes <= MAX_NODES
366+
assert self.num_nodes <= MAX_NODES
367367
create_cache = False
368368
for i in range(MAX_NODES):
369-
if not os.path.isdir(os.path.join(cachedir, 'node' + str(i))):
369+
if not os.path.isdir(os.path.join(self.options.cachedir, 'node' + str(i))):
370370
create_cache = True
371371
break
372372

@@ -375,16 +375,16 @@ def _initialize_chain(self, test_dir, num_nodes, cachedir):
375375

376376
# find and delete old cache directories if any exist
377377
for i in range(MAX_NODES):
378-
if os.path.isdir(os.path.join(cachedir, "node" + str(i))):
379-
shutil.rmtree(os.path.join(cachedir, "node" + str(i)))
378+
if os.path.isdir(os.path.join(self.options.cachedir, "node" + str(i))):
379+
shutil.rmtree(os.path.join(self.options.cachedir, "node" + str(i)))
380380

381381
# Create cache directories, run bitcoinds:
382382
for i in range(MAX_NODES):
383-
datadir = initialize_datadir(cachedir, i)
383+
datadir = initialize_datadir(self.options.cachedir, i)
384384
args = [os.getenv("BITCOIND", "bitcoind"), "-server", "-keypool=1", "-datadir=" + datadir, "-discover=0"]
385385
if i > 0:
386386
args.append("-connect=127.0.0.1:" + str(p2p_port(0)))
387-
self.nodes.append(TestNode(i, cachedir, extra_args=[], rpchost=None, timewait=None, binary=None, stderr=None, mocktime=self.mocktime, coverage_dir=None))
387+
self.nodes.append(TestNode(i, self.options.cachedir, extra_args=[], rpchost=None, timewait=None, binary=None, stderr=None, mocktime=self.mocktime, coverage_dir=None))
388388
self.nodes[i].args = args
389389
self.start_node(i)
390390

@@ -415,24 +415,24 @@ def _initialize_chain(self, test_dir, num_nodes, cachedir):
415415
self.nodes = []
416416
self.disable_mocktime()
417417
for i in range(MAX_NODES):
418-
os.remove(log_filename(cachedir, i, "debug.log"))
419-
os.remove(log_filename(cachedir, i, "db.log"))
420-
os.remove(log_filename(cachedir, i, "peers.dat"))
421-
os.remove(log_filename(cachedir, i, "fee_estimates.dat"))
422-
423-
for i in range(num_nodes):
424-
from_dir = os.path.join(cachedir, "node" + str(i))
425-
to_dir = os.path.join(test_dir, "node" + str(i))
418+
os.remove(log_filename(self.options.cachedir, i, "debug.log"))
419+
os.remove(log_filename(self.options.cachedir, i, "db.log"))
420+
os.remove(log_filename(self.options.cachedir, i, "peers.dat"))
421+
os.remove(log_filename(self.options.cachedir, i, "fee_estimates.dat"))
422+
423+
for i in range(self.num_nodes):
424+
from_dir = os.path.join(self.options.cachedir, "node" + str(i))
425+
to_dir = os.path.join(self.options.tmpdir, "node" + str(i))
426426
shutil.copytree(from_dir, to_dir)
427-
initialize_datadir(test_dir, i) # Overwrite port/rpcport in bitcoin.conf
427+
initialize_datadir(self.options.tmpdir, i) # Overwrite port/rpcport in bitcoin.conf
428428

429-
def _initialize_chain_clean(self, test_dir, num_nodes):
429+
def _initialize_chain_clean(self):
430430
"""Initialize empty blockchain for use by the test.
431431
432432
Create an empty blockchain and num_nodes wallets.
433433
Useful if a test case wants complete control over initialization."""
434-
for i in range(num_nodes):
435-
initialize_datadir(test_dir, i)
434+
for i in range(self.num_nodes):
435+
initialize_datadir(self.options.tmpdir, i)
436436

437437
class ComparisonTestFramework(BitcoinTestFramework):
438438
"""Test framework for doing p2p comparison testing
@@ -459,7 +459,7 @@ def setup_network(self):
459459
extra_args = [['-whitelist=127.0.0.1']] * self.num_nodes
460460
if hasattr(self, "extra_args"):
461461
extra_args = self.extra_args
462-
self.add_nodes(self.num_nodes, self.options.tmpdir, extra_args,
462+
self.add_nodes(self.num_nodes, extra_args,
463463
binary=[self.options.testbinary] +
464464
[self.options.refbinary] * (self.num_nodes - 1))
465465
self.start_nodes()

test/functional/wallet-dump.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def setup_network(self, split=False):
6868
# longer than the default 30 seconds due to an expensive
6969
# CWallet::TopUpKeyPool call, and the encryptwallet RPC made later in
7070
# the test often takes even longer.
71-
self.add_nodes(self.num_nodes, self.options.tmpdir, self.extra_args, timewait=60)
71+
self.add_nodes(self.num_nodes, self.extra_args, timewait=60)
7272
self.start_nodes()
7373

7474
def run_test (self):

test/functional/wallet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self):
2121
self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)]
2222

2323
def setup_network(self):
24-
self.add_nodes(4, self.options.tmpdir, self.extra_args)
24+
self.add_nodes(4, self.extra_args)
2525
self.start_node(0)
2626
self.start_node(1)
2727
self.start_node(2)

0 commit comments

Comments
 (0)