Search in sources :

Example 91 with HashMapDB

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());
}
Also used : Blockchain(org.ethereum.core.Blockchain) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) World(co.rsk.test.World) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 92 with HashMapDB

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));
}
Also used : Bloom(org.ethereum.core.Bloom) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 93 with HashMapDB

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));
}
Also used : Bloom(org.ethereum.core.Bloom) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 94 with HashMapDB

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());
}
Also used : Bloom(org.ethereum.core.Bloom) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 95 with HashMapDB

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());
}
Also used : Bloom(org.ethereum.core.Bloom) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) 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