Skip to content

Commit 7a59865

Browse files
committed
Merge bitcoin/bitcoin#27647: fuzz: wallet, add target for fees
162602b fuzz: wallet, add target for `fees` (brunoerg) Pull request description: This PR adds fuzz coverage for `wallet/fees`. Some functions may use or not (non default) values from `wallet`, `CCoinControl` or `FeeCalculation`. So the logic is to make the test sometimes fill up some attributes and others no. Obs: As soon as this PR gets some reviews, I can open the proper PR to `qa-assets` as well. ACKs for top commit: Xekyo: ACK 162602b MarcoFalke: lgtm ACK 162602b dergoegge: Code review ACK 162602b Tree-SHA512: 6545802f27aafb60bf5a119af514e9425b643780dea6650bba766bb5be813f2aaddb7afc7f0efa2943ceb26f5ea08b42c95a3c0df897493c71f2d2f99e9e4236
2 parents 681ecac + 162602b commit 7a59865

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/Makefile.test.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ endif
195195

196196
FUZZ_WALLET_SRC = \
197197
wallet/test/fuzz/coinselection.cpp \
198+
wallet/test/fuzz/fees.cpp \
198199
wallet/test/fuzz/parse_iso8601.cpp
199200

200201
if USE_SQLITE

src/wallet/test/fuzz/fees.cpp

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

0 commit comments

Comments
 (0)