use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class BlocksBloomProcessorTest method processBlocksToFillRange.
@Test
public void processBlocksToFillRange() {
World world = new World();
Blockchain blockchain = world.getBlockChain();
BlockChainBuilder.extend(blockchain, 8, false, false);
KeyValueDataSource dataSource = new HashMapDB();
BlocksBloomStore blocksBloomStore = new BlocksBloomStore(4, 2, dataSource);
BlocksBloomProcessor blocksBloomProcessor = new BlocksBloomProcessor(blocksBloomStore, world.getBlockStore());
blocksBloomProcessor.processNewBlockNumber(4);
blocksBloomProcessor.processNewBlockNumber(5);
BlocksBloom result = blocksBloomProcessor.getBlocksBloomInProcess();
Assert.assertNull(result);
Assert.assertFalse(dataSource.keys().isEmpty());
Assert.assertEquals(1, dataSource.keys().size());
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class BlocksBloomStoreTest method hasBlockNumberInStore.
@Test
public void hasBlockNumberInStore() {
KeyValueDataSource internalStore = new HashMapDB();
Bloom bloom = new Bloom();
BlocksBloom blocksBloom = new BlocksBloom();
blocksBloom.addBlockBloom(64, bloom);
blocksBloom.addBlockBloom(65, bloom);
internalStore.put(BlocksBloomStore.longToKey(64), BlocksBloomEncoder.encode(blocksBloom));
BlocksBloomStore blocksBloomStore = new BlocksBloomStore(64, 0, internalStore);
Assert.assertFalse(blocksBloomStore.hasBlockNumber(0));
Assert.assertTrue(blocksBloomStore.hasBlockNumber(64));
Assert.assertTrue(blocksBloomStore.hasBlockNumber(65));
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class BlocksBloomStoreTest method hasBlockNumberZero.
@Test
public void hasBlockNumberZero() {
BlocksBloomStore blocksBloomStore = new BlocksBloomStore(64, 0, new HashMapDB());
Assert.assertFalse(blocksBloomStore.hasBlockNumber(0));
BlocksBloom blocksBloom = new BlocksBloom();
Bloom bloom1 = new Bloom();
Bloom bloom2 = new Bloom();
blocksBloom.addBlockBloom(0, bloom1);
blocksBloom.addBlockBloom(1, bloom2);
blocksBloomStore.addBlocksBloom(blocksBloom);
Assert.assertTrue(blocksBloomStore.hasBlockNumber(0));
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class BlocksBloomStoreTest method addBlocksBloom.
@Test
public void addBlocksBloom() {
BlocksBloom blocksBloom = new BlocksBloom();
byte[] bytes1 = new byte[Bloom.BLOOM_BYTES];
bytes1[0] = 0x01;
byte[] bytes2 = new byte[Bloom.BLOOM_BYTES];
bytes2[1] = 0x10;
Bloom bloom1 = new Bloom(bytes1);
Bloom bloom2 = new Bloom(bytes2);
BlocksBloomStore blocksBloomStore = new BlocksBloomStore(64, 0, new HashMapDB());
blocksBloom.addBlockBloom(blocksBloomStore.getNoBlocks(), bloom1);
blocksBloom.addBlockBloom(blocksBloomStore.getNoBlocks() + 1, bloom2);
blocksBloomStore.addBlocksBloom(blocksBloom);
BlocksBloom actualBlocksBloom = blocksBloomStore.getBlocksBloomByNumber(blocksBloomStore.getNoBlocks());
Assert.assertEquals(blocksBloom.fromBlock(), actualBlocksBloom.fromBlock());
Assert.assertEquals(blocksBloom.toBlock(), actualBlocksBloom.toBlock());
Assert.assertEquals(blocksBloom.getBloom(), actualBlocksBloom.getBloom());
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class BlocksBloomStoreTest method addBlocksBloomUsingDataSource.
@Test
public void addBlocksBloomUsingDataSource() {
KeyValueDataSource dataSource = new HashMapDB();
BlocksBloom blocksBloom = new BlocksBloom();
byte[] bytes1 = new byte[Bloom.BLOOM_BYTES];
bytes1[0] = 0x01;
byte[] bytes2 = new byte[Bloom.BLOOM_BYTES];
bytes2[1] = 0x10;
Bloom bloom1 = new Bloom(bytes1);
Bloom bloom2 = new Bloom(bytes2);
BlocksBloomStore blocksBloomStore = new BlocksBloomStore(64, 0, dataSource);
blocksBloom.addBlockBloom(blocksBloomStore.getNoBlocks(), bloom1);
blocksBloom.addBlockBloom(blocksBloomStore.getNoBlocks() + 1, bloom2);
blocksBloomStore.addBlocksBloom(blocksBloom);
BlocksBloom actualBlocksBloom = blocksBloomStore.getBlocksBloomByNumber(blocksBloomStore.getNoBlocks());
Assert.assertEquals(blocksBloom.fromBlock(), actualBlocksBloom.fromBlock());
Assert.assertEquals(blocksBloom.toBlock(), actualBlocksBloom.toBlock());
Assert.assertEquals(blocksBloom.getBloom(), actualBlocksBloom.getBloom());
Assert.assertNotNull(dataSource.get(BlocksBloomStore.longToKey(blocksBloomStore.getNoBlocks())));
BlocksBloom result = BlocksBloomEncoder.decode(dataSource.get(BlocksBloomStore.longToKey(blocksBloomStore.getNoBlocks())));
Assert.assertNotNull(result);
Assert.assertEquals(blocksBloom.fromBlock(), result.fromBlock());
Assert.assertEquals(blocksBloom.toBlock(), result.toBlock());
Assert.assertArrayEquals(blocksBloom.getBloom().getData(), result.getBloom().getData());
BlocksBloomStore blocksBloomStore2 = new BlocksBloomStore(64, 0, dataSource);
BlocksBloom result2 = blocksBloomStore2.getBlocksBloomByNumber(blocksBloom.fromBlock());
Assert.assertNotNull(result2);
Assert.assertEquals(blocksBloom.fromBlock(), result2.fromBlock());
Assert.assertEquals(blocksBloom.toBlock(), result2.toBlock());
Assert.assertArrayEquals(blocksBloom.getBloom().getData(), result2.getBloom().getData());
}
Aggregations