Skip to content

Commit faf6304

Browse files
author
MarcoFalke
committed
test: Use mockable time in GuessVerificationProgress
Also add a test.
1 parent af65fd1 commit faf6304

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/kernel/chainparams.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,9 @@ class CRegTestParams : public CChainParams
613613
};
614614

615615
chainTxData = ChainTxData{
616-
0,
617-
0,
618-
0
616+
.nTime = 0,
617+
.tx_count = 0,
618+
.dTxRate = 0.001, // Set a non-zero rate to make it testable
619619
};
620620

621621
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5572,7 +5572,7 @@ double ChainstateManager::GuessVerificationProgress(const CBlockIndex* pindex) c
55725572
return 0.0;
55735573
}
55745574

5575-
int64_t nNow = time(nullptr);
5575+
const int64_t nNow{TicksSinceEpoch<std::chrono::seconds>(NodeClock::now())};
55765576

55775577
double fTxTotal;
55785578

test/functional/rpc_blockchain.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def run_test(self):
101101
self._test_waitforblockheight()
102102
self._test_getblock()
103103
self._test_getdeploymentinfo()
104+
self._test_verificationprogress()
104105
self._test_y2106()
105106
assert self.nodes[0].verifychain(4, 0)
106107

@@ -280,6 +281,14 @@ def _test_getdeploymentinfo(self):
280281
# calling with an explicit hash works
281282
self.check_signalling_deploymentinfo_result(self.nodes[0].getdeploymentinfo(gbci207["bestblockhash"]), gbci207["blocks"], gbci207["bestblockhash"], "started")
282283

284+
def _test_verificationprogress(self):
285+
self.log.info("Check that verificationprogress is less than 1 when the block tip is old")
286+
future = 2 * 60 * 60
287+
self.nodes[0].setmocktime(self.nodes[0].getblockchaininfo()["time"] + future + 1)
288+
assert_greater_than(1, self.nodes[0].getblockchaininfo()["verificationprogress"])
289+
self.nodes[0].setmocktime(self.nodes[0].getblockchaininfo()["time"] + future)
290+
assert_greater_than(1, self.nodes[0].getblockchaininfo()["verificationprogress"])
291+
283292
def _test_y2106(self):
284293
self.log.info("Check that block timestamps work until year 2106")
285294
self.generate(self.nodes[0], 8)[-1]

0 commit comments

Comments
 (0)