Search in sources :

Example 56 with BlockHeader

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

the class ValidGasUsedValidatorTest method blockWithInvalidGasUsedBiggerThanGasLimit.

@Test
public void blockWithInvalidGasUsedBiggerThanGasLimit() {
    BlockHeader blockHeader = Mockito.mock(BlockHeader.class);
    Mockito.when(blockHeader.getGasUsed()).thenReturn(120L);
    Mockito.when(blockHeader.getGasLimit()).thenReturn(BigInteger.valueOf(107L).toByteArray());
    Block block = new Block(blockHeader);
    ValidGasUsedRule gasUsedRule = new ValidGasUsedRule();
    Assert.assertFalse(gasUsedRule.isValid(block));
}
Also used : Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 57 with BlockHeader

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

the class ValidGasUsedValidatorTest method blockWithInvalidGasUsedLessThanZero.

@Test
public void blockWithInvalidGasUsedLessThanZero() {
    BlockHeader blockHeader = Mockito.mock(BlockHeader.class);
    Mockito.when(blockHeader.getGasUsed()).thenReturn(-120L);
    Mockito.when(blockHeader.getGasLimit()).thenReturn(BigInteger.valueOf(107L).toByteArray());
    Block block = new Block(blockHeader);
    ValidGasUsedRule gasUsedRule = new ValidGasUsedRule();
    Assert.assertFalse(gasUsedRule.isValid(block));
}
Also used : Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 58 with BlockHeader

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

the class ValidGasUsedValidatorTest method blockWithValidGasUsed.

@Test
public void blockWithValidGasUsed() {
    BlockHeader blockHeader = Mockito.mock(BlockHeader.class);
    Mockito.when(blockHeader.getGasUsed()).thenReturn(20L);
    Mockito.when(blockHeader.getGasLimit()).thenReturn(BigInteger.valueOf(107L).toByteArray());
    Block block = new Block(blockHeader);
    ValidGasUsedRule gasUsedRule = new ValidGasUsedRule();
    Assert.assertTrue(gasUsedRule.isValid(block));
}
Also used : Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 59 with BlockHeader

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

the class GitHubBasicTest method runDifficultyFrontierTest.

@Test
public void runDifficultyFrontierTest() throws IOException, ParseException {
    config.setBlockchainConfig(new MainNetConfig());
    String json = JSONReader.loadJSONFromCommit("BasicTests/difficultyFrontier.json", shacommit);
    DifficultyTestSuite testSuite = new DifficultyTestSuite(json);
    for (DifficultyTestCase testCase : testSuite.getTestCases()) {
        logger.info("Running {}\n", testCase.getName());
        BlockHeader current = testCase.getCurrent();
        BlockHeader parent = testCase.getParent();
        assertEquals(testCase.getExpectedDifficulty(), DIFFICULTY_CALCULATOR.calcDifficulty(current, parent));
    }
}
Also used : MainNetConfig(org.ethereum.config.net.MainNetConfig) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 60 with BlockHeader

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

the class BlockBuilder method build.

public static Block build(BlockHeaderTck header, List<TransactionTck> transactionsTck, List<BlockHeaderTck> unclesTck) {
    if (header == null)
        return null;
    List<BlockHeader> uncles = new ArrayList<>();
    if (unclesTck != null)
        for (BlockHeaderTck uncle : unclesTck) uncles.add(BlockHeaderBuilder.build(uncle));
    List<Transaction> transactions = new ArrayList<>();
    if (transactionsTck != null)
        for (TransactionTck tx : transactionsTck) transactions.add(TransactionBuilder.build(tx));
    BlockHeader blockHeader = BlockHeaderBuilder.build(header);
    Block block = new Block(blockHeader, transactions, uncles);
    return block;
}
Also used : Transaction(org.ethereum.core.Transaction) ArrayList(java.util.ArrayList) BlockHeaderTck(org.ethereum.jsontestsuite.model.BlockHeaderTck) Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) TransactionTck(org.ethereum.jsontestsuite.model.TransactionTck)

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