Merge bitcoin/bitcoin#31656: test: Add expected result assertions

a015b7e13daacdfb6db0eada50563dec70c5afb2 test: Add expected result assertions (yancy)

Pull request description:

  ~This is a trivial addition to the test suit, however it shouldn't be required to add debug statements and manually run the tests if someone needs to know the results of this test.~

  Add an assertion for the values returned. The goal of the test is to show that a minimal weight selection of UTXOs is returned by coin-grinder. Since there are multiple possible solutions, the added assertion shows that coin-grinder finds the solution with the lowest weight.  Without this assertion, it's ambiguous whether or not coin-grinder is returning the solution with the lowest weight.

  Remove the check that a result is returned since the expected result assertion implies a result.

ACKs for top commit:
  janb84:
    re ACK [a015b7e](a015b7e13d)
  murchandamus:
    ACK a015b7e13daacdfb6db0eada50563dec70c5afb2

Tree-SHA512: ee3c2688b4a4a07ab209f7655c3956e62a1084419df5e87c27d751a38ff64d4c3457df2317f8077149a6947cdb05b249975de2b8f0e18ca8b17b41f4735fb1c6
This commit is contained in:
Ryan Ofsky 2025-03-24 13:46:22 -04:00
commit b3162d10ea
No known key found for this signature in database
GPG Key ID: 46800E30FC748A66

View File

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