use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class BlockchainVMTest method genesisTest.
@Test
public void genesisTest() {
Block genesis = new BlockGenerator().getGenesisBlock();
Assert.assertEquals(0, genesis.getNumber());
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class BlockValidatorTest method validateEmptyBlock.
@Test
public void validateEmptyBlock() {
IndexedBlockStore blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
Block genesis = new BlockGenerator().getGenesisBlock();
blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
Block block = new BlockBuilder().parent(genesis).build();
BlockValidator validator = createValidator(blockStore);
Assert.assertTrue(validator.isValid(block));
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class BlockValidatorTest method blockInTheFuture.
@Test
public void blockInTheFuture() {
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
int validPeriod = 6000;
Block block = Mockito.mock(Block.class);
Mockito.when(block.getTimestamp()).thenReturn((System.currentTimeMillis() / 1000) + 2 * validPeriod);
Mockito.when(block.getParentHash()).thenReturn(genesis.getHash());
BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockTimeStampValidationRule(validPeriod).build();
Assert.assertFalse(validator.isValid(block));
Mockito.when(block.getTimestamp()).thenReturn((System.currentTimeMillis() / 1000) + validPeriod);
Assert.assertTrue(validator.isValid(block));
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class BlockValidatorTest method invalidUncleHasNoSavedParent.
@Test
public void invalidUncleHasNoSavedParent() {
IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block uncle1a = blockGenerator.createChildBlock(new BlockGenerator().createChildBlock(genesis));
List<BlockHeader> uncles1 = new ArrayList<>();
uncles1.add(uncle1a.getHeader());
Block block1 = blockGenerator.createChildBlock(genesis, null, uncles1, 1, null);
store.saveBlock(genesis, TEST_DIFFICULTY, true);
store.saveBlock(block1, TEST_DIFFICULTY, true);
BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockUnclesValidationRule(store).blockStore(store).build();
Assert.assertFalse(validator.isValid(block1));
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class BlockValidatorTest method invalidUnclesHash.
@Test
public void invalidUnclesHash() {
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block block1 = blockGenerator.createChildBlock(genesis);
block1.getHeader().setUnclesHash(new byte[] { 0x01 });
BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockUnclesValidationRule(null).build();
Assert.assertFalse(validator.isValid(block1));
}
Aggregations