Search in sources :

Example 81 with HashMapDB

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

the class TrieSaveRetrieveTest method saveTrieWithKeyLongValues.

@Test
public void saveTrieWithKeyLongValues() {
    HashMapDB map = new HashMapDB();
    TrieStoreImpl store = new TrieStoreImpl(map);
    Trie trie = new Trie(store).put("foo", "bar".getBytes()).put("bar", TrieValueTest.makeValue(100)).put("answer", TrieValueTest.makeValue(200));
    store.save(trie);
    Assert.assertNotEquals(0, trie.trieSize());
    int embeddableNodes = 3;
    int longValues = 2;
    Assert.assertEquals(trie.trieSize() - embeddableNodes + longValues, map.keys().size());
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 82 with HashMapDB

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

the class TrieSaveRetrieveTest method updateSaveRetrieveAndGetOneThousandKeyValuesUsingBinaryTree.

@Test
public void updateSaveRetrieveAndGetOneThousandKeyValuesUsingBinaryTree() {
    HashMapDB map = new HashMapDB();
    TrieStoreImpl store = new TrieStoreImpl(map);
    Trie trie = new Trie(store);
    for (int k = 0; k < 1000; k++) trie = trie.put(k + "", (k + "").getBytes());
    store.save(trie);
    Trie trie2 = store.retrieve(trie.getHash().getBytes()).get();
    Assert.assertNotNull(trie2);
    Assert.assertEquals(trie.getHash(), trie2.getHash());
    for (int k = 0; k < 1000; k++) {
        String key = k + "";
        byte[] expected = trie.get(key);
        byte[] value = trie2.get(key);
        Assert.assertArrayEquals(expected, value);
    }
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 83 with HashMapDB

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

the class TrieSaveRetrieveTest method retrieveTrieWithLongValuesUsingHash.

@Test
public void retrieveTrieWithLongValuesUsingHash() {
    HashMapDB map = new HashMapDB();
    TrieStoreImpl store = new TrieStoreImpl(map);
    Trie trie = new Trie(store).put("foo", "bar".getBytes()).put("bar", TrieValueTest.makeValue(100)).put("answer", TrieValueTest.makeValue(200));
    store.save(trie);
    Trie trie2 = store.retrieve(trie.getHash().getBytes()).get();
    Assert.assertNotNull(trie2);
    Assert.assertEquals(trie.trieSize(), trie2.trieSize());
    Assert.assertEquals(trie.getHash(), trie2.getHash());
    Assert.assertArrayEquals(trie.get("foo"), trie2.get("foo"));
    Assert.assertArrayEquals(trie.get("bar"), trie2.get("bar"));
    Assert.assertArrayEquals(trie.get("answer"), trie2.get("answer"));
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 84 with HashMapDB

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

the class RepositoryTest method setUp.

@Before
public void setUp() {
    trieStore = new TrieStoreImpl(new HashMapDB());
    mutableTrie = new MutableTrieImpl(trieStore, new Trie(trieStore));
    repository = new MutableRepository(mutableTrie);
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) MutableRepository(org.ethereum.db.MutableRepository) HashMapDB(org.ethereum.datasource.HashMapDB) Trie(co.rsk.trie.Trie) Before(org.junit.Before)

Example 85 with HashMapDB

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

the class BlocksBloomServiceTest method processFirstAndSecondRangeUsingEmitter.

@Test
public void processFirstAndSecondRangeUsingEmitter() {
    World world = new World();
    Blockchain blockchain = world.getBlockChain();
    BlockChainBuilder.extend(blockchain, 10, false, false);
    CompositeEthereumListener emitter = new CompositeEthereumListener();
    KeyValueDataSource dataSource = new HashMapDB();
    BlocksBloomStore blocksBloomStore = new BlocksBloomStore(4, 2, dataSource);
    BlocksBloomService blocksBloomService = new BlocksBloomService(emitter, blocksBloomStore, world.getBlockStore());
    blocksBloomService.start();
    emitter.onBlock(blockchain.getBlockByNumber(4), null);
    emitter.onBlock(blockchain.getBlockByNumber(6), null);
    emitter.onBlock(blockchain.getBlockByNumber(9), null);
    blocksBloomService.stop();
    Assert.assertFalse(dataSource.keys().isEmpty());
    Assert.assertEquals(2, dataSource.keys().size());
    Assert.assertNotNull(dataSource.get(longToKey(0)));
    Assert.assertNotNull(dataSource.get(longToKey(4)));
}
Also used : CompositeEthereumListener(org.ethereum.listener.CompositeEthereumListener) Blockchain(org.ethereum.core.Blockchain) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) World(co.rsk.test.World) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Aggregations

HashMapDB (org.ethereum.datasource.HashMapDB)208 Test (org.junit.Test)181 World (co.rsk.test.World)45 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)34 ReceiptStore (org.ethereum.db.ReceiptStore)34 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)34 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)29 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)27 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)27 TrieStore (co.rsk.trie.TrieStore)26 HashMapBlocksIndex (co.rsk.db.HashMapBlocksIndex)23 Trie (co.rsk.trie.Trie)21 Blockchain (org.ethereum.core.Blockchain)17 RskAddress (co.rsk.core.RskAddress)16 Transaction (org.ethereum.core.Transaction)16 DslParser (co.rsk.test.dsl.DslParser)15 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)13 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12