### Question:
CheckpointStateTask implements CacheableTask<Checkpoint, BeaconState> { @Override public SafeFuture<Optional<BeaconState>> performTask() { return getBaseState().thenApply(maybeState -> maybeState.map(this::regenerateFromState)); } CheckpointStateTask(final Checkpoint checkpoint, final AsyncStateProvider stateProvider); private  CheckpointStateTask(
      final Checkpoint checkpoint,
      final AsyncStateProvider stateProvider,
      final BeaconState baseState); @Override Checkpoint getKey(); @Override Stream<Checkpoint> streamIntermediateSteps(); @Override CacheableTask<Checkpoint, BeaconState> rebase(final BeaconState newBaseValue); @Override SafeFuture<Optional<BeaconState>> performTask();  }### Answer:
@Test void performTask_shouldReturnExistingStateWhenAlreadyAtCorrectSlot() { chainBuilder.generateBlocksUpToSlot(EPOCH_START_SLOT); final SignedBlockAndState base = chainBuilder.getBlockAndStateAtSlot(EPOCH_START_SLOT); when(stateProvider.getState(base.getRoot())) .thenReturn(SafeFuture.completedFuture(Optional.of(base.getState()))); final SafeFuture<Optional<BeaconState>> result = createTask(EPOCH, base.getRoot()).performTask(); assertThatSafeFuture(result).isCompletedWithOptionalContaining(base.getState()); }
@Test void performTask_shouldThrowInvalidCheckpointExceptionWhenStateIsAheadOfSlot() { chainBuilder.generateBlocksUpToSlot(EPOCH_START_SLOT.plus(1)); final SignedBlockAndState base = chainBuilder.getBlockAndStateAtSlot(EPOCH_START_SLOT.plus(1)); when(stateProvider.getState(base.getRoot())) .thenReturn(SafeFuture.completedFuture(Optional.of(base.getState()))); final SafeFuture<Optional<BeaconState>> result = createTask(EPOCH, base.getRoot()).performTask(); assertThatSafeFuture(result).isCompletedExceptionallyWith(InvalidCheckpointException.class); }
@Test void performTask_shouldProcessSlotsWhenStateIsBeforeSlot() { final UInt64 epoch = UInt64.valueOf(2); final Checkpoint checkpoint = chainBuilder.getCurrentCheckpointForEpoch(epoch); final BeaconState state = chainBuilder.getStateAtSlot(0); when(stateProvider.getState(checkpoint.getRoot())) .thenReturn(SafeFuture.completedFuture(Optional.of(state))); final CheckpointStateTask task = createTask(epoch, checkpoint.getRoot()); final SafeFuture<Optional<BeaconState>> result = task.performTask(); final BeaconState expectedState = CheckpointStateGenerator.regenerateCheckpointState(checkpoint, state); assertThatSafeFuture(result).isCompletedWithOptionalContaining(expectedState); }