aboutsummaryrefslogtreecommitdiff
path: root/src/test/fuzz/timeoffsets.cpp
diff options
context:
space:
mode:
authorstickies-v <stickies-v@protonmail.com>2024-03-07 11:23:00 +0000
committerstickies-v <stickies-v@protonmail.com>2024-04-10 17:01:27 +0200
commitee178dfcc1175e0af8163216c9c024f4bfc97965 (patch)
tree29d04d09dcc21862dcaf6627986a68b38f1e31bc /src/test/fuzz/timeoffsets.cpp
parent55361a15d1aa6984051441bce88112000688fb43 (diff)
downloadbitcoin-ee178dfcc1175e0af8163216c9c024f4bfc97965.tar.xz
Add TimeOffsets helper class
This helper class is an alternative to CMedianFilter, but without a lot of the special logic and exceptions that we needed while it was still used for consensus.
Diffstat (limited to 'src/test/fuzz/timeoffsets.cpp')
-rw-r--r--src/test/fuzz/timeoffsets.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/fuzz/timeoffsets.cpp b/src/test/fuzz/timeoffsets.cpp
new file mode 100644
index 0000000000..019337a94a
--- /dev/null
+++ b/src/test/fuzz/timeoffsets.cpp
@@ -0,0 +1,28 @@
+// Copyright (c) 2024-present The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <node/timeoffsets.h>
+#include <test/fuzz/FuzzedDataProvider.h>
+#include <test/fuzz/fuzz.h>
+#include <test/util/setup_common.h>
+
+#include <chrono>
+#include <cstdint>
+#include <functional>
+
+void initialize_timeoffsets()
+{
+ static const auto testing_setup = MakeNoLogFileContext<>(ChainType::MAIN);
+}
+
+FUZZ_TARGET(timeoffsets, .init = initialize_timeoffsets)
+{
+ FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
+ TimeOffsets offsets{};
+ LIMITED_WHILE(fuzzed_data_provider.remaining_bytes() > 0, 4'000) {
+ (void)offsets.Median();
+ offsets.Add(std::chrono::seconds{fuzzed_data_provider.ConsumeIntegral<std::chrono::seconds::rep>()});
+ offsets.WarnIfOutOfSync();
+ }
+}