Skip to content

Commit

Permalink
Refactor knapsack exact match test
Browse files Browse the repository at this point in the history
  • Loading branch information
murchandamus committed Dec 6, 2023
1 parent 171a80a commit c97ac7d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
8 changes: 8 additions & 0 deletions src/wallet/test/coinselection_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<COutput> 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)
{
Expand Down
18 changes: 0 additions & 18 deletions src/wallet/test/coinselector_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CWallet> 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)
{
Expand Down

0 comments on commit c97ac7d

Please sign in to comment.