Skip to content

Commit

Permalink
Fix clear not working (#7510)
Browse files Browse the repository at this point in the history
  • Loading branch information
asdacap authored Sep 29, 2024
1 parent 9eb5189 commit f773a71
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Nethermind/Nethermind.Db.Test/SimpleFilePublicKeyDbTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
using System.IO;

using FluentAssertions;
using Nethermind.Core.Extensions;
using Nethermind.Core.Test.IO;
using Nethermind.Logging;
Expand Down Expand Up @@ -52,5 +52,22 @@ public void Save_and_load()
Assert.True(filePublicKeyDb[kv.Key].AsSpan().SequenceEqual(kv.Value));
}
}

[Test]
public void Clear()
{
using TempPath tempPath = TempPath.GetTempFile(SimpleFilePublicKeyDb.DbFileName);
tempPath.Dispose();

SimpleFilePublicKeyDb filePublicKeyDb = new("Test", Path.GetTempPath(), LimboLogs.Instance);
using (filePublicKeyDb.StartWriteBatch())
{
filePublicKeyDb[[1, 2, 3]] = [1, 2, 3];
}

filePublicKeyDb.KeyExists([1, 2, 3]).Should().BeTrue();
filePublicKeyDb.Clear();
filePublicKeyDb.KeyExists([1, 2, 3]).Should().BeFalse();
}
}
}
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Db/SimpleFilePublicKeyDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public void Flush() { }
public void Clear()
{
File.Delete(DbPath);
_cache.Clear();
}

public IEnumerable<KeyValuePair<byte[], byte[]>> GetAll(bool ordered = false) => _cache;
Expand Down

0 comments on commit f773a71

Please sign in to comment.