Skip to content

Commit c54295c

Browse files
author
MarcoFalke
committed
Merge #18641: test: Create cached blocks not in the future
fa32097 test: Create cached blocks not in the future (MarcoFalke) Pull request description: This avoids test failures when tests assume blocks are not from the future, like in wallet_dump: https://cirrus-ci.com/task/6607130193035264?command=ci#L3306 ACKs for top commit: jonatack: ACK fa32097 Tree-SHA512: 60b6882e0e1df8c5d67f034533407a45d3685983891b67ff4631072bfd0a93a325c7ca18758d7a2df252e4fcdb7c87321cb1e84458b22782e57e719eec634c22
2 parents d7bdba4 + fa32097 commit c54295c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

test/functional/test_framework/test_framework.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,13 @@ def _initialize_chain(self):
549549
cwd=self.options.tmpdir,
550550
))
551551
self.start_node(CACHE_NODE_ID)
552+
cache_node = self.nodes[CACHE_NODE_ID]
552553

553554
# Wait for RPC connections to be ready
554-
self.nodes[CACHE_NODE_ID].wait_for_rpc_connection()
555+
cache_node.wait_for_rpc_connection()
556+
557+
# Set a time in the past, so that blocks don't end up in the future
558+
cache_node.setmocktime(cache_node.getblockheader(cache_node.getbestblockhash())['time'])
555559

556560
# Create a 199-block-long chain; each of the 4 first nodes
557561
# gets 25 mature blocks and 25 immature.
@@ -560,12 +564,12 @@ def _initialize_chain(self):
560564
# This is needed so that we are out of IBD when the test starts,
561565
# see the tip age check in IsInitialBlockDownload().
562566
for i in range(8):
563-
self.nodes[CACHE_NODE_ID].generatetoaddress(
567+
cache_node.generatetoaddress(
564568
nblocks=25 if i != 7 else 24,
565569
address=TestNode.PRIV_KEYS[i % 4].address,
566570
)
567571

568-
assert_equal(self.nodes[CACHE_NODE_ID].getblockchaininfo()["blocks"], 199)
572+
assert_equal(cache_node.getblockchaininfo()["blocks"], 199)
569573

570574
# Shut it down, and clean up cache directories:
571575
self.stop_nodes()

0 commit comments

Comments
 (0)