|
2 | 2 | // Distributed under the MIT software license, see the accompanying
|
3 | 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
4 | 4 |
|
| 5 | +#include <merkleblock.h> |
| 6 | +#include <policy/fees.h> |
5 | 7 | #include <rpc/util.h>
|
6 | 8 | #include <test/fuzz/FuzzedDataProvider.h>
|
7 | 9 | #include <test/fuzz/fuzz.h>
|
8 | 10 | #include <test/fuzz/util.h>
|
9 | 11 | #include <util/error.h>
|
10 | 12 | #include <util/translation.h>
|
11 | 13 |
|
| 14 | +#include <array> |
12 | 15 | #include <cstdint>
|
13 | 16 | #include <vector>
|
14 | 17 |
|
| 18 | +namespace { |
| 19 | +constexpr TransactionError ALL_TRANSACTION_ERROR[] = { |
| 20 | + TransactionError::OK, |
| 21 | + TransactionError::MISSING_INPUTS, |
| 22 | + TransactionError::ALREADY_IN_CHAIN, |
| 23 | + TransactionError::P2P_DISABLED, |
| 24 | + TransactionError::MEMPOOL_REJECTED, |
| 25 | + TransactionError::MEMPOOL_ERROR, |
| 26 | + TransactionError::INVALID_PSBT, |
| 27 | + TransactionError::PSBT_MISMATCH, |
| 28 | + TransactionError::SIGHASH_MISMATCH, |
| 29 | + TransactionError::MAX_FEE_EXCEEDED, |
| 30 | +}; |
| 31 | + |
| 32 | +constexpr FeeEstimateHorizon ALL_FEE_EST_HORIZON[] = { |
| 33 | + FeeEstimateHorizon::SHORT_HALFLIFE, |
| 34 | + FeeEstimateHorizon::MED_HALFLIFE, |
| 35 | + FeeEstimateHorizon::LONG_HALFLIFE, |
| 36 | +}; |
| 37 | + |
| 38 | +constexpr OutputType ALL_OUTPUT_TYPE[] = { |
| 39 | + OutputType::LEGACY, |
| 40 | + OutputType::P2SH_SEGWIT, |
| 41 | + OutputType::BECH32, |
| 42 | +}; |
| 43 | +}; // namespace |
| 44 | + |
15 | 45 | // The fuzzing kitchen sink: Fuzzing harness for functions that need to be
|
16 | 46 | // fuzzed but a.) don't belong in any existing fuzzing harness file, and
|
17 | 47 | // b.) are not important enough to warrant their own fuzzing harness file.
|
18 | 48 | FUZZ_TARGET(kitchen_sink)
|
19 | 49 | {
|
20 | 50 | FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
21 | 51 |
|
22 |
| - const TransactionError transaction_error = fuzzed_data_provider.PickValueInArray<TransactionError>({TransactionError::OK, TransactionError::MISSING_INPUTS, TransactionError::ALREADY_IN_CHAIN, TransactionError::P2P_DISABLED, TransactionError::MEMPOOL_REJECTED, TransactionError::MEMPOOL_ERROR, TransactionError::INVALID_PSBT, TransactionError::PSBT_MISMATCH, TransactionError::SIGHASH_MISMATCH, TransactionError::MAX_FEE_EXCEEDED}); |
| 52 | + const TransactionError transaction_error = fuzzed_data_provider.PickValueInArray(ALL_TRANSACTION_ERROR); |
23 | 53 | (void)JSONRPCTransactionError(transaction_error);
|
24 | 54 | (void)RPCErrorFromTransactionError(transaction_error);
|
25 | 55 | (void)TransactionErrorString(transaction_error);
|
| 56 | + |
| 57 | + (void)StringForFeeEstimateHorizon(fuzzed_data_provider.PickValueInArray(ALL_FEE_EST_HORIZON)); |
| 58 | + |
| 59 | + const OutputType output_type = fuzzed_data_provider.PickValueInArray(ALL_OUTPUT_TYPE); |
| 60 | + const std::string& output_type_string = FormatOutputType(output_type); |
| 61 | + OutputType output_type_parsed; |
| 62 | + const bool parsed = ParseOutputType(output_type_string, output_type_parsed); |
| 63 | + assert(parsed); |
| 64 | + assert(output_type == output_type_parsed); |
| 65 | + (void)ParseOutputType(fuzzed_data_provider.ConsumeRandomLengthString(64), output_type_parsed); |
| 66 | + |
| 67 | + const std::vector<uint8_t> bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider); |
| 68 | + const std::vector<bool> bits = BytesToBits(bytes); |
| 69 | + const std::vector<uint8_t> bytes_decoded = BitsToBytes(bits); |
| 70 | + assert(bytes == bytes_decoded); |
26 | 71 | }
|
0 commit comments