LCOV - code coverage report
Current view: top level - src/test/fuzz - kitchen_sink.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 5 23 21.7 %
Date: 2023-11-12 01:39:15 Functions: 1 6 16.7 %
Branches: 4 26 15.4 %

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

Generated by: LCOV version 1.14