Improve AllFeeEstimate and add unit tests
MODIFY
WalletWasabi.Tests/UnitTests/AllFeeEstimateTests.cs
WalletWasabi.Tests/UnitTests/AllFeeEstimateTests.cs
@@ -19,7 +19,7 @@ namespace WalletWasabi.Tests.UnitTests
public class AllFeeEstimateTests
{
[Fact]
- public void AllFeeEstimateSerialization()
+ public void Serialization()
{
var estimations = new Dictionary<int, int>
{
@@ -38,7 +38,7 @@ namespace WalletWasabi.Tests.UnitTests
}
[Fact]
- public void AllFeeEstimateOrdersByTarget()
+ public void OrdersByTarget()
{
var estimations = new Dictionary<int, int>
{
@@ -55,7 +55,7 @@ namespace WalletWasabi.Tests.UnitTests
}
[Fact]
- public void AllFeeEstimateHandlesDuplicate()
+ public void HandlesDuplicate()
{
var estimations = new Dictionary<int, int>
{
@@ -69,7 +69,45 @@ namespace WalletWasabi.Tests.UnitTests
}
[Fact]
- public void AllFeeEstimateHandlesInconsistentData()
+ public void HandlesOne()
+ {
+ // If there's no 2, this'll be 2.
+ var estimations = new Dictionary<int, int>
+ {
+ { 1, 20 }
+ };
+
+ var allFees = new AllFeeEstimate(EstimateSmartFeeMode.Conservative, estimations, true);
+ Assert.Single(allFees.Estimations);
+ Assert.Equal(estimations[1], allFees.Estimations[2]);
+
+ // If there's 2, 1 is dismissed.
+ estimations = new Dictionary<int, int>
+ {
+ { 1, 20 },
+ { 2, 21 }
+ };
+
+ allFees = new AllFeeEstimate(EstimateSmartFeeMode.Conservative, estimations, true);
+ Assert.Single(allFees.Estimations);
+ Assert.Equal(estimations[2], allFees.Estimations[2]);
+ }
+
+ [Fact]
+ public void EndOfTheRange()
+ {
+ var estimations = new Dictionary<int, int>
+ {
+ { 1007, 20 }
+ };
+
+ var allFees = new AllFeeEstimate(EstimateSmartFeeMode.Conservative, estimations, true);
+ var est = Assert.Single(allFees.Estimations);
+ Assert.Equal(1008, est.Key);
+ }
+
+ [Fact]
+ public void HandlesInconsistentData()
{
var estimations = new Dictionary<int, int>
{

MODIFY
WalletWasabi/Blockchain/Analysis/FeesEstimation/AllFeeEstimate.cs
WalletWasabi/Blockchain/Analysis/FeesEstimation/AllFeeEstimate.cs
@@ -23,12 +23,12 @@ namespace WalletWasabi.Blockchain.Analysis.FeesEstimation
IsAccurate = isAccurate;
var targets = Constants.ConfirmationTargets.Prepend(1).ToArray();
- var targetRanges = targets.Skip(1).Zip(targets, (x, y) => (Start: y, End: x));
+ var targetRanges = targets.Skip(1).Zip(targets.Skip(1).Prepend(0), (x, y) => (Start: y, End: x));
var filteredEstimations = estimations
.Where(x => x.Key >= targets[0] && x.Key <= targets[^1])
.OrderBy(x => x.Key)
- .Select(x => (ConfirmationTarget: x.Key, FeeRate: x.Value, Range: targetRanges.FirstOrDefault(y => y.Start < x.Key && x.Key <= y.End)))
+ .Select(x => (ConfirmationTarget: x.Key, FeeRate: x.Value, Range: targetRanges.First(y => y.Start < x.Key && x.Key <= y.End)))
.GroupBy(x => x.Range, y => y, (x, y) => (Range: x, BestEstimation: y.Last()))
.Select(x => (ConfirmationTarget: x.Range.End, x.BestEstimation.FeeRate));

Improve AllFeeEstimate and add unit tests