fuzz: Use NodeClockContext

This refactor 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.
This commit is contained in:
MarcoFalke
2025-05-06 20:12:40 +02:00
parent fa4fae6227
commit eeeeb2a0b9
25 changed files with 64 additions and 41 deletions

View File

@@ -11,6 +11,7 @@
#include <test/fuzz/util.h>
#include <test/fuzz/util/mempool.h>
#include <test/util/setup_common.h>
#include <test/util/time.h>
#include <test/util/txmempool.h>
#include <txmempool.h>
#include <util/check.h>
@@ -53,7 +54,7 @@ FUZZ_TARGET(rbf, .init = initialize_rbf)
{
SeedRandomStateForTest(SeedRand::ZEROS);
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
SetMockTime(ConsumeTime(fuzzed_data_provider));
NodeClockContext clock_ctx{ConsumeTime(fuzzed_data_provider)};
std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
if (!mtx) {
return;
@@ -95,7 +96,7 @@ FUZZ_TARGET(package_rbf, .init = initialize_package_rbf)
{
SeedRandomStateForTest(SeedRand::ZEROS);
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
SetMockTime(ConsumeTime(fuzzed_data_provider));
NodeClockContext clock_ctx{ConsumeTime(fuzzed_data_provider)};
// "Real" virtual size is not important for this test since ConsumeTxMemPoolEntry generates its own virtual size values
// so we construct small transactions for performance reasons. Child simply needs an input for later to perhaps connect to parent.