4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
"""Base class for RPC testing."""
6
6
7
+ import configparser
7
8
from enum import Enum
8
9
import logging
9
10
import optparse
@@ -97,10 +98,10 @@ def main(self):
97
98
help = "Leave bitcoinds and test.* datadir on exit or error" )
98
99
parser .add_option ("--noshutdown" , dest = "noshutdown" , default = False , action = "store_true" ,
99
100
help = "Don't stop bitcoinds after the test execution" )
100
- parser .add_option ("--srcdir" , dest = "srcdir" , default = os .path .normpath (os .path .dirname (os .path .realpath (__file__ )) + "/../../../src" ),
101
+ parser .add_option ("--srcdir" , dest = "srcdir" , default = os .path .abspath (os .path .dirname (os .path .realpath (__file__ )) + "/../../../src" ),
101
102
help = "Source directory containing bitcoind/bitcoin-cli (default: %default)" )
102
- parser .add_option ("--cachedir" , dest = "cachedir" , default = os .path .normpath (os .path .dirname (os .path .realpath (__file__ )) + "/../../cache" ),
103
- help = "Directory for caching pregenerated datadirs" )
103
+ parser .add_option ("--cachedir" , dest = "cachedir" , default = os .path .abspath (os .path .dirname (os .path .realpath (__file__ )) + "/../../cache" ),
104
+ help = "Directory for caching pregenerated datadirs (default: %default) " )
104
105
parser .add_option ("--tmpdir" , dest = "tmpdir" , help = "Root directory for datadirs" )
105
106
parser .add_option ("-l" , "--loglevel" , dest = "loglevel" , default = "INFO" ,
106
107
help = "log events at this level and higher to the console. Can be set to DEBUG, INFO, WARNING, ERROR or CRITICAL. Passing --loglevel DEBUG will output all logs to console. Note that logs at all levels are always written to the test_framework.log file in the temporary test directory." )
@@ -111,7 +112,8 @@ def main(self):
111
112
parser .add_option ("--coveragedir" , dest = "coveragedir" ,
112
113
help = "Write tested RPC commands into this directory" )
113
114
parser .add_option ("--configfile" , dest = "configfile" ,
114
- help = "Location of the test framework config file" )
115
+ default = os .path .abspath (os .path .dirname (os .path .realpath (__file__ )) + "/../../config.ini" ),
116
+ help = "Location of the test framework config file (default: %default)" )
115
117
parser .add_option ("--pdbonfailure" , dest = "pdbonfailure" , default = False , action = "store_true" ,
116
118
help = "Attach a python debugger if test fails" )
117
119
parser .add_option ("--usecli" , dest = "usecli" , default = False , action = "store_true" ,
@@ -129,6 +131,11 @@ def main(self):
129
131
130
132
self .options .cachedir = os .path .abspath (self .options .cachedir )
131
133
134
+ config = configparser .ConfigParser ()
135
+ config .read_file (open (self .options .configfile ))
136
+ self .options .bitcoind = os .getenv ("BITCOIND" , default = config ["environment" ]["BUILDDIR" ] + '/src/bitcoind' + config ["environment" ]["EXEEXT" ])
137
+ self .options .bitcoincli = os .getenv ("BITCOINCLI" , default = config ["environment" ]["BUILDDIR" ] + '/src/bitcoin-cli' + config ["environment" ]["EXEEXT" ])
138
+
132
139
# Set up temp directory and start logging
133
140
if self .options .tmpdir :
134
141
self .options .tmpdir = os .path .abspath (self .options .tmpdir )
@@ -246,12 +253,12 @@ def add_nodes(self, num_nodes, extra_args=None, rpchost=None, timewait=None, bin
246
253
if extra_args is None :
247
254
extra_args = [[]] * num_nodes
248
255
if binary is None :
249
- binary = [None ] * num_nodes
256
+ binary = [self . options . bitcoind ] * num_nodes
250
257
assert_equal (len (extra_confs ), num_nodes )
251
258
assert_equal (len (extra_args ), num_nodes )
252
259
assert_equal (len (binary ), num_nodes )
253
260
for i in range (num_nodes ):
254
- self .nodes .append (TestNode (i , get_datadir_path (self .options .tmpdir , i ), rpchost = rpchost , timewait = timewait , binary = binary [i ], stderr = None , mocktime = self .mocktime , coverage_dir = self .options .coveragedir , extra_conf = extra_confs [i ], extra_args = extra_args [i ], use_cli = self .options .usecli ))
261
+ self .nodes .append (TestNode (i , get_datadir_path (self .options .tmpdir , i ), rpchost = rpchost , timewait = timewait , bitcoind = binary [i ], bitcoin_cli = self . options . bitcoincli , stderr = None , mocktime = self .mocktime , coverage_dir = self .options .coveragedir , extra_conf = extra_confs [i ], extra_args = extra_args [i ], use_cli = self .options .usecli ))
255
262
256
263
def start_node (self , i , * args , ** kwargs ):
257
264
"""Start a bitcoind"""
@@ -399,10 +406,10 @@ def _initialize_chain(self):
399
406
# Create cache directories, run bitcoinds:
400
407
for i in range (MAX_NODES ):
401
408
datadir = initialize_datadir (self .options .cachedir , i )
402
- args = [os . getenv ( "BITCOIND" , " bitcoind" ) , "-datadir=" + datadir ]
409
+ args = [self . options . bitcoind , "-datadir=" + datadir ]
403
410
if i > 0 :
404
411
args .append ("-connect=127.0.0.1:" + str (p2p_port (0 )))
405
- self .nodes .append (TestNode (i , get_datadir_path (self .options .cachedir , i ), extra_conf = ["bind=127.0.0.1" ], extra_args = [],rpchost = None , timewait = None , binary = None , stderr = None , mocktime = self .mocktime , coverage_dir = None ))
412
+ self .nodes .append (TestNode (i , get_datadir_path (self .options .cachedir , i ), extra_conf = ["bind=127.0.0.1" ], extra_args = [], rpchost = None , timewait = None , bitcoind = self . options . bitcoind , bitcoin_cli = self . options . bitcoincli , stderr = None , mocktime = self .mocktime , coverage_dir = None ))
406
413
self .nodes [i ].args = args
407
414
self .start_node (i )
408
415
0 commit comments