Add min/max cap tests.
MODIFY
WalletWasabi.Tests/UnitTests/Blockchain/TransactionBuilding/BranchAndBoundTests.cs
WalletWasabi.Tests/UnitTests/Blockchain/TransactionBuilding/BranchAndBoundTests.cs
@@ -118,7 +118,6 @@ public class BranchAndBoundTests
Assert.Equal(new long[] { 1_000_000 }, actualSelection);
}
-
[Fact]
public void MoreSelection_MaxInputCountTest()
{
@@ -131,10 +130,10 @@ public class BranchAndBoundTests
BranchAndBound algorithm = new();
StrategyParameters parameters = new(target, inputValues, inputCosts, maxInputCount: 5);
- MoreSelectionStrategy moreStrategy = new(parameters);
- _ = algorithm.TryGetMatch(moreStrategy, out _, cts.Token);
+ MoreSelectionStrategy strategy = new(parameters);
+ _ = algorithm.TryGetMatch(strategy, out _, cts.Token);
- long[] result = moreStrategy.GetBestSelectionFound()!;
+ long[] result = strategy.GetBestSelectionFound()!;
Assert.NotNull(result);
@@ -143,6 +142,27 @@ public class BranchAndBoundTests
Assert.Equal(5, result.Length);
}
+ /// <summary>Tests that <see cref="MoreSelectionStrategy.MaxExtraPayment"/> is taken into account.</summary>
+ [Fact]
+ public void MoreSelection_Cap()
+ {
+ using CancellationTokenSource cts = new(TimeSpan.FromSeconds(30));
+
+ long[] inputValues = new long[] { 20 };
+ long[] inputCosts = new long[] { 0 };
+
+ long target = 10;
+
+ BranchAndBound algorithm = new();
+ StrategyParameters parameters = new(target, inputValues, inputCosts);
+ MoreSelectionStrategy strategy = new(parameters);
+ _ = algorithm.TryGetMatch(strategy, out _, cts.Token);
+
+ // 20 is more than allowed by the "max extra payment" parameter.
+ long[] result = strategy.GetBestSelectionFound()!;
+ Assert.Null(result);
+ }
+
[Fact]
public void LessSelection_RemainingAmountOptimization()
{
@@ -251,13 +271,34 @@ public class BranchAndBoundTests
BranchAndBound algorithm = new();
StrategyParameters parameters = new(target, inputValues, inputCosts, maxInputCount: 5);
- LessSelectionStrategy lessStrategy = new(parameters);
- _ = algorithm.TryGetMatch(lessStrategy, out _, cts.Token);
+ LessSelectionStrategy strategy = new(parameters);
+ _ = algorithm.TryGetMatch(strategy, out _, cts.Token);
- long[] actualSelection = lessStrategy.GetBestSelectionFound()!;
+ long[] actualSelection = strategy.GetBestSelectionFound()!;
Assert.NotNull(actualSelection);
Assert.Equal(new long[] { 1, 1, 1, 1, 1, }, actualSelection);
Assert.Equal(5, actualSelection.Length);
}
+
+ /// <summary>Tests that <see cref="LessSelectionStrategy.MinPaymentThreshold"/> is taken into account.</summary>
+ [Fact]
+ public void LesserSelection_Cap()
+ {
+ using CancellationTokenSource cts = new(TimeSpan.FromSeconds(30));
+
+ long[] inputValues = new long[] { 10 };
+ long[] inputCosts = new long[] { 0 };
+
+ long target = 20;
+
+ BranchAndBound algorithm = new();
+ StrategyParameters parameters = new(target, inputValues, inputCosts);
+ LessSelectionStrategy strategy = new(parameters);
+ _ = algorithm.TryGetMatch(strategy, out _, cts.Token);
+
+ // 10 is more than allowed by the "min payment threshold" parameter.
+ long[] result = strategy.GetBestSelectionFound()!;
+ Assert.Null(result);
+ }
}

Add min/max cap tests.