Search in sources :

Example 1 with RskContext

use of co.rsk.RskContext in project rskj by rsksmart.

the class StartBootstrap method main.

public static void main(String[] args) {
    setUpThread(Thread.currentThread());
    RskContext ctx = new BootstrapRskContext(args);
    PreflightChecksUtils preflightChecks = new PreflightChecksUtils(ctx);
    Runtime runtime = Runtime.getRuntime();
    NodeStopper nodeStopper = System::exit;
    runBootstrapNode(ctx, preflightChecks, runtime, nodeStopper);
}
Also used : RskContext(co.rsk.RskContext) NodeStopper(co.rsk.util.NodeStopper) PreflightChecksUtils(co.rsk.util.PreflightChecksUtils)

Example 2 with RskContext

use of co.rsk.RskContext in project rskj by rsksmart.

the class GenesisHashesTest method mainnetHashTest.

@Test
public void mainnetHashTest() {
    RskContext rskContext = new RskTestContext(new String[0]);
    // this triggers changes in the Genesis through the BlockChainLoader
    rskContext.getBlockchain();
    Genesis genesis = rskContext.getGenesis();
    assertThat(genesis.getHash(), is(new Keccak256("f88529d4ab262c0f4d042e9d8d3f2472848eaafe1a9b7213f57617eb40a9f9e0")));
    rskContext.close();
}
Also used : RskTestContext(org.ethereum.util.RskTestContext) RskContext(co.rsk.RskContext) Genesis(org.ethereum.core.Genesis) Keccak256(co.rsk.crypto.Keccak256) Test(org.junit.Test)

Example 3 with RskContext

use of co.rsk.RskContext 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 4 with RskContext

use of co.rsk.RskContext 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 5 with RskContext

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

Aggregations

RskContext (co.rsk.RskContext)20 Test (org.junit.Test)17 NodeStopper (co.rsk.util.NodeStopper)10 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)9 RskTestContext (org.ethereum.util.RskTestContext)8 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)4 BlockFactory (org.ethereum.core.BlockFactory)3 Blockchain (org.ethereum.core.Blockchain)3 HashMapDB (org.ethereum.datasource.HashMapDB)3 PreflightChecksUtils (co.rsk.util.PreflightChecksUtils)2 Genesis (org.ethereum.core.Genesis)2 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)2 BlockStore (org.ethereum.db.BlockStore)2 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)2 ReceiptStore (org.ethereum.db.ReceiptStore)2 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)2