Search in sources :

Example 1 with SignedAggregateAndProof

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

the class OkHttpValidatorRestApiClientTest method sendAggregateAndProofs_MakesExpectedRequest.

@Test
public void sendAggregateAndProofs_MakesExpectedRequest() throws Exception {
    final SignedAggregateAndProof signedAggregateAndProof = schemaObjects.signedAggregateAndProof();
    mockWebServer.enqueue(new MockResponse().setResponseCode(SC_OK));
    apiClient.sendAggregateAndProofs(List.of(signedAggregateAndProof));
    RecordedRequest request = mockWebServer.takeRequest();
    assertThat(request.getMethod()).isEqualTo("POST");
    assertThat(request.getPath()).contains(ValidatorApiMethod.SEND_SIGNED_AGGREGATE_AND_PROOF.getPath(emptyMap()));
    assertThat(request.getBody().readString(StandardCharsets.UTF_8)).isEqualTo(asJson(List.of(signedAggregateAndProof)));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) SignedAggregateAndProof(tech.pegasys.teku.api.schema.SignedAggregateAndProof) Test(org.junit.jupiter.api.Test)

Example 2 with SignedAggregateAndProof

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

the class OkHttpValidatorRestApiClientTest method sendAggregateAndProofs_WhenBadParameters_ReturnsErrorResponse.

@Test
public void sendAggregateAndProofs_WhenBadParameters_ReturnsErrorResponse() {
    final SignedAggregateAndProof signedAggregateAndProof = schemaObjects.signedAggregateAndProof();
    final PostDataFailureResponse response = new PostDataFailureResponse(SC_BAD_REQUEST, "Computer said no", List.of(new PostDataFailure(UInt64.ZERO, "Bad")));
    mockWebServer.enqueue(new MockResponse().setResponseCode(SC_BAD_REQUEST).setBody(asJson(response)));
    assertThat(apiClient.sendAggregateAndProofs(List.of(signedAggregateAndProof))).isPresent().get().usingRecursiveComparison().isEqualTo(response);
}
Also used : PostDataFailureResponse(tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse) MockResponse(okhttp3.mockwebserver.MockResponse) PostDataFailure(tech.pegasys.teku.api.response.v1.beacon.PostDataFailure) SignedAggregateAndProof(tech.pegasys.teku.api.schema.SignedAggregateAndProof) Test(org.junit.jupiter.api.Test)

Example 3 with SignedAggregateAndProof

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

the class OkHttpValidatorRestApiClientTest method sendAggregateAndProofs_WhenServerError_ThrowsRuntimeException.

@Test
public void sendAggregateAndProofs_WhenServerError_ThrowsRuntimeException() {
    final SignedAggregateAndProof signedAggregateAndProof = schemaObjects.signedAggregateAndProof();
    mockWebServer.enqueue(new MockResponse().setResponseCode(SC_INTERNAL_SERVER_ERROR));
    assertThatThrownBy(() -> apiClient.sendAggregateAndProofs(List.of(signedAggregateAndProof))).isInstanceOf(RuntimeException.class).hasMessageContaining("Unexpected response from Beacon Node API");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) SignedAggregateAndProof(tech.pegasys.teku.api.schema.SignedAggregateAndProof) Test(org.junit.jupiter.api.Test)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)3 Test (org.junit.jupiter.api.Test)3 SignedAggregateAndProof (tech.pegasys.teku.api.schema.SignedAggregateAndProof)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 PostDataFailure (tech.pegasys.teku.api.response.v1.beacon.PostDataFailure)1 PostDataFailureResponse (tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse)1