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);
}
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));
}
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);
}
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));
}
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));
}
Aggregations