Skip to content

Commit 808618b

Browse files
committed
fuzz: coinselection, add coverage for AddInputs
1 parent 90c4e6a commit 808618b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/wallet/test/fuzz/coinselection.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ FUZZ_TARGET(coinselection)
9999
}
100100

101101
// Run coinselection algorithms
102-
const auto result_bnb = SelectCoinsBnB(group_pos, target, cost_of_change, MAX_STANDARD_TX_WEIGHT);
102+
auto result_bnb = SelectCoinsBnB(group_pos, target, cost_of_change, MAX_STANDARD_TX_WEIGHT);
103103

104104
auto result_srd = SelectCoinsSRD(group_pos, target, coin_params.m_change_fee, fast_random_context, MAX_STANDARD_TX_WEIGHT);
105105
if (result_srd) {
@@ -116,6 +116,22 @@ FUZZ_TARGET(coinselection)
116116
if (total_balance >= target && subtract_fee_outputs && !HasErrorMsg(result_knapsack)) {
117117
assert(result_knapsack);
118118
}
119+
120+
std::vector<COutput> utxos;
121+
std::vector<util::Result<SelectionResult>> results{result_srd, result_knapsack, result_bnb};
122+
CAmount new_total_balance{CreateCoins(fuzzed_data_provider, utxos, coin_params, next_locktime)};
123+
if (new_total_balance > 0) {
124+
std::set<std::shared_ptr<COutput>> new_utxo_pool;
125+
for (const auto& utxo : utxos) {
126+
new_utxo_pool.insert(std::make_shared<COutput>(utxo));
127+
}
128+
for (auto& result : results) {
129+
if (!result) continue;
130+
const auto weight{result->GetWeight()};
131+
result->AddInputs(new_utxo_pool, subtract_fee_outputs);
132+
assert(result->GetWeight() > weight);
133+
}
134+
}
119135
}
120136

121137
} // namespace wallet

0 commit comments

Comments
 (0)