|
| 1 | +// Copyright (c) 2020 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 <optional.h> |
| 6 | +#include <policy/fees.h> |
| 7 | +#include <primitives/transaction.h> |
| 8 | +#include <test/fuzz/FuzzedDataProvider.h> |
| 9 | +#include <test/fuzz/fuzz.h> |
| 10 | +#include <test/fuzz/util.h> |
| 11 | +#include <txmempool.h> |
| 12 | + |
| 13 | +#include <cstdint> |
| 14 | +#include <string> |
| 15 | +#include <vector> |
| 16 | + |
| 17 | +void test_one_input(const std::vector<uint8_t>& buffer) |
| 18 | +{ |
| 19 | + FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); |
| 20 | + CBlockPolicyEstimator block_policy_estimator; |
| 21 | + while (fuzzed_data_provider.ConsumeBool()) { |
| 22 | + switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 3)) { |
| 23 | + case 0: { |
| 24 | + const Optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider); |
| 25 | + if (!mtx) { |
| 26 | + break; |
| 27 | + } |
| 28 | + const CTransaction tx{*mtx}; |
| 29 | + block_policy_estimator.processTransaction(ConsumeTxMemPoolEntry(fuzzed_data_provider, tx), fuzzed_data_provider.ConsumeBool()); |
| 30 | + if (fuzzed_data_provider.ConsumeBool()) { |
| 31 | + (void)block_policy_estimator.removeTx(tx.GetHash(), /* inBlock */ fuzzed_data_provider.ConsumeBool()); |
| 32 | + } |
| 33 | + break; |
| 34 | + } |
| 35 | + case 1: { |
| 36 | + std::vector<CTxMemPoolEntry> mempool_entries; |
| 37 | + while (fuzzed_data_provider.ConsumeBool()) { |
| 38 | + const Optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider); |
| 39 | + if (!mtx) { |
| 40 | + break; |
| 41 | + } |
| 42 | + const CTransaction tx{*mtx}; |
| 43 | + mempool_entries.push_back(ConsumeTxMemPoolEntry(fuzzed_data_provider, tx)); |
| 44 | + } |
| 45 | + std::vector<const CTxMemPoolEntry*> ptrs; |
| 46 | + ptrs.reserve(mempool_entries.size()); |
| 47 | + for (const CTxMemPoolEntry& mempool_entry : mempool_entries) { |
| 48 | + ptrs.push_back(&mempool_entry); |
| 49 | + } |
| 50 | + block_policy_estimator.processBlock(fuzzed_data_provider.ConsumeIntegral<unsigned int>(), ptrs); |
| 51 | + break; |
| 52 | + } |
| 53 | + case 2: { |
| 54 | + (void)block_policy_estimator.removeTx(ConsumeUInt256(fuzzed_data_provider), /* inBlock */ fuzzed_data_provider.ConsumeBool()); |
| 55 | + break; |
| 56 | + } |
| 57 | + case 3: { |
| 58 | + block_policy_estimator.FlushUnconfirmed(); |
| 59 | + break; |
| 60 | + } |
| 61 | + } |
| 62 | + (void)block_policy_estimator.estimateFee(fuzzed_data_provider.ConsumeIntegral<int>()); |
| 63 | + EstimationResult result; |
| 64 | + (void)block_policy_estimator.estimateRawFee(fuzzed_data_provider.ConsumeIntegral<int>(), fuzzed_data_provider.ConsumeFloatingPoint<double>(), fuzzed_data_provider.PickValueInArray({FeeEstimateHorizon::SHORT_HALFLIFE, FeeEstimateHorizon::MED_HALFLIFE, FeeEstimateHorizon::LONG_HALFLIFE}), fuzzed_data_provider.ConsumeBool() ? &result : nullptr); |
| 65 | + FeeCalculation fee_calculation; |
| 66 | + (void)block_policy_estimator.estimateSmartFee(fuzzed_data_provider.ConsumeIntegral<int>(), fuzzed_data_provider.ConsumeBool() ? &fee_calculation : nullptr, fuzzed_data_provider.ConsumeBool()); |
| 67 | + (void)block_policy_estimator.HighestTargetTracked(fuzzed_data_provider.PickValueInArray({FeeEstimateHorizon::SHORT_HALFLIFE, FeeEstimateHorizon::MED_HALFLIFE, FeeEstimateHorizon::LONG_HALFLIFE})); |
| 68 | + } |
| 69 | +} |
0 commit comments