Skip to content

Commit

Permalink
add consensus version header
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-aouadi committed Jul 24, 2024
1 parent dc65d3d commit c797ec0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static tech.pegasys.teku.ethereum.json.types.EthereumTypes.MILESTONE_TYPE;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.CACHE_NONE;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.HEADER_CONSENSUS_VERSION;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.SLOT_QUERY_DESCRIPTION;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.TAG_BEACON;
import static tech.pegasys.teku.infrastructure.json.types.SerializableTypeDefinition.listOf;
Expand All @@ -30,6 +31,7 @@
import java.util.Optional;
import tech.pegasys.teku.api.DataProvider;
import tech.pegasys.teku.api.NodeDataProvider;
import tech.pegasys.teku.api.schema.Version;
import tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil;
import tech.pegasys.teku.infrastructure.json.types.SerializableTypeDefinition;
import tech.pegasys.teku.infrastructure.restapi.endpoints.EndpointMetadata;
Expand Down Expand Up @@ -77,8 +79,13 @@ public void handleRequest(final RestApiRequest request) throws JsonProcessingExc
request.getOptionalQueryParameter(SLOT_PARAMETER.withDescription(SLOT_QUERY_DESCRIPTION));
final Optional<UInt64> committeeIndex =
request.getOptionalQueryParameter(COMMITTEE_INDEX_PARAMETER);
final ObjectAndMetaData<List<Attestation>> attestationsAndMetaData =
nodeDataProvider.getAttestationsAndMetaData(slot, committeeIndex);

request.respondOk(nodeDataProvider.getAttestationsAndMetaData(slot, committeeIndex));
request.header(
HEADER_CONSENSUS_VERSION,
Version.fromMilestone(attestationsAndMetaData.getMilestone()).name());
request.respondOk(attestationsAndMetaData);
}

private static SerializableTypeDefinition<ObjectAndMetaData<List<Attestation>>> getResponseType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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.restapi.MetadataTestUtil.getResponseStringFromMetadata;
import static tech.pegasys.teku.infrastructure.restapi.MetadataTestUtil.verifyMetadataErrorResponse;
import static tech.pegasys.teku.spec.SpecMilestone.ELECTRA;
Expand All @@ -33,6 +34,7 @@
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestTemplate;
import tech.pegasys.teku.api.schema.Version;
import tech.pegasys.teku.beaconrestapi.AbstractMigratedBeaconHandlerTest;
import tech.pegasys.teku.infrastructure.json.JsonTestUtil;
import tech.pegasys.teku.spec.SpecMilestone;
Expand Down Expand Up @@ -69,6 +71,8 @@ public void shouldReturnAttestationsWhenFound() throws JsonProcessingException {
handler.handleRequest(request);
assertThat(request.getResponseCode()).isEqualTo(SC_OK);
assertThat(request.getResponseBody()).isEqualTo(attestationsAndMetaData);
assertThat(request.getResponseHeaders(HEADER_CONSENSUS_VERSION))
.isEqualTo(Version.fromMilestone(specMilestone).name());
}

@TestTemplate
Expand All @@ -82,6 +86,8 @@ public void shouldReturnEmptyListWhenNoAttestations() throws JsonProcessingExcep
handler.handleRequest(request);
assertThat(request.getResponseCode()).isEqualTo(SC_OK);
assertThat(request.getResponseBody()).isEqualTo(attestationsAndMetaData);
assertThat(request.getResponseHeaders(HEADER_CONSENSUS_VERSION))
.isEqualTo(Version.fromMilestone(specMilestone).name());
}

@TestTemplate
Expand Down

0 comments on commit c797ec0

Please sign in to comment.