Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_framework.py
Show All 40 Lines | class TestStatus(Enum): | ||||
FAILED = 2 | FAILED = 2 | ||||
SKIPPED = 3 | SKIPPED = 3 | ||||
TEST_EXIT_PASSED = 0 | TEST_EXIT_PASSED = 0 | ||||
TEST_EXIT_FAILED = 1 | TEST_EXIT_FAILED = 1 | ||||
TEST_EXIT_SKIPPED = 77 | TEST_EXIT_SKIPPED = 77 | ||||
# Timestamp is 01.01.2019 | |||||
TIMESTAMP_IN_THE_PAST = 1546300800 | |||||
class BitcoinTestFramework(): | class BitcoinTestFramework(): | ||||
"""Base class for a bitcoin test script. | """Base class for a bitcoin test script. | ||||
Individual bitcoin test scripts should subclass this class and override the set_test_params() and run_test() methods. | Individual bitcoin test scripts should subclass this class and override the set_test_params() and run_test() methods. | ||||
Individual tests can also override the following methods to customize the test setup: | Individual tests can also override the following methods to customize the test setup: | ||||
Show All 36 Lines | def main(self): | ||||
parser.add_argument("--coveragedir", dest="coveragedir", | parser.add_argument("--coveragedir", dest="coveragedir", | ||||
help="Write tested RPC commands into this directory") | help="Write tested RPC commands into this directory") | ||||
parser.add_argument("--configfile", dest="configfile", | parser.add_argument("--configfile", dest="configfile", | ||||
help="Location of the test framework config file") | help="Location of the test framework config file") | ||||
parser.add_argument("--pdbonfailure", dest="pdbonfailure", default=False, action="store_true", | parser.add_argument("--pdbonfailure", dest="pdbonfailure", default=False, action="store_true", | ||||
help="Attach a python debugger if test fails") | help="Attach a python debugger if test fails") | ||||
parser.add_argument("--usecli", dest="usecli", default=False, action="store_true", | parser.add_argument("--usecli", dest="usecli", default=False, action="store_true", | ||||
help="use bitcoin-cli instead of RPC for all commands") | help="use bitcoin-cli instead of RPC for all commands") | ||||
parser.add_argument("--with-greatwallactivation", dest="greatwallactivation", default=False, action="store_true", | |||||
help="Activate great wall update on timestamp {}".format(TIMESTAMP_IN_THE_PAST)) | |||||
self.add_options(parser) | self.add_options(parser) | ||||
self.options = parser.parse_args() | self.options = parser.parse_args() | ||||
self.set_test_params() | self.set_test_params() | ||||
assert hasattr( | assert hasattr( | ||||
self, "num_nodes"), "Test must set self.num_nodes in set_test_params()" | self, "num_nodes"), "Test must set self.num_nodes in set_test_params()" | ||||
PortSeed.n = self.options.port_seed | PortSeed.n = self.options.port_seed | ||||
▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | def add_nodes(self, num_nodes, extra_args=None, rpchost=None, timewait=None, binary=None): | ||||
extra_args = [[]] * num_nodes | extra_args = [[]] * num_nodes | ||||
if binary is None: | if binary is None: | ||||
binary = [None] * num_nodes | binary = [None] * num_nodes | ||||
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, self.options.tmpdir, extra_args[i], rpchost, rpc_port=rpc_port(i), p2p_port=p2p_port(i), | self.nodes.append(TestNode(i, self.options.tmpdir, extra_args[i], rpchost, rpc_port=rpc_port(i), p2p_port=p2p_port(i), | ||||
timewait=timewait, binary=binary[i], stderr=None, mocktime=self.mocktime, coverage_dir=self.options.coveragedir, use_cli=self.options.usecli)) | timewait=timewait, binary=binary[i], stderr=None, mocktime=self.mocktime, coverage_dir=self.options.coveragedir, use_cli=self.options.usecli)) | ||||
if self.options.greatwallactivation: | |||||
self.nodes[i].extend_default_args( | |||||
["-greatwallactivationtime={}".format(TIMESTAMP_IN_THE_PAST)]) | |||||
def start_node(self, i, *args, **kwargs): | def start_node(self, i, *args, **kwargs): | ||||
"""Start a bitcoind""" | """Start a bitcoind""" | ||||
node = self.nodes[i] | node = self.nodes[i] | ||||
node.start(*args, **kwargs) | node.start(*args, **kwargs) | ||||
node.wait_for_rpc_connection() | node.wait_for_rpc_connection() | ||||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | def _initialize_chain(self): | ||||
timewait=None, binary=None, stderr=None, mocktime=self.mocktime, coverage_dir=None)) | timewait=None, binary=None, stderr=None, mocktime=self.mocktime, coverage_dir=None)) | ||||
self.nodes[i].clear_default_args() | self.nodes[i].clear_default_args() | ||||
self.nodes[i].extend_default_args([ | self.nodes[i].extend_default_args([ | ||||
"-server", "-keypool=1", "-datadir=" + datadir, | "-server", "-keypool=1", "-datadir=" + datadir, | ||||
"-discover=0"]) | "-discover=0"]) | ||||
if i > 0: | if i > 0: | ||||
self.nodes[i].extend_default_args( | self.nodes[i].extend_default_args( | ||||
["-connect=127.0.0.1:" + str(p2p_port(0))]) | ["-connect=127.0.0.1:" + str(p2p_port(0))]) | ||||
if self.options.greatwallactivation: | |||||
self.nodes[i].extend_default_args( | |||||
["-greatwallactivationtime={}".format(TIMESTAMP_IN_THE_PAST)]) | |||||
self.start_node(i) | self.start_node(i) | ||||
# Wait for RPC connections to be ready | # Wait for RPC connections to be ready | ||||
for node in self.nodes: | for node in self.nodes: | ||||
node.wait_for_rpc_connection() | node.wait_for_rpc_connection() | ||||
# For backwared compatibility of the python scripts with previous | # For backwared compatibility of the python scripts with previous | ||||
# versions of the cache, set mocktime to Jan 1, | # versions of the cache, set mocktime to Jan 1, | ||||
▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines |