Skip to content

Commit a015b7e

Browse files
committed
test: Add expected result assertions
This test returns the lowest weight solution. Other possibilities either exceed allowed weight or result in a higher weight. Add an assertion which shows that the lowest weight solution is found and update the test description accordingly. Remove the check that a result is returned since the expected result assertion implies a result.
1 parent 3c1f72a commit a015b7e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/wallet/test/coinselector_tests.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ BOOST_AUTO_TEST_CASE(coin_grinder_tests)
11681168

11691169
{
11701170
// ###############################################################################################################
1171-
// 3) Test selection when some coins surpass the max allowed weight while others not. --> must find a good solution
1171+
// 3) Test that the lowest-weight solution is found when some combinations would exceed the allowed weight
11721172
// ################################################################################################################
11731173
CAmount target = 25.33L * COIN;
11741174
int max_selection_weight = 10'000; // WU
@@ -1182,7 +1182,14 @@ BOOST_AUTO_TEST_CASE(coin_grinder_tests)
11821182
}
11831183
return available_coins;
11841184
});
1185-
BOOST_CHECK(res);
1185+
SelectionResult expected_result(CAmount(0), SelectionAlgorithm::CG);
1186+
for (int i = 0; i < 10; ++i) {
1187+
add_coin(2 * COIN, i, expected_result);
1188+
}
1189+
for (int j = 0; j < 17; ++j) {
1190+
add_coin(0.33 * COIN, j + 10, expected_result);
1191+
}
1192+
BOOST_CHECK(EquivalentResult(expected_result, *res));
11861193
// Demonstrate how following improvements reduce iteration count and catch any regressions in the future.
11871194
size_t expected_attempts = 37;
11881195
BOOST_CHECK_MESSAGE(res->GetSelectionsEvaluated() == expected_attempts, strprintf("Expected %i attempts, but got %i", expected_attempts, res->GetSelectionsEvaluated()));

0 commit comments

Comments
 (0)