Search in sources :

Example 1 with BLSSignature

use of tech.pegasys.teku.api.schema.BLSSignature in project teku by ConsenSys.

the class SingleQueryParameterUtilsTest method getParameterAsBLSSignature_shouldParseBytes96Data.

@Test
public void getParameterAsBLSSignature_shouldParseBytes96Data() {
    BLSSignature signature = new BLSSignature(Bytes.random(96));
    Map<String, List<String>> data = Map.of(KEY, List.of(signature.toHexString()));
    BLSSignature result = getParameterValueAsBLSSignature(data, KEY);
    assertEquals(signature, result);
}
Also used : List(java.util.List) SingleQueryParameterUtils.getParameterValueAsBLSSignature(tech.pegasys.teku.beaconrestapi.SingleQueryParameterUtils.getParameterValueAsBLSSignature) BLSSignature(tech.pegasys.teku.api.schema.BLSSignature) Test(org.junit.jupiter.api.Test)

Example 2 with BLSSignature

use of tech.pegasys.teku.api.schema.BLSSignature 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 BLSSignature

use of tech.pegasys.teku.api.schema.BLSSignature in project teku by ConsenSys.

the class OkHttpValidatorRestApiClientTest method createUnsignedBlock_MakesExpectedRequest.

@Test
public void createUnsignedBlock_MakesExpectedRequest() throws Exception {
    final UInt64 slot = UInt64.ONE;
    final BLSSignature blsSignature = schemaObjects.blsSignature();
    final Optional<Bytes32> graffiti = Optional.of(Bytes32.random());
    mockWebServer.enqueue(new MockResponse().setResponseCode(SC_NO_CONTENT));
    apiClient.createUnsignedBlock(slot, blsSignature, graffiti);
    RecordedRequest request = mockWebServer.takeRequest();
    assertThat(request.getMethod()).isEqualTo("GET");
    assertThat(request.getPath()).contains(ValidatorApiMethod.GET_UNSIGNED_BLOCK_V2.getPath(Map.of("slot", "1")));
    assertThat(request.getRequestUrl().queryParameter("randao_reveal")).isEqualTo(blsSignature.toHexString());
    assertThat(request.getRequestUrl().queryParameter("graffiti")).isEqualTo(graffiti.get().toHexString());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) 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 4 with BLSSignature

use of tech.pegasys.teku.api.schema.BLSSignature in project teku by ConsenSys.

the class OkHttpValidatorRestApiClientTest method createUnsignedBlock_WhenNoContent_ReturnsEmpty.

@Test
public void createUnsignedBlock_WhenNoContent_ReturnsEmpty() {
    final UInt64 slot = UInt64.ONE;
    final BLSSignature blsSignature = schemaObjects.blsSignature();
    final Optional<Bytes32> graffiti = Optional.of(Bytes32.random());
    mockWebServer.enqueue(new MockResponse().setResponseCode(SC_NO_CONTENT));
    assertThat(apiClient.createUnsignedBlock(slot, blsSignature, graffiti)).isEmpty();
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) 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 5 with BLSSignature

use of tech.pegasys.teku.api.schema.BLSSignature in project teku by ConsenSys.

the class OkHttpValidatorRestApiClientTest method createUnsignedBlock_WhenBadRequest_ThrowsIllegalArgumentException.

@Test
public void createUnsignedBlock_WhenBadRequest_ThrowsIllegalArgumentException() {
    final UInt64 slot = UInt64.ONE;
    final BLSSignature blsSignature = schemaObjects.blsSignature();
    final Optional<Bytes32> graffiti = Optional.of(Bytes32.random());
    mockWebServer.enqueue(new MockResponse().setResponseCode(SC_BAD_REQUEST));
    assertThatThrownBy(() -> apiClient.createUnsignedBlock(slot, blsSignature, graffiti)).isInstanceOf(IllegalArgumentException.class);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) 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

BLSSignature (tech.pegasys.teku.api.schema.BLSSignature)12 Test (org.junit.jupiter.api.Test)10 Bytes32 (org.apache.tuweni.bytes.Bytes32)6 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)6 MockResponse (okhttp3.mockwebserver.MockResponse)5 List (java.util.List)4 Response (okhttp3.Response)3 PostDataFailureResponse (tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse)3 BeaconBlock (tech.pegasys.teku.api.schema.BeaconBlock)3 SyncCommitteeMessage (tech.pegasys.teku.api.schema.altair.SyncCommitteeMessage)3 AbstractDataBackedRestAPIIntegrationTest (tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)3 DataStructureUtil (tech.pegasys.teku.spec.util.DataStructureUtil)3 GetNewBlockResponseV2 (tech.pegasys.teku.api.response.v2.validator.GetNewBlockResponseV2)2 SignedBeaconBlock (tech.pegasys.teku.api.schema.SignedBeaconBlock)2 SingleQueryParameterUtils.getParameterValueAsBLSSignature (tech.pegasys.teku.beaconrestapi.SingleQueryParameterUtils.getParameterValueAsBLSSignature)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Throwables (com.google.common.base.Throwables)1 Context (io.javalin.http.Context)1 Handler (io.javalin.http.Handler)1 HttpMethod (io.javalin.plugin.openapi.annotations.HttpMethod)1