use of co.rsk.mine.ForkDetectionDataCalculator in project rskj by rsksmart.
the class ForkDetectionDataRuleTest method invalidForRskip110ActiveAndForkDetectionDataBecauseDataDoesNotMatch.
@Test
public void invalidForRskip110ActiveAndForkDetectionDataBecauseDataDoesNotMatch() {
long blockNumber = 4242;
enableRulesAt(blockNumber, ConsensusRule.RSKIP110);
Keccak256 parentBlockHash = new Keccak256(getRandomHash());
int requiredBlocksForForkDataCalculation = 449;
List<BlockHeader> previousBlocks = IntStream.range(0, requiredBlocksForForkDataCalculation).mapToObj(i -> mock(BlockHeader.class)).collect(Collectors.toList());
ConsensusValidationMainchainView mainchainView = mock(ConsensusValidationMainchainView.class);
when(mainchainView.get(parentBlockHash, requiredBlocksForForkDataCalculation)).thenReturn(previousBlocks);
ForkDetectionDataCalculator calculator = mock(ForkDetectionDataCalculator.class);
Keccak256 blockHash = new Keccak256(getRandomHash());
byte[] forkDetectionData = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
when(calculator.calculateWithBlockHeaders(previousBlocks)).thenReturn(forkDetectionData);
ForkDetectionDataRule rule = new ForkDetectionDataRule(activationConfig, mainchainView, calculator, requiredBlocksForForkDataCalculation);
BlockHeader header = mock(BlockHeader.class);
when(header.getNumber()).thenReturn(blockNumber);
when(header.getHash()).thenReturn(blockHash);
when(header.getParentHash()).thenReturn(parentBlockHash);
byte[] headerForkDetectionData = new byte[] { 1, 2, 3, 4, 5, 6, 42, 8, 9, 10, 11, 12 };
when(header.getMiningForkDetectionData()).thenReturn(headerForkDetectionData);
assertFalse(rule.isValid(header));
}
use of co.rsk.mine.ForkDetectionDataCalculator in project rskj by rsksmart.
the class ForkDetectionDataRuleTest method validForRskip110ActiveAndForkDetectionData.
@Test
public void validForRskip110ActiveAndForkDetectionData() {
long blockNumber = 4242;
enableRulesAt(blockNumber, ConsensusRule.RSKIP110);
Keccak256 parentBlockHash = new Keccak256(getRandomHash());
int requiredBlocksForForkDataCalculation = 449;
List<BlockHeader> previousBlocks = IntStream.range(0, requiredBlocksForForkDataCalculation).mapToObj(i -> mock(BlockHeader.class)).collect(Collectors.toList());
ConsensusValidationMainchainView mainchainView = mock(ConsensusValidationMainchainView.class);
when(mainchainView.get(parentBlockHash, requiredBlocksForForkDataCalculation)).thenReturn(previousBlocks);
ForkDetectionDataCalculator calculator = mock(ForkDetectionDataCalculator.class);
Keccak256 blockHash = new Keccak256(getRandomHash());
byte[] forkDetectionData = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
when(calculator.calculateWithBlockHeaders(previousBlocks)).thenReturn(forkDetectionData);
ForkDetectionDataRule rule = new ForkDetectionDataRule(activationConfig, mainchainView, calculator, requiredBlocksForForkDataCalculation);
BlockHeader header = mock(BlockHeader.class);
when(header.getNumber()).thenReturn(blockNumber);
when(header.getHash()).thenReturn(blockHash);
when(header.getParentHash()).thenReturn(parentBlockHash);
when(header.getMiningForkDetectionData()).thenReturn(forkDetectionData);
assertTrue(rule.isValid(header));
}
Aggregations