Skip to content

Commit

Permalink
Complete storage unit test (#793)
Browse files Browse the repository at this point in the history
* Test complete

* Add MemoryStore

* Improve UT

---------

Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
  • Loading branch information
shargon and vncoelho authored Apr 4, 2023
1 parent b8b1b48 commit 4b3a76e
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions tests/Neo.Plugins.Storage.Tests/StoreTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Persistence;
using System.IO;
using System.Linq;

namespace Neo.Plugins.Storage.Tests
Expand All @@ -10,6 +11,30 @@ public class StoreTest
private const string path_leveldb = "Data_LevelDB_UT";
private const string path_rocksdb = "Data_RocksDB_UT";

[TestInitialize]
public void OnStart()
{
if (Directory.Exists(path_leveldb)) Directory.Delete(path_leveldb, true);
if (Directory.Exists(path_rocksdb)) Directory.Delete(path_rocksdb, true);
}

[TestMethod]
public void TestMemory()
{
using var store = new MemoryStore();
TestPersistenceDelete(store);
// Test all with the same store

TestStorage(store);

// Test with different storages

TestPersistenceWrite(store);
TestPersistenceRead(store, true);
TestPersistenceDelete(store);
TestPersistenceRead(store, false);
}

[TestMethod]
public void TestLevelDb()
{
Expand Down Expand Up @@ -74,13 +99,13 @@ private void TestStorage(IStore store)
Assert.IsNull(ret);
Assert.IsFalse(store.Contains(key1));

// Test seek
// Test seek in order

store.Put(new byte[] { 0x00, 0x00, 0x04 }, new byte[] { 0x04 });
store.Put(new byte[] { 0x00, 0x00, 0x00 }, new byte[] { 0x00 });
store.Put(new byte[] { 0x00, 0x00, 0x01 }, new byte[] { 0x01 });
store.Put(new byte[] { 0x00, 0x00, 0x02 }, new byte[] { 0x02 });
store.Put(new byte[] { 0x00, 0x00, 0x03 }, new byte[] { 0x03 });
store.Put(new byte[] { 0x00, 0x00, 0x04 }, new byte[] { 0x04 });

// Seek Forward

Expand All @@ -90,6 +115,8 @@ private void TestStorage(IStore store)
CollectionAssert.AreEqual(new byte[] { 0x02 }, entries[0].Value);
CollectionAssert.AreEqual(new byte[] { 0x00, 0x00, 0x03 }, entries[1].Key);
CollectionAssert.AreEqual(new byte[] { 0x03 }, entries[1].Value);
CollectionAssert.AreEqual(new byte[] { 0x00, 0x00, 0x04 }, entries[2].Key);
CollectionAssert.AreEqual(new byte[] { 0x04 }, entries[2].Value);

// Seek Backward

Expand Down

0 comments on commit 4b3a76e

Please sign in to comment.