Search in sources :

Example 1 with GetNewBlockResponseV2

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)));
}
Also used : GetNewBlockResponseV2(tech.pegasys.teku.api.response.v2.validator.GetNewBlockResponseV2) BeaconBlock(tech.pegasys.teku.api.schema.BeaconBlock) List(java.util.List) SchemaObjectProvider(tech.pegasys.teku.api.SchemaObjectProvider) Test(org.junit.jupiter.api.Test)

Example 2 with GetNewBlockResponseV2

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);
}
Also used : GetNewBlockResponseV2(tech.pegasys.teku.api.response.v2.validator.GetNewBlockResponseV2) MockResponse(okhttp3.mockwebserver.MockResponse) SignedBeaconBlock(tech.pegasys.teku.api.schema.SignedBeaconBlock) BeaconBlock(tech.pegasys.teku.api.schema.BeaconBlock) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) BLSSignature(tech.pegasys.teku.api.schema.BLSSignature) Test(org.junit.jupiter.api.Test)

Example 3 with GetNewBlockResponseV2

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);
}
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 GetNewBlockResponseV2

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);
}
Also used : GetNewBlockResponseV2(tech.pegasys.teku.api.response.v2.validator.GetNewBlockResponseV2) MockResponse(okhttp3.mockwebserver.MockResponse) SignedBeaconBlock(tech.pegasys.teku.api.schema.SignedBeaconBlock) BeaconBlock(tech.pegasys.teku.api.schema.BeaconBlock) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) BLSSignature(tech.pegasys.teku.api.schema.BLSSignature) Test(org.junit.jupiter.api.Test)

Aggregations

GetNewBlockResponseV2 (tech.pegasys.teku.api.response.v2.validator.GetNewBlockResponseV2)4 BeaconBlock (tech.pegasys.teku.api.schema.BeaconBlock)4 Test (org.junit.jupiter.api.Test)3 MockResponse (okhttp3.mockwebserver.MockResponse)2 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 BLSSignature (tech.pegasys.teku.api.schema.BLSSignature)2 SignedBeaconBlock (tech.pegasys.teku.api.schema.SignedBeaconBlock)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 IOException (java.io.IOException)1 List (java.util.List)1 SchemaObjectProvider (tech.pegasys.teku.api.SchemaObjectProvider)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 BeaconBlockPhase0 (tech.pegasys.teku.api.schema.phase0.BeaconBlockPhase0)1