Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_framework.py
Show First 20 Lines • Show All 342 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, mocktime): | def enable_mocktime(self): | ||||
"""Enable mocktime for the script. | """Enable mocktime for the script. | ||||
mocktime may be needed for scripts that use the cached version of the | mocktime may be needed for scripts that use the cached version of the | ||||
blockchain. If the cached version of the blockchain is used without | blockchain. If the cached version of the blockchain is used without | ||||
mocktime then the mempools will not sync due to IBD. | mocktime then the mempools will not sync due to IBD. | ||||
""" | |||||
if self.mocktime == 0: | For backwared compatibility of the python scripts with previous | ||||
self.mocktime = mocktime | versions of the cache, this helper function sets mocktime to Jan 1, | ||||
else: | 2014 + (201 * 10 * 60)""" | ||||
self.log.warning("mocktime overriden by test.") | self.mocktime = 1388534400 + (201 * 10 * 60) | ||||
def disable_mocktime(self): | def disable_mocktime(self): | ||||
self.mocktime = 0 | 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 | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | def _initialize_chain(self): | ||||
# 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(int(time.time()) - (201 * 10 * 60)) | self.enable_mocktime() | ||||
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, self.mocktime) | set_node_times(self.nodes, block_time) | ||||
self.nodes[peer].generate(1) | self.nodes[peer].generate(1) | ||||
self.mocktime += 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.disable_mocktime() | ||||
for i in range(MAX_NODES): | for i in range(MAX_NODES): | ||||
▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines |