use of org.ethereum.datasource.HashMapDB 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 org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class BlockValidatorTest method invalidUncleHasParentThatIsNotAncestor.
@Test
public void invalidUncleHasParentThatIsNotAncestor() {
IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block uncle1a = blockGenerator.createChildBlock(genesis);
Block uncle2a = blockGenerator.createChildBlock(uncle1a);
List<BlockHeader> uncles3 = new ArrayList<>();
uncles3.add(uncle2a.getHeader());
uncles3.add(uncle1a.getHeader());
Block block1 = blockGenerator.createChildBlock(genesis, null, null, 1, null);
Block block2 = blockGenerator.createChildBlock(block1, null, null, 1, null);
Block block3 = blockGenerator.createChildBlock(block2, null, uncles3, 1, null);
store.saveBlock(genesis, TEST_DIFFICULTY, true);
store.saveBlock(uncle1a, TEST_DIFFICULTY, false);
store.saveBlock(uncle2a, TEST_DIFFICULTY, false);
store.saveBlock(block1, TEST_DIFFICULTY, true);
store.saveBlock(block2, TEST_DIFFICULTY, true);
store.saveBlock(block3, TEST_DIFFICULTY, true);
BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockUnclesValidationRule(store).blockStore(store).build();
Assert.assertFalse(validator.isValid(block3));
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class BlockValidatorTest method invalidUncleIsAncestor.
@Test
public void invalidUncleIsAncestor() {
IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block uncle1a = blockGenerator.createChildBlock(genesis);
List<BlockHeader> uncles1 = new ArrayList<>();
uncles1.add(uncle1a.getHeader());
uncles1.add(genesis.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.datasource.HashMapDB in project rskj by rsksmart.
the class BlockValidatorTest method validateHeader.
@Test
public void validateHeader() {
IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block parent = new BlockBuilder().parent(genesis).build();
Block block = new BlockBuilder().parent(parent).build();
store.saveBlock(parent, TEST_DIFFICULTY, true);
BlockValidatorImpl validator = new BlockValidatorBuilder().addParentBlockHeaderValidator().addBlockRootValidationRule().addBlockUnclesValidationRule(null).blockStore(store).build();
Assert.assertTrue(validator.isValid(block));
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class BlockValidatorTest method invalidUnclesUncleIncludedMultipeTimes.
@Test
public void invalidUnclesUncleIncludedMultipeTimes() {
IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block uncle1a = blockGenerator.createChildBlock(genesis);
List<BlockHeader> uncles1 = new ArrayList<>();
uncles1.add(uncle1a.getHeader());
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));
}
Aggregations