Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_framework.py
Show First 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | def main(self): | ||||
success = TestStatus.FAILED | success = TestStatus.FAILED | ||||
try: | try: | ||||
if self.options.usecli and not self.supports_cli: | if self.options.usecli and not self.supports_cli: | ||||
raise SkipTest( | raise SkipTest( | ||||
"--usecli specified but test does not support using CLI") | "--usecli specified but test does not support using CLI") | ||||
self.setup_chain() | self.setup_chain() | ||||
self.setup_network() | self.setup_network() | ||||
self.import_deterministic_coinbase_privkeys() | |||||
self.run_test() | self.run_test() | ||||
success = TestStatus.PASSED | success = TestStatus.PASSED | ||||
except JSONRPCException: | except JSONRPCException: | ||||
self.log.exception("JSONRPC error") | self.log.exception("JSONRPC error") | ||||
except SkipTest as e: | except SkipTest as e: | ||||
self.log.warning("Test Skipped: {}".format(e.message)) | self.log.warning("Test Skipped: {}".format(e.message)) | ||||
success = TestStatus.SKIPPED | success = TestStatus.SKIPPED | ||||
except AssertionError: | except AssertionError: | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | class BitcoinTestFramework(): | ||||
def setup_nodes(self): | def setup_nodes(self): | ||||
"""Override this method to customize test node setup""" | """Override this method to customize test node setup""" | ||||
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, extra_args) | self.add_nodes(self.num_nodes, extra_args) | ||||
self.start_nodes() | self.start_nodes() | ||||
def import_deterministic_coinbase_privkeys(self): | |||||
if self.setup_clean_chain: | |||||
return | |||||
for n in self.nodes: | |||||
try: | |||||
n.getwalletinfo() | |||||
except JSONRPCException as e: | |||||
assert str(e).startswith('Method not found') | |||||
continue | |||||
n.importprivkey(n.get_deterministic_priv_key()[1]) | |||||
def run_test(self): | def run_test(self): | ||||
"""Tests must override this method to define test logic""" | """Tests must override this method to define test logic""" | ||||
raise NotImplementedError | raise NotImplementedError | ||||
# 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, 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""" | ||||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | def _initialize_chain(self): | ||||
# 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(self.options.cachedir, i) | datadir = initialize_datadir(self.options.cachedir, i) | ||||
self.nodes.append(TestNode(i, get_datadir_path(self.options.cachedir, i), extra_conf=["bind=127.0.0.1"], extra_args=[], host=None, rpc_port=rpc_port( | self.nodes.append(TestNode(i, get_datadir_path(self.options.cachedir, i), extra_conf=["bind=127.0.0.1"], extra_args=[], host=None, rpc_port=rpc_port( | ||||
i), p2p_port=p2p_port(i), timewait=None, bitcoind=self.options.bitcoind, bitcoin_cli=self.options.bitcoincli, mocktime=self.mocktime, coverage_dir=None)) | i), p2p_port=p2p_port(i), timewait=None, bitcoind=self.options.bitcoind, bitcoin_cli=self.options.bitcoincli, mocktime=self.mocktime, coverage_dir=None)) | ||||
self.nodes[i].clear_default_args() | self.nodes[i].clear_default_args() | ||||
self.nodes[i].extend_default_args(["-datadir=" + datadir]) | self.nodes[i].extend_default_args(["-datadir=" + datadir]) | ||||
self.nodes[i].extend_default_args(["-disablewallet"]) | |||||
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.gravitonactivation: | if self.options.gravitonactivation: | ||||
self.nodes[i].extend_default_args( | self.nodes[i].extend_default_args( | ||||
["-gravitonactivationtime={}".format(TIMESTAMP_IN_THE_PAST)]) | ["-gravitonactivationtime={}".format(TIMESTAMP_IN_THE_PAST)]) | ||||
self.start_node(i) | self.start_node(i) | ||||
Show All 13 Lines | def _initialize_chain(self): | ||||
# | # | ||||
# blocks are created with timestamps 10 minutes apart | # blocks are created with timestamps 10 minutes apart | ||||
# starting from 2010 minutes in the past | # starting from 2010 minutes in the past | ||||
block_time = self.mocktime - (201 * 10 * 60) | block_time = self.mocktime - (201 * 10 * 60) | ||||
for i in range(2): | for i in range(2): | ||||
for peer in range(4): | for peer in range(4): | ||||
for j in range(25): | for j in range(25): | ||||
set_node_times(self.nodes, block_time) | set_node_times(self.nodes, block_time) | ||||
self.nodes[peer].generate(1) | self.nodes[peer].generatetoaddress( | ||||
1, self.nodes[peer].get_deterministic_priv_key()[0]) | |||||
block_time += 10 * 60 | block_time += 10 * 60 | ||||
# Must sync before next peer starts generating blocks | # Must sync before next peer starts generating blocks | ||||
sync_blocks(self.nodes) | sync_blocks(self.nodes) | ||||
# Shut them down, and clean up cache directories: | # Shut them down, and clean up cache directories: | ||||
self.stop_nodes() | self.stop_nodes() | ||||
self.nodes = [] | self.nodes = [] | ||||
self.mocktime = 0 | self.mocktime = 0 | ||||
def cache_path(n, *paths): | def cache_path(n, *paths): | ||||
return os.path.join(get_datadir_path(self.options.cachedir, n), "regtest", *paths) | return os.path.join(get_datadir_path(self.options.cachedir, n), "regtest", *paths) | ||||
for i in range(MAX_NODES): | for i in range(MAX_NODES): | ||||
# Remove empty wallets dir | |||||
os.rmdir(cache_path(i, 'wallets')) | |||||
for entry in os.listdir(cache_path(i)): | for entry in os.listdir(cache_path(i)): | ||||
if entry not in ['wallets', 'chainstate', 'blocks']: | if entry not in ['chainstate', 'blocks']: | ||||
os.remove(cache_path(i, entry)) | os.remove(cache_path(i, entry)) | ||||
for i in range(self.num_nodes): | for i in range(self.num_nodes): | ||||
from_dir = get_datadir_path(self.options.cachedir, i) | from_dir = get_datadir_path(self.options.cachedir, i) | ||||
to_dir = get_datadir_path(self.options.tmpdir, i) | to_dir = get_datadir_path(self.options.tmpdir, i) | ||||
shutil.copytree(from_dir, to_dir) | shutil.copytree(from_dir, to_dir) | ||||
# Overwrite port/rpcport in bitcoin.conf | # Overwrite port/rpcport in bitcoin.conf | ||||
initialize_datadir(self.options.tmpdir, i) | initialize_datadir(self.options.tmpdir, i) | ||||
Show All 32 Lines |