Search in sources :

Example 1 with BlockParentDependantValidationRule

use of co.rsk.validators.BlockParentDependantValidationRule 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));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) ArrayList(java.util.ArrayList) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) SimpleBlock(co.rsk.peg.simples.SimpleBlock) BlockParentDependantValidationRule(co.rsk.validators.BlockParentDependantValidationRule) Test(org.junit.Test)

Aggregations

BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)1 SimpleBlock (co.rsk.peg.simples.SimpleBlock)1 BlockParentDependantValidationRule (co.rsk.validators.BlockParentDependantValidationRule)1 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)1 ArrayList (java.util.ArrayList)1 HashMapDB (org.ethereum.datasource.HashMapDB)1 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)1 Test (org.junit.Test)1