use of co.rsk.RskContext in project rskj by rsksmart.
the class CliToolsTest method importState.
@Test
public void importState() throws IOException {
byte[] value = new byte[42];
Random random = new Random();
random.nextBytes(value);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(ByteUtil.toHexString(value));
stringBuilder.append("\n");
File stateFile = new File(tempFolder.getRoot(), "state.txt");
try (BufferedWriter writer = new BufferedWriter(new FileWriter(stateFile))) {
writer.write(stringBuilder.toString());
}
String databaseDir = new File(tempFolder.getRoot(), "db").getAbsolutePath();
String[] args = new String[] { stateFile.getAbsolutePath() };
RskContext rskContext = mock(RskContext.class);
RskSystemProperties rskSystemProperties = mock(RskSystemProperties.class);
doReturn(databaseDir).when(rskSystemProperties).databaseDir();
doReturn(rskSystemProperties).when(rskContext).getRskSystemProperties();
NodeStopper stopper = mock(NodeStopper.class);
ImportState importStateCliTool = new ImportState();
importStateCliTool.execute(args, () -> rskContext, stopper);
byte[] key = new Keccak256(Keccak256Helper.keccak256(value)).getBytes();
KeyValueDataSource trieDB = LevelDbDataSource.makeDataSource(Paths.get(databaseDir, "unitrie"));
byte[] result = trieDB.get(key);
trieDB.close();
Assert.assertNotNull(result);
Assert.assertArrayEquals(value, result);
verify(stopper).stop(0);
}
use of co.rsk.RskContext 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);
}
use of co.rsk.RskContext in project rskj by rsksmart.
the class GenesisHashesTest method testnetHashTest.
@Test
public void testnetHashTest() {
RskContext rskContext = new RskTestContext(new String[] { "--testnet" });
// this triggers changes in the Genesis through the BlockChainLoader
rskContext.getBlockchain();
Genesis genesis = rskContext.getGenesis();
assertThat(genesis.getHash(), is(new Keccak256("cabb7fbe88cd6d922042a32ffc08ce8b1fbb37d650b9d4e7dbfe2a7469adfa42")));
rskContext.close();
}
use of co.rsk.RskContext in project rskj by rsksmart.
the class PreflightChecksUtilsTest method runChecks_invalidJavaVersion_exceptionIsThrown.
@Test
public void runChecks_invalidJavaVersion_exceptionIsThrown() throws Exception {
expectedException.expect(PreflightCheckException.class);
expectedException.expectMessage("Invalid Java Version '16'. Supported versions: 8 11");
RskContext rskContext = new RskTestContext(new String[0]);
PreflightChecksUtils preflightChecksUtilsSpy = spy(new PreflightChecksUtils(rskContext));
when(preflightChecksUtilsSpy.getJavaVersion()).thenReturn("16");
preflightChecksUtilsSpy.runChecks();
rskContext.close();
}
use of co.rsk.RskContext in project rskj by rsksmart.
the class PreflightChecksUtilsTest method runChecks_currentJavaVersionIs11_OK.
@Test
public void runChecks_currentJavaVersionIs11_OK() throws Exception {
RskContext rskContext = new RskTestContext(new String[0]);
PreflightChecksUtils preflightChecksUtilsSpy = spy(new PreflightChecksUtils(rskContext));
when(preflightChecksUtilsSpy.getJavaVersion()).thenReturn("11");
preflightChecksUtilsSpy.runChecks();
verify(preflightChecksUtilsSpy, times(1)).getJavaVersion();
verify(preflightChecksUtilsSpy, times(1)).getIntJavaVersion("11");
rskContext.close();
}
Aggregations