### Question:
Eth1BlockFetcher { public synchronized void onInSync(final UInt64 latestCanonicalBlockNumber) { if (active) { return; } active = true; LOG.debug("Beginning back-fill of Eth1 blocks"); backfillEth1Blocks(latestCanonicalBlockNumber); } Eth1BlockFetcher(
      final Eth1EventsChannel eth1EventsChannel,
      final Eth1Provider eth1Provider,
      final TimeProvider timeProvider,
      final UInt64 cacheDuration); synchronized void onInSync(final UInt64 latestCanonicalBlockNumber); void fetch(final BigInteger fromBlock, final BigInteger toBlock);  }### Answer:
@Test void shouldBackfillEth1BlocksWhenFirstInSyncUntilBlockBeforeCachePeriodReached() { final Map<Integer, Block> blocks = withBlocks( block(100, timeProvider.getTimeInSeconds()), block(99, timeProvider.getTimeInSeconds().minus(ONE)), block(98, timeProvider.getTimeInSeconds().minus(CACHE_DURATION)), block(97, timeProvider.getTimeInSeconds().minus(CACHE_DURATION).minus(ONE)), block(96, timeProvider.getTimeInSeconds().minus(CACHE_DURATION).minus(TWO))); blockFetcher.onInSync(UInt64.valueOf(100)); verifyBlockSent(blocks.get(100)); verifyBlockSent(blocks.get(99)); verifyBlockSent(blocks.get(98)); verifyNoMoreBlocksSent(); verify(eth1Provider).getGuaranteedEth1Block(UInt64.valueOf(97)); verifyBlockNotRequested(96); }
@Test void shouldNotBackfillMultipleTimes() { final UInt64 blockNumber = UInt64.valueOf(100); withBlocks( block( blockNumber.intValue(), timeProvider.getTimeInSeconds().minus(CACHE_DURATION).minus(ONE))); blockFetcher.onInSync(blockNumber); verify(eth1Provider).getGuaranteedEth1Block(blockNumber); blockFetcher.onInSync(blockNumber); verify(eth1Provider).getGuaranteedEth1Block(blockNumber); verifyNoMoreInteractions(eth1Provider); }
@Test void shouldStopBackfillWhenGenesisReached() { final Map<Integer, Block> blocks = withBlocks( block(1, timeProvider.getTimeInSeconds()), block(0, timeProvider.getTimeInSeconds().minus(ONE))); blockFetcher.onInSync(ONE); verifyBlockSent(blocks.get(1)); verifyBlockSent(blocks.get(0)); verify(eth1Provider).getGuaranteedEth1Block(ONE); verify(eth1Provider).getGuaranteedEth1Block(ZERO); verifyNoMoreInteractions(eth1Provider); }