@Test
@SuppressWarnings("unchecked")
public void blockCreatedIsAddedToBlockChain() throws InterruptedException {
final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture();
final Block blockToCreate =
new Block(
headerBuilder.buildHeader(), new BlockBody(Lists.newArrayList(), Lists.newArrayList()));
final ProtocolContext<Void> protocolContext = new ProtocolContext<>(null, null, null);
final EthHashBlockCreator blockCreator = mock(EthHashBlockCreator.class);
when(blockCreator.createBlock(anyLong())).thenReturn(blockToCreate);
final BlockImporter<Void> blockImporter = mock(BlockImporter.class);
final ProtocolSpec<Void> protocolSpec = mock(ProtocolSpec.class);
final ProtocolSchedule<Void> protocolSchedule = singleSpecSchedule(protocolSpec);
when(protocolSpec.getBlockImporter()).thenReturn(blockImporter);
when(blockImporter.importBlock(any(), any(), any())).thenReturn(true);
final MinedBlockObserver observer = mock(MinedBlockObserver.class);
final DefaultBlockScheduler scheduler = mock(DefaultBlockScheduler.class);
when(scheduler.waitUntilNextBlockCanBeMined(any())).thenReturn(5L);
final BlockMiner<Void, EthHashBlockCreator> miner =
new EthHashBlockMiner(
blockCreator,
protocolSchedule,
protocolContext,
subscribersContaining(observer),
scheduler,
headerBuilder.buildHeader());
miner.run();
verify(blockImporter).importBlock(protocolContext, blockToCreate, HeaderValidationMode.FULL);
verify(observer, times(1)).blockMined(blockToCreate);
}