use of org.ethereum.core.BlockFactory in project rskj by rsksmart.
the class GitHubBasicTest method runDifficultyTest.
@Test
public void runDifficultyTest() throws IOException, ParseException {
BlockFactory blockFactory = new BlockFactory(config.getActivationConfig());
String json = JSONReader.loadJSONFromCommit("BasicTests/difficulty.json", shacommit);
DifficultyTestSuite testSuite = new DifficultyTestSuite(json);
for (DifficultyTestCase testCase : testSuite.getTestCases()) {
logger.info("Running {}\n", testCase.getName());
BlockHeader current = testCase.getCurrent(blockFactory);
BlockHeader parent = testCase.getParent(blockFactory);
assertEquals(testCase.getExpectedDifficulty(), DIFFICULTY_CALCULATOR.calcDifficulty(current, parent));
}
}
use of org.ethereum.core.BlockFactory 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);
}
use of org.ethereum.core.BlockFactory in project rskj by rsksmart.
the class ProgramMemoryTest method createProgram.
@Before
public void createProgram() {
TestSystemProperties config = new TestSystemProperties();
program = new Program(config.getVmConfig(), new PrecompiledContracts(config, null), new BlockFactory(config.getActivationConfig()), mock(ActivationConfig.ForBlock.class), ByteUtil.EMPTY_BYTE_ARRAY, pi, null, new HashSet<>());
}
use of org.ethereum.core.BlockFactory in project rskj by rsksmart.
the class ProgramTest method setup.
@Before
public void setup() {
final ActivationConfig.ForBlock activations = getBlockchainConfig();
precompiledContract = spy(precompiledContracts.getContractForAddress(activations, PrecompiledContracts.ECRECOVER_ADDR_DW));
gasCost = precompiledContract.getGasForData(DataWord.ONE.getData());
when(repository.startTracking()).thenReturn(repository);
when(repository.getBalance(any())).thenReturn(Coin.valueOf(20l));
when(programInvoke.getOwnerAddress()).thenReturn(DataWord.ONE);
when(programInvoke.getRepository()).thenReturn(repository);
when(programInvoke.getPrevHash()).thenReturn(DataWord.ONE);
when(programInvoke.getCoinbase()).thenReturn(DataWord.ONE);
when(programInvoke.getDifficulty()).thenReturn(DataWord.ONE);
when(programInvoke.getNumber()).thenReturn(DataWord.ONE);
when(programInvoke.getGaslimit()).thenReturn(DataWord.ONE);
when(programInvoke.getTimestamp()).thenReturn(DataWord.ONE);
when(msg.getCodeAddress()).thenReturn(DataWord.ONE);
when(msg.getType()).thenReturn(MessageCall.MsgType.CALL);
when(msg.getEndowment()).thenReturn(DataWord.ONE);
when(msg.getOutDataOffs()).thenReturn(DataWord.ONE);
when(msg.getOutDataSize()).thenReturn(DataWord.ONE);
when(msg.getInDataOffs()).thenReturn(DataWord.ONE);
when(msg.getInDataSize()).thenReturn(DataWord.ONE);
when(msg.getGas()).thenReturn(DataWord.valueOf(TOTAL_GAS));
Transaction transaction = Transaction.builder().nonce(BigInteger.ONE.toByteArray()).gasPrice(BigInteger.ONE).gasLimit(BigInteger.valueOf(21000)).destination(PrecompiledContracts.BRIDGE_ADDR).chainId(config.getNetworkConstants().getChainId()).value(BigInteger.TEN).build();
when(repository.getNonce(any(RskAddress.class))).thenReturn(BigInteger.ONE);
BlockFactory blockFactory = new BlockFactory(ActivationConfigsForTest.all());
program = new Program(config.getVmConfig(), precompiledContracts, blockFactory, activations, null, programInvoke, transaction, Sets.newHashSet());
program.getResult().spendGas(TOTAL_GAS);
}
use of org.ethereum.core.BlockFactory in project rskj by rsksmart.
the class BlockFactoryTest method setUp.
@Before
public void setUp() {
activationConfig = mock(ActivationConfig.class);
factory = new BlockFactory(activationConfig);
}
Aggregations