use of tech.pegasys.teku.api.response.v2.validator.GetNewBlockResponseV2 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.response.v2.validator.GetNewBlockResponseV2 in project teku by ConsenSys.
the class OkHttpValidatorRestApiClientTest method createUnsignedBlock_WhenSuccess_ReturnsBeaconBlock.
@Test
public void createUnsignedBlock_WhenSuccess_ReturnsBeaconBlock() {
final UInt64 slot = UInt64.ONE;
final BLSSignature blsSignature = schemaObjects.blsSignature();
final Optional<Bytes32> graffiti = Optional.of(Bytes32.random());
final BeaconBlock expectedBeaconBlock = schemaObjects.beaconBlock();
mockWebServer.enqueue(new MockResponse().setResponseCode(SC_OK).setBody(asJson(new GetNewBlockResponseV2(SpecMilestone.PHASE0, expectedBeaconBlock))));
Optional<BeaconBlock> beaconBlock = apiClient.createUnsignedBlock(slot, blsSignature, graffiti);
assertThat(beaconBlock).isPresent();
assertThat(beaconBlock.get()).usingRecursiveComparison().isEqualTo(expectedBeaconBlock);
}
use of tech.pegasys.teku.api.response.v2.validator.GetNewBlockResponseV2 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.response.v2.validator.GetNewBlockResponseV2 in project teku by ConsenSys.
the class OkHttpValidatorRestApiClientTest method createUnsignedBlock_Altair_ReturnsBeaconBlock.
@Test
public void createUnsignedBlock_Altair_ReturnsBeaconBlock() {
final UInt64 slot = UInt64.ONE;
final BLSSignature blsSignature = schemaObjects.blsSignature();
final Optional<Bytes32> graffiti = Optional.of(Bytes32.random());
final BeaconBlock expectedBeaconBlock = schemaObjects.beaconBlockAltair();
mockWebServer.enqueue(new MockResponse().setResponseCode(SC_OK).setBody(asJson(new GetNewBlockResponseV2(SpecMilestone.ALTAIR, expectedBeaconBlock))));
Optional<BeaconBlock> beaconBlock = apiClient.createUnsignedBlock(slot, blsSignature, graffiti);
assertThat(beaconBlock).isPresent();
assertThat(beaconBlock.get()).usingRecursiveComparison().isEqualTo(expectedBeaconBlock);
}
Aggregations