Search in sources :

Example 1 with GetBlockResponseV2

use of tech.pegasys.teku.api.response.v2.beacon.GetBlockResponseV2 in project teku by ConsenSys.

the class GetBlockV2IntegrationTest method shouldGetAltairBlock.

@Test
public void shouldGetAltairBlock() throws IOException {
    startRestAPIAtGenesis(SpecMilestone.ALTAIR);
    final List<SignedBlockAndState> created = createBlocksAtSlots(10);
    final Response response = get("head");
    final GetBlockResponseV2 body = jsonProvider.jsonToObject(response.body().string(), GetBlockResponseV2.class);
    assertThat(body.getVersion()).isEqualTo(Version.altair);
    assertThat(body.getData()).isInstanceOf(SignedBeaconBlockAltair.class);
    final SignedBeaconBlockAltair data = (SignedBeaconBlockAltair) body.getData();
    assertThat(data.signature.toHexString()).isEqualTo(created.get(0).getBlock().getSignature().toString());
    assertThat(data.getMessage().asInternalBeaconBlock(spec).getRoot().toHexString()).isEqualTo(created.get(0).getBlock().getMessage().getRoot().toHexString());
    assertThat(data.getMessage().getBody().syncAggregate.syncCommitteeBits).isEqualTo(Bytes.fromHexString("0x00000000"));
    assertThat(response.header(HEADER_CONSENSUS_VERSION)).isEqualTo(Version.altair.name());
}
Also used : Response(okhttp3.Response) SignedBeaconBlockAltair(tech.pegasys.teku.api.schema.altair.SignedBeaconBlockAltair) GetBlockResponseV2(tech.pegasys.teku.api.response.v2.beacon.GetBlockResponseV2) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Example 2 with GetBlockResponseV2

use of tech.pegasys.teku.api.response.v2.beacon.GetBlockResponseV2 in project teku by ConsenSys.

the class GetBlock method handleJsonResult.

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

Example 3 with GetBlockResponseV2

use of tech.pegasys.teku.api.response.v2.beacon.GetBlockResponseV2 in project teku by ConsenSys.

the class GetBlockV2IntegrationTest method shouldGetBlock.

@Test
public void shouldGetBlock() throws IOException {
    startRestAPIAtGenesis(SpecMilestone.PHASE0);
    final List<SignedBlockAndState> created = createBlocksAtSlots(10);
    final Response response = get("head");
    final GetBlockResponseV2 body = jsonProvider.jsonToObject(response.body().string(), GetBlockResponseV2.class);
    assertThat(body.getVersion()).isEqualTo(Version.phase0);
    assertThat(body.data).isInstanceOf(SignedBeaconBlockPhase0.class);
    final SignedBeaconBlockPhase0 data = (SignedBeaconBlockPhase0) body.getData();
    final SignedBlockAndState block = created.get(0);
    assertThat(data).isEqualTo(SignedBeaconBlock.create(block.getBlock()));
    assertThat(response.header(HEADER_CONSENSUS_VERSION)).isEqualTo(Version.phase0.name());
}
Also used : Response(okhttp3.Response) GetBlockResponseV2(tech.pegasys.teku.api.response.v2.beacon.GetBlockResponseV2) SignedBeaconBlockPhase0(tech.pegasys.teku.api.schema.phase0.SignedBeaconBlockPhase0) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Aggregations

GetBlockResponseV2 (tech.pegasys.teku.api.response.v2.beacon.GetBlockResponseV2)3 Response (okhttp3.Response)2 Test (org.junit.jupiter.api.Test)2 AbstractDataBackedRestAPIIntegrationTest (tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)2 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)2 Version (tech.pegasys.teku.api.schema.Version)1 SignedBeaconBlockAltair (tech.pegasys.teku.api.schema.altair.SignedBeaconBlockAltair)1 SignedBeaconBlockPhase0 (tech.pegasys.teku.api.schema.phase0.SignedBeaconBlockPhase0)1