Skip to content

Commit b2eb558

Browse files
committed
fuzz: coinselection, compare GetSelectedValue with target
The valid results should have a target below the sum of the selected inputs amounts. Also, it increases the minimum value for target to make it more realistic.
1 parent 0df0438 commit b2eb558

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/wallet/test/fuzz/coinselection.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,14 @@ FUZZ_TARGET(coinselection)
115115
// Run coinselection algorithms
116116
auto result_bnb = SelectCoinsBnB(group_pos, target, coin_params.m_cost_of_change, MAX_STANDARD_TX_WEIGHT);
117117
if (result_bnb) {
118+
assert(result_bnb->GetSelectedValue() >= target);
118119
(void)result_bnb->GetShuffledInputVector();
119120
(void)result_bnb->GetInputSet();
120121
}
121122

122123
auto result_srd = SelectCoinsSRD(group_pos, target, coin_params.m_change_fee, fast_random_context, MAX_STANDARD_TX_WEIGHT);
123124
if (result_srd) {
125+
assert(result_srd->GetSelectedValue() >= target);
124126
assert(result_srd->GetChange(CHANGE_LOWER, coin_params.m_change_fee) > 0); // Demonstrate that SRD creates change of at least CHANGE_LOWER
125127
result_srd->ComputeAndSetWaste(coin_params.min_viable_change, coin_params.m_cost_of_change, coin_params.m_change_fee);
126128
(void)result_srd->GetShuffledInputVector();
@@ -130,6 +132,7 @@ FUZZ_TARGET(coinselection)
130132
CAmount change_target{GenerateChangeTarget(target, coin_params.m_change_fee, fast_random_context)};
131133
auto result_knapsack = KnapsackSolver(group_all, target, change_target, fast_random_context, MAX_STANDARD_TX_WEIGHT);
132134
if (result_knapsack) {
135+
assert(result_knapsack->GetSelectedValue() >= target);
133136
result_knapsack->ComputeAndSetWaste(coin_params.min_viable_change, coin_params.m_cost_of_change, coin_params.m_change_fee);
134137
(void)result_knapsack->GetShuffledInputVector();
135138
(void)result_knapsack->GetInputSet();

0 commit comments

Comments
 (0)