aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/test/coinselector_tests.cpp
diff options
context:
space:
mode:
authorrajarshimaitra <rajarshi149@gmail.com>2021-09-10 15:47:37 +0530
committerrajarshimaitra <rajarshi149@gmail.com>2021-09-24 15:36:58 +0530
commitefcaefc7b5ffe0495e7c809032342ee5ca4841be (patch)
treea49c8915d7c7836601d997a955fe546aaa8ac9da /src/wallet/test/coinselector_tests.cpp
parent053a5fc7d912d597cd6dc7376b479420d1eae1c0 (diff)
test: Add remaining scenarios of 0 waste
There are two more cases where waste can be 0, when: - (Fee - LTF) == -Change Cost - (Fee - LTF) == -Excess Adding these two conditions explicitly in the unit test will help pin the behavior, also demonstrate waste calculation scenarios to new readers.
Diffstat (limited to 'src/wallet/test/coinselector_tests.cpp')
-rw-r--r--src/wallet/test/coinselector_tests.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp
index 5d51809241..40d9e90d56 100644
--- a/src/wallet/test/coinselector_tests.cpp
+++ b/src/wallet/test/coinselector_tests.cpp
@@ -724,12 +724,25 @@ BOOST_AUTO_TEST_CASE(waste_test)
BOOST_CHECK_LT(waste_nochange2, waste_nochange1);
selection.clear();
- // 0 Waste only when fee == long term fee, no change, and no excess
+ // No Waste when fee == long_term_fee, no change, and no excess
add_coin(1 * COIN, 1, selection, fee, fee);
add_coin(2 * COIN, 2, selection, fee, fee);
- const CAmount exact_target = in_amt - 2 * fee;
- BOOST_CHECK_EQUAL(0, GetSelectionWaste(selection, 0, exact_target));
+ const CAmount exact_target{in_amt - fee * 2};
+ BOOST_CHECK_EQUAL(0, GetSelectionWaste(selection, /* change_cost */ 0, exact_target));
+ selection.clear();
+ // No Waste when (fee - long_term_fee) == (-cost_of_change), and no excess
+ const CAmount new_change_cost{fee_diff * 2};
+ add_coin(1 * COIN, 1, selection, fee, fee + fee_diff);
+ add_coin(2 * COIN, 2, selection, fee, fee + fee_diff);
+ BOOST_CHECK_EQUAL(0, GetSelectionWaste(selection, new_change_cost, target));
+ selection.clear();
+
+ // No Waste when (fee - long_term_fee) == (-excess), no change cost
+ const CAmount new_target{in_amt - fee * 2 - fee_diff * 2};
+ add_coin(1 * COIN, 1, selection, fee, fee + fee_diff);
+ add_coin(2 * COIN, 2, selection, fee, fee + fee_diff);
+ BOOST_CHECK_EQUAL(0, GetSelectionWaste(selection, /* change cost */ 0, new_target));
}
BOOST_AUTO_TEST_SUITE_END()