Search in sources :

Example 1 with BeaconBlock

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);
}
Also used : BeaconBlock(tech.pegasys.teku.api.schema.BeaconBlock) Test(org.junit.jupiter.api.Test)

Example 2 with BeaconBlock

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);
}
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 3 with BeaconBlock

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)));
}
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 4 with BeaconBlock

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())));
}
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 5 with BeaconBlock

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

BeaconBlock (tech.pegasys.teku.api.schema.BeaconBlock)11 Test (org.junit.jupiter.api.Test)7 GetNewBlockResponseV2 (tech.pegasys.teku.api.response.v2.validator.GetNewBlockResponseV2)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 List (java.util.List)3 GetNewBlockResponse (tech.pegasys.teku.api.response.v1.validator.GetNewBlockResponse)3 BeaconBlockPhase0 (tech.pegasys.teku.api.schema.phase0.BeaconBlockPhase0)3 IOException (java.io.IOException)2 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 BeaconBlockAltair (tech.pegasys.teku.api.schema.altair.BeaconBlockAltair)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 ObjectCodec (com.fasterxml.jackson.core.ObjectCodec)1 Bytes (org.apache.tuweni.bytes.Bytes)1 SchemaObjectProvider (tech.pegasys.teku.api.SchemaObjectProvider)1 BeaconBlockBody (tech.pegasys.teku.api.schema.BeaconBlockBody)1 Eth1Data (tech.pegasys.teku.api.schema.Eth1Data)1 Version (tech.pegasys.teku.api.schema.Version)1