From fa9f434df89745ab5a0fd1d6c07800cbe802de03 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Wed, 7 May 2025 00:57:44 +0200 Subject: [PATCH 1/3] test: Allow time_point in boost checks This is required in the next commit. --- src/test/util/common.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test/util/common.h b/src/test/util/common.h index 591f651fbaf..2fa4cb3cfe7 100644 --- a/src/test/util/common.h +++ b/src/test/util/common.h @@ -5,8 +5,9 @@ #ifndef BITCOIN_TEST_UTIL_COMMON_H #define BITCOIN_TEST_UTIL_COMMON_H -#include +#include #include +#include #include /** @@ -27,6 +28,12 @@ private: // Make types usable in BOOST_CHECK_* @{ namespace std { +template +inline std::ostream& operator<<(std::ostream& os, const std::chrono::time_point& tp) +{ + return os << tp.time_since_epoch().count(); +} + template requires std::is_enum_v inline std::ostream& operator<<(std::ostream& os, const T& e) { From fa8fe0941edfe515cb491e970371f8f84d2d8cdc Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Fri, 20 Mar 2026 10:37:35 +0100 Subject: [PATCH 2/3] fuzz: Use NodeClockContext This refactor is a follow-up to commit eeeeb2a0b902ed69b5cd5523833d3ab5d963c81f and does not change any behavior. However, it is nice to know that no global mocktime leaks from the fuzz init step to the first fuzz input, or from one fuzz input execution to the next. With the clock context, the global is re-set at the end of the context. --- src/wallet/test/fuzz/scriptpubkeyman.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/test/fuzz/scriptpubkeyman.cpp b/src/wallet/test/fuzz/scriptpubkeyman.cpp index a627c770541..fa8bc250d07 100644 --- a/src/wallet/test/fuzz/scriptpubkeyman.cpp +++ b/src/wallet/test/fuzz/scriptpubkeyman.cpp @@ -205,7 +205,7 @@ FUZZ_TARGET(spkm_migration, .init = initialize_spkm_migration) { SeedRandomStateForTest(SeedRand::ZEROS); FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; - SetMockTime(ConsumeTime(fuzzed_data_provider)); + NodeClockContext clock_ctx{ConsumeTime(fuzzed_data_provider)}; const auto& node{g_setup->m_node}; Chainstate& chainstate{node.chainman->ActiveChainstate()}; From faad08e59c4419e09eb75054bf468ca98a837ca8 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Wed, 7 May 2025 02:04:48 +0200 Subject: [PATCH 3/3] test: Use NodeClockContext in more tests --- src/bench/util_time.cpp | 5 ++-- src/bench/wallet_balance.cpp | 3 ++- src/bench/wallet_create_tx.cpp | 5 ++-- src/test/addrman_tests.cpp | 4 ++- src/test/banman_tests.cpp | 4 +-- src/test/chainstate_write_tests.cpp | 6 +++-- src/test/denialofservice_tests.cpp | 39 +++++++++++++++-------------- src/test/mempool_tests.cpp | 16 ++++++------ src/test/orphanage_tests.cpp | 5 ++-- src/test/testnet4_miner_tests.cpp | 21 ++++++---------- src/test/util_tests.cpp | 4 +-- 11 files changed, 57 insertions(+), 55 deletions(-) diff --git a/src/bench/util_time.cpp b/src/bench/util_time.cpp index bc3e3892f1f..19ffd0e0498 100644 --- a/src/bench/util_time.cpp +++ b/src/bench/util_time.cpp @@ -3,7 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include - +#include #include static void BenchTimeDeprecated(benchmark::Bench& bench) @@ -15,11 +15,10 @@ static void BenchTimeDeprecated(benchmark::Bench& bench) static void BenchTimeMock(benchmark::Bench& bench) { - SetMockTime(111); + NodeClockContext clock_ctx{111s}; bench.run([&] { (void)GetTime(); }); - SetMockTime(0); } static void BenchTimeMillis(benchmark::Bench& bench) diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp index 03774ef54ac..45f23494280 100644 --- a/src/bench/wallet_balance.cpp +++ b/src/bench/wallet_balance.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -32,7 +33,7 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b // Set clock to genesis block, so the descriptors/keys creation time don't interfere with the blocks scanning process. // The reason is 'generatetoaddress', which creates a chain with deterministic timestamps in the past. - SetMockTime(test_setup->m_node.chainman->GetParams().GenesisBlock().nTime); + NodeClockContext clock_ctx{test_setup->m_node.chainman->GetParams().GenesisBlock().Time()}; CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockableWalletDatabase()}; { LOCK(wallet.cs_wallet); diff --git a/src/bench/wallet_create_tx.cpp b/src/bench/wallet_create_tx.cpp index 8ff1e39a2f8..11125e26fed 100644 --- a/src/bench/wallet_create_tx.cpp +++ b/src/bench/wallet_create_tx.cpp @@ -20,6 +20,7 @@ #include