Skip to content

Commit 4781f5c

Browse files
committed
test: Recreate simple BnB failure tests
1 parent a94030a commit 4781f5c

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

src/wallet/test/coinselection_tests.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,18 @@ static void TestBnBSuccess(std::string test_title, std::vector<OutputGroup>& utx
109109
BOOST_CHECK_MESSAGE(result->GetSelectedValue() == expected_amount, strprintf("Selected amount mismatch in BnB-Success: %s. Expected %d, but got %d", test_title, expected_amount, result->GetSelectedValue()));
110110
}
111111

112+
static void TestBnBFail(std::string test_title, std::vector<OutputGroup>& utxo_pool, const CAmount& selection_target)
113+
{
114+
BOOST_CHECK_MESSAGE(!SelectCoinsBnB(utxo_pool, selection_target, /*cost_of_change=*/default_cs_params.m_cost_of_change, /*max_selection_weight=*/MAX_STANDARD_TX_WEIGHT), "BnB-Fail: " + test_title);
115+
}
116+
112117
BOOST_AUTO_TEST_CASE(bnb_test)
113118
{
114119
std::vector<OutputGroup> utxo_pool;
120+
121+
// Fail for empty UTXO pool
122+
TestBnBFail("Empty UTXO pool", utxo_pool, /*selection_target=*/1 * CENT);
123+
115124
AddCoins(utxo_pool, {1 * CENT, 3 * CENT, 5 * CENT});
116125

117126
// Simple success cases
@@ -124,6 +133,14 @@ BOOST_AUTO_TEST_CASE(bnb_test)
124133
// BnB finds changeless solution while overshooting by up to cost_of_change
125134
TestBnBSuccess("Select upper bound", utxo_pool, /*selection_target=*/4 * CENT - default_cs_params.m_cost_of_change, /*expected_input_amounts=*/{1 * CENT, 3 * CENT});
126135

136+
// BnB fails to find changeless solution when overshooting by cost_of_change + 1 sat
137+
TestBnBFail("Overshoot upper bound", utxo_pool, /*selection_target=*/4 * CENT - default_cs_params.m_cost_of_change - 1);
138+
139+
// Simple cases without BnB solution
140+
TestBnBFail("Smallest combination too big", utxo_pool, /*selection_target=*/0.5 * CENT);
141+
TestBnBFail("No UTXO combination in target window", utxo_pool, /*selection_target=*/7 * CENT);
142+
TestBnBFail("Select more than available", utxo_pool, /*selection_target=*/10 * CENT);
143+
127144
// Test skipping of equivalent input sets
128145
std::vector<OutputGroup> clone_pool;
129146
AddCoins(clone_pool, {2 * CENT, 7 * CENT, 7 * CENT});

src/wallet/test/coinselector_tests.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -199,27 +199,6 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
199199
// Known Outcome tests //
200200
/////////////////////////
201201

202-
// Empty utxo pool
203-
BOOST_CHECK(!SelectCoinsBnB(GroupCoins(utxo_pool), 1 * CENT, 0.5 * CENT));
204-
205-
// Add utxos
206-
add_coin(1 * CENT, 1, utxo_pool);
207-
add_coin(2 * CENT, 2, utxo_pool);
208-
add_coin(3 * CENT, 3, utxo_pool);
209-
add_coin(4 * CENT, 4, utxo_pool);
210-
211-
// Select 11 Cent, not possible
212-
BOOST_CHECK(!SelectCoinsBnB(GroupCoins(utxo_pool), 11 * CENT, 0.5 * CENT));
213-
expected_result.Clear();
214-
215-
// Cost of change is less than the difference between target value and utxo sum
216-
BOOST_CHECK(!SelectCoinsBnB(GroupCoins(utxo_pool), 0.9 * CENT, 0));
217-
expected_result.Clear();
218-
219-
// Select 0.25 Cent, not possible
220-
BOOST_CHECK(!SelectCoinsBnB(GroupCoins(utxo_pool), 0.25 * CENT, 0.5 * CENT));
221-
expected_result.Clear();
222-
223202
// Iteration exhaustion test
224203
CAmount target = make_hard_case(17, utxo_pool);
225204
BOOST_CHECK(!SelectCoinsBnB(GroupCoins(utxo_pool), target, 1)); // Should exhaust

0 commit comments

Comments
 (0)