Search in sources :

Example 6 with BlockFactory

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));
    }
}
Also used : BlockFactory(org.ethereum.core.BlockFactory) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 7 with BlockFactory

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);
}
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 8 with BlockFactory

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<>());
}
Also used : Program(org.ethereum.vm.program.Program) BlockFactory(org.ethereum.core.BlockFactory) TestSystemProperties(co.rsk.config.TestSystemProperties) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 9 with BlockFactory

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);
}
Also used : Transaction(org.ethereum.core.Transaction) BlockFactory(org.ethereum.core.BlockFactory) RskAddress(co.rsk.core.RskAddress) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Before(org.junit.Before)

Example 10 with BlockFactory

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);
}
Also used : BlockFactory(org.ethereum.core.BlockFactory) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Before(org.junit.Before)

Aggregations

BlockFactory (org.ethereum.core.BlockFactory)20 Test (org.junit.Test)7 Block (org.ethereum.core.Block)6 TestSystemProperties (co.rsk.config.TestSystemProperties)4 BlockHeader (org.ethereum.core.BlockHeader)4 Blockchain (org.ethereum.core.Blockchain)4 Before (org.junit.Before)4 RskContext (co.rsk.RskContext)3 DifficultyCalculator (co.rsk.core.DifficultyCalculator)3 Keccak256 (co.rsk.crypto.Keccak256)3 World (co.rsk.test.World)3 NodeStopper (co.rsk.util.NodeStopper)3 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)3 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)3 HashMapDB (org.ethereum.datasource.HashMapDB)3 BlockStore (org.ethereum.db.BlockStore)3 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)2 BlockMiner (co.rsk.blockchain.utils.BlockMiner)2 ConsensusValidationMainchainView (co.rsk.core.bc.ConsensusValidationMainchainView)2 PeersInformation (co.rsk.net.sync.PeersInformation)2