Skip to content

Commit

Permalink
fix integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Feb 23, 2023
1 parent 84a2720 commit 44fcec9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlobSidecar> requestBlobSidecars(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,18 @@ public SafeFuture<Void> requestBlockAndBlobsSidecarByRoot(
method,
new BeaconBlockAndBlobsSidecarByRootRequestMessage(blockRoots),
listener))
.orElse(
SafeFuture.failedFuture(
new UnsupportedOperationException(
"BlockAndBlobsSidecarByRoot method is not available")));
.orElse(failWithUnsupportedMethodException("BlockAndBlobsSidecarByRoot"));
}

@Override
public SafeFuture<Void> requestBlobSidecarsByRoot(
final List<BlobIdentifier> blobIdentifiers, final RpcResponseListener<BlobSidecar> listener)
throws RpcException {
final Optional<Eth2RpcMethod<BlobSidecarsByRootRequestMessage, BlobSidecar>> rpcMethod =
rpcMethods.blobSidecarsByRoot();
if (rpcMethod.isEmpty()) {
return failWithUnsupportedMethodException("BlobSidecarsByRoot");
}
final BlobSidecarsByRootRequestMessageSchema requestSchema =
blobSidecarsByRootRequestMessageSchema.get();
final long requestMaxLength = requestSchema.getMaxLength();
Expand All @@ -270,17 +272,10 @@ public SafeFuture<Void> 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
Expand Down Expand Up @@ -312,9 +307,7 @@ public SafeFuture<Optional<BlobSidecar>> requestBlobSidecarByRoot(
new BlobSidecarsByRootRequestMessage(
blobSidecarsByRootRequestMessageSchema.get(),
Collections.singletonList(blobIdentifier))))
.orElse(
SafeFuture.failedFuture(
new UnsupportedOperationException("BlobSidecarsByRoot method is not available")));
.orElse(failWithUnsupportedMethodException("BlobSidecarsByRoot"));
}

@Override
Expand All @@ -326,10 +319,7 @@ public SafeFuture<Optional<SignedBeaconBlockAndBlobsSidecar>> requestBlockAndBlo
method ->
requestOptionalItem(
method, new BeaconBlockAndBlobsSidecarByRootRequestMessage(List.of(blockRoot))))
.orElse(
SafeFuture.failedFuture(
new UnsupportedOperationException(
"BlockAndBlobsSidecarByRoot method is not available")));
.orElse(failWithUnsupportedMethodException("BlockAndBlobsSidecarByRoot"));
}

@Override
Expand Down Expand Up @@ -369,9 +359,7 @@ public SafeFuture<Void> requestBlobsSidecarsByRange(
}
return requestStream(method, request, listener);
})
.orElse(
SafeFuture.failedFuture(
new UnsupportedOperationException("BlobsSidecarsByRange method is not available")));
.orElse(failWithUnsupportedMethodException("BlobsSidecarsByRange"));
}

@Override
Expand Down Expand Up @@ -466,7 +454,7 @@ private <I extends RpcRequest, O extends SszData> SafeFuture<Void> requestStream
private <I extends RpcRequest, O extends SszData> SafeFuture<Void> sendEth2Request(
final Eth2RpcMethod<I, O> method,
final I request,
Eth2RpcResponseHandler<O, ?> responseHandler) {
final Eth2RpcResponseHandler<O, ?> responseHandler) {
outstandingRequests.incrementAndGet();

return this.sendRequest(method, request, responseHandler)
Expand All @@ -478,6 +466,11 @@ private <I extends RpcRequest, O extends SszData> SafeFuture<Void> sendEth2Reque
.alwaysRun(outstandingRequests::decrementAndGet);
}

private <T> SafeFuture<T> failWithUnsupportedMethodException(final String method) {
return SafeFuture.failedFuture(
new UnsupportedOperationException(method + " method is not supported"));
}

@Override
public boolean equals(final Object o) {
if (this == o) {
Expand Down

0 comments on commit 44fcec9

Please sign in to comment.