Skip to content

Commit

Permalink
add consensus header to GetBlockAttestationsV2 API (#8465)
Browse files Browse the repository at this point in the history
* add consensus header to GetBlockAttestationsV2 API
  • Loading branch information
mehdi-aouadi authored Jul 24, 2024
1 parent e55c9cb commit 3882303
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.EXECUTION_OPTIMISTIC;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.FINALIZED;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.HEADER_CONSENSUS_VERSION;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.TAG_BEACON;
import static tech.pegasys.teku.infrastructure.json.types.CoreTypes.BOOLEAN_TYPE;
import static tech.pegasys.teku.infrastructure.json.types.SerializableTypeDefinition.listOf;
Expand All @@ -28,6 +29,7 @@
import java.util.function.Predicate;
import tech.pegasys.teku.api.ChainDataProvider;
import tech.pegasys.teku.api.DataProvider;
import tech.pegasys.teku.api.schema.Version;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition;
import tech.pegasys.teku.infrastructure.json.types.SerializableOneOfTypeDefinition;
Expand Down Expand Up @@ -75,9 +77,15 @@ public void handleRequest(final RestApiRequest request) throws JsonProcessingExc

request.respondAsync(
future.thenApply(
maybeObjectAndMetaData ->
maybeObjectAndMetaData
.map(AsyncApiResponse::respondOk)
maybeAttestationsAndMetadata ->
maybeAttestationsAndMetadata
.map(
attestationsAndMetadata -> {
request.header(
HEADER_CONSENSUS_VERSION,
Version.fromMilestone(attestationsAndMetadata.getMilestone()).name());
return AsyncApiResponse.respondOk(attestationsAndMetadata);
})
.orElseGet(AsyncApiResponse::respondNotFound)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_BAD_REQUEST;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_INTERNAL_SERVER_ERROR;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.HEADER_CONSENSUS_VERSION;
import static tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition.listOf;
import static tech.pegasys.teku.infrastructure.restapi.MetadataTestUtil.getResponseStringFromMetadata;
import static tech.pegasys.teku.infrastructure.restapi.MetadataTestUtil.verifyMetadataErrorResponse;
Expand All @@ -29,6 +30,7 @@
import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.api.schema.Version;
import tech.pegasys.teku.beaconrestapi.AbstractMigratedBeaconHandlerTest;
import tech.pegasys.teku.ethereum.json.types.SharedApiTypes;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
Expand Down Expand Up @@ -91,6 +93,8 @@ public void shouldReturnBlockAttestationsInformationForPhase0() throws JsonProce
assertThat(request.getResponseCode()).isEqualTo(SC_OK);
assertThat(phase0responseData.getData().size()).isGreaterThan(0);
assertThat(request.getResponseBody()).isEqualTo(optionalData.get());
assertThat(request.getResponseHeaders(HEADER_CONSENSUS_VERSION))
.isEqualTo(Version.fromMilestone(phase0responseData.getMilestone()).name());
}

@Test
Expand All @@ -105,6 +109,8 @@ public void shouldReturnBlockAttestationsInformationForElectra() throws JsonProc
assertThat(request.getResponseCode()).isEqualTo(SC_OK);
assertThat(electraResponseData.getData().size()).isGreaterThan(0);
assertThat(request.getResponseBody()).isEqualTo(optionalData.get());
assertThat(request.getResponseHeaders(HEADER_CONSENSUS_VERSION))
.isEqualTo(Version.fromMilestone(electraResponseData.getMilestone()).name());
}

@Test
Expand Down

0 comments on commit 3882303

Please sign in to comment.