public void TestReference2() { var l = MPTNode.NewLeaf(Encoding.ASCII.GetBytes("leaf")); var store = new MemoryStore(); var snapshot = store.GetSnapshot(); var cache = new MPTCache(snapshot, Prefix); cache.PutNode(l); cache.PutNode(l); cache.DeleteNode(l.Hash); var rl = cache.Resolve(l.Hash); Assert.AreEqual(1, rl.Reference); }
public void TestPutAndChangedBranch() { var l = MPTNode.NewLeaf(Encoding.ASCII.GetBytes("leaf")); var b = MPTNode.NewBranch(); var h = b.Hash; var store = new MemoryStore(); var snapshot = store.GetSnapshot(); var cache = new MPTCache(snapshot, Prefix); cache.PutNode(b); var rb = cache.Resolve(h); Assert.AreEqual(h, rb.Hash); foreach (var n in rb.Children) { Assert.IsTrue(n.IsEmpty); } rb.Children[1] = l; rb.SetDirty(); var rb1 = cache.Resolve(h); Assert.AreEqual(h, rb1.Hash); foreach (var n in rb1.Children) { Assert.IsTrue(n.IsEmpty); } }
public void TestPutAndChangedLeaf() { var l = MPTNode.NewLeaf(Encoding.ASCII.GetBytes("leaf")); var h = l.Hash; var store = new MemoryStore(); var snapshot = store.GetSnapshot(); var cache = new MPTCache(snapshot, Prefix); cache.PutNode(l); var rl = cache.Resolve(l.Hash); Assert.AreEqual(h, rl.Hash); Assert.AreEqual("leaf", Encoding.ASCII.GetString(rl.Value)); l.Value = new byte[] { 0x01 }; l.SetDirty(); var rl1 = cache.Resolve(h); Assert.AreEqual(h, rl1.Hash); Assert.AreEqual("leaf", Encoding.ASCII.GetString(rl1.Value)); }
public void TestReference1() { var l = MPTNode.NewLeaf(Encoding.ASCII.GetBytes("leaf")); var store = new MemoryStore(); var snapshot = store.GetSnapshot(); var cache = new MPTCache(snapshot, Prefix); cache.PutNode(l); cache.Commit(); snapshot.Commit(); var snapshot1 = store.GetSnapshot(); var cache1 = new MPTCache(snapshot1, Prefix); cache1.PutNode(l); cache1.Commit(); snapshot1.Commit(); var snapshot2 = store.GetSnapshot(); var cache2 = new MPTCache(snapshot2, Prefix); var rl = cache2.Resolve(l.Hash); Assert.AreEqual(2, rl.Reference); }
public void TestPutAndChangedExtension() { var e = MPTNode.NewExtension(new byte[] { 0x01 }, new MPTNode()); var h = e.Hash; var store = new MemoryStore(); var snapshot = store.GetSnapshot(); var cache = new MPTCache(snapshot, Prefix); cache.PutNode(e); var re = cache.Resolve(e.Hash); Assert.AreEqual(e.Hash, re.Hash); Assert.AreEqual(e.Key.ToHexString(), re.Key.ToHexString()); Assert.IsTrue(re.Next.IsEmpty); e.Key = new byte[] { 0x02 }; e.Next = e; e.SetDirty(); var re1 = cache.Resolve(h); Assert.AreEqual(h, re1.Hash); Assert.AreEqual("01", re1.Key.ToHexString()); Assert.IsTrue(re1.Next.IsEmpty); }