@@ -73,9 +73,9 @@ def add_options(self, parser):
73
73
def setup_chain (self ):
74
74
self .log .info ("Initializing test directory " + self .options .tmpdir )
75
75
if self .setup_clean_chain :
76
- self ._initialize_chain_clean (self . options . tmpdir , self . num_nodes )
76
+ self ._initialize_chain_clean ()
77
77
else :
78
- self ._initialize_chain (self . options . tmpdir , self . num_nodes , self . options . cachedir )
78
+ self ._initialize_chain ()
79
79
80
80
def setup_network (self ):
81
81
self .setup_nodes ()
@@ -91,7 +91,7 @@ def setup_nodes(self):
91
91
extra_args = None
92
92
if hasattr (self , "extra_args" ):
93
93
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 )
95
95
self .start_nodes ()
96
96
97
97
def run_test (self ):
@@ -205,7 +205,7 @@ def main(self):
205
205
206
206
# Public helper methods. These can be accessed by the subclass test scripts.
207
207
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 ):
209
209
"""Instantiate TestNode objects"""
210
210
211
211
if extra_args is None :
@@ -215,7 +215,7 @@ def add_nodes(self, num_nodes, dirname, extra_args=None, rpchost=None, timewait=
215
215
assert_equal (len (extra_args ), num_nodes )
216
216
assert_equal (len (binary ), num_nodes )
217
217
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 ))
219
219
220
220
def start_node (self , i , extra_args = None , stderr = None ):
221
221
"""Start a bitcoind"""
@@ -357,16 +357,16 @@ def _start_logging(self):
357
357
rpc_handler .setLevel (logging .DEBUG )
358
358
rpc_logger .addHandler (rpc_handler )
359
359
360
- def _initialize_chain (self , test_dir , num_nodes , cachedir ):
360
+ def _initialize_chain (self ):
361
361
"""Initialize a pre-mined blockchain for use by the test.
362
362
363
363
Create a cache of a 200-block-long chain (with wallet) for MAX_NODES
364
364
Afterward, create num_nodes copies from the cache."""
365
365
366
- assert num_nodes <= MAX_NODES
366
+ assert self . num_nodes <= MAX_NODES
367
367
create_cache = False
368
368
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 ))):
370
370
create_cache = True
371
371
break
372
372
@@ -375,16 +375,16 @@ def _initialize_chain(self, test_dir, num_nodes, cachedir):
375
375
376
376
# find and delete old cache directories if any exist
377
377
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 )))
380
380
381
381
# Create cache directories, run bitcoinds:
382
382
for i in range (MAX_NODES ):
383
- datadir = initialize_datadir (cachedir , i )
383
+ datadir = initialize_datadir (self . options . cachedir , i )
384
384
args = [os .getenv ("BITCOIND" , "bitcoind" ), "-server" , "-keypool=1" , "-datadir=" + datadir , "-discover=0" ]
385
385
if i > 0 :
386
386
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 ))
388
388
self .nodes [i ].args = args
389
389
self .start_node (i )
390
390
@@ -415,24 +415,24 @@ def _initialize_chain(self, test_dir, num_nodes, cachedir):
415
415
self .nodes = []
416
416
self .disable_mocktime ()
417
417
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 ))
426
426
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
428
428
429
- def _initialize_chain_clean (self , test_dir , num_nodes ):
429
+ def _initialize_chain_clean (self ):
430
430
"""Initialize empty blockchain for use by the test.
431
431
432
432
Create an empty blockchain and num_nodes wallets.
433
433
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 )
436
436
437
437
class ComparisonTestFramework (BitcoinTestFramework ):
438
438
"""Test framework for doing p2p comparison testing
@@ -459,7 +459,7 @@ def setup_network(self):
459
459
extra_args = [['-whitelist=127.0.0.1' ]] * self .num_nodes
460
460
if hasattr (self , "extra_args" ):
461
461
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 ,
463
463
binary = [self .options .testbinary ] +
464
464
[self .options .refbinary ] * (self .num_nodes - 1 ))
465
465
self .start_nodes ()
0 commit comments