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())));
}
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())));
}
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);
}
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);
}
Aggregations