use of tech.pegasys.teku.api.response.v1.beacon.FinalityCheckpointsResponse 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.FinalityCheckpointsResponse 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.FinalityCheckpointsResponse 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);
}
use of tech.pegasys.teku.api.response.v1.beacon.FinalityCheckpointsResponse in project teku by ConsenSys.
the class ChainDataProviderTest method getStateFinalityCheckpoints_shouldGetCheckpointsAfterFinalized.
@Test
public void getStateFinalityCheckpoints_shouldGetCheckpointsAfterFinalized() {
final ChainDataProvider provider = new ChainDataProvider(spec, recentChainData, mockCombinedChainDataClient);
final SignedBlockAndState blockAndState = data.randomSignedBlockAndState(UInt64.valueOf(42));
final tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState internalState = blockAndState.getState();
final FinalityCheckpointsResponse expected = new FinalityCheckpointsResponse(new tech.pegasys.teku.api.schema.Checkpoint(internalState.getPrevious_justified_checkpoint()), new tech.pegasys.teku.api.schema.Checkpoint(internalState.getCurrent_justified_checkpoint()), new tech.pegasys.teku.api.schema.Checkpoint(internalState.getFinalized_checkpoint()));
when(mockCombinedChainDataClient.getChainHead()).thenReturn(Optional.of(tech.pegasys.teku.storage.client.ChainHead.create(blockAndState)));
assertThatSafeFuture(provider.getStateFinalityCheckpoints("head")).isCompletedWithOptionalContaining(addMetaData(expected, ZERO));
}
Aggregations