Skip to content

Commit 3842732

Browse files
committed
test: Add testing of value_ret for SelectCoinsBnB
Fix that the early bailout optimization tests did not test the actual selection because their utxo pool was polluted by the make_hard_case test preceding.
1 parent 29b4ee6 commit 3842732

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/wallet/test/coinselector_tests.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,15 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
150150
add_coin(1 * CENT, 1, actual_selection);
151151
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), 1 * CENT, 0.5 * CENT, selection, value_ret, not_input_fees));
152152
BOOST_CHECK(equal_sets(selection, actual_selection));
153+
BOOST_CHECK_EQUAL(value_ret, 1 * CENT);
153154
actual_selection.clear();
154155
selection.clear();
155156

156157
// Select 2 Cent
157158
add_coin(2 * CENT, 2, actual_selection);
158159
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), 2 * CENT, 0.5 * CENT, selection, value_ret, not_input_fees));
159160
BOOST_CHECK(equal_sets(selection, actual_selection));
161+
BOOST_CHECK_EQUAL(value_ret, 2 * CENT);
160162
actual_selection.clear();
161163
selection.clear();
162164

@@ -165,6 +167,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
165167
add_coin(2 * CENT, 2, actual_selection);
166168
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), 5 * CENT, 0.5 * CENT, selection, value_ret, not_input_fees));
167169
BOOST_CHECK(equal_sets(selection, actual_selection));
170+
BOOST_CHECK_EQUAL(value_ret, 5 * CENT);
168171
actual_selection.clear();
169172
selection.clear();
170173

@@ -181,6 +184,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
181184
add_coin(1 * CENT, 1, actual_selection);
182185
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), 10 * CENT, 0.5 * CENT, selection, value_ret, not_input_fees));
183186
BOOST_CHECK(equal_sets(selection, actual_selection));
187+
BOOST_CHECK_EQUAL(value_ret, 10 * CENT);
184188
actual_selection.clear();
185189
selection.clear();
186190

@@ -190,6 +194,9 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
190194
add_coin(3 * CENT, 3, actual_selection);
191195
add_coin(2 * CENT, 2, actual_selection);
192196
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), 10 * CENT, 5000, selection, value_ret, not_input_fees));
197+
BOOST_CHECK_EQUAL(value_ret, 10 * CENT);
198+
// FIXME: this test is redundant with the above, because 1 Cent is selected, not "too small"
199+
// BOOST_CHECK(equal_sets(selection, actual_selection));
193200

194201
// Select 0.25 Cent, not possible
195202
BOOST_CHECK(!SelectCoinsBnB(GroupCoins(utxo_pool), 0.25 * CENT, 0.5 * CENT, selection, value_ret, not_input_fees));
@@ -203,6 +210,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
203210
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), target, 0, selection, value_ret, not_input_fees)); // Should not exhaust
204211

205212
// Test same value early bailout optimization
213+
utxo_pool.clear();
206214
add_coin(7 * CENT, 7, actual_selection);
207215
add_coin(7 * CENT, 7, actual_selection);
208216
add_coin(7 * CENT, 7, actual_selection);
@@ -217,6 +225,8 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
217225
add_coin(5 * CENT, 7, utxo_pool);
218226
}
219227
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), 30 * CENT, 5000, selection, value_ret, not_input_fees));
228+
BOOST_CHECK_EQUAL(value_ret, 30 * CENT);
229+
BOOST_CHECK(equal_sets(selection, actual_selection));
220230

221231
////////////////////
222232
// Behavior tests //

0 commit comments

Comments
 (0)