public void TestTryDelete() { var r1 = new ExtensionNode(); r1.Key = "0a0c0001".HexToBytes(); var r = new ExtensionNode(); r.Key = "0a0c".HexToBytes(); var b = new BranchNode(); r.Next = b; var l1 = new ExtensionNode(); l1.Key = new byte[] { 0x01 }; var v1 = new LeafNode(); v1.Value = "abcd".HexToBytes(); l1.Next = v1; b.Children[0] = l1; var l2 = new ExtensionNode(); l2.Key = new byte[] { 0x09 }; var v2 = new LeafNode(); v2.Value = "2222".HexToBytes(); l2.Next = v2; b.Children[9] = l2; r1.Next = v1; Assert.AreEqual("0xdea3ab46e9461e885ed7091c1e533e0a8030b248d39cbc638962394eaca0fbb3", r1.GetHash().ToString()); Assert.AreEqual("0x93e8e1ffe2f83dd92fca67330e273bcc811bf64b8f8d9d1b25d5e7366b47d60d", r.GetHash().ToString()); var mpt = new MPTTrie(rootHash, mptdb); var result = true; result = mpt.TryGet("ac99".HexToBytes(), out byte[] value); Assert.IsTrue(result); result = mpt.TryDelete("ac99".HexToBytes()); Assert.IsTrue(result); result = mpt.TryDelete("acae".HexToBytes()); Assert.IsTrue(result); Assert.AreEqual("0xdea3ab46e9461e885ed7091c1e533e0a8030b248d39cbc638962394eaca0fbb3", mpt.GetRoot().ToString()); }
public void TestBranchNodeRemainValue() { var store = new MemoryStore(); var mpt = new MPTTrie(null, store); var result = mpt.Put("ac11".HexToBytes(), "ac11".HexToBytes()); Assert.IsTrue(result); result = mpt.Put("ac22".HexToBytes(), "ac22".HexToBytes()); Assert.IsTrue(result); result = mpt.Put("ac".HexToBytes(), "ac".HexToBytes()); Assert.IsTrue(result); result = mpt.TryDelete("ac11".HexToBytes()); Assert.IsTrue(result); result = mpt.TryDelete("ac22".HexToBytes()); Assert.IsTrue(result); Assert.AreEqual("{\"key\":\"0a0c\",\"next\":{\"value\":\"ac\"}}", mpt.ToJson().ToString()); }
public void TestDeleteSameValue() { var store = new MemoryStore(); var mpt = new MPTTrie(null, store); var result = mpt.Put("ac01".HexToBytes(), "abcd".HexToBytes()); Assert.IsTrue(result); result = mpt.Put("ac02".HexToBytes(), "abcd".HexToBytes()); Assert.IsTrue(result); result = mpt.TryGet("ac01".HexToBytes(), out byte[] value); Assert.IsTrue(result); result = mpt.TryGet("ac02".HexToBytes(), out value); Assert.IsTrue(result); result = mpt.TryDelete("ac01".HexToBytes()); result = mpt.TryGet("ac02".HexToBytes(), out value); Assert.IsTrue(result); var mpt0 = new MPTTrie(mpt.GetRoot(), store); result = mpt0.TryGet("ac02".HexToBytes(), out value); Assert.IsTrue(result); }
public override void DeleteInternal(TKey key) { batch?.Delete(prefix, key); mptTrie.TryDelete(key.ToArray()); }