LCOV - code coverage report
Current view: top level - src/wallet/test/fuzz - fees.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 53 53 100.0 %
Date: 2023-09-26 12:08:55 Functions: 14 14 100.0 %

          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         173 : const TestingSetup* g_setup;
      18         173 : static std::unique_ptr<CWallet> g_wallet_ptr;
      19             : 
      20           1 : void initialize_setup()
      21             : {
      22           1 :     static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
      23           1 :     g_setup = testing_setup.get();
      24           1 :     const auto& node{g_setup->m_node};
      25           1 :     g_wallet_ptr = std::make_unique<CWallet>(node.chain.get(), "", CreateMockableWalletDatabase());
      26           1 : }
      27         173 : 
      28         995 : FUZZ_TARGET(wallet_fees, .init = initialize_setup)
      29             : {
      30         649 :     FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
      31         649 :     const auto& node{g_setup->m_node};
      32         649 :     Chainstate* chainstate = &node.chainman->ActiveChainstate();
      33         649 :     CWallet& wallet = *g_wallet_ptr;
      34             :     {
      35         822 :         LOCK(wallet.cs_wallet);
      36         649 :         wallet.SetLastBlockProcessed(chainstate->m_chain.Height(), chainstate->m_chain.Tip()->GetBlockHash());
      37         649 :     }
      38             : 
      39         649 :     if (fuzzed_data_provider.ConsumeBool()) {
      40         205 :         wallet.m_discard_rate = CFeeRate{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
      41         205 :     }
      42         649 :     (void)GetDiscardRate(wallet);
      43             : 
      44         649 :     const auto tx_bytes{fuzzed_data_provider.ConsumeIntegral<unsigned int>()};
      45             : 
      46         649 :     if (fuzzed_data_provider.ConsumeBool()) {
      47         170 :         wallet.m_pay_tx_fee = CFeeRate{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
      48         170 :         wallet.m_min_fee = CFeeRate{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
      49         170 :     }
      50             : 
      51         649 :     (void)GetRequiredFee(wallet, tx_bytes);
      52         649 :     (void)GetRequiredFeeRate(wallet);
      53         346 : 
      54         649 :     CCoinControl coin_control;
      55         649 :     if (fuzzed_data_provider.ConsumeBool()) {
      56         111 :         coin_control.m_feerate = CFeeRate{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
      57         111 :     }
      58         649 :     if (fuzzed_data_provider.ConsumeBool()) {
      59         137 :         coin_control.m_confirm_target = fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, 999'000);
      60         137 :     }
      61             : 
      62         649 :     FeeCalculation fee_calculation;
      63         649 :     FeeCalculation* maybe_fee_calculation{fuzzed_data_provider.ConsumeBool() ? nullptr : &fee_calculation};
      64         649 :     (void)GetMinimumFeeRate(wallet, coin_control, maybe_fee_calculation);
      65         649 :     (void)GetMinimumFee(wallet, tx_bytes, coin_control, maybe_fee_calculation);
      66         649 : }
      67             : } // namespace
      68             : } // namespace wallet

Generated by: LCOV version 1.14