It is less code this way:
diff --git a/src/test/fuzz/difference_formatter.cpp b/src/test/fuzz/difference_formatter.cpp
index 49e859ffdc..38b54352c1 100644
--- a/src/test/fuzz/difference_formatter.cpp
+++ b/src/test/fuzz/difference_formatter.cpp
@@ -4,25 +4,13 @@
#include <blockencodings.h>
#include <streams.h>
-#include <test/fuzz/FuzzedDataProvider.h>
+#include <random.h>
#include <test/fuzz/fuzz.h>
#include <vector>
namespace {
-// Test struct for VectorFormatter<DifferenceFormatter>
-// Used in BlockTransactionsRequest
-struct TestDifferenceFormatterType {
- std::vector<uint16_t> indexes;
-
- SERIALIZE_METHODS(TestDifferenceFormatterType, obj) {
- READWRITE(Using<VectorFormatter<DifferenceFormatter>>(obj.indexes));
- }
-};
-
void VerifyDifferenceFormatterInvariants(const std::vector<uint16_t>& indexes) {
- if (indexes.empty()) return;
-
// Core invariant: strictly monotonic increasing (no duplicates allowed)
for (size_t i = 1; i < indexes.size(); ++i) {
assert(indexes[i] > indexes[i-1]); // Must be STRICTLY greater
@@ -32,15 +20,15 @@ void VerifyDifferenceFormatterInvariants(const std::vector<uint16_t>& indexes) {
FUZZ_TARGET(difference_formatter)
{
- FuzzedDataProvider fdp{buffer.data(), buffer.size()};
-
- auto random_bytes = fdp.ConsumeRemainingBytes<uint8_t>();
- DataStream ss{random_bytes};
+ const auto block_hash = InsecureRandomContext{{}}.rand256();
+ DataStream ss{};
+ ss << block_hash << std::span{buffer};
// Test deserialization
try {
- TestDifferenceFormatterType test_container;
+ BlockTransactionsRequest test_container;
ss >> test_container;
+ assert(test_container.blockhash==block_hash);
// If deserialization succeeded, verify the DifferenceFormatter invariants
VerifyDifferenceFormatterInvariants(test_container.indexes);
@@ -48,5 +36,4 @@ FUZZ_TARGET(difference_formatter)
} catch (const std::ios_base::failure&) {
// Expected for malformed input
}
-
}
Other changes include:
- No need to copy the full buffer twice (FuzzedDataProvider and DataStream)
- Remove not needed
indexes.empty() check