Branch data Line data Source code
1 : : // Copyright (c) 2025-present The Bitcoin Core developers
2 : : // Distributed under the MIT software license, see the accompanying
3 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 : :
5 : : #include <blockencodings.h>
6 : : #include <random.h>
7 : : #include <streams.h>
8 : : #include <test/fuzz/fuzz.h>
9 : : #include <util/check.h>
10 : :
11 : : #include <vector>
12 : :
13 [ + - ]: 538 : FUZZ_TARGET(difference_formatter)
14 : : {
15 : 62 : const auto block_hash = InsecureRandomContext{{}}.rand256();
16 : 62 : DataStream ss{};
17 [ + - + - ]: 62 : ss << block_hash << std::span{buffer};
18 : :
19 : : // Test deserialization
20 : 62 : try {
21 : 62 : BlockTransactionsRequest test_container;
22 [ + + ]: 62 : ss >> test_container;
23 [ - + ]: 25 : assert(test_container.blockhash == block_hash);
24 : :
25 : : // Invariant: strictly monotonic increasing (no duplicates allowed)
26 [ - + + + ]: 11435 : for (size_t i = 1; i < test_container.indexes.size(); ++i) {
27 [ - + ]: 11410 : assert(test_container.indexes[i] > test_container.indexes[i-1]);
28 : : }
29 : :
30 [ - + ]: 62 : } catch (const std::ios_base::failure&) {
31 : : // Expected for malformed input
32 : 37 : }
33 : 62 : }
|