From c97ac7d7df11ccada88738f15f137fe1b7c22ac1 Mon Sep 17 00:00:00 2001 From: Murch Date: Tue, 5 Dec 2023 19:35:57 -0500 Subject: [PATCH] Refactor knapsack exact match test --- src/wallet/test/coinselection_tests.cpp | 8 ++++++++ src/wallet/test/coinselector_tests.cpp | 18 ------------------ 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/wallet/test/coinselection_tests.cpp b/src/wallet/test/coinselection_tests.cpp index 11709bb3a554cd..ed77d84efa475e 100644 --- a/src/wallet/test/coinselection_tests.cpp +++ b/src/wallet/test/coinselection_tests.cpp @@ -196,6 +196,14 @@ BOOST_AUTO_TEST_CASE(knapsack_predictable_test) TestKnapsackMatch("Select more to get min_change", utxo_pool, /*selection_target=*/ 9.976 * CENT, /*expected_input_amounts=*/ {11 * CENT}); } +BOOST_AUTO_TEST_CASE(knapsack_exact_match_test) +{ + std::vector exact_match_pool; + AddDuplicateCoins(exact_match_pool, /*count=*/ 1000, /*amount=*/ 5 * CENT); + AddDuplicateCoins(exact_match_pool, /*count=*/ 1000, /*amount=*/ 3 * CENT); + TestKnapsackMatch("Find exact match in large UTXO pool", exact_match_pool, /*selection_target=*/ 8 * CENT, /*expected_input_amounts=*/ {5 * CENT, 3 * CENT}); +} + /** Check if this selection is equal to another one. Equal means same inputs (i.e same value and prevout) */ static bool EqualResult(const SelectionResult& a, const SelectionResult& b) { diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp index 4bc7c0369f388f..b059e62f2f1e0c 100644 --- a/src/wallet/test/coinselector_tests.cpp +++ b/src/wallet/test/coinselector_tests.cpp @@ -151,24 +151,6 @@ BOOST_AUTO_TEST_CASE(tx_creation_bnb_sffo_restriction) BOOST_CHECK(CreateTransaction(*wallet, {recipient}, /*change_pos=*/-1, coin_control)); } -BOOST_AUTO_TEST_CASE(ApproximateBestSubset) -{ - FastRandomContext rand{}; - std::unique_ptr wallet = NewWallet(m_node); - - CoinsResult available_coins; - - // Test vValue sort order - for (int i = 0; i < 1000; i++) - add_coin(available_coins, *wallet, 1000 * COIN); - add_coin(available_coins, *wallet, 3 * COIN); - - const auto result = KnapsackSolver(KnapsackGroupOutputs(available_coins, *wallet, filter_standard), 1003 * COIN, CENT, rand); - BOOST_CHECK(result); - BOOST_CHECK_EQUAL(result->GetSelectedValue(), 1003 * COIN); - BOOST_CHECK_EQUAL(result->GetInputSet().size(), 2U); -} - // Tests that with the ideal conditions, the coin selector will always be able to find a solution that can pay the target value BOOST_AUTO_TEST_CASE(SelectCoins_test) {