Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Neo Plugin Store] Unit test #3399

Merged
merged 14 commits into from
Jul 11, 2024
48 changes: 48 additions & 0 deletions tests/Neo.Plugins.Storage.Tests/StoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,54 @@ public void TestLevelDb()
TestPersistenceRead(plugin.GetStore(path_leveldb), false);
}

[TestMethod]
public void TestLevelDbSnapshot()
{
using var plugin = new LevelDBStore();
using var store = plugin.GetStore(path_leveldb);

var snapshot = store.GetSnapshot();

var testKey = new byte[] { 0x01, 0x02, 0x03 };
var testValue = new byte[] { 0x04, 0x05, 0x06 };

snapshot.Put(testKey,testValue);
// Data saved to the leveldb snapshot shall not be visible to the store
Assert.IsNull(snapshot.TryGet(testKey));
snapshot.Commit();

// After commit, the data shall be visible to the store and to the snapshot
CollectionAssert.AreEqual(testValue, snapshot.TryGet(testKey));
var b = store.TryGet(testKey);
CollectionAssert.AreEqual(testValue,b );

snapshot.Dispose();
}

[TestMethod]
public void TestLevelDbMultiSnapshot()
{
using var plugin = new LevelDBStore();
using var store = plugin.GetStore(path_leveldb);

var snapshot = store.GetSnapshot();
var snapshot2 = store.GetSnapshot();

var testKey = new byte[] { 0x01, 0x02, 0x03 };
var testValue = new byte[] { 0x04, 0x05, 0x06 };

snapshot.Put(testKey,testValue);
CollectionAssert.AreEqual(testValue, snapshot.TryGet(testKey));
snapshot.Commit();
CollectionAssert.AreEqual(testValue, store.TryGet(testKey));

var ret = snapshot2.TryGet(testKey);
Assert.IsNull(ret);

snapshot.Dispose();
snapshot2.Dispose();
}

[TestMethod]
public void TestRocksDb()
{
Expand Down
Loading