Search in sources :

Example 11 with BlockHeader

use of org.ethereum.core.BlockHeader in project rskj by rsksmart.

the class GasLimitRuleTests method getBlock.

private static Block getBlock(long gasLimitValue) {
    byte[] gasLimit = new DataWord(gasLimitValue).getData();
    BlockHeader header = new BlockHeader(null, null, RskAddress.nullAddress().getBytes(), null, BlockDifficulty.ZERO.getBytes(), 0, gasLimit, 0, 0, null, null, 0);
    return new Block(header);
}
Also used : Block(org.ethereum.core.Block) DataWord(org.ethereum.vm.DataWord) BlockHeader(org.ethereum.core.BlockHeader)

Example 12 with BlockHeader

use of org.ethereum.core.BlockHeader in project rskj by rsksmart.

the class LocalBasicTest method runDifficultyTest.

@Test
public void runDifficultyTest() throws IOException, ParseException {
    config.setGenesisInfo("frontier.json");
    config.setBlockchainConfig(new MainNetConfig());
    String json = getJSON("difficulty");
    DifficultyTestSuite testSuite = new DifficultyTestSuite(json);
    for (DifficultyTestCase testCase : testSuite.getTestCases()) {
        logger.info("Running {}\n", testCase.getName());
        BlockHeader current = testCase.getCurrent();
        BlockHeader parent = testCase.getParent();
        BlockDifficulty calc = new DifficultyCalculator(config).calcDifficulty(current, parent);
        int c = calc.compareTo(parent.getDifficulty());
        if (c > 0)
            logger.info(" Difficulty increase test\n");
        else if (c < 0)
            logger.info(" Difficulty decrease test\n");
        else
            logger.info(" Difficulty without change test\n");
        assertEquals(testCase.getExpectedDifficulty(), calc);
    }
}
Also used : DifficultyTestCase(org.ethereum.jsontestsuite.DifficultyTestCase) BlockDifficulty(co.rsk.core.BlockDifficulty) DifficultyCalculator(co.rsk.core.DifficultyCalculator) MainNetConfig(org.ethereum.config.net.MainNetConfig) BlockHeader(org.ethereum.core.BlockHeader) DifficultyTestSuite(org.ethereum.jsontestsuite.DifficultyTestSuite) Test(org.junit.Test)

Example 13 with BlockHeader

use of org.ethereum.core.BlockHeader in project rskj by rsksmart.

the class HashRateCalculatorTest method init.

@Before
public void init() {
    blockStore = Mockito.mock(BlockStore.class);
    block = Mockito.mock(Block.class);
    blockHeader = Mockito.mock(BlockHeader.class);
    Mockito.when(block.getHeader()).thenReturn(blockHeader);
    Mockito.when(block.getHash()).thenReturn(new Keccak256(FAKE_GENERIC_HASH));
    Mockito.when(blockHeader.getParentHash()).thenReturn(new Keccak256(FAKE_GENERIC_HASH)).thenReturn(new Keccak256(OHTER_FAKE_GENERIC_HASH)).thenReturn(new Keccak256(FAKE_GENERIC_HASH)).thenReturn(null);
    Mockito.when(blockHeader.getHash()).thenReturn(new Keccak256(FAKE_GENERIC_HASH));
    Mockito.when(blockStore.getBlockByHash(Mockito.any())).thenReturn(block).thenReturn(block).thenReturn(block).thenReturn(null);
    Mockito.when(blockStore.getBestBlock()).thenReturn(block);
    Mockito.when(blockStore.getBlockByHash(Mockito.any())).thenReturn(block);
}
Also used : BlockStore(org.ethereum.db.BlockStore) Block(org.ethereum.core.Block) Keccak256(co.rsk.crypto.Keccak256) BlockHeader(org.ethereum.core.BlockHeader) Before(org.junit.Before)

Example 14 with BlockHeader

use of org.ethereum.core.BlockHeader in project rskj by rsksmart.

the class BodyResponseMessageTest method createMessage.

@Test
public void createMessage() {
    List<Transaction> transactions = new ArrayList<>();
    for (int k = 1; k <= 10; k++) transactions.add(createTransaction(k));
    List<BlockHeader> uncles = new ArrayList<>();
    BlockGenerator blockGenerator = new BlockGenerator();
    Block parent = blockGenerator.getGenesisBlock();
    for (int k = 1; k < 10; k++) {
        Block block = blockGenerator.createChildBlock(parent);
        uncles.add(block.getHeader());
        parent = block;
    }
    BodyResponseMessage message = new BodyResponseMessage(100, transactions, uncles);
    Assert.assertEquals(100, message.getId());
    Assert.assertNotNull(message.getTransactions());
    Assert.assertEquals(transactions.size(), message.getTransactions().size());
    Assert.assertEquals(transactions, message.getTransactions());
    Assert.assertNotNull(message.getUncles());
    Assert.assertEquals(uncles.size(), message.getUncles().size());
    for (int k = 0; k < uncles.size(); k++) Assert.assertArrayEquals(uncles.get(k).getEncoded(), message.getUncles().get(k).getEncoded());
}
Also used : Transaction(org.ethereum.core.Transaction) ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 15 with BlockHeader

use of org.ethereum.core.BlockHeader in project rskj by rsksmart.

the class DifficultyRuleTest method getHeader.

private static BlockHeader getHeader(long difficultyValue) {
    byte[] difficulty = new DataWord(difficultyValue).getData();
    BlockHeader header = new BlockHeader(null, null, RskAddress.nullAddress().getBytes(), null, difficulty, 0, null, 0, 0, null, null, 0);
    return header;
}
Also used : DataWord(org.ethereum.vm.DataWord) BlockHeader(org.ethereum.core.BlockHeader)

Aggregations

BlockHeader (org.ethereum.core.BlockHeader)65 Test (org.junit.Test)36 Block (org.ethereum.core.Block)27 ArrayList (java.util.ArrayList)13 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)9 BlockDifficulty (co.rsk.core.BlockDifficulty)5 Keccak256 (co.rsk.crypto.Keccak256)5 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)4 BlockBuilder (co.rsk.test.builders.BlockBuilder)4 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)4 BlockStore (org.ethereum.db.BlockStore)4 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)3 BigInteger (java.math.BigInteger)3 MainNetConfig (org.ethereum.config.net.MainNetConfig)3 DataWord (org.ethereum.vm.DataWord)3 DifficultyCalculator (co.rsk.core.DifficultyCalculator)2 BlockChainImplTest (co.rsk.core.bc.BlockChainImplTest)2 HashSet (java.util.HashSet)2 Bloom (org.ethereum.core.Bloom)2 Transaction (org.ethereum.core.Transaction)2