Skip to content

Commit 0d473c5

Browse files
committed
[tests] move mocktime property and functions to BitcoinTestFramework
1 parent cad967a commit 0d473c5

File tree

4 files changed

+22
-30
lines changed

4 files changed

+22
-30
lines changed

test/functional/listtransactions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self):
2323

2424
def setup_nodes(self):
2525
#This test requires mocktime
26-
enable_mocktime()
26+
self.enable_mocktime()
2727
self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir)
2828

2929
def run_test(self):

test/functional/receivedby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(self):
3131

3232
def setup_nodes(self):
3333
#This test requires mocktime
34-
enable_mocktime()
34+
self.enable_mocktime()
3535
self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir)
3636

3737
def run_test(self):

test/functional/test_framework/test_framework.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@
2626
assert_equal,
2727
check_json_precision,
2828
connect_nodes_bi,
29-
disable_mocktime,
3029
disconnect_nodes,
31-
enable_mocktime,
32-
get_mocktime,
3330
get_rpc_proxy,
3431
initialize_datadir,
3532
get_datadir_path,
@@ -73,6 +70,7 @@ def __init__(self):
7370
self.setup_clean_chain = False
7471
self.nodes = []
7572
self.bitcoind_processes = {}
73+
self.mocktime = 0
7674

7775
def add_options(self, parser):
7876
pass
@@ -211,7 +209,7 @@ def start_node(self, i, dirname, extra_args=None, rpchost=None, timewait=None, b
211209
datadir = os.path.join(dirname, "node" + str(i))
212210
if binary is None:
213211
binary = os.getenv("BITCOIND", "bitcoind")
214-
args = [binary, "-datadir=" + datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-logtimemicros", "-debug", "-debugexclude=libevent", "-debugexclude=leveldb", "-mocktime=" + str(get_mocktime()), "-uacomment=testnode%d" % i]
212+
args = [binary, "-datadir=" + datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-logtimemicros", "-debug", "-debugexclude=libevent", "-debugexclude=leveldb", "-mocktime=" + str(self.mocktime), "-uacomment=testnode%d" % i]
215213
if extra_args is not None:
216214
args.extend(extra_args)
217215
self.bitcoind_processes[i] = subprocess.Popen(args, stderr=stderr)
@@ -312,6 +310,21 @@ def sync_all(self, node_groups=None):
312310
sync_blocks(group)
313311
sync_mempools(group)
314312

313+
def enable_mocktime(self):
314+
"""Enable mocktime for the script.
315+
316+
mocktime may be needed for scripts that use the cached version of the
317+
blockchain. If the cached version of the blockchain is used without
318+
mocktime then the mempools will not sync due to IBD.
319+
320+
For backwared compatibility of the python scripts with previous
321+
versions of the cache, this helper function sets mocktime to Jan 1,
322+
2014 + (201 * 10 * 60)"""
323+
self.mocktime = 1388534400 + (201 * 10 * 60)
324+
325+
def disable_mocktime(self):
326+
self.mocktime = 0
327+
315328
# Private helper methods. These should not be accessed by the subclass test scripts.
316329

317330
def _start_logging(self):
@@ -389,8 +402,8 @@ def _initialize_chain(self, test_dir, num_nodes, cachedir):
389402
#
390403
# blocks are created with timestamps 10 minutes apart
391404
# starting from 2010 minutes in the past
392-
enable_mocktime()
393-
block_time = get_mocktime() - (201 * 10 * 60)
405+
self.enable_mocktime()
406+
block_time = self.mocktime - (201 * 10 * 60)
394407
for i in range(2):
395408
for peer in range(4):
396409
for j in range(25):
@@ -403,7 +416,7 @@ def _initialize_chain(self, test_dir, num_nodes, cachedir):
403416
# Shut them down, and clean up cache directories:
404417
self.stop_nodes()
405418
self.nodes = []
406-
disable_mocktime()
419+
self.disable_mocktime()
407420
for i in range(MAX_NODES):
408421
os.remove(log_filename(cachedir, i, "debug.log"))
409422
os.remove(log_filename(cachedir, i, "db.log"))

test/functional/test_framework/util.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,6 @@ class PortSeed:
3030
# Must be initialized with a unique integer for each process
3131
n = None
3232

33-
# Set Mocktime default to OFF.
34-
# MOCKTIME is only needed for scripts that use the
35-
# cached version of the blockchain. If the cached
36-
# version of the blockchain is used without MOCKTIME
37-
# then the mempools will not sync due to IBD.
38-
MOCKTIME = 0
39-
40-
def enable_mocktime():
41-
# For backwared compatibility of the python scripts
42-
# with previous versions of the cache, set MOCKTIME
43-
# to Jan 1, 2014 + (201 * 10 * 60)
44-
global MOCKTIME
45-
MOCKTIME = 1388534400 + (201 * 10 * 60)
46-
47-
def disable_mocktime():
48-
global MOCKTIME
49-
MOCKTIME = 0
50-
51-
def get_mocktime():
52-
return MOCKTIME
53-
5433
def get_rpc_proxy(url, node_number, timeout=None, coveragedir=None):
5534
"""
5635
Args:

0 commit comments

Comments
 (0)