Skip to content

Commit c92eb6c

Browse files
committed
Merge bitcoin/bitcoin#25562: test: add tests for negative waste during coin selection
98ea43d test: add tests for negative waste during coin selection (ishaanam) Pull request description: #25495 mentions that waste can be negative when the current feerate is less than the long term feerate. There are currently no waste tests for negative waste, so this PR adds two of them. ACKs for top commit: achow101: ACK 98ea43d glozow: light code review ACK 98ea43d, good to have tests for negative waste Tree-SHA512: d194d370f1257975959d3c601fea9f82c30c1aabc3e8bedc997c62659283fe681cc527e59df1a0187b3c91e8067c60374dd5ce0237561bd882edafe6a575a9b9
2 parents 0817cc3 + 98ea43d commit c92eb6c

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/wallet/test/coinselector_tests.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,23 @@ BOOST_AUTO_TEST_CASE(waste_test)
867867
const CAmount new_target{in_amt - fee * 2 - fee_diff * 2};
868868
add_coin(1 * COIN, 1, selection, fee, fee + fee_diff);
869869
add_coin(2 * COIN, 2, selection, fee, fee + fee_diff);
870-
BOOST_CHECK_EQUAL(0, GetSelectionWaste(selection, /* change cost */ 0, new_target));
870+
BOOST_CHECK_EQUAL(0, GetSelectionWaste(selection, /*change_cost=*/ 0, new_target));
871+
selection.clear();
872+
873+
// Negative waste when the long term fee is greater than the current fee and the selected value == target
874+
const CAmount exact_target1{3 * COIN - 2 * fee};
875+
const CAmount target_waste1{-2 * fee_diff}; // = (2 * fee) - (2 * (fee + fee_diff))
876+
add_coin(1 * COIN, 1, selection, fee, fee + fee_diff);
877+
add_coin(2 * COIN, 2, selection, fee, fee + fee_diff);
878+
BOOST_CHECK_EQUAL(target_waste1, GetSelectionWaste(selection, /*change_cost=*/ 0, exact_target1));
879+
selection.clear();
880+
881+
// Negative waste when the long term fee is greater than the current fee and change_cost < - (inputs * (fee - long_term_fee))
882+
const CAmount large_fee_diff{90};
883+
const CAmount target_waste2{-2 * large_fee_diff + change_cost}; // = (2 * fee) - (2 * (fee + large_fee_diff)) + change_cost
884+
add_coin(1 * COIN, 1, selection, fee, fee + large_fee_diff);
885+
add_coin(2 * COIN, 2, selection, fee, fee + large_fee_diff);
886+
BOOST_CHECK_EQUAL(target_waste2, GetSelectionWaste(selection, change_cost, target));
871887
}
872888

873889
BOOST_AUTO_TEST_CASE(effective_value_test)

0 commit comments

Comments
 (0)