public void TestGetProof() { var r = new ExtensionNode(); r.Key = "0a0c".HexToBytes(); var b = new BranchNode(); var l1 = new ExtensionNode(); l1.Key = new byte[] { 0x01 }; var l2 = new ExtensionNode(); l2.Key = new byte[] { 0x09 }; var v1 = new LeafNode(); v1.Value = "abcd".HexToBytes(); var v2 = new LeafNode(); v2.Value = "2222".HexToBytes(); var v3 = new LeafNode(); v3.Value = Encoding.ASCII.GetBytes("hello"); var h1 = new HashNode(); h1.Hash = v3.GetHash(); var l3 = new ExtensionNode(); l3.Next = h1; l3.Key = "0e".HexToBytes(); r.Next = b; b.Children[0] = l1; l1.Next = v1; b.Children[9] = l2; l2.Next = v2; b.Children[10] = l3; var mpt = new MPTTrie(rootHash, mptdb); Assert.AreEqual(r.GetHash().ToString(), mpt.GetRoot().ToString()); var result = mpt.GetProof("ac01".HexToBytes(), out HashSet <byte[]> proof); Assert.IsTrue(result); Assert.AreEqual(4, proof.Count); Assert.IsTrue(proof.Contains(b.Encode())); Assert.IsTrue(proof.Contains(r.Encode())); Assert.IsTrue(proof.Contains(l1.Encode())); Assert.IsTrue(proof.Contains(v1.Encode())); }
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()); }