Search in sources :

Example 1 with PostDataFailure

use of tech.pegasys.teku.api.response.v1.beacon.PostDataFailure in project teku by ConsenSys.

the class ValidatorDataProviderTest method submitAttestation_shouldSubmitAnInternalAttestationStructure.

@TestTemplate
void submitAttestation_shouldSubmitAnInternalAttestationStructure() {
    tech.pegasys.teku.spec.datastructures.operations.Attestation internalAttestation = dataStructureUtil.randomAttestation();
    Attestation attestation = new Attestation(internalAttestation);
    final List<SubmitDataError> errors = List.of(new SubmitDataError(ZERO, "Nope"));
    final SafeFuture<List<SubmitDataError>> result = SafeFuture.completedFuture(errors);
    when(validatorApiChannel.sendSignedAttestations(any())).thenReturn(result);
    assertThatSafeFuture(provider.submitAttestations(List.of(attestation))).isCompletedWithOptionalContaining(new PostDataFailureResponse(SC_BAD_REQUEST, ValidatorDataProvider.PARTIAL_PUBLISH_FAILURE_MESSAGE, List.of(new PostDataFailure(ZERO, "Nope"))));
    verify(validatorApiChannel).sendSignedAttestations(args.capture());
    assertThat(args.getValue()).hasSize(1);
    assertThatSszData(args.getValue().get(0)).isEqualByAllMeansTo(internalAttestation);
}
Also used : PostDataFailureResponse(tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse) PostDataFailure(tech.pegasys.teku.api.response.v1.beacon.PostDataFailure) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) IntList(it.unimi.dsi.fastutil.ints.IntList) Attestation(tech.pegasys.teku.api.schema.Attestation) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) TestTemplate(org.junit.jupiter.api.TestTemplate)

Example 2 with PostDataFailure

use of tech.pegasys.teku.api.response.v1.beacon.PostDataFailure in project teku by ConsenSys.

the class RemoteValidatorApiHandlerTest method sendSignedAttestation_InvokeApiWithCorrectRequest.

@Test
public void sendSignedAttestation_InvokeApiWithCorrectRequest() {
    final Attestation attestation = dataStructureUtil.randomAttestation();
    final PostDataFailureResponse failureResponse = new PostDataFailureResponse(SC_BAD_REQUEST, "Oh no", List.of(new PostDataFailure(UInt64.ZERO, "Bad")));
    when(apiClient.sendSignedAttestations(any())).thenReturn(Optional.of(failureResponse));
    final tech.pegasys.teku.api.schema.Attestation schemaAttestation = new tech.pegasys.teku.api.schema.Attestation(attestation);
    @SuppressWarnings("unchecked") ArgumentCaptor<List<tech.pegasys.teku.api.schema.Attestation>> argumentCaptor = ArgumentCaptor.forClass(List.class);
    final SafeFuture<List<SubmitDataError>> result = apiHandler.sendSignedAttestations(List.of(attestation));
    asyncRunner.executeQueuedActions();
    verify(apiClient).sendSignedAttestations(argumentCaptor.capture());
    assertThat(argumentCaptor.getValue()).usingRecursiveComparison().isEqualTo(List.of(schemaAttestation));
    assertThat(result).isCompletedWithValue(List.of(new SubmitDataError(UInt64.ZERO, "Bad")));
}
Also used : Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) PostDataFailureResponse(tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse) PostDataFailure(tech.pegasys.teku.api.response.v1.beacon.PostDataFailure) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) IntList(it.unimi.dsi.fastutil.ints.IntList) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Test(org.junit.jupiter.api.Test)

Example 3 with PostDataFailure

use of tech.pegasys.teku.api.response.v1.beacon.PostDataFailure in project teku by ConsenSys.

the class PostAttestationTest method shouldReportInvalidAttestations.

@Test
void shouldReportInvalidAttestations() throws Exception {
    final PostDataFailureResponse failureResponse = new PostDataFailureResponse(SC_BAD_REQUEST, "Some attestations failed to publish, refer to errors for details", List.of(new PostDataFailure(UInt64.ZERO, "Darn")));
    when(provider.submitAttestations(any())).thenReturn(SafeFuture.completedFuture(Optional.of(failureResponse)));
    when(context.body()).thenReturn(jsonProvider.objectToJSON(List.of(attestation)));
    handler.handle(context);
    @SuppressWarnings("unchecked") final ArgumentCaptor<CompletableFuture<Object>> captor = ArgumentCaptor.forClass(SafeFuture.class);
    verify(context).future(captor.capture());
    verify(context).status(SC_BAD_REQUEST);
    final CompletableFuture<Object> bodyResult = captor.getValue();
    final String value = jsonProvider.objectToJSON(failureResponse);
    assertThat(bodyResult).isCompletedWithValue(value);
}
Also used : PostDataFailureResponse(tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse) PostDataFailure(tech.pegasys.teku.api.response.v1.beacon.PostDataFailure) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.jupiter.api.Test)

Example 4 with PostDataFailure

use of tech.pegasys.teku.api.response.v1.beacon.PostDataFailure 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 5 with PostDataFailure

use of tech.pegasys.teku.api.response.v1.beacon.PostDataFailure in project teku by ConsenSys.

the class OkHttpValidatorRestApiClientTest method sendSignedAttestation_WhenBadParameters_ThrowsIllegalArgumentException.

@Test
public void sendSignedAttestation_WhenBadParameters_ThrowsIllegalArgumentException() {
    final Attestation attestation = schemaObjects.attestation();
    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.sendSignedAttestations(List.of(attestation))).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) Attestation(tech.pegasys.teku.api.schema.Attestation) Test(org.junit.jupiter.api.Test)

Aggregations

PostDataFailure (tech.pegasys.teku.api.response.v1.beacon.PostDataFailure)6 PostDataFailureResponse (tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse)6 Test (org.junit.jupiter.api.Test)5 MockResponse (okhttp3.mockwebserver.MockResponse)3 IntList (it.unimi.dsi.fastutil.ints.IntList)2 Collections.emptyList (java.util.Collections.emptyList)2 List (java.util.List)2 Attestation (tech.pegasys.teku.api.schema.Attestation)2 SubmitDataError (tech.pegasys.teku.validator.api.SubmitDataError)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 Collectors.toList (java.util.stream.Collectors.toList)1 TestTemplate (org.junit.jupiter.api.TestTemplate)1 SignedAggregateAndProof (tech.pegasys.teku.api.schema.SignedAggregateAndProof)1 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)1