@Test void blockSlotGreaterThanPreviousBlockSlot() { UInt64 START_SLOT = UInt64.valueOf(1); UInt64 COUNT = UInt64.valueOf(4); UInt64 STEP = UInt64.valueOf(1); listenerWrapper = new BlocksByRangeListenerWrapper(peer, listener, START_SLOT, COUNT, STEP); final SignedBeaconBlock block1 = dataStructureUtil.randomSignedBeaconBlock(1); final SignedBeaconBlock block2 = dataStructureUtil.randomSignedBeaconBlock(1); listenerWrapper.onResponse(block1).join(); SafeFuture<?> result = listenerWrapper.onResponse(block2); assertThat(result).isCompletedExceptionally(); assertThatThrownBy(result::get) .hasCauseExactlyInstanceOf(BlocksByRangeResponseInvalidResponseException.class); assertThatThrownBy(result::get) .hasMessageContaining( BlocksByRangeResponseInvalidResponseException.InvalidResponseType .BLOCK_SLOT_NOT_GREATER_THAN_PREVIOUS_BLOCK_SLOT .describe()); }
private boolean blockSlotGreaterThanPreviousBlockSlot(UInt64 blockSlot) { if (maybeSlotOfLastBlock.isEmpty()) { return true; } UInt64 lastBlockSlot = maybeSlotOfLastBlock.get(); return blockSlot.isGreaterThan(lastBlockSlot); }
BlocksByRangeListenerWrapper implements ResponseStreamListener<SignedBeaconBlock> { private boolean blockSlotGreaterThanPreviousBlockSlot(UInt64 blockSlot) { if (maybeSlotOfLastBlock.isEmpty()) { return true; } UInt64 lastBlockSlot = maybeSlotOfLastBlock.get(); return blockSlot.isGreaterThan(lastBlockSlot); } }
BlocksByRangeListenerWrapper implements ResponseStreamListener<SignedBeaconBlock> { private boolean blockSlotGreaterThanPreviousBlockSlot(UInt64 blockSlot) { if (maybeSlotOfLastBlock.isEmpty()) { return true; } UInt64 lastBlockSlot = maybeSlotOfLastBlock.get(); return blockSlot.isGreaterThan(lastBlockSlot); } BlocksByRangeListenerWrapper(
      Peer peer,
      ResponseStreamListener<SignedBeaconBlock> blockResponseListener,
      UInt64 startSlot,
      UInt64 count,
      UInt64 step); }
BlocksByRangeListenerWrapper implements ResponseStreamListener<SignedBeaconBlock> { private boolean blockSlotGreaterThanPreviousBlockSlot(UInt64 blockSlot) { if (maybeSlotOfLastBlock.isEmpty()) { return true; } UInt64 lastBlockSlot = maybeSlotOfLastBlock.get(); return blockSlot.isGreaterThan(lastBlockSlot); } BlocksByRangeListenerWrapper(
      Peer peer,
      ResponseStreamListener<SignedBeaconBlock> blockResponseListener,
      UInt64 startSlot,
      UInt64 count,
      UInt64 step); @Override SafeFuture<?> onResponse(SignedBeaconBlock response); }
BlocksByRangeListenerWrapper implements ResponseStreamListener<SignedBeaconBlock> { private boolean blockSlotGreaterThanPreviousBlockSlot(UInt64 blockSlot) { if (maybeSlotOfLastBlock.isEmpty()) { return true; } UInt64 lastBlockSlot = maybeSlotOfLastBlock.get(); return blockSlot.isGreaterThan(lastBlockSlot); } BlocksByRangeListenerWrapper(
      Peer peer,
      ResponseStreamListener<SignedBeaconBlock> blockResponseListener,
      UInt64 startSlot,
      UInt64 count,
      UInt64 step); @Override SafeFuture<?> onResponse(SignedBeaconBlock response);  }