use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class NodeBlockProcessorUnclesTest method addBlockWithTwoKnownUncles.
@Test
public void addBlockWithTwoKnownUncles() {
BlockChainBuilder blockChainBuilder = new BlockChainBuilder();
BlockChainImpl blockChain = blockChainBuilder.build();
org.ethereum.db.BlockStore blockStore = blockChainBuilder.getBlockStore();
NodeBlockProcessor processor = createNodeBlockProcessor(blockChain);
Block genesis = blockChain.getBestBlock();
BlockBuilder blockBuilder = new BlockBuilder(blockChain, null, blockStore).trieStore(blockChainBuilder.getTrieStore());
blockBuilder.parent(blockChain.getBestBlock());
Block block1 = blockBuilder.parent(genesis).build();
Block uncle1 = blockBuilder.parent(genesis).build();
Block uncle2 = blockBuilder.parent(genesis).build();
List<BlockHeader> uncles = new ArrayList<>();
uncles.add(uncle1.getHeader());
uncles.add(uncle2.getHeader());
Block block2 = blockBuilder.parent(block1).uncles(uncles).build();
processor.processBlock(null, block1);
processor.processBlock(null, uncle1);
processor.processBlock(null, uncle2);
SimplePeer sender = new SimplePeer();
processor.processBlock(sender, block2);
Assert.assertEquals(2, blockChain.getBestBlock().getNumber());
Assert.assertArrayEquals(block2.getHash().getBytes(), blockChain.getBestBlockHash());
Assert.assertTrue(sender.getGetBlockMessages().isEmpty());
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class HashRateCalculatorTest method init.
@Before
public void init() {
blockStore = Mockito.mock(BlockStore.class);
block = Mockito.mock(Block.class);
blockHeader = Mockito.mock(BlockHeader.class);
Mockito.when(block.getHeader()).thenReturn(blockHeader);
Mockito.when(block.getHash()).thenReturn(new Keccak256(FAKE_GENERIC_HASH));
Mockito.when(blockHeader.getParentHash()).thenReturn(new Keccak256(FAKE_GENERIC_HASH)).thenReturn(new Keccak256(OHTER_FAKE_GENERIC_HASH)).thenReturn(new Keccak256(FAKE_GENERIC_HASH)).thenReturn(null);
Mockito.when(blockHeader.getHash()).thenReturn(new Keccak256(FAKE_GENERIC_HASH));
Mockito.when(blockStore.getBlockByHash(Mockito.any())).thenReturn(block).thenReturn(block).thenReturn(block).thenReturn(null);
Mockito.when(blockStore.getBestBlock()).thenReturn(block);
Mockito.when(blockStore.getBlockByHash(Mockito.any())).thenReturn(block);
}
use of org.ethereum.core.BlockHeader 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 org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class ForkDetectionDataRuleTest method validForBlocksBeforeRskip110.
@Test
public void validForBlocksBeforeRskip110() {
long blockNumber = 4242;
ForkDetectionDataRule rule = new ForkDetectionDataRule(activationConfig, mock(ConsensusValidationMainchainView.class), mock(ForkDetectionDataCalculator.class), 449);
BlockHeader header = mock(BlockHeader.class);
when(header.getNumber()).thenReturn(blockNumber);
assertTrue(rule.isValid(header));
}
use of org.ethereum.core.BlockHeader 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