Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_framework.py
Show All 17 Lines | |||||
from .authproxy import JSONRPCException | from .authproxy import JSONRPCException | ||||
from . import coverage | from . import coverage | ||||
from .test_node import TestNode | from .test_node import TestNode | ||||
from .util import ( | from .util import ( | ||||
assert_equal, | assert_equal, | ||||
check_json_precision, | check_json_precision, | ||||
connect_nodes_bi, | connect_nodes_bi, | ||||
disconnect_nodes, | disconnect_nodes, | ||||
get_datadir_path, | |||||
initialize_datadir, | initialize_datadir, | ||||
log_filename, | |||||
MAX_NODES, | MAX_NODES, | ||||
p2p_port, | p2p_port, | ||||
PortSeed, | PortSeed, | ||||
rpc_port, | rpc_port, | ||||
set_node_times, | set_node_times, | ||||
sync_blocks, | sync_blocks, | ||||
sync_mempools, | sync_mempools, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 358 Lines • ▼ Show 20 Lines | def _initialize_chain(self): | ||||
"""Initialize a pre-mined blockchain for use by the test. | """Initialize a pre-mined blockchain for use by the test. | ||||
Create a cache of a 200-block-long chain (with wallet) for MAX_NODES | Create a cache of a 200-block-long chain (with wallet) for MAX_NODES | ||||
Afterward, create num_nodes copies from the cache.""" | Afterward, create num_nodes copies from the cache.""" | ||||
assert self.num_nodes <= MAX_NODES | assert self.num_nodes <= MAX_NODES | ||||
create_cache = False | create_cache = False | ||||
for i in range(MAX_NODES): | for i in range(MAX_NODES): | ||||
if not os.path.isdir(os.path.join(self.options.cachedir, 'node' + str(i))): | if not os.path.isdir(get_datadir_path(self.options.cachedir, i)): | ||||
create_cache = True | create_cache = True | ||||
break | break | ||||
if create_cache: | if create_cache: | ||||
self.log.debug("Creating data directories from cached datadir") | self.log.debug("Creating data directories from cached datadir") | ||||
# find and delete old cache directories if any exist | # find and delete old cache directories if any exist | ||||
for i in range(MAX_NODES): | for i in range(MAX_NODES): | ||||
if os.path.isdir(os.path.join(self.options.cachedir, "node" + str(i))): | if os.path.isdir(get_datadir_path(self.options.cachedir, i)): | ||||
shutil.rmtree(os.path.join( | shutil.rmtree(get_datadir_path(self.options.cachedir, i)) | ||||
self.options.cachedir, "node" + str(i))) | |||||
# 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, self.options.cachedir, extra_args=[], host=None, rpc_port=rpc_port(i), p2p_port=p2p_port(i), | self.nodes.append(TestNode(i, self.options.cachedir, extra_args=[], host=None, rpc_port=rpc_port(i), p2p_port=p2p_port(i), | ||||
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([ | ||||
Show All 32 Lines | def _initialize_chain(self): | ||||
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): | |||||
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): | ||||
os.remove(log_filename(self.options.cachedir, i, "debug.log")) | for entry in os.listdir(cache_path(i)): | ||||
os.remove(log_filename( | if entry not in ['wallets', 'chainstate', 'blocks']: | ||||
self.options.cachedir, i, "wallets/db.log")) | os.remove(cache_path(i, entry)) | ||||
os.remove(log_filename(self.options.cachedir, i, "peers.dat")) | |||||
for i in range(self.num_nodes): | for i in range(self.num_nodes): | ||||
from_dir = os.path.join(self.options.cachedir, "node" + str(i)) | from_dir = get_datadir_path(self.options.cachedir, i) | ||||
to_dir = os.path.join(self.options.tmpdir, "node" + str(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) | ||||
def _initialize_chain_clean(self): | def _initialize_chain_clean(self): | ||||
"""Initialize empty blockchain for use by the test. | """Initialize empty blockchain for use by the test. | ||||
Create an empty blockchain and num_nodes wallets. | Create an empty blockchain and num_nodes wallets. | ||||
Show All 40 Lines |