aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework
diff options
context:
space:
mode:
authorglozow <gloriajzhao@gmail.com>2023-08-11 16:51:39 +0200
committerglozow <gloriajzhao@gmail.com>2023-08-14 15:53:33 +0100
commit61e77bb901bca038b46064dc4531e12c2ab50673 (patch)
treeaa0966e10c7a3232492c0da36154812ef0582efe /test/functional/test_framework
parente92013e178727429fdf81ef180efffdad9f0ff5a (diff)
[test framework] make it easier to fast-forward setmocktime
Have each TestNode keep track of the last timestamp it called setmocktime with, and add a bumpmocktime() function to bump by a number of seconds. Makes it easy to fast forward n seconds without keeping track of what the last timestamp was.
Diffstat (limited to 'test/functional/test_framework')
-rwxr-xr-xtest/functional/test_framework/test_node.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py
index 0615a430fd..db02b15e37 100755
--- a/test/functional/test_framework/test_node.py
+++ b/test/functional/test_framework/test_node.py
@@ -144,6 +144,8 @@ class TestNode():
self.p2ps = []
self.timeout_factor = timeout_factor
+ self.mocktime = None
+
AddressKeyPair = collections.namedtuple('AddressKeyPair', ['address', 'key'])
PRIV_KEYS = [
# address , privkey
@@ -324,6 +326,15 @@ class TestNode():
assert not invalid_call
return self.__getattr__('generatetodescriptor')(*args, **kwargs)
+ def setmocktime(self, timestamp):
+ """Wrapper for setmocktime RPC, sets self.mocktime"""
+ if timestamp == 0:
+ # setmocktime(0) resets to system time.
+ self.mocktime = None
+ else:
+ self.mocktime = timestamp
+ return self.__getattr__('setmocktime')(timestamp)
+
def get_wallet_rpc(self, wallet_name):
if self.use_cli:
return RPCOverloadWrapper(self.cli("-rpcwallet={}".format(wallet_name)), True, self.descriptors)
@@ -699,6 +710,13 @@ class TestNode():
wait_until_helper(lambda: self.num_test_p2p_connections() == 0, timeout_factor=self.timeout_factor)
+ def bumpmocktime(self, seconds):
+ """Fast forward using setmocktime to self.mocktime + seconds. Requires setmocktime to have
+ been called at some point in the past."""
+ assert self.mocktime
+ self.mocktime += seconds
+ self.setmocktime(self.mocktime)
+
class TestNodeCLIAttr:
def __init__(self, cli, command):