use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class BlockTimeStampValidationRuleTest method timestampsAreCloseEnough.
@Test
public void timestampsAreCloseEnough() {
int validPeriod = 540;
BlockTimeStampValidationRule validationRule = new BlockTimeStampValidationRule(validPeriod, postRskip179Config, timeProvider, bitcoinNetworkParameters);
byte[] bitcoinMergedMiningHeader = new byte[0];
when(timeProvider.currentTimeMillis()).thenReturn(10_000_000L);
BlockHeader header = mock(BlockHeader.class);
Block block = mock(Block.class);
when(block.getHeader()).thenReturn(header);
when(header.getBitcoinMergedMiningHeader()).thenReturn(bitcoinMergedMiningHeader);
BtcBlock btcBlock = mock(BtcBlock.class);
MessageSerializer messageSerializer = mock(MessageSerializer.class);
when(messageSerializer.makeBlock(eq(bitcoinMergedMiningHeader))).thenReturn(btcBlock);
when(bitcoinNetworkParameters.getDefaultSerializer()).thenReturn(messageSerializer);
when(btcBlock.getTimeSeconds()).thenReturn(1_000L);
when(header.getTimestamp()).thenReturn(1_000L);
assertTrue(validationRule.isValid(header));
when(btcBlock.getTimeSeconds()).thenReturn(1_000L + MAX_TIMESTAMPS_DIFF_IN_SECS);
when(header.getTimestamp()).thenReturn(1_000L);
assertFalse(validationRule.isValid(header));
when(btcBlock.getTimeSeconds()).thenReturn(1_000L + MAX_TIMESTAMPS_DIFF_IN_SECS);
when(header.getTimestamp()).thenReturn(1_001L);
assertTrue(validationRule.isValid(header));
when(btcBlock.getTimeSeconds()).thenReturn(1_001L);
when(header.getTimestamp()).thenReturn(1_000L + MAX_TIMESTAMPS_DIFF_IN_SECS);
assertTrue(validationRule.isValid(header));
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class BlockTimeStampValidationRuleTest method blockInTheFutureLimit.
@Test
public void blockInTheFutureLimit() {
int validPeriod = 540;
BlockTimeStampValidationRule validationRule = new BlockTimeStampValidationRule(validPeriod, preRskip179Config, timeProvider);
when(timeProvider.currentTimeMillis()).thenReturn(10_000_000L);
BlockHeader header = mock(BlockHeader.class);
Block block = mock(Block.class);
when(block.getHeader()).thenReturn(header);
when(header.getTimestamp()).thenReturn(10_000L + validPeriod);
assertTrue(validationRule.isValid(header));
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class BlockTimeStampValidationRuleTest method blockInThePast.
@Test
public void blockInThePast() {
int validPeriod = 540;
BlockTimeStampValidationRule validationRule = new BlockTimeStampValidationRule(validPeriod, preRskip179Config, timeProvider);
when(timeProvider.currentTimeMillis()).thenReturn(10_000_000L);
BlockHeader header = mock(BlockHeader.class);
Block block = mock(Block.class);
when(block.getHeader()).thenReturn(header);
when(header.getTimestamp()).thenReturn(10_000L - 1000);
assertTrue(validationRule.isValid(header));
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class BlockTimeStampValidationRuleTest method blockTimeGreaterThanParentTime.
@Test
public void blockTimeGreaterThanParentTime() {
int validPeriod = 540;
BlockTimeStampValidationRule validationRule = new BlockTimeStampValidationRule(validPeriod, preRskip179Config, timeProvider);
when(timeProvider.currentTimeMillis()).thenReturn(10_000_000L);
BlockHeader header = mock(BlockHeader.class);
Block block = mock(Block.class);
when(block.getHeader()).thenReturn(header);
Block parent = mock(Block.class);
when(header.getTimestamp()).thenReturn(10_000L);
when(parent.getTimestamp()).thenReturn(10_000L - 1000);
assertTrue(validationRule.isValid(header, parent));
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class BlockUnclesValidationRuleTest method rejectBlockWithSiblingUncle.
@Test
public void rejectBlockWithSiblingUncle() {
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block block1 = blockGenerator.createChildBlock(genesis);
Block uncle = blockGenerator.createChildBlock(block1);
List<BlockHeader> uncles = new ArrayList<>();
uncles.add(uncle.getHeader());
Block block = blockGenerator.createChildBlock(block1, null, uncles, 1, null);
BlockStore blockStore = new IndexedBlockStore(null, new HashMapDB(), new HashMapBlocksIndex());
blockStore.saveBlock(genesis, new BlockDifficulty(BigInteger.valueOf(1)), true);
blockStore.saveBlock(block1, new BlockDifficulty(BigInteger.valueOf(2)), true);
BlockUnclesValidationRule rule = new BlockUnclesValidationRule(blockStore, 10, 10, new BlockHeaderCompositeRule(), new BlockHeaderParentCompositeRule());
Assert.assertFalse(rule.isValid(block));
}
Aggregations