Search in sources :

Example 1 with PostDataFailureResponse

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

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

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

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

the class PostSyncCommitteesIntegrationTest method shouldSubmitSyncCommitteesAndGetResponse.

@Test
void shouldSubmitSyncCommitteesAndGetResponse() throws IOException {
    spec = TestSpecFactory.createMinimalAltair();
    DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
    startRestAPIAtGenesis(SpecMilestone.ALTAIR);
    final List<SyncCommitteeMessage> requestBody = List.of(new SyncCommitteeMessage(UInt64.ONE, dataStructureUtil.randomBytes32(), dataStructureUtil.randomUInt64(), new BLSSignature(dataStructureUtil.randomSignature())));
    final SafeFuture<List<SubmitDataError>> future = SafeFuture.completedFuture(List.of(new SubmitDataError(UInt64.ZERO, errorString)));
    when(validatorApiChannel.sendSyncCommitteeMessages(requestBody.get(0).asInternalCommitteeSignature(spec).stream().collect(Collectors.toList()))).thenReturn(future);
    Response response = post(PostSyncCommittees.ROUTE, jsonProvider.objectToJSON(requestBody));
    assertThat(response.code()).isEqualTo(SC_BAD_REQUEST);
    final PostDataFailureResponse responseBody = jsonProvider.jsonToObject(response.body().string(), PostDataFailureResponse.class);
    assertThat(responseBody.failures.get(0).message).isEqualTo(errorString);
}
Also used : PostDataFailureResponse(tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse) Response(okhttp3.Response) PostDataFailureResponse(tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse) List(java.util.List) SyncCommitteeMessage(tech.pegasys.teku.api.schema.altair.SyncCommitteeMessage) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) BLSSignature(tech.pegasys.teku.api.schema.BLSSignature) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Example 5 with PostDataFailureResponse

use of tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse 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)

Aggregations

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