Skip to content

Commit fae2c8b

Browse files
author
MarcoFalke
committed
fuzz: Allow to pass min/max to ConsumeTime
1 parent 549d20a commit fae2c8b

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/test/fuzz/util.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <test/fuzz/util.h>
66
#include <test/util/script.h>
77
#include <util/rbf.h>
8+
#include <util/time.h>
89
#include <version.h>
910

1011
FuzzedSock::FuzzedSock(FuzzedDataProvider& fuzzed_data_provider)
@@ -216,6 +217,14 @@ void FillNode(FuzzedDataProvider& fuzzed_data_provider, CNode& node, bool init_v
216217
}
217218
}
218219

220+
int64_t ConsumeTime(FuzzedDataProvider& fuzzed_data_provider, const std::optional<int64_t>& min, const std::optional<int64_t>& max) noexcept
221+
{
222+
// Avoid t=0 (1970-01-01T00:00:00Z) since SetMockTime(0) disables mocktime.
223+
static const int64_t time_min = ParseISO8601DateTime("1970-01-01T00:00:01Z");
224+
static const int64_t time_max = ParseISO8601DateTime("9999-12-31T23:59:59Z");
225+
return fuzzed_data_provider.ConsumeIntegralInRange<int64_t>(min.value_or(time_min), max.value_or(time_max));
226+
}
227+
219228
CMutableTransaction ConsumeTransaction(FuzzedDataProvider& fuzzed_data_provider, const std::optional<std::vector<uint256>>& prevout_txids, const int max_num_in, const int max_num_out) noexcept
220229
{
221230
CMutableTransaction tx_mut;

src/test/fuzz/util.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <test/util/net.h>
2727
#include <txmempool.h>
2828
#include <uint256.h>
29-
#include <util/time.h>
3029
#include <version.h>
3130

3231
#include <algorithm>
@@ -127,13 +126,7 @@ template <typename WeakEnumType, size_t size>
127126
return fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(0, MAX_MONEY);
128127
}
129128

130-
[[nodiscard]] inline int64_t ConsumeTime(FuzzedDataProvider& fuzzed_data_provider) noexcept
131-
{
132-
// Avoid t=0 (1970-01-01T00:00:00Z) since SetMockTime(0) is a no-op.
133-
static const int64_t time_min = ParseISO8601DateTime("1970-01-01T00:00:01Z");
134-
static const int64_t time_max = ParseISO8601DateTime("9999-12-31T23:59:59Z");
135-
return fuzzed_data_provider.ConsumeIntegralInRange<int64_t>(time_min, time_max);
136-
}
129+
[[nodiscard]] int64_t ConsumeTime(FuzzedDataProvider& fuzzed_data_provider, const std::optional<int64_t>& min = std::nullopt, const std::optional<int64_t>& max = std::nullopt) noexcept;
137130

138131
[[nodiscard]] CMutableTransaction ConsumeTransaction(FuzzedDataProvider& fuzzed_data_provider, const std::optional<std::vector<uint256>>& prevout_txids, const int max_num_in = 10, const int max_num_out = 10) noexcept;
139132

0 commit comments

Comments
 (0)