Search in sources :

Example 1 with FinalityCheckpointsResponse

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);
}
Also used : GetStateFinalityCheckpointsResponse(tech.pegasys.teku.api.response.v1.beacon.GetStateFinalityCheckpointsResponse)

Example 2 with FinalityCheckpointsResponse

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

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

Example 4 with FinalityCheckpointsResponse

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));
}
Also used : SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) FinalityCheckpointsResponse(tech.pegasys.teku.api.response.v1.beacon.FinalityCheckpointsResponse) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 FinalityCheckpointsResponse (tech.pegasys.teku.api.response.v1.beacon.FinalityCheckpointsResponse)3 GetStateFinalityCheckpointsResponse (tech.pegasys.teku.api.response.v1.beacon.GetStateFinalityCheckpointsResponse)3 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 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)1