Esempio n. 1
0
        public async Task Browse_empty()
        {
            IDb db = new MemDb();
            DepositDetailsRocksRepository repository = new DepositDetailsRocksRepository(db, new DepositDetailsDecoder());

            foreach (DepositDetails details in _cases)
            {
                await repository.AddAsync(details);
            }

            PagedResult <DepositDetails> result = await repository.BrowseAsync(new GetDeposits { EligibleToRefund = true });

            result.Items.Should().HaveCount(0);
        }
Esempio n. 2
0
            public DbContext(ILogger logger, ILogManager logManager)
            {
                _logger         = logger;
                RemoteDb        = new MemDb();
                LocalDb         = new MemDb();
                RemoteStateDb   = RemoteDb;
                LocalStateDb    = LocalDb;
                LocalCodeDb     = new MemDb();
                RemoteCodeDb    = new MemDb();
                RemoteTrieStore = new TrieStore(RemoteStateDb, logManager);

                RemoteStateTree = new StateTree(RemoteTrieStore, logManager);
                LocalStateTree  = new StateTree(new TrieStore(LocalStateDb, logManager), logManager);
            }
Esempio n. 3
0
        public BlockTreeBuilder(Block genesisBlock)
        {
            MemDb blocksDb  = new MemDb();
            MemDb headersDb = new MemDb();

            // so we automatically include in all tests my questionable decision of storing Head block header at 00...
            blocksDb.Set(Keccak.Zero, Rlp.Encode(Build.A.BlockHeader.TestObject).Bytes);

            _genesisBlock = genesisBlock;
            var blockInfoDb = new MemDb();

            ChainLevelInfoRepository = new ChainLevelInfoRepository(blockInfoDb);
            TestObjectInternal       = new BlockTree(blocksDb, headersDb, blockInfoDb, ChainLevelInfoRepository, RopstenSpecProvider.Instance, Substitute.For <ITxPool>(), Substitute.For <IBloomStorage>(), LimboLogs.Instance);
        }
Esempio n. 4
0
        public async Task Browse_unconfirmed_only()
        {
            IDb db = new MemDb();
            DepositDetailsRocksRepository repository = new DepositDetailsRocksRepository(db, new DepositDetailsDecoder());

            foreach (DepositDetails details in _cases)
            {
                await repository.AddAsync(details);
            }

            PagedResult <DepositDetails> result = await repository.BrowseAsync(new GetDeposits { OnlyUnconfirmed = true });

            result.Items.Should().HaveCount(01);
        }
        public void Can_restore_count_from_the_database(uint leafCount)
        {
            MemDb        memDb        = new MemDb();
            BaselineTree baselineTree = BuildATree(memDb);

            for (int i = 0; i < leafCount; i++)
            {
                baselineTree.Insert(_testLeaves[0]);
            }

            BaselineTree baselineTreeRestored = BuildATree(memDb);

            baselineTreeRestored.Count.Should().Be(leafCount);
        }
Esempio n. 6
0
        public void Scenario_traverse_leaf_update_new_value()
        {
            MemDb     db   = new MemDb();
            StateTree tree = new StateTree(db);

            tree.Set(new Keccak("1111111111111111111111111111111111111111111111111111111111111111"), _account0);
            tree.Set(new Keccak("1111111111111111111111111111111111111111111111111111111111111111"), _account1);
            tree.UpdateRootHash();
            Keccak rootHash = tree.RootHash;

            Assert.AreEqual("0xaa5c248d4b4b8c27a654296a8e0cc51131eb9011d9166fa0fca56a966489e169", rootHash.ToString(true));
            tree.Commit();
            Assert.AreEqual("0xaa5c248d4b4b8c27a654296a8e0cc51131eb9011d9166fa0fca56a966489e169", rootHash.ToString(true));
        }
Esempio n. 7
0
        public void Minimal_writes_when_setting_on_empty_scenario_3()
        {
            MemDb     db   = new MemDb();
            StateTree tree = new StateTree(db);

            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb00000000"), _account0);
            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb1eeeeeb0"), _account0);
            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb1eeeeeb1"), _account0);
            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb1eeeeeb1"), null);
            tree.Commit();
            Assert.AreEqual(4, db.WritesCount, "writes"); // extension, branch, 2x leaf
            Assert.AreEqual(4, Metrics.TreeNodeHashCalculations, "hashes");
            Assert.AreEqual(4, Metrics.TreeNodeRlpEncodings, "encodings");
        }
        public void Best_block_is_0_when_no_block_was_suggested()
        {
            IBlockTree      blockTree      = Substitute.For <IBlockTree>();
            IReceiptStorage receiptStorage = Substitute.For <IReceiptStorage>();
            IDb             stateDb        = new MemDb();
            SyncConfig      syncConfig     = new SyncConfig();

            syncConfig.PivotNumber = "1";

            SyncProgressResolver syncProgressResolver = new SyncProgressResolver(blockTree, receiptStorage, stateDb, new MemDb(), syncConfig, LimboLogs.Instance);

            blockTree.BestSuggestedBody.Returns((Block)null);
            Assert.AreEqual(0, syncProgressResolver.FindBestFullBlock());
        }
Esempio n. 9
0
        public void Scenario_traverse_leaf_update_with_extension()
        {
            MemDb     db   = new MemDb();
            StateTree tree = new StateTree(db);

            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb11111111111111111111111111111111"), _account0);
            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb00000000000000000000000000000000"), _account1);
            tree.UpdateRootHash();
            Keccak rootHash = tree.RootHash;

            Assert.AreEqual("0x215a4bab4cf2d5ebbaa59c82ae94c9707fcf4cc0ca1fe7e18f918e46db428ef9", rootHash.ToString(true));
            tree.Commit();
            Assert.AreEqual("0x215a4bab4cf2d5ebbaa59c82ae94c9707fcf4cc0ca1fe7e18f918e46db428ef9", rootHash.ToString(true));
        }
Esempio n. 10
0
        public void Scenario_traverse_leaf_delete_missing()
        {
            MemDb     db   = new MemDb();
            StateTree tree = new StateTree(db);

            tree.Set(new Keccak("1111111111111111111111111111111111111111111111111111111111111111"), _account0);
            tree.Set(new Keccak("1111111111111111111111111111111ddddddddddddddddddddddddddddddddd"), null);
            tree.UpdateRootHash();
            Keccak rootHash = tree.RootHash;

            Assert.AreEqual("0x491fbb33aaff22c0a7ff68d5c81ec114dddf89d022ccdee838a0e9d6cd45cab4", rootHash.ToString(true));
            tree.Commit();
            Assert.AreEqual("0x491fbb33aaff22c0a7ff68d5c81ec114dddf89d022ccdee838a0e9d6cd45cab4", rootHash.ToString(true));
        }
Esempio n. 11
0
        public void Scenario_traverse_leaf_read_matching_leaf()
        {
            MemDb     db   = new MemDb();
            StateTree tree = new StateTree(db);

            tree.Set(new Keccak("1111111111111111111111111111111111111111111111111111111111111111"), _account0);
            tree.Set(new Keccak("1111111111111111111111111111111111111111111111111111111111111111"), null);
            tree.UpdateRootHash();
            Keccak rootHash = tree.RootHash;

            Assert.AreEqual("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", rootHash.ToString(true));
            tree.Commit();
            Assert.AreEqual("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", rootHash.ToString(true));
        }
Esempio n. 12
0
        public async Task Can_load_blocks_from_db()
        {
            for (int chainLength = 2; chainLength <= 32; chainLength++)
            {
                Block genesisBlock = Build.A.Block.Genesis.TestObject;

                MemDb blocksDb     = new MemDb();
                MemDb blockInfosDb = new MemDb();
                MemDb headersDb    = new MemDb();

                BlockTree testTree = Build.A.BlockTree(genesisBlock).OfChainLength(chainLength).TestObject;
                for (int i = 0; i < testTree.Head.Number + 1; i++)
                {
                    Block ithBlock = testTree.FindBlock(i, BlockTreeLookupOptions.None);
                    blocksDb.Set(ithBlock.Hash, Rlp.Encode(ithBlock).Bytes);

                    headersDb.Set(ithBlock.Hash, Rlp.Encode(ithBlock.Header).Bytes);

                    ChainLevelInfo ithLevel = new ChainLevelInfo(
                        true,
                        new BlockInfo[1]
                    {
                        new BlockInfo(
                            ithBlock.Hash,
                            ithBlock.TotalDifficulty.Value)
                        {
                            WasProcessed = true
                        }
                    });
                    blockInfosDb.Set(i, Rlp.Encode(ithLevel).Bytes);
                }

                blockInfosDb.Set(Keccak.Zero, genesisBlock.Header.Hash.Bytes);
                headersDb.Set(genesisBlock.Header.Hash, Rlp.Encode(genesisBlock.Header).Bytes);

                BlockTree blockTree = new BlockTree(
                    blocksDb,
                    headersDb,
                    blockInfosDb,
                    new ChainLevelInfoRepository(blockInfosDb),
                    OlympicSpecProvider.Instance,
                    NullBloomStorage.Instance,
                    LimboLogs.Instance);

                DbBlocksLoader loader = new DbBlocksLoader(blockTree, LimboNoErrorLogger.Instance);
                await blockTree.Accept(loader, CancellationToken.None);

                Assert.AreEqual(testTree.Head.Hash, blockTree.BestSuggestedHeader.Hash, $"head {chainLength}");
            }
        }
Esempio n. 13
0
        public void Header_block_is_0_when_no_header_was_suggested()
        {
            IBlockTree      blockTree      = Substitute.For <IBlockTree>();
            IReceiptStorage receiptStorage = Substitute.For <IReceiptStorage>();
            IDb             stateDb        = new MemDb();
            SyncConfig      syncConfig     = new();

            syncConfig.PivotNumber = "1";
            ProgressTracker progressTracker = new(blockTree, stateDb, LimboLogs.Instance);

            SyncProgressResolver syncProgressResolver = new(blockTree, receiptStorage, stateDb, NullTrieNodeResolver.Instance, progressTracker, syncConfig, LimboLogs.Instance);

            blockTree.BestSuggestedHeader.Returns((BlockHeader)null);
            Assert.AreEqual(0, syncProgressResolver.FindBestHeader());
        }
Esempio n. 14
0
        public void Scenario_traverse_branch_delete_missing()
        {
            MemDb     db   = new MemDb();
            StateTree tree = new StateTree(new TrieStore(db, LimboLogs.Instance), LimboLogs.Instance);

            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb00000"), _account0);
            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb11111"), _account1);
            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb22222"), null);
            tree.UpdateRootHash();
            Keccak rootHash = tree.RootHash;

            Assert.AreEqual("0x94a193704e99c219d9a21428eb37d6d2d71b3d2cea80c77ff0e201c0df70a283", rootHash.ToString(true));
            tree.Commit(0);
            Assert.AreEqual("0x94a193704e99c219d9a21428eb37d6d2d71b3d2cea80c77ff0e201c0df70a283", rootHash.ToString(true));
        }
Esempio n. 15
0
        public void Can_restore_count_from_the_database(uint leafCount)
        {
            MemDb        memDb         = new MemDb();
            var          metadataMemDb = new MemDb();
            BaselineTree baselineTree  = new ShaBaselineTree(memDb, metadataMemDb, new byte[] { }, _truncationLength, LimboNoErrorLogger.Instance);

            for (int i = 0; i < leafCount; i++)
            {
                baselineTree.Insert(_testLeaves[0]);
            }

            BaselineTree baselineTreeRestored = new ShaBaselineTree(memDb, metadataMemDb, new byte[] { }, _truncationLength, LimboNoErrorLogger.Instance);

            baselineTreeRestored.Count.Should().Be(leafCount);
        }
Esempio n. 16
0
        private static PatriciaTree BuildATreeFromNode(TrieNode node)
        {
            TrieNode.AllowBranchValues = true;
            Rlp rlp = node.RlpEncode();

            node.ResolveKey(true);

            MemDb memDb = new MemDb();

            memDb[node.Keccak.Bytes] = rlp.Bytes;

            PatriciaTree tree = new PatriciaTree(memDb, node.Keccak, false, true);

            return(tree);
        }
Esempio n. 17
0
        public void Scenario_traverse_branch_update_missing()
        {
            MemDb     db   = new MemDb();
            StateTree tree = new StateTree(new TrieStore(db, LimboLogs.Instance), LimboLogs.Instance);

            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb00000"), _account0);
            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb11111"), _account1);
            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb22222"), _account2);
            tree.UpdateRootHash();
            Keccak rootHash = tree.RootHash;

            Assert.AreEqual("0xc063af0bd3dd88320bc852ff8452049c42fbc06d1a69661567bd427572824cbf", rootHash.ToString(true));
            tree.Commit(0);
            Assert.AreEqual("0xc063af0bd3dd88320bc852ff8452049c42fbc06d1a69661567bd427572824cbf", rootHash.ToString(true));
        }
Esempio n. 18
0
        public void Scenario_traverse_extension_new_branching()
        {
            MemDb     db   = new MemDb();
            StateTree tree = new StateTree(new TrieStore(db, LimboLogs.Instance), LimboLogs.Instance);

            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb00000000"), _account0);
            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb11111111"), _account1);
            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeedddddddddddddddddddddddd"), _account2);
            tree.UpdateRootHash();
            Keccak rootHash = tree.RootHash;

            Assert.AreEqual("0x543c960143a2a06b685d6b92f0c37000273e616bc23888521e7edf15ad06da46", rootHash.ToString(true));
            tree.Commit(0);
            Assert.AreEqual("0x543c960143a2a06b685d6b92f0c37000273e616bc23888521e7edf15ad06da46", rootHash.ToString(true));
        }
Esempio n. 19
0
        public void Extension_with_branch_with_two_same_children()
        {
            MemDb        memDb        = new MemDb();
            TrieStore    trieStore    = new TrieStore(memDb, Prune.WhenCacheReaches(1.MB()), Persist.EveryBlock, _logManager);
            PatriciaTree patriciaTree = new PatriciaTree(trieStore, _logManager);

            patriciaTree.Set(_keyA, _longLeaf1);
            patriciaTree.Set(_keyB, _longLeaf1);
            patriciaTree.Commit(0);
            memDb.Keys.Should().HaveCount(4);
            PatriciaTree checkTree = CreateCheckTree(memDb, patriciaTree);

            checkTree.Get(_keyA).Should().BeEquivalentTo(_longLeaf1);
            checkTree.Get(_keyB).Should().BeEquivalentTo(_longLeaf1);
        }
Esempio n. 20
0
        public void Scenario_traverse_leaf_read_missing()
        {
            MemDb     db   = new MemDb();
            StateTree tree = new StateTree(new TrieStore(db, LimboLogs.Instance), LimboLogs.Instance);

            tree.Set(new Keccak("1111111111111111111111111111111111111111111111111111111111111111"), _account0);
            Account account = tree.Get(new Keccak("111111111111111111111111111111111111111111111111111111111ddddddd"));

            Assert.Null(account);
            tree.UpdateRootHash();
            Keccak rootHash = tree.RootHash;

            Assert.AreEqual("0x491fbb33aaff22c0a7ff68d5c81ec114dddf89d022ccdee838a0e9d6cd45cab4", rootHash.ToString(true));
            tree.Commit(0);
            Assert.AreEqual("0x491fbb33aaff22c0a7ff68d5c81ec114dddf89d022ccdee838a0e9d6cd45cab4", rootHash.ToString(true));
        }
Esempio n. 21
0
        public void Scenario_traverse_extension_delete_missing()
        {
            MemDb     db   = new MemDb();
            StateTree tree = new StateTree(new TrieStore(db, LimboLogs.Instance), LimboLogs.Instance);

            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb00000000"), _account0);
            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb11111111"), _account1);
            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeddddddddddddddddddddddddd"), null);
            Assert.AreEqual(0, db.ReadsCount);
            tree.UpdateRootHash();
            Keccak rootHash = tree.RootHash;

            Assert.AreEqual("0xf99f1d3234bad8d63d818db36ff63eefc8916263e654db8b800d3bd03f6339a5", rootHash.ToString(true));
            tree.Commit(0);
            Assert.AreEqual("0xf99f1d3234bad8d63d818db36ff63eefc8916263e654db8b800d3bd03f6339a5", rootHash.ToString(true));
        }
Esempio n. 22
0
        public void Is_fast_block_finished_returns_true_when_no_fast_block_sync_is_used()
        {
            IBlockTree      blockTree      = Substitute.For <IBlockTree>();
            IReceiptStorage receiptStorage = Substitute.For <IReceiptStorage>();
            IDb             stateDb        = new MemDb();
            SyncConfig      syncConfig     = new SyncConfig();

            syncConfig.FastBlocks  = false;
            syncConfig.PivotNumber = "1";

            SyncProgressResolver syncProgressResolver = new SyncProgressResolver(blockTree, receiptStorage, stateDb, new MemDb(), syncConfig, LimboLogs.Instance);

            Assert.True(syncProgressResolver.IsFastBlocksHeadersFinished());
            Assert.True(syncProgressResolver.IsFastBlocksBodiesFinished());
            Assert.True(syncProgressResolver.IsFastBlocksReceiptsFinished());
        }
Esempio n. 23
0
        public void Sets_head_block_hash_in_db_on_new_head_block()
        {
            MemDb blocksDb     = new MemDb();
            MemDb blockInfosDb = new MemDb();

            BlockTree blockTree = new BlockTree(blocksDb, blockInfosDb, OlympicSpecProvider.Instance, Substitute.For <ITransactionPool>(), LimboLogs.Instance);
            Block     block0    = Build.A.Block.WithNumber(0).WithDifficulty(1).TestObject;
            Block     block1    = Build.A.Block.WithNumber(1).WithDifficulty(2).WithParent(block0).TestObject;

            AddToMain(blockTree, block0);
            AddToMain(blockTree, block1);

            var dec = new Keccak(blockInfosDb.Get(Keccak.Zero));

            Assert.AreEqual(block1.Hash, dec);
        }
Esempio n. 24
0
        public void Sets_head_block_info_in_db_on_new_head_block()
        {
            MemDb blocksDb     = new MemDb();
            MemDb blockInfosDb = new MemDb();

            BlockTree blockTree = new BlockTree(blocksDb, blockInfosDb, new MemDb(), OlympicSpecProvider.Instance, NullLogManager.Instance);
            Block     block0    = Build.A.Block.WithNumber(0).WithDifficulty(1).TestObject;
            Block     block1    = Build.A.Block.WithNumber(1).WithDifficulty(2).WithParent(block0).TestObject;

            AddToMain(blockTree, block0);
            AddToMain(blockTree, block1);

            BlockHeader storedInDb = Rlp.Decode <BlockHeader>(new Rlp(blocksDb.Get(Keccak.Zero)));

            Assert.AreEqual(block1.Hash, storedInDb.Hash);
        }
Esempio n. 25
0
        public void Can_read_beyond_cache()
        {
            IKeyValueStore   keyValueStore    = new MemDb();
            WitnessCollector witnessCollector = new(keyValueStore, LimboLogs.Instance);

            for (int i = 0; i < 255; i++)
            {
                witnessCollector.Add(TestItem.Keccaks[i]);
                witnessCollector.Persist(TestItem.Keccaks[i]);
            }

            witnessCollector.Persist(TestItem.KeccakA);
            witnessCollector.Persist(TestItem.KeccakB);

            witnessCollector.Load(TestItem.Keccaks[0]);
        }
Esempio n. 26
0
        public void Scenario_traverse_extension_create_new_extension()
        {
            MemDb     db   = new MemDb();
            StateTree tree = new StateTree(new TrieStore(db, LimboLogs.Instance), LimboLogs.Instance);

            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb00000000"), _account0);
            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb11111111"), _account1);
            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeaaaaaaaaaaaaaaaab00000000"), _account2);
            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeaaaaaaaaaaaaaaaab11111111"), _account3);
            Assert.AreEqual(0, db.ReadsCount);
            tree.UpdateRootHash();
            Keccak rootHash = tree.RootHash;

            Assert.AreEqual("0x0918112fc898173562441709a2c1cbedb80d1aaecaeadf2f3e9492eeaa568c67", rootHash.ToString(true));
            tree.Commit(0);
            Assert.AreEqual("0x0918112fc898173562441709a2c1cbedb80d1aaecaeadf2f3e9492eeaa568c67", rootHash.ToString(true));
        }
Esempio n. 27
0
        public void Single_leaf_delete_same_block()
        {
            MemDb        memDb        = new MemDb();
            TrieStore    trieStore    = new TrieStore(memDb, Prune.WhenCacheReaches(1.MB()), No.Persistence, _logManager);
            PatriciaTree patriciaTree = new PatriciaTree(trieStore, _logManager);

            patriciaTree.Set(_keyA, _longLeaf1);
            patriciaTree.Set(_keyA, Array.Empty <byte>());
            patriciaTree.Commit(0);

            // leaf (root)
            memDb.Keys.Should().HaveCount(0);

            PatriciaTree checkTree = CreateCheckTree(memDb, patriciaTree);

            checkTree.Get(_keyA).Should().BeNull();
        }
Esempio n. 28
0
        public void Scenario_traverse_branch_read_missing()
        {
            MemDb     db   = new MemDb();
            StateTree tree = new StateTree(db);

            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb00000"), _account0);
            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb11111"), _account1);
            Account account = tree.Get(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb22222"));

            Assert.Null(account);
            tree.UpdateRootHash();
            Keccak rootHash = tree.RootHash;

            Assert.AreEqual("0x94a193704e99c219d9a21428eb37d6d2d71b3d2cea80c77ff0e201c0df70a283", rootHash.ToString(true));
            tree.Commit();
            Assert.AreEqual("0x94a193704e99c219d9a21428eb37d6d2d71b3d2cea80c77ff0e201c0df70a283", rootHash.ToString(true));
        }
Esempio n. 29
0
        public void Scenario_traverse_extension_read_missing()
        {
            MemDb     db   = new MemDb();
            StateTree tree = new StateTree(db);

            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb00000000"), _account0);
            tree.Set(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb11111111"), _account1);
            Account account = tree.Get(new Keccak("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeedddddddddddddddddddddddd"));

            Assert.Null(account);
            tree.UpdateRootHash();
            Keccak rootHash = tree.RootHash;

            Assert.AreEqual("0xf99f1d3234bad8d63d818db36ff63eefc8916263e654db8b800d3bd03f6339a5", rootHash.ToString(true));
            tree.Commit();
            Assert.AreEqual("0xf99f1d3234bad8d63d818db36ff63eefc8916263e654db8b800d3bd03f6339a5", rootHash.ToString(true));
        }
        public void Setup()
        {
            _genesisBlock   = Build.A.Block.WithNumber(0).TestObject;
            _blockTree      = Build.A.BlockTree(_genesisBlock).OfChainLength(1).TestObject;
            _stateDb        = new MemDb();
            _receiptsDb     = new MemDb();
            _receiptStorage = Substitute.For <IReceiptStorage>();
            BlockchainConfig quickConfig = new BlockchainConfig();

            quickConfig.SyncTimerInterval = 100;

            IHeaderValidator      headerValidator      = Build.A.HeaderValidator.ThatAlwaysReturnsTrue.TestObject;
            IBlockValidator       blockValidator       = Build.A.BlockValidator.ThatAlwaysReturnsTrue.TestObject;
            ITransactionValidator transactionValidator = Build.A.TransactionValidator.ThatAlwaysReturnsTrue.TestObject;

            _manager = new QueueBasedSyncManager(_stateDb, _blockTree, blockValidator, headerValidator, transactionValidator, NullLogManager.Instance, quickConfig, new PerfService(NullLogManager.Instance), _receiptStorage);
        }