Skip to content

Commit 8132644

Browse files
committed
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.
1 parent 6b58eb6 commit 8132644

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/wallet/test/coinselection_tests.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,31 @@ BOOST_AUTO_TEST_CASE(bnb_test)
220220
}
221221
}
222222

223+
BOOST_AUTO_TEST_CASE(bnb_exhaustion_with_solution_test)
224+
{
225+
std::vector<OutputGroup> utxo_pool;
226+
227+
CAmount selection_target{0};
228+
const size_t pairs{17};
229+
for (size_t i = 0; i < pairs; ++i) {
230+
const CAmount base{CAmount{1} << (pairs + i)};
231+
selection_target += base;
232+
utxo_pool.push_back(MakeCoin(base, /*is_eff_value=*/true, default_cs_params));
233+
utxo_pool.push_back(MakeCoin(base + (CAmount{1} << (pairs - 1 - i)), /*is_eff_value=*/true, default_cs_params));
234+
}
235+
236+
// Add an exact-match solution that is found immediately. BnB must still report that the algorithm did not
237+
// complete once the remaining hard case pushes the search into the attempt limit.
238+
AddCoins(utxo_pool, {selection_target}, default_cs_params);
239+
240+
const auto result{SelectCoinsBnB(utxo_pool, selection_target, /*cost_of_change=*/0, MAX_STANDARD_TX_WEIGHT)};
241+
BOOST_CHECK_MESSAGE(result, "Falsy result in BnB-Success: Exhaust with early solution");
242+
BOOST_CHECK_EQUAL(result->GetSelectedEffectiveValue(), selection_target);
243+
BOOST_CHECK_EQUAL(result->GetInputSet().size(), 1U);
244+
BOOST_CHECK_EQUAL(result->GetSelectionsEvaluated(), 100'000U);
245+
BOOST_CHECK(!result->GetAlgoCompleted());
246+
}
247+
223248
BOOST_AUTO_TEST_CASE(bnb_feerate_sensitivity_test)
224249
{
225250
// Create sets of UTXOs with the same effective amounts at different feerates (but different absolute amounts)

0 commit comments

Comments
 (0)