Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Neo/Persistence/IReadOnlyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IReadOnlyStore
/// </summary>
/// <param name="keyOrPrefix">The key(i.e. start key) or prefix to be sought.</param>
/// <param name="direction">The direction of seek.</param>
/// <returns>An enumerator containing all the entries after seeking.</returns>
/// <returns>An enumerator containing all the entries after (Forward) or before(Backward) seeking.</returns>
IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction);

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Plugins/LevelDBStore/IO/Data/LevelDB/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public static class Helper
{
public static IEnumerable<(byte[], byte[])> Seek(this DB db, ReadOptions options, byte[] keyOrPrefix, SeekDirection direction)
{
if (keyOrPrefix == null) keyOrPrefix = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only in levelDb?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only in levelDb?

Same as MemoryStore and RocksDbStore.


using Iterator it = db.CreateIterator(options);
if (direction == SeekDirection.Forward)
{
Expand Down
14 changes: 14 additions & 0 deletions tests/Neo.Plugins.Storage.Tests/StoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,20 @@ private void TestStorage(IStore store)
CollectionAssert.AreEqual(new byte[] { 0x01 }, entries[0].Value);
CollectionAssert.AreEqual(new byte[] { 0x00, 0x00, 0x00 }, entries[1].Key);
CollectionAssert.AreEqual(new byte[] { 0x00 }, entries[1].Value);

// Seek null
entries = store.Seek(null, SeekDirection.Forward).ToArray();
Assert.AreEqual(3, entries.Length);
CollectionAssert.AreEqual(new byte[] { 0x00, 0x00, 0x00 }, entries[0].Key);
CollectionAssert.AreEqual(new byte[] { 0x00, 0x00, 0x01 }, entries[1].Key);
CollectionAssert.AreEqual(new byte[] { 0x00, 0x01, 0x02 }, entries[2].Key);

// Seek empty
entries = store.Seek([], SeekDirection.Forward).ToArray();
Assert.AreEqual(3, entries.Length);
CollectionAssert.AreEqual(new byte[] { 0x00, 0x00, 0x00 }, entries[0].Key);
CollectionAssert.AreEqual(new byte[] { 0x00, 0x00, 0x01 }, entries[1].Key);
CollectionAssert.AreEqual(new byte[] { 0x00, 0x01, 0x02 }, entries[2].Key);
}
}

Expand Down
Loading