Search in sources :

Example 56 with World

use of co.rsk.test.World in project rskj by rsksmart.

the class WorldDslProcessorTest method processAccountNewCommandWithBalanceAndCode.

@Test
public void processAccountNewCommandWithBalanceAndCode() throws DslProcessorException {
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    DslParser parser = new DslParser("account_new acc1 1000000 01020304");
    processor.processCommands(parser);
    Account account = world.getAccountByName("acc1");
    Assert.assertNotNull(account);
    RepositorySnapshot repository = world.getRepositoryLocator().snapshotAt(world.getBlockChain().getBestBlock().getHeader());
    Assert.assertEquals(new BigInteger("1000000"), repository.getBalance(account.getAddress()).asBigInteger());
    byte[] code = repository.getCode(account.getAddress());
    Assert.assertNotNull(code);
    Assert.assertArrayEquals(new byte[] { 0x01, 0x02, 0x03, 0x04 }, code);
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Account(org.ethereum.core.Account) RepositorySnapshot(co.rsk.db.RepositorySnapshot) DslParser(co.rsk.test.dsl.DslParser) BigInteger(java.math.BigInteger) World(co.rsk.test.World) Test(org.junit.Test)

Example 57 with World

use of co.rsk.test.World 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)

Example 58 with World

use of co.rsk.test.World in project rskj by rsksmart.

the class BlocksBloomServiceTest method processFirstRange.

@Test
public void processFirstRange() {
    World world = new World();
    Blockchain blockchain = world.getBlockChain();
    BlockChainBuilder.extend(blockchain, 8, 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.processNewBlock(4);
    blocksBloomService.processNewBlock(6);
    Assert.assertFalse(dataSource.keys().isEmpty());
    Assert.assertEquals(1, dataSource.keys().size());
    Assert.assertNotNull(dataSource.get(longToKey(0)));
}
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)

Example 59 with World

use of co.rsk.test.World in project rskj by rsksmart.

the class BlocksBloomProcessorTest method processBlocksInSecondRangeOnly.

@Test
public void processBlocksInSecondRangeOnly() {
    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(6);
    blocksBloomProcessor.processNewBlockNumber(4);
    BlocksBloom result = blocksBloomProcessor.getBlocksBloomInProcess();
    Assert.assertNotNull(result);
    Assert.assertEquals(4, result.fromBlock());
    Assert.assertEquals(4, result.toBlock());
    Assert.assertTrue(dataSource.keys().isEmpty());
}
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 60 with World

use of co.rsk.test.World in project rskj by rsksmart.

the class BlocksBloomProcessorTest method processNewBlockTwice.

@Test
public void processNewBlockTwice() {
    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(4);
    BlocksBloom result = blocksBloomProcessor.getBlocksBloomInProcess();
    Assert.assertNotNull(result);
    Assert.assertEquals(0, result.fromBlock());
    Assert.assertEquals(2, result.toBlock());
    Assert.assertTrue(dataSource.keys().isEmpty());
}
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)

Aggregations

World (co.rsk.test.World)198 Test (org.junit.Test)169 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)55 DslParser (co.rsk.test.dsl.DslParser)52 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)46 HashMapDB (org.ethereum.datasource.HashMapDB)45 AccountBuilder (co.rsk.test.builders.AccountBuilder)36 Block (org.ethereum.core.Block)36 ReceiptStore (org.ethereum.db.ReceiptStore)34 BlockBuilder (co.rsk.test.builders.BlockBuilder)31 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)31 Blockchain (org.ethereum.core.Blockchain)30 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)24 Transaction (org.ethereum.core.Transaction)23 BigInteger (java.math.BigInteger)17 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)15 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Account (org.ethereum.core.Account)15 TestSystemProperties (co.rsk.config.TestSystemProperties)14