Search in sources :

Example 1 with SignedBeaconBlockPhase0

use of tech.pegasys.teku.api.schema.phase0.SignedBeaconBlockPhase0 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)

Example 2 with SignedBeaconBlockPhase0

use of tech.pegasys.teku.api.schema.phase0.SignedBeaconBlockPhase0 in project teku by ConsenSys.

the class ValidatorDataProvider method parseBlock.

public SignedBeaconBlock parseBlock(final JsonProvider jsonProvider, final String jsonBlock) throws JsonProcessingException {
    final ObjectMapper mapper = jsonProvider.getObjectMapper();
    final JsonNode jsonNode = mapper.readTree(jsonBlock);
    final UInt64 slot = mapper.treeToValue(jsonNode.findValue("slot"), UInt64.class);
    final SignedBeaconBlock signedBeaconBlock;
    checkNotNull(slot, "Slot was not found in json block");
    switch(spec.atSlot(slot).getMilestone()) {
        case PHASE0:
            signedBeaconBlock = mapper.treeToValue(jsonNode, SignedBeaconBlockPhase0.class);
            break;
        case ALTAIR:
            signedBeaconBlock = mapper.treeToValue(jsonNode, SignedBeaconBlockAltair.class);
            break;
        case BELLATRIX:
            signedBeaconBlock = mapper.treeToValue(jsonNode, SignedBeaconBlockBellatrix.class);
            break;
        default:
            throw new IllegalArgumentException("Could not determine milestone for slot " + slot);
    }
    return signedBeaconBlock;
}
Also used : SignedBeaconBlockBellatrix(tech.pegasys.teku.api.schema.bellatrix.SignedBeaconBlockBellatrix) SignedBeaconBlockAltair(tech.pegasys.teku.api.schema.altair.SignedBeaconBlockAltair) SignedBeaconBlockPhase0(tech.pegasys.teku.api.schema.phase0.SignedBeaconBlockPhase0) JsonNode(com.fasterxml.jackson.databind.JsonNode) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBeaconBlock(tech.pegasys.teku.api.schema.SignedBeaconBlock) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

SignedBeaconBlockPhase0 (tech.pegasys.teku.api.schema.phase0.SignedBeaconBlockPhase0)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Response (okhttp3.Response)1 Test (org.junit.jupiter.api.Test)1 GetBlockResponseV2 (tech.pegasys.teku.api.response.v2.beacon.GetBlockResponseV2)1 SignedBeaconBlock (tech.pegasys.teku.api.schema.SignedBeaconBlock)1 SignedBeaconBlockAltair (tech.pegasys.teku.api.schema.altair.SignedBeaconBlockAltair)1 SignedBeaconBlockBellatrix (tech.pegasys.teku.api.schema.bellatrix.SignedBeaconBlockBellatrix)1 AbstractDataBackedRestAPIIntegrationTest (tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)1