Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_framework.py
Show First 20 Lines • Show All 343 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) | ||||
def enable_mocktime(self): | |||||
"""Enable mocktime for the script. | |||||
mocktime may be needed for scripts that use the cached version of the | |||||
blockchain. If the cached version of the blockchain is used without | |||||
mocktime then the mempools will not sync due to IBD. | |||||
For backwared compatibility of the python scripts with previous | |||||
versions of the cache, this helper function sets mocktime to Jan 1, | |||||
2014 + (201 * 10 * 60)""" | |||||
self.mocktime = 1388534400 + (201 * 10 * 60) | |||||
def disable_mocktime(self): | |||||
self.mocktime = 0 | |||||
# 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(self.options.tmpdir + '/test_framework.log') | fh = logging.FileHandler(self.options.tmpdir + '/test_framework.log') | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | def _initialize_chain(self): | ||||
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))]) | ||||
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 | |||||
# versions of the cache, set mocktime to Jan 1, | |||||
# 2014 + (201 * 10 * 60) | |||||
self.mocktime = 1388534400 + (201 * 10 * 60) | |||||
# Create a 200-block-long chain; each of the 4 first nodes | # Create a 200-block-long chain; each of the 4 first nodes | ||||
# gets 25 mature blocks and 25 immature. | # gets 25 mature blocks and 25 immature. | ||||
# Note: To preserve compatibility with older versions of | # Note: To preserve compatibility with older versions of | ||||
# initialize_chain, only 4 nodes will generate coins. | # initialize_chain, only 4 nodes will generate coins. | ||||
# | # | ||||
# 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 | ||||
self.enable_mocktime() | |||||
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].generate(1) | ||||
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.disable_mocktime() | self.mocktime = 0 | ||||
for i in range(MAX_NODES): | for i in range(MAX_NODES): | ||||
os.remove(log_filename(self.options.cachedir, i, "debug.log")) | os.remove(log_filename(self.options.cachedir, i, "debug.log")) | ||||
os.remove(log_filename( | os.remove(log_filename( | ||||
self.options.cachedir, i, "wallets/db.log")) | self.options.cachedir, i, "wallets/db.log")) | ||||
os.remove(log_filename(self.options.cachedir, i, "peers.dat")) | 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 = os.path.join(self.options.cachedir, "node" + str(i)) | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |