@Test void blockSlotSmallerThanFromSlot() { UInt64 START_SLOT = UInt64.valueOf(1); UInt64 COUNT = UInt64.valueOf(4); UInt64 STEP = UInt64.valueOf(2); listenerWrapper = new BlocksByRangeListenerWrapper(peer, listener, START_SLOT, COUNT, STEP); final SignedBeaconBlock block1 = dataStructureUtil.randomSignedBeaconBlock(0); SafeFuture<?> result = listenerWrapper.onResponse(block1); assertThat(result).isCompletedExceptionally(); assertThatThrownBy(result::get) .hasCauseExactlyInstanceOf(BlocksByRangeResponseInvalidResponseException.class); assertThatThrownBy(result::get) .hasMessageContaining( BlocksByRangeResponseInvalidResponseException.InvalidResponseType .BLOCK_SLOT_NOT_IN_RANGE .describe()); }
@Override public SafeFuture<?> onResponse(SignedBeaconBlock response) { return SafeFuture.of( () -> { UInt64 blockSlot = response.getSlot(); if (!blockSlotIsInRange(blockSlot)) { throw new BlocksByRangeResponseInvalidResponseException(peer, BLOCK_SLOT_NOT_IN_RANGE); } if (!blockSlotMatchesTheStep(blockSlot)) { throw new BlocksByRangeResponseInvalidResponseException( peer, BLOCK_SLOT_DOES_NOT_MATCH_STEP); } if (!blockSlotGreaterThanPreviousBlockSlot(blockSlot)) { throw new BlocksByRangeResponseInvalidResponseException( peer, BLOCK_SLOT_NOT_GREATER_THAN_PREVIOUS_BLOCK_SLOT); } if (!blockParentRootMatches(response.getParent_root())) { throw new BlocksByRangeResponseInvalidResponseException( peer, BLOCK_PARENT_ROOT_DOES_NOT_MATCH); } maybeSlotOfLastBlock = Optional.of(blockSlot); maybeRootOfLastBlock = Optional.of(response.getRoot()); return blockResponseListener.onResponse(response); }); }
BlocksByRangeListenerWrapper implements ResponseStreamListener<SignedBeaconBlock> { @Override public SafeFuture<?> onResponse(SignedBeaconBlock response) { return SafeFuture.of( () -> { UInt64 blockSlot = response.getSlot(); if (!blockSlotIsInRange(blockSlot)) { throw new BlocksByRangeResponseInvalidResponseException(peer, BLOCK_SLOT_NOT_IN_RANGE); } if (!blockSlotMatchesTheStep(blockSlot)) { throw new BlocksByRangeResponseInvalidResponseException( peer, BLOCK_SLOT_DOES_NOT_MATCH_STEP); } if (!blockSlotGreaterThanPreviousBlockSlot(blockSlot)) { throw new BlocksByRangeResponseInvalidResponseException( peer, BLOCK_SLOT_NOT_GREATER_THAN_PREVIOUS_BLOCK_SLOT); } if (!blockParentRootMatches(response.getParent_root())) { throw new BlocksByRangeResponseInvalidResponseException( peer, BLOCK_PARENT_ROOT_DOES_NOT_MATCH); } maybeSlotOfLastBlock = Optional.of(blockSlot); maybeRootOfLastBlock = Optional.of(response.getRoot()); return blockResponseListener.onResponse(response); }); } }
BlocksByRangeListenerWrapper implements ResponseStreamListener<SignedBeaconBlock> { @Override public SafeFuture<?> onResponse(SignedBeaconBlock response) { return SafeFuture.of( () -> { UInt64 blockSlot = response.getSlot(); if (!blockSlotIsInRange(blockSlot)) { throw new BlocksByRangeResponseInvalidResponseException(peer, BLOCK_SLOT_NOT_IN_RANGE); } if (!blockSlotMatchesTheStep(blockSlot)) { throw new BlocksByRangeResponseInvalidResponseException( peer, BLOCK_SLOT_DOES_NOT_MATCH_STEP); } if (!blockSlotGreaterThanPreviousBlockSlot(blockSlot)) { throw new BlocksByRangeResponseInvalidResponseException( peer, BLOCK_SLOT_NOT_GREATER_THAN_PREVIOUS_BLOCK_SLOT); } if (!blockParentRootMatches(response.getParent_root())) { throw new BlocksByRangeResponseInvalidResponseException( peer, BLOCK_PARENT_ROOT_DOES_NOT_MATCH); } maybeSlotOfLastBlock = Optional.of(blockSlot); maybeRootOfLastBlock = Optional.of(response.getRoot()); return blockResponseListener.onResponse(response); }); } BlocksByRangeListenerWrapper(
      Peer peer,
      ResponseStreamListener<SignedBeaconBlock> blockResponseListener,
      UInt64 startSlot,
      UInt64 count,
      UInt64 step); }
BlocksByRangeListenerWrapper implements ResponseStreamListener<SignedBeaconBlock> { @Override public SafeFuture<?> onResponse(SignedBeaconBlock response) { return SafeFuture.of( () -> { UInt64 blockSlot = response.getSlot(); if (!blockSlotIsInRange(blockSlot)) { throw new BlocksByRangeResponseInvalidResponseException(peer, BLOCK_SLOT_NOT_IN_RANGE); } if (!blockSlotMatchesTheStep(blockSlot)) { throw new BlocksByRangeResponseInvalidResponseException( peer, BLOCK_SLOT_DOES_NOT_MATCH_STEP); } if (!blockSlotGreaterThanPreviousBlockSlot(blockSlot)) { throw new BlocksByRangeResponseInvalidResponseException( peer, BLOCK_SLOT_NOT_GREATER_THAN_PREVIOUS_BLOCK_SLOT); } if (!blockParentRootMatches(response.getParent_root())) { throw new BlocksByRangeResponseInvalidResponseException( peer, BLOCK_PARENT_ROOT_DOES_NOT_MATCH); } maybeSlotOfLastBlock = Optional.of(blockSlot); maybeRootOfLastBlock = Optional.of(response.getRoot()); return blockResponseListener.onResponse(response); }); } BlocksByRangeListenerWrapper(
      Peer peer,
      ResponseStreamListener<SignedBeaconBlock> blockResponseListener,
      UInt64 startSlot,
      UInt64 count,
      UInt64 step); @Override SafeFuture<?> onResponse(SignedBeaconBlock response); }
BlocksByRangeListenerWrapper implements ResponseStreamListener<SignedBeaconBlock> { @Override public SafeFuture<?> onResponse(SignedBeaconBlock response) { return SafeFuture.of( () -> { UInt64 blockSlot = response.getSlot(); if (!blockSlotIsInRange(blockSlot)) { throw new BlocksByRangeResponseInvalidResponseException(peer, BLOCK_SLOT_NOT_IN_RANGE); } if (!blockSlotMatchesTheStep(blockSlot)) { throw new BlocksByRangeResponseInvalidResponseException( peer, BLOCK_SLOT_DOES_NOT_MATCH_STEP); } if (!blockSlotGreaterThanPreviousBlockSlot(blockSlot)) { throw new BlocksByRangeResponseInvalidResponseException( peer, BLOCK_SLOT_NOT_GREATER_THAN_PREVIOUS_BLOCK_SLOT); } if (!blockParentRootMatches(response.getParent_root())) { throw new BlocksByRangeResponseInvalidResponseException( peer, BLOCK_PARENT_ROOT_DOES_NOT_MATCH); } maybeSlotOfLastBlock = Optional.of(blockSlot); maybeRootOfLastBlock = Optional.of(response.getRoot()); return blockResponseListener.onResponse(response); }); } BlocksByRangeListenerWrapper(
      Peer peer,
      ResponseStreamListener<SignedBeaconBlock> blockResponseListener,
      UInt64 startSlot,
      UInt64 count,
      UInt64 step); @Override SafeFuture<?> onResponse(SignedBeaconBlock response);  }