Esempio n. 1
0
        public void TestBranchDeleteDirty()
        {
            var snapshot = new TestSnapshot();
            var mpt      = new MPTTrie <TestKey, TestValue>(snapshot, null);

            mpt.Put("10".HexToBytes(), "01".HexToBytes());
            mpt.Put("20".HexToBytes(), "02".HexToBytes());
            mpt.Put("30".HexToBytes(), "03".HexToBytes());
            mpt.Commit();
            Assert.AreEqual(7, snapshot.Size);
            var mpt1 = new MPTTrie <TestKey, TestValue>(snapshot, mpt.Root.Hash);

            mpt1.Delete("10".HexToBytes());
            mpt1.Commit();
            Assert.AreEqual(5, snapshot.Size);
            var mpt2 = new MPTTrie <TestKey, TestValue>(snapshot, mpt1.Root.Hash);

            mpt2.Delete("20".HexToBytes());
            mpt2.Commit();
            Assert.AreEqual(2, snapshot.Size);
            var mpt3 = new MPTTrie <TestKey, TestValue>(snapshot, mpt2.Root.Hash);

            mpt3.Delete("30".HexToBytes());
            mpt3.Commit();
            Assert.AreEqual(0, snapshot.Size);
        }
Esempio n. 2
0
        public void TestExtensionPutDirty()
        {
            var snapshot = new TestSnapshot();
            var mpt      = new MPTTrie <TestKey, TestValue>(snapshot, null);

            mpt.Put("a1".HexToBytes(), "01".HexToBytes());
            mpt.Put("a2".HexToBytes(), "02".HexToBytes());
            mpt.Commit();
            Assert.AreEqual(4, snapshot.Size);
            var mpt1 = new MPTTrie <TestKey, TestValue>(snapshot, mpt.Root.Hash);

            mpt1.Put("a3".HexToBytes(), "03".HexToBytes());
            mpt1.Commit();
            Assert.AreEqual(5, snapshot.Size);
        }
Esempio n. 3
0
        public void TestFindStatesIssue652()
        {
            var snapshot = new TestSnapshot();
            var mpt      = new MPTTrie <TestKey, TestValue>(snapshot, null);

            mpt.Put("abc1".HexToBytes(), "01".HexToBytes());
            mpt.Put("abc3".HexToBytes(), "02".HexToBytes());
            var r = mpt.Find("ab".HexToBytes(), "abd2".HexToBytes()).ToList();

            Assert.AreEqual(0, r.Count);
            r = mpt.Find("ab".HexToBytes(), "abb2".HexToBytes()).ToList();
            Assert.AreEqual(2, r.Count);
            r = mpt.Find("ab".HexToBytes(), "abc2".HexToBytes()).ToList();
            Assert.AreEqual(1, r.Count);
        }
Esempio n. 4
0
        public void TestReference2()
        {
            var snapshot = new TestSnapshot();
            var mpt      = new MPTTrie <TestKey, TestValue>(snapshot, null);

            mpt.Put("a101".HexToBytes(), "01".HexToBytes());
            mpt.Put("a201".HexToBytes(), "01".HexToBytes());
            mpt.Put("a301".HexToBytes(), "01".HexToBytes());
            mpt.Commit();
            Assert.AreEqual(4, snapshot.Size);
            mpt.Delete("a301".HexToBytes());
            mpt.Commit();
            Assert.AreEqual(4, snapshot.Size);
            mpt.Delete("a201".HexToBytes());
            mpt.Commit();
            Assert.AreEqual(2, snapshot.Size);
            Assert.AreEqual("01", mpt["a101".HexToBytes()].ToArray().ToHexString());
        }
Esempio n. 5
0
        public void TestBranchNodeRemainValue()
        {
            var snapshot = new TestSnapshot();
            var mpt      = new MPTTrie <TestKey, TestValue>(snapshot, null);

            Assert.IsTrue(mpt.Put("ac11".HexToBytes(), "ac11".HexToBytes()));
            Assert.IsTrue(mpt.Put("ac22".HexToBytes(), "ac22".HexToBytes()));
            Assert.IsTrue(mpt.Put("ac".HexToBytes(), "ac".HexToBytes()));
            mpt.Commit();
            Assert.AreEqual(7, snapshot.Size);
            Assert.IsTrue(mpt.Delete("ac11".HexToBytes()));
            mpt.Commit();
            Assert.AreEqual(5, snapshot.Size);
            Assert.IsTrue(mpt.Delete("ac22".HexToBytes()));
            Assert.IsNotNull(mpt["ac".HexToBytes()]);
            mpt.Commit();
            Assert.AreEqual(2, snapshot.Size);
        }
Esempio n. 6
0
        public void TestFindWithFrom()
        {
            var snapshot = new TestSnapshot();
            var mpt      = new MPTTrie <TestKey, TestValue>(snapshot, null);

            mpt.Put("aa".HexToBytes(), "02".HexToBytes());
            mpt.Put("aa10".HexToBytes(), "03".HexToBytes());
            mpt.Put("aa50".HexToBytes(), "04".HexToBytes());
            var r = mpt.Find("aa".HexToBytes()).ToList();

            Assert.AreEqual(3, r.Count);
            r = mpt.Find("aa".HexToBytes(), "aa30".HexToBytes()).ToList();
            Assert.AreEqual(1, r.Count);
            r = mpt.Find("aa".HexToBytes(), "aa60".HexToBytes()).ToList();
            Assert.AreEqual(0, r.Count);
            r = mpt.Find("aa".HexToBytes(), "aa10".HexToBytes()).ToList();
            Assert.AreEqual(1, r.Count);
        }
Esempio n. 7
0
        public void TestEmptyValueIssue633()
        {
            var key      = "01".HexToBytes();
            var snapshot = new TestSnapshot();
            var mpt      = new MPTTrie <TestKey, TestValue>(snapshot, null);

            mpt.Put(key, Array.Empty <byte>());
            var val = mpt["01".HexToBytes()];

            Assert.IsNotNull(val);
            Assert.AreEqual(0, val.Size);
            var r = mpt.TryGetProof(key, out var proof);

            Assert.IsTrue(r);
            val = MPTTrie <TestKey, TestValue> .VerifyProof(mpt.Root.Hash, key, proof);

            Assert.IsNotNull(val);
            Assert.AreEqual(0, val.Size);
        }