### Question:
BlockUnclesValidationRule implements BlockValidationRule { @Override public boolean isValid(Block block) { if (!blockValidationRule.isValid(block)) { return false; } List<BlockHeader> uncles = block.getUncleList(); if (CollectionUtils.isNotEmpty(uncles) && !validateUncleList(block.getNumber(), uncles, FamilyUtils.getAncestors(blockStore, block, uncleGenerationLimit), FamilyUtils.getUsedUncles(blockStore, block, uncleGenerationLimit))) { logger.warn("Uncles list validation failed"); return false; } return true; } BlockUnclesValidationRule(UscSystemProperties config, BlockStore blockStore, int uncleListLimit,
                                     int uncleGenerationLimit, BlockValidationRule validations,
                                     BlockParentDependantValidationRule parentValidations); @Override boolean isValid(Block block); boolean validateUncleList(long blockNumber, List<BlockHeader> uncles, Set<Keccak256> ancestors, Set<Keccak256> used); static final String INVALIDUNCLE; }### Answer:
@Test public void rejectBlockWithSiblingUncle() { BlockGenerator blockGenerator = new BlockGenerator(); Block genesis = blockGenerator.getGenesisBlock(); Block block1 = blockGenerator.createChildBlock(genesis); Block uncle = blockGenerator.createChildBlock(block1); List<BlockHeader> uncles = new ArrayList<>(); uncles.add(uncle.getHeader()); Block block = blockGenerator.createChildBlock(block1, null, uncles, 1, null); BlockChainImpl blockChain = BlockChainImplTest.createBlockChain(); BlockStore store = blockChain.getBlockStore(); store.saveBlock(genesis, new BlockDifficulty(BigInteger.valueOf(1)), true); store.saveBlock(block1, new BlockDifficulty(BigInteger.valueOf(2)), true); BlockUnclesValidationRule rule = new BlockUnclesValidationRule(config, store, 10, 10, new BlockCompositeRule(), new BlockParentCompositeRule()); Assert.assertFalse(rule.isValid(block)); }
@Test public void rejectBlockWithUncleHavingHigherNumber() { BlockGenerator blockGenerator = new BlockGenerator(); Block genesis = blockGenerator.getGenesisBlock(); Block block1 = blockGenerator.createChildBlock(genesis); Block uncle1 = blockGenerator.createChildBlock(block1); Block uncle2 = blockGenerator.createChildBlock(uncle1); List<BlockHeader> uncles = new ArrayList<>(); uncles.add(uncle2.getHeader()); Block block = blockGenerator.createChildBlock(block1, null, uncles, 1, null); BlockChainImpl blockChain = BlockChainImplTest.createBlockChain(); BlockStore store = blockChain.getBlockStore(); store.saveBlock(genesis, new BlockDifficulty(BigInteger.valueOf(1)), true); store.saveBlock(block1, new BlockDifficulty(BigInteger.valueOf(2)), true); BlockUnclesValidationRule rule = new BlockUnclesValidationRule(config, store, 10, 10, new BlockCompositeRule(), new BlockParentCompositeRule()); Assert.assertFalse(rule.isValid(block)); }