Skip to content

Commit fab0d85

Browse files
author
MarcoFalke
committed
qa: Remove mocktime unless required
1 parent 3e4fd40 commit fab0d85

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

test/functional/rpc_blockchain.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from test_framework.blocktools import (
3636
create_block,
3737
create_coinbase,
38+
TIME_GENESIS_BLOCK,
3839
)
3940
from test_framework.messages import (
4041
msg_block,
@@ -46,9 +47,11 @@
4647

4748
class BlockchainTest(BitcoinTestFramework):
4849
def set_test_params(self):
50+
self.setup_clean_chain = True
4951
self.num_nodes = 1
5052

5153
def run_test(self):
54+
self.mine_chain()
5255
self.restart_node(0, extra_args=['-stopatheight=207', '-prune=1']) # Set extra args with pruning after rescan is complete
5356

5457
self._test_getblockchaininfo()
@@ -61,6 +64,15 @@ def run_test(self):
6164
self._test_waitforblockheight()
6265
assert self.nodes[0].verifychain(4, 0)
6366

67+
def mine_chain(self):
68+
self.log.info('Create some old blocks')
69+
address = self.nodes[0].get_deterministic_priv_key().address
70+
for t in range(TIME_GENESIS_BLOCK, TIME_GENESIS_BLOCK + 200 * 600, 600):
71+
# ten-minute steps from genesis block time
72+
self.nodes[0].setmocktime(t)
73+
self.nodes[0].generatetoaddress(1, address)
74+
assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 200)
75+
6476
def _test_getblockchaininfo(self):
6577
self.log.info("Test getblockchaininfo")
6678

test/functional/test_framework/test_framework.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
get_datadir_path,
3030
initialize_datadir,
3131
p2p_port,
32-
set_node_times,
3332
sync_blocks,
3433
sync_mempools,
3534
)
3635

36+
3737
class TestStatus(Enum):
3838
PASSED = 1
3939
FAILED = 2
@@ -94,7 +94,6 @@ def __init__(self):
9494
self.setup_clean_chain = False
9595
self.nodes = []
9696
self.network_thread = None
97-
self.mocktime = 0
9897
self.rpc_timeout = 60 # Wait for up to 60 seconds for the RPC server to respond
9998
self.supports_cli = False
10099
self.bind_to_localhost_only = True
@@ -316,7 +315,6 @@ def add_nodes(self, num_nodes, extra_args=None, *, rpchost=None, binary=None):
316315
timewait=self.rpc_timeout,
317316
bitcoind=binary[i],
318317
bitcoin_cli=self.options.bitcoincli,
319-
mocktime=self.mocktime,
320318
coverage_dir=self.options.coveragedir,
321319
cwd=self.options.tmpdir,
322320
extra_conf=extra_confs[i],
@@ -468,7 +466,6 @@ def _initialize_chain(self):
468466
timewait=self.rpc_timeout,
469467
bitcoind=self.options.bitcoind,
470468
bitcoin_cli=self.options.bitcoincli,
471-
mocktime=self.mocktime,
472469
coverage_dir=None,
473470
cwd=self.options.tmpdir,
474471
))
@@ -479,32 +476,18 @@ def _initialize_chain(self):
479476
for node in self.nodes:
480477
node.wait_for_rpc_connection()
481478

482-
# For backward compatibility of the python scripts with previous
483-
# versions of the cache, set mocktime to Jan 1,
484-
# 2014 + (201 * 10 * 60)"""
485-
self.mocktime = 1388534400 + (201 * 10 * 60)
486-
487479
# Create a 200-block-long chain; each of the 4 first nodes
488480
# gets 25 mature blocks and 25 immature.
489-
# Note: To preserve compatibility with older versions of
490-
# initialize_chain, only 4 nodes will generate coins.
491-
#
492-
# blocks are created with timestamps 10 minutes apart
493-
# starting from 2010 minutes in the past
494-
block_time = self.mocktime - (201 * 10 * 60)
495481
for i in range(2):
496482
for peer in range(4):
497483
for j in range(25):
498-
set_node_times(self.nodes, block_time)
499484
self.nodes[peer].generatetoaddress(1, self.nodes[peer].get_deterministic_priv_key().address)
500-
block_time += 10 * 60
501485
# Must sync before next peer starts generating blocks
502486
sync_blocks(self.nodes)
503487

504488
# Shut them down, and clean up cache directories:
505489
self.stop_nodes()
506490
self.nodes = []
507-
self.mocktime = 0
508491

509492
def cache_path(n, *paths):
510493
return os.path.join(get_datadir_path(self.options.cachedir, n), "regtest", *paths)

test/functional/test_framework/test_node.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class TestNode():
6161
To make things easier for the test writer, any unrecognised messages will
6262
be dispatched to the RPC connection."""
6363

64-
def __init__(self, i, datadir, *, rpchost, timewait, bitcoind, bitcoin_cli, mocktime, coverage_dir, cwd, extra_conf=None, extra_args=None, use_cli=False, start_perf=False):
64+
def __init__(self, i, datadir, *, rpchost, timewait, bitcoind, bitcoin_cli, coverage_dir, cwd, extra_conf=None, extra_args=None, use_cli=False, start_perf=False):
6565
"""
6666
Kwargs:
6767
start_perf (bool): If True, begin profiling the node with `perf` as soon as
@@ -90,8 +90,7 @@ def __init__(self, i, datadir, *, rpchost, timewait, bitcoind, bitcoin_cli, mock
9090
"-debug",
9191
"-debugexclude=libevent",
9292
"-debugexclude=leveldb",
93-
"-mocktime=" + str(mocktime),
94-
"-uacomment=testnode%d" % i
93+
"-uacomment=testnode%d" % i,
9594
]
9695

9796
self.cli = TestNodeCLI(bitcoin_cli, self.datadir)

test/functional/wallet_create_tx.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,25 @@
77
from test_framework.util import (
88
assert_equal,
99
)
10+
from test_framework.blocktools import (
11+
TIME_GENESIS_BLOCK,
12+
)
1013

1114

1215
class CreateTxWalletTest(BitcoinTestFramework):
1316
def set_test_params(self):
14-
self.setup_clean_chain = False
17+
self.setup_clean_chain = True
1518
self.num_nodes = 1
1619

1720
def skip_test_if_missing_module(self):
1821
self.skip_if_no_wallet()
1922

2023
def run_test(self):
24+
self.log.info('Create some old blocks')
25+
self.nodes[0].setmocktime(TIME_GENESIS_BLOCK)
26+
self.nodes[0].generate(200)
27+
self.nodes[0].setmocktime(0)
28+
2129
self.log.info('Check that we have some (old) blocks and that anti-fee-sniping is disabled')
2230
assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 200)
2331
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)

0 commit comments

Comments
 (0)