[tests] move mocktime property and functions to BitcoinTestFramework
This commit is contained in:
parent
cad967a892
commit
0d473c539e
4 changed files with 22 additions and 30 deletions
|
@ -23,7 +23,7 @@ class ListTransactionsTest(BitcoinTestFramework):
|
||||||
|
|
||||||
def setup_nodes(self):
|
def setup_nodes(self):
|
||||||
#This test requires mocktime
|
#This test requires mocktime
|
||||||
enable_mocktime()
|
self.enable_mocktime()
|
||||||
self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir)
|
self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir)
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
|
|
|
@ -31,7 +31,7 @@ class ReceivedByTest(BitcoinTestFramework):
|
||||||
|
|
||||||
def setup_nodes(self):
|
def setup_nodes(self):
|
||||||
#This test requires mocktime
|
#This test requires mocktime
|
||||||
enable_mocktime()
|
self.enable_mocktime()
|
||||||
self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir)
|
self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir)
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
|
|
|
@ -26,10 +26,7 @@ from .util import (
|
||||||
assert_equal,
|
assert_equal,
|
||||||
check_json_precision,
|
check_json_precision,
|
||||||
connect_nodes_bi,
|
connect_nodes_bi,
|
||||||
disable_mocktime,
|
|
||||||
disconnect_nodes,
|
disconnect_nodes,
|
||||||
enable_mocktime,
|
|
||||||
get_mocktime,
|
|
||||||
get_rpc_proxy,
|
get_rpc_proxy,
|
||||||
initialize_datadir,
|
initialize_datadir,
|
||||||
get_datadir_path,
|
get_datadir_path,
|
||||||
|
@ -73,6 +70,7 @@ class BitcoinTestFramework(object):
|
||||||
self.setup_clean_chain = False
|
self.setup_clean_chain = False
|
||||||
self.nodes = []
|
self.nodes = []
|
||||||
self.bitcoind_processes = {}
|
self.bitcoind_processes = {}
|
||||||
|
self.mocktime = 0
|
||||||
|
|
||||||
def add_options(self, parser):
|
def add_options(self, parser):
|
||||||
pass
|
pass
|
||||||
|
@ -211,7 +209,7 @@ class BitcoinTestFramework(object):
|
||||||
datadir = os.path.join(dirname, "node" + str(i))
|
datadir = os.path.join(dirname, "node" + str(i))
|
||||||
if binary is None:
|
if binary is None:
|
||||||
binary = os.getenv("BITCOIND", "bitcoind")
|
binary = os.getenv("BITCOIND", "bitcoind")
|
||||||
args = [binary, "-datadir=" + datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-logtimemicros", "-debug", "-debugexclude=libevent", "-debugexclude=leveldb", "-mocktime=" + str(get_mocktime()), "-uacomment=testnode%d" % i]
|
args = [binary, "-datadir=" + datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-logtimemicros", "-debug", "-debugexclude=libevent", "-debugexclude=leveldb", "-mocktime=" + str(self.mocktime), "-uacomment=testnode%d" % i]
|
||||||
if extra_args is not None:
|
if extra_args is not None:
|
||||||
args.extend(extra_args)
|
args.extend(extra_args)
|
||||||
self.bitcoind_processes[i] = subprocess.Popen(args, stderr=stderr)
|
self.bitcoind_processes[i] = subprocess.Popen(args, stderr=stderr)
|
||||||
|
@ -312,6 +310,21 @@ class BitcoinTestFramework(object):
|
||||||
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):
|
||||||
|
@ -389,8 +402,8 @@ class BitcoinTestFramework(object):
|
||||||
#
|
#
|
||||||
# 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
|
||||||
enable_mocktime()
|
self.enable_mocktime()
|
||||||
block_time = get_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):
|
||||||
|
@ -403,7 +416,7 @@ class BitcoinTestFramework(object):
|
||||||
# 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 = []
|
||||||
disable_mocktime()
|
self.disable_mocktime()
|
||||||
for i in range(MAX_NODES):
|
for i in range(MAX_NODES):
|
||||||
os.remove(log_filename(cachedir, i, "debug.log"))
|
os.remove(log_filename(cachedir, i, "debug.log"))
|
||||||
os.remove(log_filename(cachedir, i, "db.log"))
|
os.remove(log_filename(cachedir, i, "db.log"))
|
||||||
|
|
|
@ -30,27 +30,6 @@ class PortSeed:
|
||||||
# Must be initialized with a unique integer for each process
|
# Must be initialized with a unique integer for each process
|
||||||
n = None
|
n = None
|
||||||
|
|
||||||
# Set Mocktime default to OFF.
|
|
||||||
# MOCKTIME is only 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.
|
|
||||||
MOCKTIME = 0
|
|
||||||
|
|
||||||
def enable_mocktime():
|
|
||||||
# For backwared compatibility of the python scripts
|
|
||||||
# with previous versions of the cache, set MOCKTIME
|
|
||||||
# to Jan 1, 2014 + (201 * 10 * 60)
|
|
||||||
global MOCKTIME
|
|
||||||
MOCKTIME = 1388534400 + (201 * 10 * 60)
|
|
||||||
|
|
||||||
def disable_mocktime():
|
|
||||||
global MOCKTIME
|
|
||||||
MOCKTIME = 0
|
|
||||||
|
|
||||||
def get_mocktime():
|
|
||||||
return MOCKTIME
|
|
||||||
|
|
||||||
def get_rpc_proxy(url, node_number, timeout=None, coveragedir=None):
|
def get_rpc_proxy(url, node_number, timeout=None, coveragedir=None):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
|
|
Loading…
Reference in a new issue