LCOV - code coverage report
Current view: top level - src/test/fuzz - policy_estimator.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 1 61 1.6 %
Date: 2024-01-03 14:57:27 Functions: 1 8 12.5 %
Branches: 1 115 0.9 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2020-2022 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 <kernel/mempool_entry.h>
       6                 :            : #include <policy/fees.h>
       7                 :            : #include <policy/fees_args.h>
       8                 :            : #include <primitives/transaction.h>
       9                 :            : #include <streams.h>
      10                 :            : #include <test/fuzz/FuzzedDataProvider.h>
      11                 :            : #include <test/fuzz/fuzz.h>
      12                 :            : #include <test/fuzz/util.h>
      13                 :            : #include <test/fuzz/util/mempool.h>
      14                 :            : #include <test/util/setup_common.h>
      15                 :            : 
      16                 :            : #include <memory>
      17                 :            : #include <optional>
      18                 :            : #include <vector>
      19                 :            : 
      20                 :            : namespace {
      21                 :            : const BasicTestingSetup* g_setup;
      22                 :            : } // namespace
      23                 :            : 
      24                 :          0 : void initialize_policy_estimator()
      25                 :            : {
      26 [ #  # ][ #  # ]:          0 :     static const auto testing_setup = MakeNoLogFileContext<>();
                 [ #  # ]
      27                 :          0 :     g_setup = testing_setup.get();
      28                 :          0 : }
      29                 :            : 
      30         [ +  - ]:          4 : FUZZ_TARGET(policy_estimator, .init = initialize_policy_estimator)
      31                 :            : {
      32                 :          0 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      33                 :          0 :     bool good_data{true};
      34                 :            : 
      35         [ #  # ]:          0 :     CBlockPolicyEstimator block_policy_estimator{FeeestPath(*g_setup->m_node.args), DEFAULT_ACCEPT_STALE_FEE_ESTIMATES};
      36 [ #  # ][ #  # ]:          0 :     LIMITED_WHILE(good_data && fuzzed_data_provider.ConsumeBool(), 10'000)
         [ #  # ][ #  # ]
      37                 :            :     {
      38         [ #  # ]:          0 :         CallOneOf(
      39                 :            :             fuzzed_data_provider,
      40                 :          0 :             [&] {
      41                 :          0 :                 const std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
      42         [ #  # ]:          0 :                 if (!mtx) {
      43                 :          0 :                     good_data = false;
      44                 :          0 :                     return;
      45                 :            :                 }
      46         [ #  # ]:          0 :                 const CTransaction tx{*mtx};
      47                 :          0 :                 const CTxMemPoolEntry& entry = ConsumeTxMemPoolEntry(fuzzed_data_provider, tx);
      48 [ #  # ][ #  # ]:          0 :                 const auto tx_info = NewMempoolTransactionInfo(entry.GetSharedTx(), entry.GetFee(),
                 [ #  # ]
      49 [ #  # ][ #  # ]:          0 :                                                                entry.GetTxSize(), entry.GetHeight(),
      50                 :            :                                                                /* m_from_disconnected_block */ false,
      51                 :            :                                                                /* m_submitted_in_package */ false,
      52                 :            :                                                                /* m_chainstate_is_current */ true,
      53         [ #  # ]:          0 :                                                                /* m_has_no_mempool_parents */ fuzzed_data_provider.ConsumeBool());
      54         [ #  # ]:          0 :                 block_policy_estimator.processTransaction(tx_info);
      55 [ #  # ][ #  # ]:          0 :                 if (fuzzed_data_provider.ConsumeBool()) {
      56 [ #  # ][ #  # ]:          0 :                     (void)block_policy_estimator.removeTx(tx.GetHash());
                 [ #  # ]
      57                 :          0 :                 }
      58         [ #  # ]:          0 :             },
      59                 :          0 :             [&] {
      60                 :          0 :                 std::list<CTxMemPoolEntry> mempool_entries;
      61 [ #  # ][ #  # ]:          0 :                 LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000)
                 [ #  # ]
      62                 :            :                 {
      63                 :          0 :                     const std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
      64         [ #  # ]:          0 :                     if (!mtx) {
      65                 :          0 :                         good_data = false;
      66                 :          0 :                         break;
      67                 :            :                     }
      68         [ #  # ]:          0 :                     const CTransaction tx{*mtx};
      69         [ #  # ]:          0 :                     mempool_entries.emplace_back(CTxMemPoolEntry::ExplicitCopy, ConsumeTxMemPoolEntry(fuzzed_data_provider, tx));
      70      [ #  #  # ]:          0 :                 }
      71                 :          0 :                 std::vector<RemovedMempoolTransactionInfo> txs;
      72         [ #  # ]:          0 :                 txs.reserve(mempool_entries.size());
      73         [ #  # ]:          0 :                 for (const CTxMemPoolEntry& mempool_entry : mempool_entries) {
      74         [ #  # ]:          0 :                     txs.emplace_back(mempool_entry);
      75                 :            :                 }
      76 [ #  # ][ #  # ]:          0 :                 block_policy_estimator.processBlock(txs, fuzzed_data_provider.ConsumeIntegral<unsigned int>());
      77                 :          0 :             },
      78                 :          0 :             [&] {
      79                 :          0 :                 (void)block_policy_estimator.removeTx(ConsumeUInt256(fuzzed_data_provider));
      80                 :          0 :             },
      81                 :          0 :             [&] {
      82                 :          0 :                 block_policy_estimator.FlushUnconfirmed();
      83                 :          0 :             });
      84 [ #  # ][ #  # ]:          0 :         (void)block_policy_estimator.estimateFee(fuzzed_data_provider.ConsumeIntegral<int>());
      85                 :          0 :         EstimationResult result;
      86 [ #  # ][ #  # ]:          0 :         (void)block_policy_estimator.estimateRawFee(fuzzed_data_provider.ConsumeIntegral<int>(), fuzzed_data_provider.ConsumeFloatingPoint<double>(), fuzzed_data_provider.PickValueInArray(ALL_FEE_ESTIMATE_HORIZONS), fuzzed_data_provider.ConsumeBool() ? &result : nullptr);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      87                 :          0 :         FeeCalculation fee_calculation;
      88 [ #  # ][ #  # ]:          0 :         (void)block_policy_estimator.estimateSmartFee(fuzzed_data_provider.ConsumeIntegral<int>(), fuzzed_data_provider.ConsumeBool() ? &fee_calculation : nullptr, fuzzed_data_provider.ConsumeBool());
         [ #  # ][ #  # ]
                 [ #  # ]
      89 [ #  # ][ #  # ]:          0 :         (void)block_policy_estimator.HighestTargetTracked(fuzzed_data_provider.PickValueInArray(ALL_FEE_ESTIMATE_HORIZONS));
      90                 :          0 :     }
      91                 :            :     {
      92         [ #  # ]:          0 :         FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
      93 [ #  # ][ #  # ]:          0 :         AutoFile fuzzed_auto_file{fuzzed_file_provider.open()};
      94         [ #  # ]:          0 :         block_policy_estimator.Write(fuzzed_auto_file);
      95         [ #  # ]:          0 :         block_policy_estimator.Read(fuzzed_auto_file);
      96                 :          0 :     }
      97                 :          0 : }

Generated by: LCOV version 1.14