LCOV - code coverage report
Current view: top level - src/wallet/test/fuzz - coincontrol.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 4 60 6.7 %
Date: 2023-11-10 23:46:46 Functions: 1 19 5.3 %
Branches: 4 42 9.5 %

           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/test/util.h>
      11                 :            : 
      12                 :            : namespace wallet {
      13                 :            : namespace {
      14                 :            : 
      15                 :            : const TestingSetup* g_setup;
      16                 :            : 
      17         [ +  - ]:          2 : void initialize_coincontrol()
      18         [ +  - ]:          2 : {
      19 [ #  # ][ #  # ]:          0 :     static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
                 [ #  # ]
      20                 :          0 :     g_setup = testing_setup.get();
      21                 :          0 : }
      22                 :            : 
      23         [ +  - ]:          4 : FUZZ_TARGET(coincontrol, .init = initialize_coincontrol)
      24                 :            : {
      25                 :          0 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      26                 :          0 :     const auto& node = g_setup->m_node;
      27                 :          0 :     ArgsManager& args = *node.args;
      28                 :            : 
      29                 :            :     // for GetBoolArg to return true sometimes
      30 [ #  # ][ #  # ]:          0 :     args.ForceSetArg("-avoidpartialspends", fuzzed_data_provider.ConsumeBool()?"1":"0");
         [ #  # ][ #  # ]
                 [ #  # ]
      31                 :            : 
      32                 :          0 :     CCoinControl coin_control;
      33         [ #  # ]:          0 :     COutPoint out_point;
      34                 :            : 
      35 [ +  - ][ #  # ]:          2 :     LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000)
         [ #  # ][ #  # ]
      36                 :            :     {
      37         [ #  # ]:          0 :         CallOneOf(
      38                 :            :             fuzzed_data_provider,
      39                 :          0 :             [&] {
      40                 :          0 :                 std::optional<COutPoint> optional_out_point = ConsumeDeserializable<COutPoint>(fuzzed_data_provider);
      41         [ #  # ]:          0 :                 if (!optional_out_point) {
      42                 :          0 :                     return;
      43                 :            :                 }
      44                 :          0 :                 out_point = *optional_out_point;
      45                 :          0 :             },
      46                 :          0 :             [&] {
      47                 :          0 :                 (void)coin_control.HasSelected();
      48                 :          0 :             },
      49                 :          0 :             [&] {
      50                 :          0 :                 (void)coin_control.IsSelected(out_point);
      51                 :          0 :             },
      52                 :          0 :             [&] {
      53                 :          0 :                 (void)coin_control.IsExternalSelected(out_point);
      54                 :          0 :             },
      55                 :          0 :             [&] {
      56                 :          0 :                 (void)coin_control.GetExternalOutput(out_point);
      57                 :          0 :             },
      58                 :          0 :             [&] {
      59                 :          0 :                 (void)coin_control.Select(out_point);
      60                 :          0 :             },
      61                 :          0 :             [&] {
      62         [ #  # ]:          0 :                 const CTxOut tx_out{ConsumeMoney(fuzzed_data_provider), ConsumeScript(fuzzed_data_provider)};
      63         [ #  # ]:          0 :                 (void)coin_control.SelectExternal(out_point, tx_out);
      64                 :          0 :             },
      65                 :          0 :             [&] {
      66                 :          0 :                 (void)coin_control.UnSelect(out_point);
      67                 :          0 :             },
      68                 :          0 :             [&] {
      69                 :          0 :                 (void)coin_control.UnSelectAll();
      70                 :          0 :             },
      71                 :          0 :             [&] {
      72                 :          0 :                 (void)coin_control.ListSelected();
      73                 :          0 :             },
      74                 :          0 :             [&] {
      75                 :          0 :                 int64_t weight{fuzzed_data_provider.ConsumeIntegral<int64_t>()};
      76                 :          0 :                 (void)coin_control.SetInputWeight(out_point, weight);
      77                 :          0 :             },
      78                 :          0 :             [&] {
      79                 :            :                 // Condition to avoid the assertion in GetInputWeight
      80         [ #  # ]:          0 :                 if (coin_control.HasInputWeight(out_point)) {
      81                 :          0 :                     (void)coin_control.GetInputWeight(out_point);
      82                 :          0 :                 }
      83                 :          0 :             });
      84                 :          0 :     }
      85                 :          0 : }
      86                 :            : } // namespace
      87                 :            : } // namespace wallet

Generated by: LCOV version 1.14