public void TestCachedFind_Last() { var snapshot = Blockchain.Singleton.GetSnapshot(); var storages = snapshot.Storages; var cache = new CloneCache <StorageKey, StorageItem>(storages); storages.DeleteWhere((k, v) => k.ScriptHash == UInt160.Zero); storages.Add ( new StorageKey() { Key = new byte[] { 0x00, 0x01 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); storages.Add ( new StorageKey() { Key = new byte[] { 0x01, 0x01 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); cache.Add ( new StorageKey() { Key = new byte[] { 0x00, 0x02 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); cache.Add ( new StorageKey() { Key = new byte[] { 0x01, 0x02 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); CollectionAssert.AreEqual( cache.Find(new byte[21]).Select(u => u.Key.Key[1]).ToArray(), new byte[] { 0x01, 0x02 } ); storages.DeleteWhere((k, v) => k.ScriptHash == UInt160.Zero); }
public void TestCachedFind_Empty() { var snapshot = Blockchain.Singleton.GetSnapshot(); var storages = snapshot.Storages.CreateSnapshot(); var cache = new CloneCache <StorageKey, StorageItem>(storages); cache.Add ( new StorageKey() { Key = new byte[] { 0x00, 0x02 }, Id = 0 }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); cache.Add ( new StorageKey() { Key = new byte[] { 0x01, 0x02 }, Id = 0 }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); CollectionAssert.AreEqual( cache.Find(new byte[5]).Select(u => u.Key.Key[1]).ToArray(), new byte[] { 0x02 } ); }
public void TestAddInternal() { cloneCache.Add(new MyKey("key1"), new MyValue("value1")); AssertionExtensions.Should((object)cloneCache[new MyKey("key1")]).Be(new MyValue("value1")); cloneCache.Commit(); myDataCache[new MyKey("key1")].Should().Be(new MyValue("value1")); }
public void TestAddInternal() { cloneCache.Add(new MyKey("key1"), new MyValue("value1")); cloneCache[new MyKey("key1")].Should().Be(new MyValue("value1")); cloneCache.Commit(); myDataCache[new MyKey("key1")].Should().Be(new MyValue("value1")); }
public void TestCachedFind_Between() { var snapshot = TestBlockchain.GetStore().GetSnapshot(); var storages = snapshot.Storages; var cache = new CloneCache <StorageKey, StorageItem>(storages); storages.DeleteWhere((k, v) => k.ScriptHash == UInt160.Zero); storages.Add ( new StorageKey() { Key = new byte[] { 0x01, 0x01 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); storages.Add ( new StorageKey() { Key = new byte[] { 0x00, 0x01 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); storages.Add ( new StorageKey() { Key = new byte[] { 0x00, 0x03 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); cache.Add ( new StorageKey() { Key = new byte[] { 0x01, 0x02 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); cache.Add ( new StorageKey() { Key = new byte[] { 0x00, 0x02 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); CollectionAssert.AreEqual( Enumerable.Select <KeyValuePair <StorageKey, StorageItem>, byte>(cache.Find(new byte[21]), u => u.Key.Key[1]).ToArray(), new byte[] { 0x01, 0x02, 0x03 } ); storages.DeleteWhere((k, v) => k.ScriptHash == UInt160.Zero); }