It is less code this way:
0diff --git a/src/test/fuzz/difference_formatter.cpp b/src/test/fuzz/difference_formatter.cpp
1index 49e859ffdc..38b54352c1 100644
2--- a/src/test/fuzz/difference_formatter.cpp
3+++ b/src/test/fuzz/difference_formatter.cpp
4@@ -4,25 +4,13 @@
5
6 #include <blockencodings.h>
7 #include <streams.h>
8-#include <test/fuzz/FuzzedDataProvider.h>
9+#include <random.h>
10 #include <test/fuzz/fuzz.h>
11
12 #include <vector>
13
14 namespace {
15-// Test struct for VectorFormatter<DifferenceFormatter>
16-// Used in BlockTransactionsRequest
17-struct TestDifferenceFormatterType {
18- std::vector<uint16_t> indexes;
19-
20- SERIALIZE_METHODS(TestDifferenceFormatterType, obj) {
21- READWRITE(Using<VectorFormatter<DifferenceFormatter>>(obj.indexes));
22- }
23-};
24-
25 void VerifyDifferenceFormatterInvariants(const std::vector<uint16_t>& indexes) {
26- if (indexes.empty()) return;
27-
28 // Core invariant: strictly monotonic increasing (no duplicates allowed)
29 for (size_t i = 1; i < indexes.size(); ++i) {
30 assert(indexes[i] > indexes[i-1]); // Must be STRICTLY greater
31@@ -32,15 +20,15 @@ void VerifyDifferenceFormatterInvariants(const std::vector<uint16_t>& indexes) {
32
33 FUZZ_TARGET(difference_formatter)
34 {
35- FuzzedDataProvider fdp{buffer.data(), buffer.size()};
36-
37- auto random_bytes = fdp.ConsumeRemainingBytes<uint8_t>();
38- DataStream ss{random_bytes};
39+ const auto block_hash = InsecureRandomContext{{}}.rand256();
40+ DataStream ss{};
41+ ss << block_hash << std::span{buffer};
42
43 // Test deserialization
44 try {
45- TestDifferenceFormatterType test_container;
46+ BlockTransactionsRequest test_container;
47 ss >> test_container;
48+ assert(test_container.blockhash==block_hash);
49
50 // If deserialization succeeded, verify the DifferenceFormatter invariants
51 VerifyDifferenceFormatterInvariants(test_container.indexes);
52@@ -48,5 +36,4 @@ FUZZ_TARGET(difference_formatter)
53 } catch (const std::ios_base::failure&) {
54 // Expected for malformed input
55 }
56-
57 }
Other changes include:
- No need to copy the full buffer twice (FuzzedDataProvider and DataStream)
- Remove not needed
indexes.empty()
check