Skip to content

Commit

Permalink
Merge pull request #12778 from turbolay/fixTryShouldNotThrow
Browse files Browse the repository at this point in the history
`TryRemoveLastFilterIfNewerThanAsync` should not throw
  • Loading branch information
turbolay committed Apr 10, 2024
2 parents 63e3a21 + d93076e commit baaab5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions WalletWasabi.Tests/UnitTests/Stores/IndexStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.Backend.Models;
using WalletWasabi.Blockchain.Blocks;
using WalletWasabi.Helpers;
using WalletWasabi.Stores;
Expand All @@ -19,14 +20,22 @@ public class IndexStoreTests
[Fact]
public async Task IndexStoreTestsAsync()
{
using CancellationTokenSource testDeadlineCts = new(TimeSpan.FromMinutes(1));
using CancellationTokenSource testCts = new(TimeSpan.FromMinutes(1));

string directory = GetWorkDirectory();
await IoHelpers.TryDeleteDirectoryAsync(directory);
IoHelpers.EnsureContainingDirectoryExists(directory);

await using var indexStore = new IndexStore(directory, Network.Main, new SmartHeaderChain());
await indexStore.InitializeAsync(testDeadlineCts.Token);
await indexStore.InitializeAsync(testCts.Token);

// Remove starting filter.
FilterModel? filterModel = await indexStore.TryRemoveLastFilterAsync();
Assert.NotNull(filterModel);

// No filter to remove.
filterModel = await indexStore.TryRemoveLastFilterAsync();
Assert.Null(filterModel);
}

private string GetWorkDirectory([CallerFilePath] string callerFilePath = "", [CallerMemberName] string callerMemberName = "")
Expand Down
4 changes: 2 additions & 2 deletions WalletWasabi/Stores/IndexStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,14 @@ public async Task<FilterModel[]> FetchBatchAsync(uint fromHeight, int batchSize,
{
if (!IndexStorage.TryRemoveLast(out filter))
{
throw new InvalidOperationException("No last filter.");
return null;
}
}
else
{
if (!IndexStorage.TryRemoveLastIfNewerThan(height.Value, out filter))
{
throw new InvalidOperationException("No last filter.");
return null;
}
}

Expand Down

0 comments on commit baaab5e

Please sign in to comment.