Bitcoin Core 28.99.0
P2P Digital Currency
coincontrol.cpp
Go to the documentation of this file.
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
6#include <test/fuzz/fuzz.h>
7#include <test/fuzz/util.h>
10#include <wallet/test/util.h>
11
12namespace wallet {
13namespace {
14
15const TestingSetup* g_setup;
16
17void initialize_coincontrol()
18{
19 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
20 g_setup = testing_setup.get();
21}
22
23FUZZ_TARGET(coincontrol, .init = initialize_coincontrol)
24{
25 FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
26 const auto& node = g_setup->m_node;
27 ArgsManager& args = *node.args;
28
29 // for GetBoolArg to return true sometimes
30 args.ForceSetArg("-avoidpartialspends", fuzzed_data_provider.ConsumeBool()?"1":"0");
31
32 CCoinControl coin_control;
33 COutPoint out_point;
34
35 LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000)
36 {
38 fuzzed_data_provider,
39 [&] {
40 std::optional<COutPoint> optional_out_point = ConsumeDeserializable<COutPoint>(fuzzed_data_provider);
41 if (!optional_out_point) {
42 return;
43 }
44 out_point = *optional_out_point;
45 },
46 [&] {
47 (void)coin_control.HasSelected();
48 },
49 [&] {
50 (void)coin_control.IsSelected(out_point);
51 },
52 [&] {
53 (void)coin_control.IsExternalSelected(out_point);
54 },
55 [&] {
56 (void)coin_control.GetExternalOutput(out_point);
57 },
58 [&] {
59 (void)coin_control.Select(out_point);
60 },
61 [&] {
62 const CTxOut tx_out{ConsumeMoney(fuzzed_data_provider), ConsumeScript(fuzzed_data_provider)};
63 (void)coin_control.Select(out_point).SetTxOut(tx_out);
64 },
65 [&] {
66 (void)coin_control.UnSelect(out_point);
67 },
68 [&] {
69 (void)coin_control.UnSelectAll();
70 },
71 [&] {
72 (void)coin_control.ListSelected();
73 },
74 [&] {
75 int64_t weight{fuzzed_data_provider.ConsumeIntegral<int64_t>()};
76 (void)coin_control.SetInputWeight(out_point, weight);
77 },
78 [&] {
79 (void)coin_control.GetInputWeight(out_point);
80 });
81 }
82}
83} // namespace
84} // namespace wallet
ArgsManager & args
Definition: bitcoind.cpp:277
void ForceSetArg(const std::string &strArg, const std::string &strValue)
Definition: args.cpp:546
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:29
An output of a transaction.
Definition: transaction.h:150
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
Definition: fuzz.h:22
Definition: messages.h:20
FUZZ_TARGET(coin_grinder)
node::NodeContext m_node
Definition: setup_common.h:65
Testing setup that configures a complete environment.
Definition: setup_common.h:120
CScript ConsumeScript(FuzzedDataProvider &fuzzed_data_provider, const bool maybe_p2wsh) noexcept
Definition: util.cpp:93
CAmount ConsumeMoney(FuzzedDataProvider &fuzzed_data_provider, const std::optional< CAmount > &max) noexcept
Definition: util.cpp:29
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
Definition: util.h:35