Bitcoin Core 32.99.0
P2P Digital Currency
kitchen_sink.cpp
Go to the documentation of this file.
1// Copyright (c) 2020-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 <common/messages.h>
6#include <merkleblock.h>
7#include <node/types.h>
8#include <outputtype.h>
10#include <rpc/util.h>
12#include <test/fuzz/fuzz.h>
13#include <test/fuzz/util.h>
14#include <util/check.h>
15#include <util/translation.h>
16
17#include <cstdint>
18#include <optional>
19#include <string>
20#include <vector>
21
24
25namespace {
26constexpr TransactionError ALL_TRANSACTION_ERROR[] = {
27 TransactionError::MISSING_INPUTS,
28 TransactionError::ALREADY_IN_UTXO_SET,
29 TransactionError::MEMPOOL_REJECTED,
30 TransactionError::MEMPOOL_ERROR,
31 TransactionError::MAX_FEE_EXCEEDED,
32};
33}; // namespace
34
35// The fuzzing kitchen sink: Fuzzing harness for functions that need to be
36// fuzzed but a.) don't belong in any existing fuzzing harness file, and
37// b.) are not important enough to warrant their own fuzzing harness file.
38FUZZ_TARGET(kitchen_sink)
39{
40 FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
41
42 const TransactionError transaction_error = fuzzed_data_provider.PickValueInArray(ALL_TRANSACTION_ERROR);
43 (void)JSONRPCTransactionError(transaction_error);
44 (void)RPCErrorFromTransactionError(transaction_error);
45 (void)TransactionErrorString(transaction_error);
46
48
50 const std::string& output_type_string = FormatOutputType(output_type);
51 const std::optional<OutputType> parsed = ParseOutputType(output_type_string);
52 assert(parsed);
53 assert(output_type == parsed.value());
55
56 const std::vector<uint8_t> bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider);
57 const std::vector<bool> bits = BytesToBits(bytes);
58 const std::vector<uint8_t> bytes_decoded = BitsToBytes(bits);
59 assert(bytes == bytes_decoded);
60}
constexpr auto ALL_FEE_ESTIMATE_HORIZONS
std::string ConsumeRandomLengthString(size_t max_length)
T PickValueInArray(const T(&array)[size])
FUZZ_TARGET(kitchen_sink)
std::vector< unsigned char > BitsToBytes(const std::vector< bool > &bits)
Definition: merkleblock.cpp:13
std::vector< bool > BytesToBits(const std::vector< unsigned char > &bytes)
Definition: merkleblock.cpp:22
is a home for simple string functions returning descriptive messages that are used in RPC and GUI int...
bilingual_str TransactionErrorString(const TransactionError err)
Definition: messages.cpp:118
TransactionError
Definition: types.h:19
is a home for public enum and struct type definitions that are used internally by node code,...
std::optional< OutputType > ParseOutputType(std::string_view type)
Definition: outputtype.cpp:23
const std::string & FormatOutputType(OutputType type)
Definition: outputtype.cpp:37
OutputType
Definition: outputtype.h:18
constexpr auto OUTPUT_TYPES
Definition: outputtype.h:26
std::string StringForFeeEstimateHorizon(FeeEstimateHorizon horizon)
UniValue JSONRPCTransactionError(TransactionError terr, const std::string &err_string)
Definition: util.cpp:415
RPCErrorCode RPCErrorFromTransactionError(TransactionError terr)
Definition: util.cpp:396
std::vector< B > ConsumeRandomLengthByteVector(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
Definition: util.h:63
assert(!tx.IsCoinBase())
FuzzedDataProvider & fuzzed_data_provider
Definition: fees.cpp:45