use of org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.
the class BlockValidatorTest method invalidUncleHasNoCommonAncestor.
@Test
public void invalidUncleHasNoCommonAncestor() {
IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block uncle1a = blockGenerator.createChildBlock(new SimpleBlock(null, null, TestUtils.randomAddress().getBytes(), null, TEST_DIFFICULTY.getBytes(), 0, null, 0L, 0L, new byte[] {}, null, null, null, Block.getTxTrie(null).getHash().getBytes(), null, null, null));
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(uncle1a, TEST_DIFFICULTY, false);
store.saveBlock(block1, TEST_DIFFICULTY, true);
BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockUnclesValidationRule(store).blockStore(store).build();
Assert.assertFalse(validator.isValid(block1));
}
use of org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.
the class BlockValidatorTest method invalidPOWUncles.
@Test
public void invalidPOWUncles() {
IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
BlockGenerator blockGenerator = new BlockGenerator();
Blockchain blockchain = BlockChainBuilder.ofSize(30, true);
Block genesis = blockchain.getBlockByNumber(0);
Block uncle1a = blockchain.getBlockByNumber(1);
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(uncle1a, TEST_DIFFICULTY, false);
BlockParentDependantValidationRule parentValidationRule = Mockito.mock(BlockParentDependantValidationRule.class);
Mockito.when(parentValidationRule.isValid(Mockito.any(), Mockito.any())).thenReturn(true);
BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockUnclesValidationRule(store, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), parentValidationRule).blockStore(store).build();
Assert.assertFalse(validator.isValid(block1));
}
use of org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.
the class BlockValidatorTest method getBlockOneAncestorSet.
@Test
public void getBlockOneAncestorSet() {
IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
store.saveBlock(genesis, TEST_DIFFICULTY, true);
Block block = new BlockGenerator().createChildBlock(genesis);
Set<Keccak256> ancestors = FamilyUtils.getAncestors(store, block, 6);
Assert.assertFalse(ancestors.isEmpty());
Assert.assertTrue(ancestors.contains(genesis.getHash()));
Assert.assertFalse(ancestors.contains(block.getHash()));
}
use of org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.
the class BlockValidatorTest method parentInvalidNumber.
@Test
public void parentInvalidNumber() {
IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block block = new BlockBuilder().parent(genesis).build();
block.getHeader().setNumber(25L);
BlockValidatorImpl validator = new BlockValidatorBuilder().addParentNumberRule().blockStore(store).build();
Assert.assertFalse(validator.isValid(block));
}
use of org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.
the class BlockChainImplTest method createBlockChain.
public static BlockChainImpl createBlockChain(Repository repository) {
IndexedBlockStore blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
BlockValidatorBuilder validatorBuilder = new BlockValidatorBuilder();
validatorBuilder.addBlockRootValidationRule().addBlockUnclesValidationRule(blockStore).addBlockTxsValidationRule(repository).blockStore(blockStore);
BlockValidatorImpl blockValidator = validatorBuilder.build();
return createBlockChain(repository, blockStore, blockValidator);
}
Aggregations