diff options
author | brunoerg <brunoely.gc@gmail.com> | 2023-05-04 14:52:03 -0300 |
---|---|---|
committer | brunoerg <brunoely.gc@gmail.com> | 2023-08-23 14:47:11 -0300 |
commit | 808618b8a25b1d9cfc4e4f1a5b4c6fff02972396 (patch) | |
tree | 3ece340e77444899f1cb8f3f5cbadc821bad7bba | |
parent | 90c4e6a241eee605809ab1b4331e620b92f05933 (diff) |
fuzz: coinselection, add coverage for `AddInputs`
-rw-r--r-- | src/wallet/test/fuzz/coinselection.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/wallet/test/fuzz/coinselection.cpp b/src/wallet/test/fuzz/coinselection.cpp index 6545d9ad9e..1a682599fe 100644 --- a/src/wallet/test/fuzz/coinselection.cpp +++ b/src/wallet/test/fuzz/coinselection.cpp @@ -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) { @@ -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 |