use of tech.pegasys.teku.api.schema.BeaconBlock in project teku by ConsenSys.
the class BeaconBlockBodyAltairTest method asInternalBeaconBlockBody_ShouldConvertAltairBlock.
@Test
void asInternalBeaconBlockBody_ShouldConvertAltairBlock() {
final tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock internalBlock = dataStructureUtil.randomBeaconBlock(ONE);
final BeaconBlock block = schemaObjectProvider.getBeaconBlock(internalBlock);
assertThat(block).isInstanceOf(BeaconBlockAltair.class);
assertThat(block.asInternalBeaconBlock(spec)).isEqualTo(internalBlock);
}
use of tech.pegasys.teku.api.schema.BeaconBlock 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);
}
use of tech.pegasys.teku.api.schema.BeaconBlock in project teku by ConsenSys.
the class GetNewBlockV2Test method shouldReturnBlockWithoutGraffiti.
@Test
void shouldReturnBlockWithoutGraffiti() throws Exception {
final Map<String, String> pathParams = Map.of(SLOT, "1");
final SchemaObjectProvider schemaProvider = new SchemaObjectProvider(spec);
final Map<String, List<String>> queryParams = Map.of(RANDAO_REVEAL, List.of(signature.toHexString()));
final tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock randomBeaconBlock = dataStructureUtil.randomBeaconBlock(ONE);
final BeaconBlock altairBlock = schemaProvider.getBeaconBlock(randomBeaconBlock);
when(context.queryParamMap()).thenReturn(queryParams);
when(context.pathParamMap()).thenReturn(pathParams);
when(provider.getMilestoneAtSlot(UInt64.ONE)).thenReturn(SpecMilestone.ALTAIR);
when(provider.getUnsignedBeaconBlockAtSlot(ONE, signature, Optional.empty())).thenReturn(SafeFuture.completedFuture(Optional.of(altairBlock)));
handler.handle(context);
verify(context).future(args.capture());
SafeFuture<String> result = args.getValue();
assertThat(result).isCompletedWithValue(jsonProvider.objectToJSON(new GetNewBlockResponseV2(SpecMilestone.ALTAIR, altairBlock)));
}
use of tech.pegasys.teku.api.schema.BeaconBlock 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.BeaconBlock 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())));
}
Aggregations