From 44fcec9be43b16cce8ffb9119be6e9cd5d8656e4 Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Thu, 23 Feb 2023 09:24:09 +0000 Subject: [PATCH] fix integration test --- .../BlobSidecarsByRootIntegrationTest.java | 2 +- .../BlobsSidecarsByRangeIntegrationTest.java | 2 +- .../eth2/peers/DefaultEth2Peer.java | 45 ++++++++----------- 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/BlobSidecarsByRootIntegrationTest.java b/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/BlobSidecarsByRootIntegrationTest.java index 31172aebd50..42a5328022f 100644 --- a/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/BlobSidecarsByRootIntegrationTest.java +++ b/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/BlobSidecarsByRootIntegrationTest.java @@ -37,7 +37,7 @@ public void shouldFailBeforeDenebMilestone() { final Eth2Peer peer = createPeer(TestSpecFactory.createMinimalCapella()); assertThatThrownBy(() -> requestBlobSidecars(peer, List.of())) .hasRootCauseInstanceOf(UnsupportedOperationException.class) - .hasMessageContaining("BlobSidecarsByRoot method is not available"); + .hasMessageContaining("BlobSidecarsByRoot method is not supported"); } private List requestBlobSidecars( diff --git a/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/BlobsSidecarsByRangeIntegrationTest.java b/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/BlobsSidecarsByRangeIntegrationTest.java index 96fa25369bd..8cb61c07e7c 100644 --- a/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/BlobsSidecarsByRangeIntegrationTest.java +++ b/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/BlobsSidecarsByRangeIntegrationTest.java @@ -42,7 +42,7 @@ public void shouldFailBeforeDenebMilestone() { final Eth2Peer peer = createPeer(); assertThatThrownBy(() -> requestBlobsSideCars(peer, UInt64.ONE, UInt64.valueOf(2))) .hasRootCauseInstanceOf(UnsupportedOperationException.class) - .hasMessageContaining("BlobsSidecarsByRange method is not available"); + .hasMessageContaining("BlobsSidecarsByRange method is not supported"); } @Test diff --git a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/DefaultEth2Peer.java b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/DefaultEth2Peer.java index 7028de93aa3..bcf8b976147 100644 --- a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/DefaultEth2Peer.java +++ b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/DefaultEth2Peer.java @@ -252,16 +252,18 @@ public SafeFuture requestBlockAndBlobsSidecarByRoot( method, new BeaconBlockAndBlobsSidecarByRootRequestMessage(blockRoots), listener)) - .orElse( - SafeFuture.failedFuture( - new UnsupportedOperationException( - "BlockAndBlobsSidecarByRoot method is not available"))); + .orElse(failWithUnsupportedMethodException("BlockAndBlobsSidecarByRoot")); } @Override public SafeFuture requestBlobSidecarsByRoot( final List blobIdentifiers, final RpcResponseListener listener) throws RpcException { + final Optional> rpcMethod = + rpcMethods.blobSidecarsByRoot(); + if (rpcMethod.isEmpty()) { + return failWithUnsupportedMethodException("BlobSidecarsByRoot"); + } final BlobSidecarsByRootRequestMessageSchema requestSchema = blobSidecarsByRootRequestMessageSchema.get(); final long requestMaxLength = requestSchema.getMaxLength(); @@ -270,17 +272,10 @@ public SafeFuture requestBlobSidecarsByRoot( INVALID_REQUEST_CODE, "Only a maximum of " + requestMaxLength + " blob sidecars per request"); } - return rpcMethods - .blobSidecarsByRoot() - .map( - method -> - requestStream( - method, - new BlobSidecarsByRootRequestMessage(requestSchema, blobIdentifiers), - listener)) - .orElse( - SafeFuture.failedFuture( - new UnsupportedOperationException("BlobSidecarsByRoot method is not available"))); + return requestStream( + rpcMethod.get(), + new BlobSidecarsByRootRequestMessage(requestSchema, blobIdentifiers), + listener); } @Override @@ -312,9 +307,7 @@ public SafeFuture> requestBlobSidecarByRoot( new BlobSidecarsByRootRequestMessage( blobSidecarsByRootRequestMessageSchema.get(), Collections.singletonList(blobIdentifier)))) - .orElse( - SafeFuture.failedFuture( - new UnsupportedOperationException("BlobSidecarsByRoot method is not available"))); + .orElse(failWithUnsupportedMethodException("BlobSidecarsByRoot")); } @Override @@ -326,10 +319,7 @@ public SafeFuture> requestBlockAndBlo method -> requestOptionalItem( method, new BeaconBlockAndBlobsSidecarByRootRequestMessage(List.of(blockRoot)))) - .orElse( - SafeFuture.failedFuture( - new UnsupportedOperationException( - "BlockAndBlobsSidecarByRoot method is not available"))); + .orElse(failWithUnsupportedMethodException("BlockAndBlobsSidecarByRoot")); } @Override @@ -369,9 +359,7 @@ public SafeFuture requestBlobsSidecarsByRange( } return requestStream(method, request, listener); }) - .orElse( - SafeFuture.failedFuture( - new UnsupportedOperationException("BlobsSidecarsByRange method is not available"))); + .orElse(failWithUnsupportedMethodException("BlobsSidecarsByRange")); } @Override @@ -466,7 +454,7 @@ private SafeFuture requestStream private SafeFuture sendEth2Request( final Eth2RpcMethod method, final I request, - Eth2RpcResponseHandler responseHandler) { + final Eth2RpcResponseHandler responseHandler) { outstandingRequests.incrementAndGet(); return this.sendRequest(method, request, responseHandler) @@ -478,6 +466,11 @@ private SafeFuture sendEth2Reque .alwaysRun(outstandingRequests::decrementAndGet); } + private SafeFuture failWithUnsupportedMethodException(final String method) { + return SafeFuture.failedFuture( + new UnsupportedOperationException(method + " method is not supported")); + } + @Override public boolean equals(final Object o) { if (this == o) {