Search in sources :

Example 1 with BlockHeader

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

the class BlockStoreTest method saveHeader.

@Test
public void saveHeader() {
    BlockStore store = new BlockStore();
    BlockHeader blockHeader = new BlockHeader(new byte[] {}, new byte[] {}, RskAddress.nullAddress().getBytes(), new Bloom().getData(), new byte[] {}, 1, new byte[] {}, 0, 0, new byte[] {}, new byte[] {}, new byte[] {}, new byte[] {}, new byte[] {}, 0);
    store.saveHeader(blockHeader);
    Assert.assertTrue(store.hasHeader(blockHeader.getHash()));
}
Also used : Bloom(org.ethereum.core.Bloom) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 2 with BlockHeader

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

the class ExtraDataRuleTests method blockWithValidLongerExtraDataThanAccepted.

@Test
public void blockWithValidLongerExtraDataThanAccepted() {
    BlockHeader blockHeader = Mockito.mock(BlockHeader.class);
    Mockito.when(blockHeader.getExtraData()).thenReturn(new byte[43]);
    Block block = new Block(blockHeader);
    ExtraDataRule rule = new ExtraDataRule(42);
    Assert.assertFalse(rule.isValid(block));
}
Also used : Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 3 with BlockHeader

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

the class ExtraDataRuleTests method blockWithValidExtraData.

@Test
public void blockWithValidExtraData() {
    BlockHeader blockHeader = Mockito.mock(BlockHeader.class);
    Mockito.when(blockHeader.getExtraData()).thenReturn(new byte[32]);
    Block block = new Block(blockHeader);
    ExtraDataRule rule = new ExtraDataRule(42);
    Assert.assertTrue(rule.isValid(block));
}
Also used : Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 4 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 5 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)

Aggregations

BlockHeader (org.ethereum.core.BlockHeader)189 Test (org.junit.Test)128 Block (org.ethereum.core.Block)83 Keccak256 (co.rsk.crypto.Keccak256)31 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)30 ArrayList (java.util.ArrayList)23 BlockStore (org.ethereum.db.BlockStore)21 RLPList (org.ethereum.util.RLPList)20 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)14 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)9 BlockDifficulty (co.rsk.core.BlockDifficulty)7 ConsensusValidationMainchainView (co.rsk.core.bc.ConsensusValidationMainchainView)7 ForkDetectionDataCalculator (co.rsk.mine.ForkDetectionDataCalculator)7 BigInteger (java.math.BigInteger)7 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)6 SimplePeer (co.rsk.net.simples.SimplePeer)6 BlockBuilder (co.rsk.test.builders.BlockBuilder)6 Trie (co.rsk.trie.Trie)4 Before (org.junit.Before)4 DifficultyCalculator (co.rsk.core.DifficultyCalculator)3