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);
}
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);
}
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);
}
Aggregations