mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
[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.
This commit is contained in:
parent
e92013e178
commit
61e77bb901
1 changed files with 18 additions and 0 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Reference in a new issue