Search in sources :

Example 11 with NodeStopper

use of co.rsk.util.NodeStopper in project rskj by rsksmart.

the class CliToolsTest method connectBlocks.

@Test
public void connectBlocks() 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(blockchain).when(rskContext).getBlockchain();
    doReturn(world.getBlockStore()).when(rskContext).getBlockStore();
    doReturn(world.getTrieStore()).when(rskContext).getTrieStore();
    doReturn(receiptStore).when(rskContext).getReceiptStore();
    doReturn(new BlockFactory(ActivationConfigsForTest.all())).when(rskContext).getBlockFactory();
    NodeStopper stopper = mock(NodeStopper.class);
    ConnectBlocks connectBlocksCliTool = new ConnectBlocks();
    connectBlocksCliTool.execute(args, () -> rskContext, stopper);
    Assert.assertEquals(2, blockchain.getBestBlock().getNumber());
    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)

Aggregations

NodeStopper (co.rsk.util.NodeStopper)11 RskContext (co.rsk.RskContext)10 Test (org.junit.Test)10 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)9 World (co.rsk.test.World)6 DslParser (co.rsk.test.dsl.DslParser)6 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)6 Block (org.ethereum.core.Block)6 Keccak256 (co.rsk.crypto.Keccak256)3 BlockFactory (org.ethereum.core.BlockFactory)3 Blockchain (org.ethereum.core.Blockchain)3 HashMapDB (org.ethereum.datasource.HashMapDB)3 PreflightChecksUtils (co.rsk.util.PreflightChecksUtils)2 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)2 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)2 ReceiptStore (org.ethereum.db.ReceiptStore)2 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)2 NodeRunner (co.rsk.NodeRunner)1 RskSystemProperties (co.rsk.config.RskSystemProperties)1 TestSystemProperties (co.rsk.config.TestSystemProperties)1