Skip to content

Commit

Permalink
fuzz: coinselection, add coverage for AddInputs
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoerg committed Aug 23, 2023
1 parent 90c4e6a commit 808618b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/wallet/test/fuzz/coinselection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ FUZZ_TARGET(coinselection)
}

// Run coinselection algorithms
const auto result_bnb = SelectCoinsBnB(group_pos, target, cost_of_change, MAX_STANDARD_TX_WEIGHT);
auto result_bnb = SelectCoinsBnB(group_pos, target, cost_of_change, MAX_STANDARD_TX_WEIGHT);

auto result_srd = SelectCoinsSRD(group_pos, target, coin_params.m_change_fee, fast_random_context, MAX_STANDARD_TX_WEIGHT);
if (result_srd) {
Expand All @@ -116,6 +116,22 @@ FUZZ_TARGET(coinselection)
if (total_balance >= target && subtract_fee_outputs && !HasErrorMsg(result_knapsack)) {
assert(result_knapsack);
}

std::vector<COutput> utxos;
std::vector<util::Result<SelectionResult>> results{result_srd, result_knapsack, result_bnb};
CAmount new_total_balance{CreateCoins(fuzzed_data_provider, utxos, coin_params, next_locktime)};
if (new_total_balance > 0) {
std::set<std::shared_ptr<COutput>> new_utxo_pool;
for (const auto& utxo : utxos) {
new_utxo_pool.insert(std::make_shared<COutput>(utxo));
}
for (auto& result : results) {
if (!result) continue;
const auto weight{result->GetWeight()};
result->AddInputs(new_utxo_pool, subtract_fee_outputs);
assert(result->GetWeight() > weight);
}
}
}

} // namespace wallet

0 comments on commit 808618b

Please sign in to comment.