Search in sources :

Example 81 with World

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

the class Web3ImplTest method getUnknownTransactionByBlockNumberAndIndex.

@Test
public void getUnknownTransactionByBlockNumberAndIndex() {
    World world = new World();
    Web3Impl web3 = createWeb3(world);
    Block genesis = world.getBlockChain().getBestBlock();
    Block block1 = new BlockBuilder(world.getBlockChain(), world.getBridgeSupportFactory(), world.getBlockStore()).trieStore(world.getTrieStore()).parent(genesis).build();
    assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block1));
    TransactionResultDTO tr = web3.eth_getTransactionByBlockNumberAndIndex("0x1", "0x0");
    Assert.assertNull(tr);
}
Also used : TransactionResultDTO(org.ethereum.rpc.dto.TransactionResultDTO) World(co.rsk.test.World) BlockBuilder(co.rsk.test.builders.BlockBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 82 with World

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

the class CliToolsTest method executeBlocks.

@Test
public void executeBlocks() throws FileNotFoundException, DslProcessorException {
    DslParser parser = DslParser.fromResource("dsl/contracts02.txt");
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    processor.processCommands(parser);
    String[] args = new String[] { "1", "2" };
    RskContext rskContext = mock(RskContext.class);
    doReturn(world.getBlockExecutor()).when(rskContext).getBlockExecutor();
    doReturn(world.getBlockStore()).when(rskContext).getBlockStore();
    doReturn(world.getTrieStore()).when(rskContext).getTrieStore();
    doReturn(world.getStateRootHandler()).when(rskContext).getStateRootHandler();
    NodeStopper stopper = mock(NodeStopper.class);
    ExecuteBlocks executeBlocksCliTool = new ExecuteBlocks();
    executeBlocksCliTool.execute(args, () -> rskContext, stopper);
    Assert.assertEquals(2, world.getBlockChain().getBestBlock().getNumber());
    verify(stopper).stop(0);
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) RskContext(co.rsk.RskContext) DslParser(co.rsk.test.dsl.DslParser) NodeStopper(co.rsk.util.NodeStopper) World(co.rsk.test.World) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 83 with World

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

the class CliToolsTest method importBlocks.

@Test
public void importBlocks() throws IOException, DslProcessorException {
    DslParser parser = DslParser.fromResource("dsl/blocks01b.txt");
    ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
    World world = new World(receiptStore);
    WorldDslProcessor processor = new WorldDslProcessor(world);
    processor.processCommands(parser);
    Blockchain blockchain = world.getBlockChain();
    Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
    Block block1 = world.getBlockByName("b01");
    Block block2 = world.getBlockByName("b02");
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("1,");
    stringBuilder.append(ByteUtil.toHexString(block1.getHash().getBytes()));
    stringBuilder.append(",02,");
    stringBuilder.append(ByteUtil.toHexString(block1.getEncoded()));
    stringBuilder.append("\n");
    stringBuilder.append("1,");
    stringBuilder.append(ByteUtil.toHexString(block2.getHash().getBytes()));
    stringBuilder.append(",03,");
    stringBuilder.append(ByteUtil.toHexString(block2.getEncoded()));
    stringBuilder.append("\n");
    File blocksFile = new File(tempFolder.getRoot(), "blocks.txt");
    try (BufferedWriter writer = new BufferedWriter(new FileWriter(blocksFile))) {
        writer.write(stringBuilder.toString());
    }
    String[] args = new String[] { blocksFile.getAbsolutePath() };
    RskContext rskContext = mock(RskContext.class);
    doReturn(world.getBlockStore()).when(rskContext).getBlockStore();
    doReturn(new BlockFactory(ActivationConfigsForTest.all())).when(rskContext).getBlockFactory();
    NodeStopper stopper = mock(NodeStopper.class);
    ImportBlocks importBlocksCliTool = new ImportBlocks();
    importBlocksCliTool.execute(args, () -> rskContext, stopper);
    Assert.assertEquals(block1.getHash(), blockchain.getBlockByNumber(1).getHash());
    Assert.assertEquals(block2.getHash(), blockchain.getBlockByNumber(2).getHash());
    verify(stopper).stop(0);
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) BlockFactory(org.ethereum.core.BlockFactory) Blockchain(org.ethereum.core.Blockchain) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) RskContext(co.rsk.RskContext) DslParser(co.rsk.test.dsl.DslParser) Block(org.ethereum.core.Block) NodeStopper(co.rsk.util.NodeStopper) ReceiptStore(org.ethereum.db.ReceiptStore) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 84 with World

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

the class CliToolsTest method exportBlocks.

@Test
public void exportBlocks() throws IOException, DslProcessorException {
    DslParser parser = DslParser.fromResource("dsl/blocks01.txt");
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    processor.processCommands(parser);
    File blocksFile = new File(tempFolder.getRoot(), "blocks.txt");
    String[] args = new String[] { "0", "2", blocksFile.getAbsolutePath() };
    RskContext rskContext = mock(RskContext.class);
    doReturn(world.getBlockStore()).when(rskContext).getBlockStore();
    NodeStopper stopper = mock(NodeStopper.class);
    ExportBlocks exportBlocksCliTool = new ExportBlocks();
    exportBlocksCliTool.execute(args, () -> rskContext, stopper);
    String data = new String(Files.readAllBytes(blocksFile.toPath()), StandardCharsets.UTF_8);
    Blockchain blockchain = world.getBlockChain();
    BlockStore blockStore = world.getBlockStore();
    for (long n = 0; n < 3; n++) {
        Block block = blockchain.getBlockByNumber(n);
        BlockDifficulty totalDifficulty = blockStore.getTotalDifficultyForHash(block.getHash().getBytes());
        String line = block.getNumber() + "," + block.getHash().toHexString() + "," + ByteUtil.toHexString(totalDifficulty.getBytes()) + "," + ByteUtil.toHexString(block.getEncoded());
        Assert.assertTrue(data.contains(line));
    }
    verify(stopper).stop(0);
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockStore(org.ethereum.db.BlockStore) Blockchain(org.ethereum.core.Blockchain) World(co.rsk.test.World) BlockDifficulty(co.rsk.core.BlockDifficulty) RskContext(co.rsk.RskContext) DslParser(co.rsk.test.dsl.DslParser) NodeStopper(co.rsk.util.NodeStopper) Block(org.ethereum.core.Block) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 85 with World

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

the class TwoAsyncNodeTest method createNode.

private static SimpleAsyncNode createNode(int size) {
    final World world = new World();
    final NetBlockStore store = new NetBlockStore();
    final Blockchain blockchain = world.getBlockChain();
    List<Block> blocks = new BlockGenerator().getBlockChain(blockchain.getBestBlock(), size);
    for (Block b : blocks) blockchain.tryToConnect(b);
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    NodeMessageHandler handler = new NodeMessageHandler(config, processor, null, null, null, null, mock(StatusResolver.class));
    return new SimpleAsyncNode(handler, blockchain);
}
Also used : Blockchain(org.ethereum.core.Blockchain) World(co.rsk.test.World) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Block(org.ethereum.core.Block) SyncConfiguration(co.rsk.net.sync.SyncConfiguration)

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