test: wallet: BnB incomplete result on attempt-limit success

BnB can return a valid selection before exhausting
the search tree, then hit TOTAL_TRIES while continuing
to look for a better one. Add a unit test for that path
using a known exhaustion fixture plus an exact-match
coin, and assert the result is marked incomplete via
GetAlgoCompleted() == false.

Co-authored-by: Murch <murch@murch.one>
This commit is contained in:
Bruno Garcia
2026-06-22 20:23:04 -03:00
parent 6b58eb6d51
commit 6ee05c4b18

View File

@@ -220,6 +220,26 @@ BOOST_AUTO_TEST_CASE(bnb_test)
}
}
BOOST_AUTO_TEST_CASE(bnb_exhaustion_with_solution_test)
{
std::vector<OutputGroup> utxo_pool;
utxo_pool.reserve(19);
CAmount selection_target{800'000};
// A hard case with no exact-match solution: BnB must still report that the algorithm did not complete once the
// search is pushed into the attempt limit, even though it finds a solution within cost_of_change of the target.
for (size_t i = 0; i < 19; ++i) {
utxo_pool.push_back(MakeCoin(100'000 + i, /*is_eff_value=*/true, default_cs_params));
}
const auto result{SelectCoinsBnB(utxo_pool, selection_target, /*cost_of_change=*/default_cs_params.m_cost_of_change, MAX_STANDARD_TX_WEIGHT)};
BOOST_CHECK_MESSAGE(result, "Falsy result in BnB-Success: Exhaust with early solution");
BOOST_CHECK(result->GetSelectedEffectiveValue() > selection_target + 28);
BOOST_CHECK_EQUAL(result->GetInputSet().size(), 8U);
BOOST_CHECK_EQUAL(result->GetSelectionsEvaluated(), 100'000U);
BOOST_CHECK(!result->GetAlgoCompleted());
}
BOOST_AUTO_TEST_CASE(bnb_feerate_sensitivity_test)
{
// Create sets of UTXOs with the same effective amounts at different feerates (but different absolute amounts)