LCOV - code coverage report
Current view: top level - src/test/fuzz - policy_estimator.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 4 55 7.3 %
Date: 2023-09-26 12:08:55 Functions: 5 11 45.5 %

          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 <test/fuzz/FuzzedDataProvider.h>
      10             : #include <test/fuzz/fuzz.h>
      11             : #include <test/fuzz/util.h>
      12             : #include <test/fuzz/util/mempool.h>
      13             : #include <test/util/setup_common.h>
      14             : #include <txmempool.h>
      15             : 
      16             : #include <cstdint>
      17           2 : #include <optional>
      18           2 : #include <string>
      19             : #include <vector>
      20             : 
      21             : namespace {
      22             : const BasicTestingSetup* g_setup;
      23             : } // namespace
      24             : 
      25           0 : void initialize_policy_estimator()
      26             : {
      27           0 :     static const auto testing_setup = MakeNoLogFileContext<>();
      28           0 :     g_setup = testing_setup.get();
      29           0 : }
      30             : 
      31           4 : FUZZ_TARGET(policy_estimator, .init = initialize_policy_estimator)
      32             : {
      33           0 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      34           0 :     CBlockPolicyEstimator block_policy_estimator{FeeestPath(*g_setup->m_node.args), DEFAULT_ACCEPT_STALE_FEE_ESTIMATES};
      35           0 :     LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
      36           0 :         CallOneOf(
      37             :             fuzzed_data_provider,
      38           0 :             [&] {
      39           0 :                 const std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
      40           0 :                 if (!mtx) {
      41           0 :                     return;
      42             :                 }
      43           0 :                 const CTransaction tx{*mtx};
      44           0 :                 block_policy_estimator.processTransaction(ConsumeTxMemPoolEntry(fuzzed_data_provider, tx), fuzzed_data_provider.ConsumeBool());
      45           0 :                 if (fuzzed_data_provider.ConsumeBool()) {
      46           0 :                     (void)block_policy_estimator.removeTx(tx.GetHash(), /*inBlock=*/fuzzed_data_provider.ConsumeBool());
      47           0 :                 }
      48           0 :             },
      49           0 :             [&] {
      50           0 :                 std::vector<CTxMemPoolEntry> mempool_entries;
      51           0 :                 LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
      52           0 :                     const std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
      53           0 :                     if (!mtx) {
      54           0 :                         break;
      55             :                     }
      56           0 :                     const CTransaction tx{*mtx};
      57           0 :                     mempool_entries.push_back(ConsumeTxMemPoolEntry(fuzzed_data_provider, tx));
      58           0 :                 }
      59           0 :                 std::vector<const CTxMemPoolEntry*> ptrs;
      60           0 :                 ptrs.reserve(mempool_entries.size());
      61           0 :                 for (const CTxMemPoolEntry& mempool_entry : mempool_entries) {
      62           0 :                     ptrs.push_back(&mempool_entry);
      63             :                 }
      64           0 :                 block_policy_estimator.processBlock(fuzzed_data_provider.ConsumeIntegral<unsigned int>(), ptrs);
      65           0 :             },
      66           0 :             [&] {
      67           0 :                 (void)block_policy_estimator.removeTx(ConsumeUInt256(fuzzed_data_provider), /*inBlock=*/fuzzed_data_provider.ConsumeBool());
      68           0 :             },
      69           0 :             [&] {
      70           0 :                 block_policy_estimator.FlushUnconfirmed();
      71           0 :             });
      72           0 :         (void)block_policy_estimator.estimateFee(fuzzed_data_provider.ConsumeIntegral<int>());
      73           0 :         EstimationResult result;
      74           2 :         (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);
      75           0 :         FeeCalculation fee_calculation;
      76           0 :         (void)block_policy_estimator.estimateSmartFee(fuzzed_data_provider.ConsumeIntegral<int>(), fuzzed_data_provider.ConsumeBool() ? &fee_calculation : nullptr, fuzzed_data_provider.ConsumeBool());
      77           0 :         (void)block_policy_estimator.HighestTargetTracked(fuzzed_data_provider.PickValueInArray(ALL_FEE_ESTIMATE_HORIZONS));
      78           0 :     }
      79             :     {
      80           0 :         FuzzedAutoFileProvider fuzzed_auto_file_provider = ConsumeAutoFile(fuzzed_data_provider);
      81           0 :         AutoFile fuzzed_auto_file{fuzzed_auto_file_provider.open()};
      82           0 :         block_policy_estimator.Write(fuzzed_auto_file);
      83           0 :         block_policy_estimator.Read(fuzzed_auto_file);
      84           0 :     }
      85           0 : }

Generated by: LCOV version 1.14