LCOV - code coverage report
Current view: top level - src/wallet/test/fuzz - fees.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 97.4 % 39 38
Test Date: 2025-09-10 04:04:06 Functions: 100.0 % 3 3
Branches: 65.4 % 52 34

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2022-present 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 <test/fuzz/FuzzedDataProvider.h>
       6                 :             : #include <test/fuzz/fuzz.h>
       7                 :             : #include <test/fuzz/util.h>
       8                 :             : #include <test/util/setup_common.h>
       9                 :             : #include <validation.h>
      10                 :             : #include <wallet/coincontrol.h>
      11                 :             : #include <wallet/fees.h>
      12                 :             : #include <wallet/test/util.h>
      13                 :             : #include <wallet/wallet.h>
      14                 :             : 
      15                 :             : namespace wallet {
      16                 :             : namespace {
      17                 :             : const TestingSetup* g_setup;
      18                 :             : 
      19                 :           1 : void initialize_setup()
      20                 :             : {
      21   [ +  -  +  -  :           1 :     static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
                   +  - ]
      22                 :           1 :     g_setup = testing_setup.get();
      23                 :           1 : }
      24                 :             : 
      25         [ +  - ]:         535 : FUZZ_TARGET(wallet_fees, .init = initialize_setup)
      26                 :             : {
      27                 :          79 :     SeedRandomStateForTest(SeedRand::ZEROS);
      28                 :          79 :     FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
      29                 :          79 :     SetMockTime(ConsumeTime(fuzzed_data_provider));
      30                 :          79 :     const auto& node{g_setup->m_node};
      31                 :          79 :     Chainstate* chainstate = &node.chainman->ActiveChainstate();
      32   [ +  -  +  - ]:          79 :     std::unique_ptr<CWallet> wallet_ptr{std::make_unique<CWallet>(node.chain.get(), "", CreateMockableWalletDatabase())};
      33         [ +  - ]:          79 :     CWallet& wallet{*wallet_ptr};
      34                 :          79 :     {
      35         [ +  - ]:          79 :         LOCK(wallet.cs_wallet);
      36   [ -  +  +  - ]:         158 :         wallet.SetLastBlockProcessed(chainstate->m_chain.Height(), chainstate->m_chain.Tip()->GetBlockHash());
      37                 :           0 :     }
      38                 :             : 
      39         [ +  + ]:          79 :     if (fuzzed_data_provider.ConsumeBool()) {
      40                 :          17 :         wallet.m_fallback_fee = CFeeRate{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
      41                 :             :     }
      42                 :             : 
      43         [ +  + ]:          79 :     if (fuzzed_data_provider.ConsumeBool()) {
      44                 :          10 :         wallet.m_discard_rate = CFeeRate{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
      45                 :             :     }
      46         [ +  - ]:          79 :     (void)GetDiscardRate(wallet);
      47                 :             : 
      48                 :          79 :     const auto tx_bytes{fuzzed_data_provider.ConsumeIntegralInRange(0, std::numeric_limits<int32_t>::max())};
      49         [ +  + ]:          79 :     if (fuzzed_data_provider.ConsumeBool()) {
      50                 :          19 :         wallet.m_pay_tx_fee = CFeeRate{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
      51                 :          19 :         wallet.m_min_fee = CFeeRate{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
      52                 :             :     }
      53                 :             : 
      54         [ +  - ]:          79 :     (void)GetRequiredFee(wallet, tx_bytes);
      55         [ +  - ]:          79 :     (void)GetRequiredFeeRate(wallet);
      56                 :             : 
      57         [ +  - ]:          79 :     CCoinControl coin_control;
      58         [ +  + ]:          79 :     if (fuzzed_data_provider.ConsumeBool()) {
      59         [ -  + ]:          10 :         coin_control.m_feerate = CFeeRate{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
      60                 :             :     }
      61         [ +  + ]:          79 :     if (fuzzed_data_provider.ConsumeBool()) {
      62                 :          13 :         coin_control.m_confirm_target = fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, 999'000);
      63                 :             :     }
      64         [ +  + ]:          79 :     if (fuzzed_data_provider.ConsumeBool()) {
      65         [ +  + ]:          11 :         coin_control.m_fee_mode = fuzzed_data_provider.ConsumeBool() ? FeeEstimateMode::CONSERVATIVE : FeeEstimateMode::ECONOMICAL;
      66                 :             :     }
      67                 :             : 
      68                 :          79 :     FeeCalculation fee_calculation;
      69         [ +  + ]:          79 :     FeeCalculation* maybe_fee_calculation{fuzzed_data_provider.ConsumeBool() ? nullptr : &fee_calculation};
      70         [ +  - ]:          79 :     (void)GetMinimumFeeRate(wallet, coin_control, maybe_fee_calculation);
      71         [ +  - ]:          79 :     (void)GetMinimumFee(wallet, tx_bytes, coin_control, maybe_fee_calculation);
      72         [ +  - ]:         158 : }
      73                 :             : } // namespace
      74                 :             : } // namespace wallet
        

Generated by: LCOV version 2.0-1