Branch data Line data Source code
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>
9 : : #include <policy/fees/block_policy_estimator.h>
10 : : #include <rpc/util.h>
11 : : #include <test/fuzz/FuzzedDataProvider.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 : :
22 : : using common::TransactionErrorString;
23 : : using node::TransactionError;
24 : :
25 : : namespace {
26 : : constexpr 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 : : TransactionError::MAX_FEE_RATE_EXCEEDED,
33 : : };
34 : : }; // namespace
35 : :
36 : : // The fuzzing kitchen sink: Fuzzing harness for functions that need to be
37 : : // fuzzed but a.) don't belong in any existing fuzzing harness file, and
38 : : // b.) are not important enough to warrant their own fuzzing harness file.
39 [ + - ]: 522 : FUZZ_TARGET(kitchen_sink)
40 : : {
41 : 46 : FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
42 : :
43 : 46 : const TransactionError transaction_error = fuzzed_data_provider.PickValueInArray(ALL_TRANSACTION_ERROR);
44 [ + - ]: 46 : (void)JSONRPCTransactionError(transaction_error);
45 : 46 : (void)RPCErrorFromTransactionError(transaction_error);
46 : 46 : (void)TransactionErrorString(transaction_error);
47 : :
48 : 46 : (void)StringForFeeEstimateHorizon(fuzzed_data_provider.PickValueInArray(ALL_FEE_ESTIMATE_HORIZONS));
49 : :
50 : 46 : const OutputType output_type = fuzzed_data_provider.PickValueInArray(OUTPUT_TYPES);
51 : 46 : const std::string& output_type_string = FormatOutputType(output_type);
52 [ - + ]: 46 : const std::optional<OutputType> parsed = ParseOutputType(output_type_string);
53 [ - + ]: 46 : assert(parsed);
54 [ - + ]: 46 : assert(output_type == parsed.value());
55 [ - + + - ]: 46 : (void)ParseOutputType(fuzzed_data_provider.ConsumeRandomLengthString(64));
56 : :
57 : 46 : const std::vector<uint8_t> bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider);
58 [ + - ]: 46 : const std::vector<bool> bits = BytesToBits(bytes);
59 [ + - ]: 46 : const std::vector<uint8_t> bytes_decoded = BitsToBytes(bits);
60 [ - + ]: 46 : assert(bytes == bytes_decoded);
61 : 46 : }
|