Search in sources :

Example 1 with GetStateFinalityCheckpointsResponse

use of tech.pegasys.teku.api.response.v1.beacon.GetStateFinalityCheckpointsResponse in project teku by ConsenSys.

the class TekuNode method fetchStateFinalityCheckpoints.

private Optional<FinalityCheckpointsResponse> fetchStateFinalityCheckpoints() throws IOException {
    final String result = httpClient.get(getRestApiUrl(), "/eth/v1/beacon/states/head/finality_checkpoints");
    if (result.isEmpty()) {
        return Optional.empty();
    }
    final GetStateFinalityCheckpointsResponse response = jsonProvider.jsonToObject(result, GetStateFinalityCheckpointsResponse.class);
    return Optional.of(response.data);
}
Also used : GetStateFinalityCheckpointsResponse(tech.pegasys.teku.api.response.v1.beacon.GetStateFinalityCheckpointsResponse)

Example 2 with GetStateFinalityCheckpointsResponse

use of tech.pegasys.teku.api.response.v1.beacon.GetStateFinalityCheckpointsResponse in project teku by ConsenSys.

the class GetStateFinalityCheckpointsTest method shouldReturnFinalityCheckpointsInfo.

@Test
public void shouldReturnFinalityCheckpointsInfo() throws Exception {
    final GetStateFinalityCheckpoints handler = new GetStateFinalityCheckpoints(chainDataProvider, jsonProvider);
    when(context.pathParamMap()).thenReturn(Map.of("state_id", "head"));
    when(chainDataProvider.getStateFinalityCheckpoints("head")).thenReturn(SafeFuture.completedFuture(Optional.of(new ObjectAndMetaData<>(FinalityCheckpointsResponse.fromState(state), spec.getGenesisSpec().getMilestone(), false, spec.isMilestoneSupported(SpecMilestone.BELLATRIX)))));
    handler.handle(context);
    final FinalityCheckpointsResponse expectedResponse = new FinalityCheckpointsResponse(new Checkpoint(state.getPrevious_justified_checkpoint()), new Checkpoint(state.getCurrent_justified_checkpoint()), new Checkpoint(state.getFinalized_checkpoint()));
    final GetStateFinalityCheckpointsResponse response = getResponseFromFuture(GetStateFinalityCheckpointsResponse.class);
    assertThat(response.data).isEqualTo(expectedResponse);
}
Also used : Checkpoint(tech.pegasys.teku.api.schema.Checkpoint) FinalityCheckpointsResponse(tech.pegasys.teku.api.response.v1.beacon.FinalityCheckpointsResponse) GetStateFinalityCheckpointsResponse(tech.pegasys.teku.api.response.v1.beacon.GetStateFinalityCheckpointsResponse) GetStateFinalityCheckpointsResponse(tech.pegasys.teku.api.response.v1.beacon.GetStateFinalityCheckpointsResponse) AbstractBeaconHandlerTest(tech.pegasys.teku.beaconrestapi.AbstractBeaconHandlerTest) Test(org.junit.jupiter.api.Test)

Example 3 with GetStateFinalityCheckpointsResponse

use of tech.pegasys.teku.api.response.v1.beacon.GetStateFinalityCheckpointsResponse in project teku by ConsenSys.

the class GetStateFinalityCheckpointsTest method shouldGetEmptyCheckpointsAtGenesis.

@Test
public void shouldGetEmptyCheckpointsAtGenesis() throws IOException {
    startRestAPIAtGenesis();
    final Response response = get("genesis");
    assertThat(response.code()).isEqualTo(SC_OK);
    final GetStateFinalityCheckpointsResponse body = jsonProvider.jsonToObject(response.body().string(), GetStateFinalityCheckpointsResponse.class);
    final FinalityCheckpointsResponse data = body.data;
    assertThat(data.current_justified).isEqualTo(Checkpoint.EMPTY);
    assertThat(data.previous_justified).isEqualTo(Checkpoint.EMPTY);
    assertThat(data.finalized).isEqualTo(Checkpoint.EMPTY);
}
Also used : FinalityCheckpointsResponse(tech.pegasys.teku.api.response.v1.beacon.FinalityCheckpointsResponse) Response(okhttp3.Response) GetStateFinalityCheckpointsResponse(tech.pegasys.teku.api.response.v1.beacon.GetStateFinalityCheckpointsResponse) FinalityCheckpointsResponse(tech.pegasys.teku.api.response.v1.beacon.FinalityCheckpointsResponse) GetStateFinalityCheckpointsResponse(tech.pegasys.teku.api.response.v1.beacon.GetStateFinalityCheckpointsResponse) GetStateFinalityCheckpointsResponse(tech.pegasys.teku.api.response.v1.beacon.GetStateFinalityCheckpointsResponse) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Aggregations

GetStateFinalityCheckpointsResponse (tech.pegasys.teku.api.response.v1.beacon.GetStateFinalityCheckpointsResponse)3 Test (org.junit.jupiter.api.Test)2 FinalityCheckpointsResponse (tech.pegasys.teku.api.response.v1.beacon.FinalityCheckpointsResponse)2 Response (okhttp3.Response)1 Checkpoint (tech.pegasys.teku.api.schema.Checkpoint)1 AbstractBeaconHandlerTest (tech.pegasys.teku.beaconrestapi.AbstractBeaconHandlerTest)1 AbstractDataBackedRestAPIIntegrationTest (tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)1