Search in sources :

Example 1 with BlockHeaderParentDependantValidationRule

use of co.rsk.validators.BlockHeaderParentDependantValidationRule in project rskj by rsksmart.

the class BlockValidatorTest method invalidPOWUncles.

@Test
public void invalidPOWUncles() {
    IndexedBlockStore store = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex());
    BlockGenerator blockGenerator = new BlockGenerator();
    Blockchain blockchain = new 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);
    BlockHeaderParentDependantValidationRule parentValidationRule = mock(BlockHeaderParentDependantValidationRule.class);
    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) BlockHeaderParentDependantValidationRule(co.rsk.validators.BlockHeaderParentDependantValidationRule) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) BtcBlock(co.rsk.bitcoinj.core.BtcBlock) HashMapBlocksIndex(co.rsk.db.HashMapBlocksIndex) Test(org.junit.Test)

Aggregations

BtcBlock (co.rsk.bitcoinj.core.BtcBlock)1 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)1 HashMapBlocksIndex (co.rsk.db.HashMapBlocksIndex)1 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)1 BlockHeaderParentDependantValidationRule (co.rsk.validators.BlockHeaderParentDependantValidationRule)1 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)1 HashMapDB (org.ethereum.datasource.HashMapDB)1 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)1 Test (org.junit.Test)1