add test with input costs + comment changes
MODIFY
WalletWasabi.Tests/UnitTests/Blockchain/TransactionBuilding/BranchAndBoundTests.cs
WalletWasabi.Tests/UnitTests/Blockchain/TransactionBuilding/BranchAndBoundTests.cs
@@ -32,8 +32,6 @@ public class BranchAndBoundTests
public void CheapestSelection_ExactMatchIsAlsoCheapest()
{
long[] inputValues = new long[] { 35, 17, 10, 5, 3, 2 };
-
- // Make the second input very expensive to spend so that it is not selected (not likely in reality).
long[] inputCosts = new long[] { 1, 5, 1, 1, 1, 1 };
long target = 27;
@@ -77,7 +75,7 @@ public class BranchAndBoundTests
}
[Fact]
- public void LesserSelection_NoInputCost()
+ public void LesserSelection_NoInputCosts()
{
long[] inputValues = new long[] { 35, 17, 10, 5, 3, 2 };
long[] inputCosts = new long[] { 0, 0, 0, 0, 0, 0 };
@@ -97,4 +95,26 @@ public class BranchAndBoundTests
// Target 26, closest match is 25. (17, 5, 3)
Assert.Equal(new long[] { 17, 5, 3 }, actualSelection);
}
+
+ [Fact]
+ public void LesserSelection_WithInputCosts()
+ {
+ long[] inputValues = new long[] { 35, 17, 10, 5, 3, 2 };
+ long[] inputCosts = new long[] { 1, 2, 1, 3, 1, 1 };
+
+ long target = 32;
+
+ BranchAndBound algorithm = new();
+ CheapestSelectionStrategy strategy = new(SuggestionType.Less, target, inputValues, inputCosts);
+ bool wasSuccessful = algorithm.TryGetMatch(strategy, out List<long>? selectedCoins);
+
+ Assert.False(wasSuccessful);
+ Assert.Null(selectedCoins);
+
+ long[] actualSelection = strategy.GetBestSelectionFound()!;
+ Assert.NotNull(actualSelection);
+
+ // Target 32, closest match is 31: (17 + 2) + (5 + 3) + (3 + 1) = 31
+ Assert.Equal(new long[] { 17, 5, 3 }, actualSelection);
+ }
}

MODIFY
WalletWasabi/Blockchain/TransactionBuilding/BnB/CheapestSelectionStrategy.cs
WalletWasabi/Blockchain/TransactionBuilding/BnB/CheapestSelectionStrategy.cs
@@ -152,7 +152,7 @@ public class CheapestSelectionStrategy
}
else
{
- throw new NotImplementedException($"{SuggestionType} is not supported.");
+ throw new NotImplementedException($"{SuggestionType} suggestion type is not supported.");
}
}
}

MODIFY
WalletWasabi/Blockchain/TransactionBuilding/ChangelessTransactionCoinSelector.cs
WalletWasabi/Blockchain/TransactionBuilding/ChangelessTransactionCoinSelector.cs
@@ -56,7 +56,7 @@ public static class ChangelessTransactionCoinSelector
if (solution is not null)
{
- // Sanity check: do not return solution that is much higher or lower than the target.
+ // Sanity check: do not return solution that is much higher or much lower than the target.
if (solution.Sum() > target * MaxExtraPayment || solution.Sum() < target * MinPaymentThreshold)
{
return false;

add test with input costs + comment changes