Coverage Report

Created: 2025-02-21 14:37

/root/bitcoin/src/test/fuzz/kitchen_sink.cpp
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2020-2021 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 <common/messages.h>
6
#include <merkleblock.h>
7
#include <node/types.h>
8
#include <policy/fees.h>
9
#include <rpc/util.h>
10
#include <test/fuzz/FuzzedDataProvider.h>
11
#include <test/fuzz/fuzz.h>
12
#include <test/fuzz/util.h>
13
#include <util/translation.h>
14
15
#include <array>
16
#include <cstdint>
17
#include <optional>
18
#include <vector>
19
20
using common::TransactionErrorString;
21
using node::TransactionError;
22
23
namespace {
24
constexpr TransactionError ALL_TRANSACTION_ERROR[] = {
25
    TransactionError::MISSING_INPUTS,
26
    TransactionError::ALREADY_IN_UTXO_SET,
27
    TransactionError::MEMPOOL_REJECTED,
28
    TransactionError::MEMPOOL_ERROR,
29
    TransactionError::MAX_FEE_EXCEEDED,
30
};
31
}; // namespace
32
33
// The fuzzing kitchen sink: Fuzzing harness for functions that need to be
34
// fuzzed but a.) don't belong in any existing fuzzing harness file, and
35
// b.) are not important enough to warrant their own fuzzing harness file.
36
FUZZ_TARGET(kitchen_sink)
37
0
{
38
0
    FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
39
40
0
    const TransactionError transaction_error = fuzzed_data_provider.PickValueInArray(ALL_TRANSACTION_ERROR);
41
0
    (void)JSONRPCTransactionError(transaction_error);
42
0
    (void)RPCErrorFromTransactionError(transaction_error);
43
0
    (void)TransactionErrorString(transaction_error);
44
45
0
    (void)StringForFeeEstimateHorizon(fuzzed_data_provider.PickValueInArray(ALL_FEE_ESTIMATE_HORIZONS));
46
47
0
    const OutputType output_type = fuzzed_data_provider.PickValueInArray(OUTPUT_TYPES);
48
0
    const std::string& output_type_string = FormatOutputType(output_type);
49
0
    const std::optional<OutputType> parsed = ParseOutputType(output_type_string);
50
0
    assert(parsed);
51
0
    assert(output_type == parsed.value());
52
0
    (void)ParseOutputType(fuzzed_data_provider.ConsumeRandomLengthString(64));
53
54
0
    const std::vector<uint8_t> bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider);
55
0
    const std::vector<bool> bits = BytesToBits(bytes);
56
0
    const std::vector<uint8_t> bytes_decoded = BitsToBytes(bits);
57
0
    assert(bytes == bytes_decoded);
58
0
}