private Block createEmptyBlock(final KeyPair blockSigner) { final BlockHeader header = TestHelpers.createCliqueSignedBlockHeader(headerBuilder, blockSigner, validatorList); return new Block(header, new BlockBody(Lists.newArrayList(), Lists.newArrayList())); }
private BlockResult blockResult(final BlockHeader header) { final Block block = new Block(header, new BlockBody(Collections.emptyList(), Collections.emptyList())); return new BlockResult( header, Collections.emptyList(), Collections.emptyList(), UInt256.ZERO, block.calculateSize()); }
private BlockResult blockResult(final BlockHeader header) { final Block block = new Block(header, new BlockBody(Collections.emptyList(), Collections.emptyList())); return new BlockResult( header, Collections.emptyList(), Collections.emptyList(), UInt256.ZERO, block.calculateSize()); }
@Test public void voteTallyNotUpdatedWhenFastBlockImportFails() { final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture(); final Block block = new Block(headerBuilder.buildHeader(), new BlockBody(emptyList(), emptyList())); when(delegate.fastImportBlock(context, block, emptyList(), HeaderValidationMode.LIGHT)) .thenReturn(false); importer.fastImportBlock(context, block, emptyList(), HeaderValidationMode.LIGHT); verifyZeroInteractions(voteTallyUpdater); }
@Test public void voteTallyNotUpdatedWhenBlockImportFails() { final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture(); final Block block = new Block(headerBuilder.buildHeader(), new BlockBody(emptyList(), emptyList())); when(delegate.importBlock(context, block, HeaderValidationMode.FULL, HeaderValidationMode.FULL)) .thenReturn(false); importer.importBlock(context, block, HeaderValidationMode.FULL); verifyZeroInteractions(voteTallyUpdater); }
private void buildCreatedBlock() { IbftExtraData extraData = new IbftExtraData( BytesValue.wrap(new byte[32]), emptyList(), Optional.empty(), 0, validators); headerTestFixture.extraData(extraData.encode()); final BlockHeader header = headerTestFixture.buildHeader(); createdBlock = new Block(header, new BlockBody(emptyList(), emptyList())); }
private void simulateAddingBlock() { final BlockBody blockBody = new BlockBody(Collections.emptyList(), Collections.emptyList()); final Block testBlock = new Block(blockHeader, blockBody); newBlockHeadersSubscriptionService.onBlockAdded( BlockAddedEvent.createForHeadAdvancement(testBlock), blockchainQueries.getBlockchain()); verify(blockchainQueries, times(1)).getBlockchain(); }
@Test public void voteTallyUpdatedWhenFastBlockImportSucceeds() { final Block block = new Block( new BlockHeaderTestFixture().buildHeader(), new BlockBody(emptyList(), emptyList())); when(delegate.fastImportBlock(context, block, emptyList(), HeaderValidationMode.LIGHT)) .thenReturn(true); importer.fastImportBlock(context, block, emptyList(), HeaderValidationMode.LIGHT); verify(voteTallyUpdater).updateForBlock(block.getHeader(), voteTally); } }
@Test public void shouldBecomeInSyncWhenOurBlockchainCatchesUp() { setupOutOfSyncState(); when(blockchain.getChainHeadBlockNumber()).thenReturn(TARGET_SYNC_NUMBER); blockAddedObserver.onBlockAdded( BlockAddedEvent.createForHeadAdvancement( new Block( targetBlockHeader(), new BlockBody(Collections.emptyList(), Collections.emptyList()))), blockchain); assertThat(syncState.isInSync()).isTrue(); verify(inSyncListener).onSyncStatusChanged(true); }
@Test public void voteTallyUpdatedWhenBlockImportSucceeds() { final Block block = new Block( new BlockHeaderTestFixture().buildHeader(), new BlockBody(emptyList(), emptyList())); when(delegate.importBlock(context, block, HeaderValidationMode.FULL, HeaderValidationMode.FULL)) .thenReturn(true); importer.importBlock(context, block, HeaderValidationMode.FULL); verify(voteTallyUpdater).updateForBlock(block.getHeader(), voteTally); }
private Block createEmptyBlock( final long blockNumber, final Hash parentHash, final KeyPair signer) { headerTestFixture.number(blockNumber).parentHash(parentHash); final BlockHeader header = TestHelpers.createCliqueSignedBlockHeader(headerTestFixture, signer, validators); return new Block(header, new BlockBody(Lists.emptyList(), Lists.emptyList())); } }
@Test public void newChainHeadHeaderEventIsAddedToTheQueue() { final Blockchain mockBlockchain = mock(Blockchain.class); final IbftEventQueue mockQueue = mock(IbftEventQueue.class); final BlockAddedEvent mockBlockAddedEvent = mock(BlockAddedEvent.class); final IbftChainObserver ibftChainObserver = new IbftChainObserver(mockQueue); final BlockHeader header = new BlockHeaderTestFixture() .number(1234) .coinbase(Address.ECREC) .parentHash(Hash.EMPTY_LIST_HASH) .buildHeader(); final Block block = new Block(header, new BlockBody(emptyList(), emptyList())); when(mockBlockAddedEvent.getEventType()).thenReturn(BlockAddedEvent.EventType.HEAD_ADVANCED); when(mockBlockAddedEvent.getBlock()).thenReturn(block); ibftChainObserver.onBlockAdded(mockBlockAddedEvent, mockBlockchain); final ArgumentCaptor<IbftEvent> ibftEventArgumentCaptor = ArgumentCaptor.forClass(IbftEvent.class); verify(mockQueue).add(ibftEventArgumentCaptor.capture()); assertThat(ibftEventArgumentCaptor.getValue() instanceof NewChainHead).isTrue(); assertThat(((NewChainHead) ibftEventArgumentCaptor.getValue()).getNewChainHeadHeader()) .isEqualTo(header); }
private Block appendBlock( final UInt256 difficulty, final BlockHeader parentBlock, final Transaction... transactionsToAdd) { final List<Transaction> transactionList = asList(transactionsToAdd); final Block block = new Block( new BlockHeaderTestFixture() .difficulty(difficulty) .parentHash(parentBlock.getHash()) .number(parentBlock.getNumber() + 1) .buildHeader(), new BlockBody(transactionList, emptyList())); final List<TransactionReceipt> transactionReceipts = transactionList .stream() .map(transaction -> new TransactionReceipt(1, 1, emptyList())) .collect(toList()); blockchain.appendBlock(block, transactionReceipts); return block; }
private Block createEmptyBlock(final long blockNumber, final Hash parentHash) { headerBuilder.number(blockNumber).parentHash(parentHash).coinbase(AddressHelpers.ofValue(0)); return new Block( headerBuilder.buildHeader(), new BlockBody(Lists.emptyList(), Lists.emptyList())); }
@Test public void shouldNotRecheckTrailingPeersWhenBlockAddedIsNotAMultipleOf100() { addPeerWithEstimatedHeight(1); addPeerWithEstimatedHeight(3); addPeerWithEstimatedHeight(2); final BlockAddedEvent blockAddedEvent = BlockAddedEvent.createForHeadAdvancement( new Block( new BlockHeaderTestFixture().number(599).buildHeader(), new BlockBody(emptyList(), emptyList()))); trailingPeerLimiter.onBlockAdded(blockAddedEvent, blockchain); assertDisconnections(); }
@Test public void shouldRecheckTrailingPeersWhenBlockAddedThatIsMultipleOf100() { final EthPeer ethPeer1 = addPeerWithEstimatedHeight(1); addPeerWithEstimatedHeight(3); addPeerWithEstimatedHeight(2); final BlockAddedEvent blockAddedEvent = BlockAddedEvent.createForHeadAdvancement( new Block( new BlockHeaderTestFixture().number(500).buildHeader(), new BlockBody(emptyList(), emptyList()))); trailingPeerLimiter.onBlockAdded(blockAddedEvent, blockchain); assertDisconnections(ethPeer1); }
public static BlockBody readBody(final long num) throws IOException { final RLPInput input = new BytesValueRLPInput( BytesValue.wrap( Resources.toByteArray( EthHashTest.class.getResource(String.format("block_%d.blocks", num)))), false); input.enterList(); input.skipNext(); final List<Transaction> transactions = input.readList(Transaction::readFrom); final List<BlockHeader> ommers = input.readList(rlp -> BlockHeader.readFrom(rlp, MainnetBlockHashFunction::createHash)); return new BlockBody(transactions, ommers); }
public static Block readBlock(final long num) throws IOException { final RLPInput input = new BytesValueRLPInput( BytesValue.wrap( Resources.toByteArray( EthHashTest.class.getResource(String.format("block_%d.blocks", num)))), false); input.enterList(); final BlockHeader header = BlockHeader.readFrom(input, MainnetBlockHashFunction::createHash); final List<Transaction> transactions = input.readList(Transaction::readFrom); final List<BlockHeader> ommers = input.readList(rlp -> BlockHeader.readFrom(rlp, MainnetBlockHashFunction::createHash)); final BlockBody body = new BlockBody(transactions, ommers); return new Block(header, body); } }
@Before public void setup() { protocolSchedule = CliqueProtocolSchedule.create( GenesisConfigFile.DEFAULT.getConfigOptions(), proposerKeyPair); final Address otherAddress = Util.publicKeyToAddress(otherKeyPair.getPublicKey()); validatorList.add(otherAddress); final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class); when(voteTallyCache.getVoteTallyAfterBlock(any())).thenReturn(new VoteTally(validatorList)); voteProposer = new VoteProposer(); final CliqueContext cliqueContext = new CliqueContext(voteTallyCache, voteProposer, null); final Block genesis = GenesisState.fromConfig(GenesisConfigFile.mainnet(), protocolSchedule).getBlock(); blockchain = createInMemoryBlockchain(genesis); protocolContext = new ProtocolContext<>(blockchain, stateArchive, cliqueContext); // Add a block above the genesis final BlockHeaderTestFixture headerTestFixture = new BlockHeaderTestFixture(); headerTestFixture.number(1).parentHash(genesis.getHeader().getHash()); final Block emptyBlock = new Block( TestHelpers.createCliqueSignedBlockHeader( headerTestFixture, otherKeyPair, validatorList), new BlockBody(Lists.newArrayList(), Lists.newArrayList())); blockchain.appendBlock(emptyBlock, Lists.newArrayList()); }
public Block getBlock() { final RLPInput input = new BytesValueRLPInput(rlp, false); input.enterList(); final BlockHeader header = BlockHeader.readFrom(input, MainnetBlockHashFunction::createHash); final BlockBody body = new BlockBody( input.readList(Transaction::readFrom), input.readList( rlp -> BlockHeader.readFrom(rlp, MainnetBlockHashFunction::createHash))); return new Block(header, body); } }