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());
}
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);
}
}
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"));
}
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);
}
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)));
}
Aggregations