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);
}
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")));
}
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);
}
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);
}
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);
}
Aggregations