LCOV - code coverage report
Current view: top level - src/wallet/test/fuzz - fees.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 86.0 % 43 37
Test Date: 2024-09-01 05:20:30 Functions: 66.7 % 3 2
Branches: 53.8 % 52 28

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

Generated by: LCOV version 2.0-1