Search in sources :

Example 1 with GetStateResponseV2

use of tech.pegasys.teku.api.response.v2.debug.GetStateResponseV2 in project teku by ConsenSys.

the class GetStateIntegrationTest method shouldGetAltairStateAsJson.

@Test
public void shouldGetAltairStateAsJson() throws IOException {
    startRestAPIAtGenesis(SpecMilestone.ALTAIR);
    final Response response = get("head", HEADER_ACCEPT_JSON);
    assertThat(response.code()).isEqualTo(SC_OK);
    final GetStateResponseV2 stateResponse = jsonProvider.jsonToObject(response.body().string(), GetStateResponseV2.class);
    assertThat(stateResponse).isNotNull();
    assertThat(stateResponse.version).isEqualTo(Version.altair);
    assertThat(stateResponse.data).isInstanceOf(BeaconStateAltair.class);
    assertThat(response.header(HEADER_CONSENSUS_VERSION)).isEqualTo(Version.altair.name());
}
Also used : Response(okhttp3.Response) GetStateResponseV2(tech.pegasys.teku.api.response.v2.debug.GetStateResponseV2) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Example 2 with GetStateResponseV2

use of tech.pegasys.teku.api.response.v2.debug.GetStateResponseV2 in project teku by ConsenSys.

the class GetStateResponseV2Deserializer method deserialize.

@Override
public GetStateResponseV2 deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException {
    JsonNode node = jp.getCodec().readTree(jp);
    final Version version = Version.valueOf(node.findValue("version").asText().toLowerCase(Locale.ROOT));
    final JsonNode executionOptimisticNode = node.findValue("execution_optimistic");
    final Boolean executionOptimistic = executionOptimisticNode != null ? executionOptimisticNode.asBoolean() : null;
    final BeaconState state;
    switch(version) {
        case altair:
            state = mapper.treeToValue(node.findValue("data"), BeaconStateAltair.class);
            break;
        case phase0:
            state = mapper.treeToValue(node.findValue("data"), BeaconStatePhase0.class);
            break;
        default:
            throw new IOException("Milestone was not able to be decoded");
    }
    return new GetStateResponseV2(version, executionOptimistic, state);
}
Also used : GetStateResponseV2(tech.pegasys.teku.api.response.v2.debug.GetStateResponseV2) Version(tech.pegasys.teku.api.schema.Version) JsonNode(com.fasterxml.jackson.databind.JsonNode) BeaconStatePhase0(tech.pegasys.teku.api.schema.phase0.BeaconStatePhase0) IOException(java.io.IOException) BeaconStateAltair(tech.pegasys.teku.api.schema.altair.BeaconStateAltair) BeaconState(tech.pegasys.teku.api.schema.BeaconState)

Example 3 with GetStateResponseV2

use of tech.pegasys.teku.api.response.v2.debug.GetStateResponseV2 in project teku by ConsenSys.

the class GetState method handleJsonResult.

private Optional<String> handleJsonResult(Context ctx, final ObjectAndMetaData<BeaconState> response) throws JsonProcessingException {
    final Version version = Version.fromMilestone(response.getMilestone());
    ctx.header(HEADER_CONSENSUS_VERSION, version.name());
    return Optional.of(jsonProvider.objectToJSON(new GetStateResponseV2(version, response.isExecutionOptimisticForApi(), response.getData())));
}
Also used : GetStateResponseV2(tech.pegasys.teku.api.response.v2.debug.GetStateResponseV2) Version(tech.pegasys.teku.api.schema.Version)

Example 4 with GetStateResponseV2

use of tech.pegasys.teku.api.response.v2.debug.GetStateResponseV2 in project teku by ConsenSys.

the class GetStateIntegrationTest method shouldGetPhase0StateAsJson.

@Test
public void shouldGetPhase0StateAsJson() throws IOException {
    startRestAPIAtGenesis(SpecMilestone.PHASE0);
    final Response response = get("head", HEADER_ACCEPT_JSON);
    assertThat(response.code()).isEqualTo(SC_OK);
    final GetStateResponseV2 stateResponse = jsonProvider.jsonToObject(response.body().string(), GetStateResponseV2.class);
    assertThat(stateResponse).isNotNull();
    assertThat(stateResponse.version).isEqualTo(Version.phase0);
    assertThat(stateResponse.data).isInstanceOf(BeaconStatePhase0.class);
    assertThat(response.header(HEADER_CONSENSUS_VERSION)).isEqualTo(Version.phase0.name());
}
Also used : Response(okhttp3.Response) GetStateResponseV2(tech.pegasys.teku.api.response.v2.debug.GetStateResponseV2) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Aggregations

GetStateResponseV2 (tech.pegasys.teku.api.response.v2.debug.GetStateResponseV2)4 Response (okhttp3.Response)2 Test (org.junit.jupiter.api.Test)2 Version (tech.pegasys.teku.api.schema.Version)2 AbstractDataBackedRestAPIIntegrationTest (tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 IOException (java.io.IOException)1 BeaconState (tech.pegasys.teku.api.schema.BeaconState)1 BeaconStateAltair (tech.pegasys.teku.api.schema.altair.BeaconStateAltair)1 BeaconStatePhase0 (tech.pegasys.teku.api.schema.phase0.BeaconStatePhase0)1