Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_framework.py
Show First 20 Lines • Show All 266 Lines • ▼ Show 20 Lines | def import_deterministic_coinbase_privkeys(self): | ||||
continue | continue | ||||
n.importprivkey(n.get_deterministic_priv_key()[1]) | 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, binary=None): | def add_nodes(self, num_nodes, extra_args=None, | ||||
*, rpchost=None, binary=None): | |||||
"""Instantiate TestNode objects. | """Instantiate TestNode objects. | ||||
Should only be called once after the nodes have been specified in | Should only be called once after the nodes have been specified in | ||||
set_test_params().""" | set_test_params().""" | ||||
if self.bind_to_localhost_only: | if self.bind_to_localhost_only: | ||||
extra_confs = [["bind=127.0.0.1"]] * num_nodes | extra_confs = [["bind=127.0.0.1"]] * num_nodes | ||||
else: | else: | ||||
extra_confs = [[]] * num_nodes | extra_confs = [[]] * num_nodes | ||||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | class BitcoinTestFramework(): | ||||
def sync_all(self, node_groups=None): | def sync_all(self, node_groups=None): | ||||
if not node_groups: | if not node_groups: | ||||
node_groups = [self.nodes] | node_groups = [self.nodes] | ||||
for group in node_groups: | for group in node_groups: | ||||
sync_blocks(group) | sync_blocks(group) | ||||
sync_mempools(group) | sync_mempools(group) | ||||
# Private helper methods. These should not be accessed by the subclass test scripts. | # Private helper methods. These should not be accessed by the subclass | ||||
# test scripts. | |||||
def _start_logging(self): | def _start_logging(self): | ||||
# Add logger and logging handlers | # Add logger and logging handlers | ||||
self.log = logging.getLogger('TestFramework') | self.log = logging.getLogger('TestFramework') | ||||
self.log.setLevel(logging.DEBUG) | self.log.setLevel(logging.DEBUG) | ||||
# Create file handler to log all messages | # Create file handler to log all messages | ||||
fh = logging.FileHandler( | fh = logging.FileHandler( | ||||
self.options.tmpdir + '/test_framework.log', encoding='utf-8') | self.options.tmpdir + '/test_framework.log', encoding='utf-8') | ||||
fh.setLevel(logging.DEBUG) | fh.setLevel(logging.DEBUG) | ||||
# Create console handler to log messages to stderr. By default this | # Create console handler to log messages to stderr. By default this | ||||
# logs only error messages, but can be configured with --loglevel. | # logs only error messages, but can be configured with --loglevel. | ||||
ch = logging.StreamHandler(sys.stdout) | ch = logging.StreamHandler(sys.stdout) | ||||
# User can provide log level as a number or string (eg DEBUG). loglevel | # User can provide log level as a number or string (eg DEBUG). loglevel | ||||
# was caught as a string, so try to convert it to an int | # was caught as a string, so try to convert it to an int | ||||
ll = int(self.options.loglevel) if self.options.loglevel.isdigit( | ll = int(self.options.loglevel) if self.options.loglevel.isdigit( | ||||
) else self.options.loglevel.upper() | ) else self.options.loglevel.upper() | ||||
ch.setLevel(ll) | ch.setLevel(ll) | ||||
# Format logs the same as bitcoind's debug.log with microprecision (so log files can be concatenated and sorted) | # Format logs the same as bitcoind's debug.log with microprecision (so | ||||
# log files can be concatenated and sorted) | |||||
formatter = logging.Formatter( | formatter = logging.Formatter( | ||||
fmt='%(asctime)s.%(msecs)03d000Z %(name)s (%(levelname)s): %(message)s', datefmt='%Y-%m-%dT%H:%M:%S') | fmt='%(asctime)s.%(msecs)03d000Z %(name)s (%(levelname)s): %(message)s', datefmt='%Y-%m-%dT%H:%M:%S') | ||||
formatter.converter = time.gmtime | formatter.converter = time.gmtime | ||||
fh.setFormatter(formatter) | fh.setFormatter(formatter) | ||||
ch.setFormatter(formatter) | ch.setFormatter(formatter) | ||||
# add the handlers to the logger | # add the handlers to the logger | ||||
self.log.addHandler(fh) | self.log.addHandler(fh) | ||||
self.log.addHandler(ch) | self.log.addHandler(ch) | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | def _initialize_chain(self): | ||||
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 | # Remove empty wallets dir | ||||
os.rmdir(cache_path(i, 'wallets')) | 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 ['chainstate', 'blocks']: | if entry not in ['chainstate', 'blocks']: | ||||
os.remove(cache_path(i, entry)) | os.remove(cache_path(i, entry)) | ||||
▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines |