From faf87c3535c51ab2d5c64ed9660d7b3846975469 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Mon, 24 Aug 2026 12:30:34 +0200 Subject: [PATCH] test: refactor: Use FakeNodeClock over manual/global SetMockTime Using SetMockTime in tests is problematic, because it often requires verbose calls to `SetMockTime(GetTime() + offset)`. Also, it requires manual `SetMockTime(0);` at the end. Fix both issues by using FakeNodeClock. --- src/test/httpserver_tests.cpp | 2 +- src/test/mempool_fee_estimator_tests.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/httpserver_tests.cpp b/src/test/httpserver_tests.cpp index 96d6c387676..9262a940c25 100644 --- a/src/test/httpserver_tests.cpp +++ b/src/test/httpserver_tests.cpp @@ -805,7 +805,7 @@ BOOST_AUTO_TEST_CASE(http_server_socket_tests) { // Hard code the timestamp for the Date header in the HTTP response // Wed Dec 11 00:47:09 2024 UTC - SetMockTime(1733878029); + FakeNodeClock clock{1733878029s}; // Prepare a request handler that just stores received requests so we can examine them. // Mutex is required to prevent a race between this test's main thread and the server's I/O loop. diff --git a/src/test/mempool_fee_estimator_tests.cpp b/src/test/mempool_fee_estimator_tests.cpp index 23b84b0b488..c75c7c7237b 100644 --- a/src/test/mempool_fee_estimator_tests.cpp +++ b/src/test/mempool_fee_estimator_tests.cpp @@ -105,6 +105,7 @@ BOOST_AUTO_TEST_CASE(calculate_max_weight_percentiles) BOOST_AUTO_TEST_CASE(mempool_fee_rate_estimator_cache) { + FakeNodeClock clock{}; MemPoolFeeRateEstimatorCache cache; const uint256 tip_hash{uint256::ONE}; const uint256 next_tip_hash{uint256{2}}; @@ -122,10 +123,9 @@ BOOST_AUTO_TEST_CASE(mempool_fee_rate_estimator_cache) BOOST_CHECK(cached->m_economical == economical); BOOST_CHECK(!cache.GetCachedEstimate(next_tip_hash)); - SetMockTime(GetTime() + CACHE_LIFE + std::chrono::seconds{1}); + clock += CACHE_LIFE + std::chrono::seconds{1}; BOOST_CHECK(cache.IsStale()); BOOST_CHECK(!cache.GetCachedEstimate(tip_hash)); - SetMockTime(0); } BOOST_AUTO_TEST_CASE(MempoolFeeRateEstimator)