@@ -866,7 +866,23 @@ BOOST_AUTO_TEST_CASE(waste_test)
866
866
const CAmount new_target{in_amt - fee * 2 - fee_diff * 2 };
867
867
add_coin (1 * COIN, 1 , selection, fee, fee + fee_diff);
868
868
add_coin (2 * COIN, 2 , selection, fee, fee + fee_diff);
869
- BOOST_CHECK_EQUAL (0 , GetSelectionWaste (selection, /* change cost */ 0 , new_target));
869
+ BOOST_CHECK_EQUAL (0 , GetSelectionWaste (selection, /* change_cost=*/ 0 , new_target));
870
+ selection.clear ();
871
+
872
+ // Negative waste when the long term fee is greater than the current fee and the selected value == target
873
+ const CAmount exact_target1{3 * COIN - 2 * fee};
874
+ const CAmount target_waste1{-2 * fee_diff}; // = (2 * fee) - (2 * (fee + fee_diff))
875
+ add_coin (1 * COIN, 1 , selection, fee, fee + fee_diff);
876
+ add_coin (2 * COIN, 2 , selection, fee, fee + fee_diff);
877
+ BOOST_CHECK_EQUAL (target_waste1, GetSelectionWaste (selection, /* change_cost=*/ 0 , exact_target1));
878
+ selection.clear ();
879
+
880
+ // Negative waste when the long term fee is greater than the current fee and change_cost < - (inputs * (fee - long_term_fee))
881
+ const CAmount large_fee_diff{90 };
882
+ const CAmount target_waste2{-2 * large_fee_diff + change_cost}; // = (2 * fee) - (2 * (fee + large_fee_diff)) + change_cost
883
+ add_coin (1 * COIN, 1 , selection, fee, fee + large_fee_diff);
884
+ add_coin (2 * COIN, 2 , selection, fee, fee + large_fee_diff);
885
+ BOOST_CHECK_EQUAL (target_waste2, GetSelectionWaste (selection, change_cost, target));
870
886
}
871
887
872
888
BOOST_AUTO_TEST_CASE (effective_value_test)
0 commit comments