public void Capacity_grwoth_and_shrinkage() { StateDb db = new StateDb(new MemDb()); for (int i = 0; i < 16; i++) { _hash1 = Keccak.Compute(_hash1.Bytes); db.Set(_hash1, _bytes1); } db.Restore(-1); byte[] getResult = db.Get(_hash1); Assert.AreEqual(null, getResult); for (int i = 0; i < 16; i++) { _hash1 = Keccak.Compute(_hash1.Bytes); db.Set(_hash1, _bytes1); } db.Commit(); getResult = db.Get(_hash1); Assert.AreEqual(_bytes1, getResult); }
public async Task Can_read_dependent_items_from_state_db_while_waiting_for_dependencies() { StateDb codeDb = new StateDb(); StateDb stateDB = new StateDb(); MemDb tempDb = new MemDb(); SyncConfig syncConfig = new SyncConfig(); syncConfig.FastSync = true; IBlockTree blockTree = Substitute.For <IBlockTree>(); ISyncPeerPool pool = Substitute.For <ISyncPeerPool>(); SyncProgressResolver syncProgressResolver = new SyncProgressResolver(blockTree, NullReceiptStorage.Instance, stateDB, new MemDb(), syncConfig, LimboLogs.Instance); ISyncModeSelector syncModeSelector = new MultiSyncModeSelector(syncProgressResolver, pool, syncConfig, LimboLogs.Instance); StateSyncFeed stateSyncFeed = new StateSyncFeed(codeDb, stateDB, tempDb, syncModeSelector, blockTree, LimboLogs.Instance); // so we want to setup a trie in a structure of -> branch into two leaves // so we can respond with the branch node and with leaves missing // and we can prove that we can read the branch from the temp DB while it is still missing from the State DB AccountDecoder accountDecoder = new AccountDecoder(); TrieNode leaf = TrieNodeFactory.CreateLeaf(new HexPrefix(true, new byte[] { 1, 2, 3 }), accountDecoder.Encode(Account.TotallyEmpty).Bytes); TrieNode branch = TrieNodeFactory.CreateBranch(); branch.SetChild(1, leaf); branch.ResolveKey(true); // PatriciaTree tree = new PatriciaTree(); // tree = new PatriciaTree(); // tree.Set(branch.Keccak.Bytes, branch.Value); stateSyncFeed.ResetStateRoot(0, branch.Keccak); var request = await stateSyncFeed.PrepareRequest(); BuildRequestAndHandleResponse(branch, request, stateSyncFeed); byte[] value = tempDb.Get(branch.Keccak); value.Should().BeEquivalentTo(branch.FullRlp); byte[] valueFromState = stateDB.Get(branch.Keccak); valueFromState.Should().BeNull(); request = await stateSyncFeed.PrepareRequest(); BuildRequestAndHandleResponse(leaf, request, stateSyncFeed); value = tempDb.Get(branch.Keccak); value.Should().BeNull(); valueFromState = stateDB.Get(branch.Keccak); valueFromState.Should().BeEquivalentTo(branch.FullRlp); }
public void Set_get() { StateDb db = new StateDb(new MemDb()); db.Set(_hash1, _bytes1); byte[] getResult = db.Get(_hash1); Assert.AreEqual(_bytes1, getResult); }
public void Set_restore_get() { StateDb db = new StateDb(new MemDb()); db.Set(_hash1, _bytes1); db.Restore(-1); byte[] getResult = db.Get(_hash1); Assert.AreEqual(null, getResult); }
public void Restore_in_the_middle() { StateDb db = new StateDb(new MemDb()); db.Set(_hash1, _bytes1); int snapshot = db.TakeSnapshot(); db.Set(_hash2, _bytes2); db.Restore(snapshot); byte[] getResult = db.Get(_hash2); Assert.IsNull(getResult); }