예제 #1
0
        public void TestTryGetResolve()
        {
            var mpt    = new MPTTrie(rootHash, mptdb);
            var result = mpt.TryGet("acae".HexToBytes(), out byte[] value);

            Assert.IsTrue(result);
            Assert.IsTrue(Encoding.ASCII.GetBytes("hello").SequenceEqual(value));
        }
예제 #2
0
        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);
        }
예제 #3
0
        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());
        }
예제 #4
0
        public void TestTryGet()
        {
            var mpt    = new MPTTrie(rootHash, mptdb);
            var result = mpt.TryGet("ac01".HexToBytes(), out byte[] value);

            Assert.IsTrue(result);
            Assert.AreEqual("abcd", value.ToHexString());

            result = mpt.TryGet("ac99".HexToBytes(), out value);
            Assert.IsTrue(result);
            Assert.AreEqual("2222", value.ToHexString());

            result = mpt.TryGet("ab99".HexToBytes(), out value);
            Assert.IsFalse(result);

            result = mpt.TryGet("ac39".HexToBytes(), out value);
            Assert.IsFalse(result);

            result = mpt.TryGet("ac02".HexToBytes(), out value);
            Assert.IsFalse(result);

            result = mpt.TryGet("ac9910".HexToBytes(), out value);
            Assert.AreEqual(false, result);
        }