/root/bitcoin/src/wallet/test/fuzz/coincontrol.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | void initialize_coincontrol() |
18 | 0 | { |
19 | 0 | static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(); |
20 | 0 | g_setup = testing_setup.get(); |
21 | 0 | } |
22 | | |
23 | | FUZZ_TARGET(coincontrol, .init = initialize_coincontrol) |
24 | 0 | { |
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 | 0 | LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) |
36 | 0 | { |
37 | 0 | CallOneOf( |
38 | 0 | 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 | 0 | } |
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.Select(out_point).SetTxOut(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 | 0 | (void)coin_control.GetInputWeight(out_point); |
80 | 0 | }); |
81 | 0 | } |
82 | 0 | } |
83 | | } // namespace |
84 | | } // namespace wallet |