Search in sources :

Example 1 with BeaconBlockPhase0

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

the class GetNewBlockTest method shouldReturnBlockWithoutGraffiti.

@Test
void shouldReturnBlockWithoutGraffiti() throws Exception {
    final Map<String, String> pathParams = Map.of(SLOT, "1");
    final Map<String, List<String>> queryParams = Map.of(RANDAO_REVEAL, List.of(signature.toHexString()));
    Optional<BeaconBlock> optionalBeaconBlock = Optional.of(new BeaconBlockPhase0(dataStructureUtil.randomBeaconBlock(dataStructureUtil.randomLong())));
    when(context.queryParamMap()).thenReturn(queryParams);
    when(context.pathParamMap()).thenReturn(pathParams);
    when(provider.getMilestoneAtSlot(UInt64.ONE)).thenReturn(SpecMilestone.PHASE0);
    when(provider.getUnsignedBeaconBlockAtSlot(ONE, signature, Optional.empty())).thenReturn(SafeFuture.completedFuture(optionalBeaconBlock));
    handler.handle(context);
    verify(context).future(args.capture());
    SafeFuture<String> result = args.getValue();
    assertThat(result).isCompletedWithValue(jsonProvider.objectToJSON(new GetNewBlockResponse(optionalBeaconBlock.get())));
}
Also used : BeaconBlockPhase0(tech.pegasys.teku.api.schema.phase0.BeaconBlockPhase0) BeaconBlock(tech.pegasys.teku.api.schema.BeaconBlock) List(java.util.List) GetNewBlockResponse(tech.pegasys.teku.api.response.v1.validator.GetNewBlockResponse) Test(org.junit.jupiter.api.Test)

Example 2 with BeaconBlockPhase0

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

the class GetNewBlockTest method shouldReturnBlockWithGraffiti.

@Test
void shouldReturnBlockWithGraffiti() throws Exception {
    final Map<String, List<String>> params = Map.of(RANDAO_REVEAL, List.of(signature.toHexString()), RestApiConstants.GRAFFITI, List.of(graffiti.toHexString()));
    Optional<BeaconBlock> optionalBeaconBlock = Optional.of(new BeaconBlockPhase0(dataStructureUtil.randomBeaconBlock(dataStructureUtil.randomLong())));
    when(context.queryParamMap()).thenReturn(params);
    when(context.pathParamMap()).thenReturn(Map.of(SLOT, "1"));
    when(provider.getMilestoneAtSlot(UInt64.ONE)).thenReturn(SpecMilestone.PHASE0);
    when(provider.getUnsignedBeaconBlockAtSlot(ONE, signature, Optional.of(graffiti))).thenReturn(SafeFuture.completedFuture(optionalBeaconBlock));
    handler.handle(context);
    verify(context).future(args.capture());
    SafeFuture<String> result = args.getValue();
    assertThat(result).isCompletedWithValue(jsonProvider.objectToJSON(new GetNewBlockResponse(optionalBeaconBlock.get())));
}
Also used : BeaconBlockPhase0(tech.pegasys.teku.api.schema.phase0.BeaconBlockPhase0) BeaconBlock(tech.pegasys.teku.api.schema.BeaconBlock) List(java.util.List) GetNewBlockResponse(tech.pegasys.teku.api.response.v1.validator.GetNewBlockResponse) Test(org.junit.jupiter.api.Test)

Example 3 with BeaconBlockPhase0

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

the class GetNewBlockResponseV2Deserializer method deserialize.

@Override
public GetNewBlockResponseV2 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 BeaconBlock block;
    switch(version) {
        case bellatrix:
            block = mapper.treeToValue(node.findValue("data"), BeaconBlockBellatrix.class);
            break;
        case altair:
            block = mapper.treeToValue(node.findValue("data"), BeaconBlockAltair.class);
            break;
        case phase0:
            block = mapper.treeToValue(node.findValue("data"), BeaconBlockPhase0.class);
            break;
        default:
            throw new IOException("Milestone was not able to be decoded");
    }
    return new GetNewBlockResponseV2(version, block);
}
Also used : GetNewBlockResponseV2(tech.pegasys.teku.api.response.v2.validator.GetNewBlockResponseV2) BeaconBlockPhase0(tech.pegasys.teku.api.schema.phase0.BeaconBlockPhase0) Version(tech.pegasys.teku.api.schema.Version) BeaconBlock(tech.pegasys.teku.api.schema.BeaconBlock) BeaconBlockBellatrix(tech.pegasys.teku.api.schema.bellatrix.BeaconBlockBellatrix) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) BeaconBlockAltair(tech.pegasys.teku.api.schema.altair.BeaconBlockAltair)

Example 4 with BeaconBlockPhase0

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

the class PostBlockTest method shouldReturnBadRequestIfArgumentNotSignedBeaconBlock.

@Test
void shouldReturnBadRequestIfArgumentNotSignedBeaconBlock() throws Exception {
    final String notASignedBlock = jsonProvider.objectToJSON(new BeaconBlockPhase0(dataStructureUtil.randomBeaconBlock(3)));
    when(syncDataProvider.isSyncing()).thenReturn(false);
    when(context.body()).thenReturn(notASignedBlock);
    when(validatorDataProvider.parseBlock(any(), any())).thenThrow(mock(JsonProcessingException.class));
    handler.handle(context);
    verify(context).status(SC_BAD_REQUEST);
}
Also used : BeaconBlockPhase0(tech.pegasys.teku.api.schema.phase0.BeaconBlockPhase0) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.jupiter.api.Test)

Aggregations

BeaconBlockPhase0 (tech.pegasys.teku.api.schema.phase0.BeaconBlockPhase0)4 Test (org.junit.jupiter.api.Test)3 BeaconBlock (tech.pegasys.teku.api.schema.BeaconBlock)3 List (java.util.List)2 GetNewBlockResponse (tech.pegasys.teku.api.response.v1.validator.GetNewBlockResponse)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 IOException (java.io.IOException)1 GetNewBlockResponseV2 (tech.pegasys.teku.api.response.v2.validator.GetNewBlockResponseV2)1 Version (tech.pegasys.teku.api.schema.Version)1 BeaconBlockAltair (tech.pegasys.teku.api.schema.altair.BeaconBlockAltair)1 BeaconBlockBellatrix (tech.pegasys.teku.api.schema.bellatrix.BeaconBlockBellatrix)1