Search in sources :

Example 51 with BlockHeader

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

the class GasLimitCalculatorTest method validByConsensus.

private boolean validByConsensus(BigInteger newGas, BigInteger parentGas) {
    BlockHeader header = getHeader(newGas.intValue());
    BlockHeader parent = getHeader(parentGas.intValue());
    return rule.validate(header, parent);
}
Also used : BlockHeader(org.ethereum.core.BlockHeader)

Example 52 with BlockHeader

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

the class RskCustomCacheTest method elementExpiration.

@Test
@Ignore
public void elementExpiration() throws InterruptedException {
    RskCustomCache cache = new RskCustomCache(800L);
    BlockHeader header1 = Mockito.mock(BlockHeader.class);
    cache.put(KEY, header1);
    BlockHeader header2 = Mockito.mock(BlockHeader.class);
    cache.put(OTHER_KEY, header2);
    Assert.assertEquals(header1, cache.get(KEY));
    Assert.assertEquals(header2, cache.get(OTHER_KEY));
    cache.get(OTHER_KEY);
    Thread.sleep(700);
    Assert.assertEquals(header2, cache.get(OTHER_KEY));
    Thread.sleep(400);
    // header2 should not be removed, it was accessed
    Assert.assertNotNull(cache.get(OTHER_KEY));
    Assert.assertNull(cache.get(KEY));
    Thread.sleep(2 * WAIT_PERIOD);
    // header2 should be removed, it was not accessed
    Assert.assertNull(cache.get(OTHER_KEY));
}
Also used : BlockHeader(org.ethereum.core.BlockHeader) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 53 with BlockHeader

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

the class BlockDifficultyValidationRuleTest method testDifficulty.

@Test
public void testDifficulty() {
    DifficultyCalculator difficultyCalculator = new DifficultyCalculator(config);
    BlockDifficultyRule validationRule = new BlockDifficultyRule(difficultyCalculator);
    Block block = Mockito.mock(Block.class);
    Block parent = Mockito.mock(Block.class);
    long parentTimestamp = 0;
    long blockTimeStamp = 10;
    BlockDifficulty parentDifficulty = new BlockDifficulty(new BigInteger("2048"));
    BlockDifficulty blockDifficulty = new BlockDifficulty(new BigInteger("2049"));
    // blockDifficulty = blockDifficulty.add(AbstractConfig.getConstants().getDifficultyBoundDivisor());
    Mockito.when(block.getDifficulty()).thenReturn(blockDifficulty);
    BlockHeader blockHeader = getEmptyHeader(blockDifficulty, blockTimeStamp, 1);
    BlockHeader parentHeader = Mockito.mock(BlockHeader.class);
    Mockito.when(parentHeader.getDifficulty()).thenReturn(parentDifficulty);
    Mockito.when(block.getHeader()).thenReturn(blockHeader);
    Mockito.when(parent.getHeader()).thenReturn(parentHeader);
    Mockito.when(parent.getDifficulty()).thenReturn(parentDifficulty);
    Mockito.when(parent.getTimestamp()).thenReturn(parentTimestamp);
    Assert.assertEquals(validationRule.isValid(block, parent), true);
}
Also used : DifficultyCalculator(co.rsk.core.DifficultyCalculator) BlockDifficulty(co.rsk.core.BlockDifficulty) Block(org.ethereum.core.Block) BigInteger(java.math.BigInteger) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 54 with BlockHeader

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

the class BlockUnclesValidationRuleTest method rejectBlockWithUncleHavingHigherNumber.

@Test
public void rejectBlockWithUncleHavingHigherNumber() {
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block block1 = blockGenerator.createChildBlock(genesis);
    Block uncle1 = blockGenerator.createChildBlock(block1);
    Block uncle2 = blockGenerator.createChildBlock(uncle1);
    List<BlockHeader> uncles = new ArrayList<>();
    uncles.add(uncle2.getHeader());
    Block block = blockGenerator.createChildBlock(block1, null, uncles, 1, null);
    BlockChainImpl blockChain = BlockChainImplTest.createBlockChain();
    BlockStore store = blockChain.getBlockStore();
    store.saveBlock(genesis, new BlockDifficulty(BigInteger.valueOf(1)), true);
    store.saveBlock(block1, new BlockDifficulty(BigInteger.valueOf(2)), true);
    BlockUnclesValidationRule rule = new BlockUnclesValidationRule(config, store, 10, 10, new BlockCompositeRule(), new BlockParentCompositeRule());
    Assert.assertFalse(rule.isValid(block));
}
Also used : BlockDifficulty(co.rsk.core.BlockDifficulty) BlockStore(org.ethereum.db.BlockStore) ArrayList(java.util.ArrayList) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test) BlockChainImplTest(co.rsk.core.bc.BlockChainImplTest)

Example 55 with BlockHeader

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

the class ExtraDataRuleTests method blockWithValidNullExtraData.

@Test
public void blockWithValidNullExtraData() {
    BlockHeader blockHeader = Mockito.mock(BlockHeader.class);
    Mockito.when(blockHeader.getExtraData()).thenReturn(null);
    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)

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