Search in sources :

Example 36 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class SecureTrieImplStoreTest method retrieveTrieWithLongValuesByHash.

@Test
public void retrieveTrieWithLongValuesByHash() {
    HashMapDB map = new HashMapDB();
    TrieStoreImpl store = new TrieStoreImpl(map);
    Trie trie = new TrieImpl(store, true).put("bar", TrieImplValueTest.makeValue(100)).put("foo", TrieImplValueTest.makeValue(200));
    trie.save();
    int size = trie.trieSize();
    Trie trie2 = store.retrieve(trie.getHash().getBytes());
    Assert.assertEquals(1, store.getRetrieveCount());
    Assert.assertEquals(size, trie2.trieSize());
    Assert.assertEquals(size, store.getRetrieveCount());
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 37 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class SecureTrieImplStoreTest method saveFullTrieUpdateAndSaveAgainUsingBinaryTrie.

@Test
public void saveFullTrieUpdateAndSaveAgainUsingBinaryTrie() {
    HashMapDB map = new HashMapDB();
    TrieStoreImpl store = new TrieStoreImpl(map);
    Trie trie = new TrieImpl(store, true).put("foo", "bar".getBytes());
    trie.save();
    Assert.assertEquals(trie.trieSize(), store.getSaveCount());
    trie = trie.put("foo", "bar2".getBytes());
    trie.save();
    Assert.assertEquals(trie.trieSize() + 1, store.getSaveCount());
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 38 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class SecureTrieImplStoreTest method saveFullTrieWithLongValueTwice.

@Test
public void saveFullTrieWithLongValueTwice() {
    HashMapDB map = new HashMapDB();
    TrieStoreImpl store = new TrieStoreImpl(map);
    Trie trie = new TrieImpl(store, true).put("foo", TrieImplValueTest.makeValue(100));
    trie.save();
    Assert.assertEquals(2, store.getSaveCount());
    trie.save();
    Assert.assertEquals(2, store.getSaveCount());
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 39 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class SecureTrieImplStoreTest method saveFullTrieUpdateAndSaveAgain.

@Test
public void saveFullTrieUpdateAndSaveAgain() {
    HashMapDB map = new HashMapDB();
    TrieStoreImpl store = new TrieStoreImpl(map);
    Trie trie = new TrieImpl(store, true).put("foo", "bar".getBytes());
    trie.save();
    Assert.assertEquals(trie.trieSize(), store.getSaveCount());
    trie = trie.put("foo", "bar2".getBytes());
    trie.save();
    Assert.assertEquals(trie.trieSize() + 1, store.getSaveCount());
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 40 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class SecureTrieImplStoreTest method saveTrieNode.

@Test
public void saveTrieNode() {
    HashMapDB map = new HashMapDB();
    TrieStoreImpl store = new TrieStoreImpl(map);
    Trie trie = new TrieImpl(store, true).put("foo", "bar".getBytes());
    store.save(trie);
    Assert.assertEquals(1, map.keys().size());
    Assert.assertNotNull(map.get(trie.getHash().getBytes()));
    Assert.assertArrayEquals(trie.toMessage(), map.get(trie.getHash().getBytes()));
    Assert.assertEquals(1, store.getSaveCount());
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Aggregations

HashMapDB (org.ethereum.datasource.HashMapDB)141 Test (org.junit.Test)130 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)28 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)23 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)22 SimpleBlock (co.rsk.peg.simples.SimpleBlock)18 ArrayList (java.util.ArrayList)18 RepositoryImpl (co.rsk.db.RepositoryImpl)15 DataWord (org.ethereum.vm.DataWord)14 Repository (org.ethereum.core.Repository)12 RskAddress (co.rsk.core.RskAddress)11 TrieStore (co.rsk.trie.TrieStore)10 BlockBuilder (co.rsk.test.builders.BlockBuilder)9 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)8 ReceiptStore (org.ethereum.db.ReceiptStore)8 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)8 Keccak256 (co.rsk.crypto.Keccak256)7 World (co.rsk.test.World)7 TrieImpl (co.rsk.trie.TrieImpl)6 TestUtils.randomDataWord (org.ethereum.TestUtils.randomDataWord)6