From b25bccb42aeb7b56f64d09708140c27d15dc8c4e Mon Sep 17 00:00:00 2001 From: Murch Date: Fri, 1 Mar 2024 15:41:19 -0500 Subject: [PATCH] [test] Recreate simple BnB failure tests --- src/wallet/test/coinselection_tests.cpp | 17 +++++++++++++++++ src/wallet/test/coinselector_tests.cpp | 21 --------------------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/wallet/test/coinselection_tests.cpp b/src/wallet/test/coinselection_tests.cpp index 0ee50ac3e72b67..87894306c86db7 100644 --- a/src/wallet/test/coinselection_tests.cpp +++ b/src/wallet/test/coinselection_tests.cpp @@ -130,9 +130,18 @@ static void TestBnBSuccess(std::string test_title, std::vector& utxo_po expected_result.Clear(); } +static void TestBnBFail(std::string test_title, std::vector& utxo_pool, const CAmount& selection_target) +{ + BOOST_CHECK_MESSAGE(!SelectCoinsBnB(GroupCoins(utxo_pool), selection_target, /*cost_of_change=*/ default_cs_params.m_cost_of_change, /*max_weight=*/MAX_STANDARD_TX_WEIGHT), "BnB-Fail: " + test_title); +} + BOOST_AUTO_TEST_CASE(bnb_test) { std::vector utxo_pool; + + // Fail for empty UTXO pool + TestBnBFail("Empty UTXO pool", utxo_pool, /*selection_target=*/ 1 * CENT); + AddCoins(utxo_pool, {1 * CENT, 3 * CENT, 5 * CENT}); // Simple success cases @@ -145,6 +154,14 @@ BOOST_AUTO_TEST_CASE(bnb_test) // BnB finds changeless solution while overshooting by up to cost_of_change TestBnBSuccess("Select upper bound", utxo_pool, /*selection_target=*/ 9 * CENT - default_cs_params.m_cost_of_change, /*expected_input_amounts=*/ {1 * CENT, 3 * CENT, 5 * CENT}); + // BnB fails to find changeless solution when overshooting by cost_of_change + 1 sat + TestBnBFail("Overshoot upper bound", utxo_pool, /*selection_target=*/ 9 * CENT - default_cs_params.m_cost_of_change - 1); + + // Simple cases without BnB solution + TestBnBFail("Smallest combination too big", utxo_pool, /*selection_target=*/ 0.5 * CENT); + TestBnBFail("No UTXO combination in target window", utxo_pool, /*selection_target=*/ 7 * CENT); + TestBnBFail("Select more than available", utxo_pool, /*selection_target=*/ 10 * CENT); + // Test skipping of equivalent input sets std::vector clone_pool; AddCoins(clone_pool, {2 * CENT, 7 * CENT, 7 * CENT}); diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp index 4f83c72e9d5c3f..4f4d030aaf461c 100644 --- a/src/wallet/test/coinselector_tests.cpp +++ b/src/wallet/test/coinselector_tests.cpp @@ -199,27 +199,6 @@ BOOST_AUTO_TEST_CASE(bnb_search_test) // Known Outcome tests // ///////////////////////// - // Empty utxo pool - BOOST_CHECK(!SelectCoinsBnB(GroupCoins(utxo_pool), 1 * CENT, 0.5 * CENT)); - - // Add utxos - add_coin(1 * CENT, 1, utxo_pool); - add_coin(2 * CENT, 2, utxo_pool); - add_coin(3 * CENT, 3, utxo_pool); - add_coin(4 * CENT, 4, utxo_pool); - - // Select 11 Cent, not possible - BOOST_CHECK(!SelectCoinsBnB(GroupCoins(utxo_pool), 11 * CENT, 0.5 * CENT)); - expected_result.Clear(); - - // Cost of change is less than the difference between target value and utxo sum - BOOST_CHECK(!SelectCoinsBnB(GroupCoins(utxo_pool), 0.9 * CENT, 0)); - expected_result.Clear(); - - // Select 0.25 Cent, not possible - BOOST_CHECK(!SelectCoinsBnB(GroupCoins(utxo_pool), 0.25 * CENT, 0.5 * CENT)); - expected_result.Clear(); - // Iteration exhaustion test CAmount target = make_hard_case(17, utxo_pool); BOOST_CHECK(!SelectCoinsBnB(GroupCoins(utxo_pool), target, 1)); // Should exhaust