Add LastKnownChange correct behavior test
MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/UtxoPrisonWardenTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/UtxoPrisonWardenTests.cs
@@ -61,6 +61,32 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
await w2.StopAsync(CancellationToken.None);
}
+ [Fact]
+ public async Task NoPrisonSerializationAsync()
+ {
+ // Don't serialize when there's no change.
+ var workDir = Common.GetWorkDir();
+ await IoHelpers.TryDeleteDirectoryAsync(workDir);
+
+ // Create prison.
+ CoordinatorParameters coordinatorParameters = new(workDir) { UtxoWardenPeriod = TimeSpan.FromMilliseconds(1) };
+ using var w = new Warden(coordinatorParameters.UtxoWardenPeriod, coordinatorParameters.PrisonFilePath, coordinatorParameters.RuntimeCoordinatorConfig);
+ await w.StartAsync(CancellationToken.None);
+ var i1 = new Inmate(BitcoinFactory.CreateOutPoint(), Punishment.Noted, DateTimeOffset.FromUnixTimeSeconds(DateTimeOffset.UtcNow.ToUnixTimeSeconds()), 1);
+ var i2 = new Inmate(BitcoinFactory.CreateOutPoint(), Punishment.Banned, DateTimeOffset.FromUnixTimeSeconds(DateTimeOffset.UtcNow.ToUnixTimeSeconds()), 2);
+ w.Prison.Punish(i1);
+ w.Prison.Punish(i2);
+
+ // Wait until serializes.
+ await Task.Delay(50);
+
+ // Make sure it does not serialize again as there was no change.
+ File.Delete(w.PrisonFilePath);
+ await Task.Delay(50);
+ Assert.False(File.Exists(w.PrisonFilePath));
+ await w.StopAsync(CancellationToken.None);
+ }
+
[Fact]
public async Task ReleasesInmatesAsync()
{

MODIFY
WalletWasabi/WabiSabi/Backend/Banning/Warden.cs
WalletWasabi/WabiSabi/Backend/Banning/Warden.cs
@@ -26,7 +26,7 @@ namespace WalletWasabi.WabiSabi.Backend.Banning
public Prison Prison { get; }
public Guid LastKnownChange { get; private set; }
- private string PrisonFilePath { get; }
+ public string PrisonFilePath { get; }
public WabiSabiConfig Config { get; }
private static Prison DeserializePrison(string prisonFilePath)

Add LastKnownChange correct behavior test