Search in sources :

Example 1 with GetNewBlockResponse

use of tech.pegasys.teku.api.response.v1.validator.GetNewBlockResponse in project teku by ConsenSys.

the class GetNewBlockResponseV1Deserializer method deserialize.

@Override
public GetNewBlockResponse deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException {
    JsonNode node = jp.getCodec().readTree(jp);
    final BeaconBlock block = mapper.treeToValue(node.findValue("data"), BeaconBlockPhase0.class);
    return new GetNewBlockResponse(block);
}
Also used : BeaconBlock(tech.pegasys.teku.api.schema.BeaconBlock) JsonNode(com.fasterxml.jackson.databind.JsonNode) GetNewBlockResponse(tech.pegasys.teku.api.response.v1.validator.GetNewBlockResponse)

Example 2 with GetNewBlockResponse

use of tech.pegasys.teku.api.response.v1.validator.GetNewBlockResponse 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 3 with GetNewBlockResponse

use of tech.pegasys.teku.api.response.v1.validator.GetNewBlockResponse 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)

Aggregations

GetNewBlockResponse (tech.pegasys.teku.api.response.v1.validator.GetNewBlockResponse)3 BeaconBlock (tech.pegasys.teku.api.schema.BeaconBlock)3 List (java.util.List)2 Test (org.junit.jupiter.api.Test)2 BeaconBlockPhase0 (tech.pegasys.teku.api.schema.phase0.BeaconBlockPhase0)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1