use of tech.pegasys.teku.validator.api.SubmitDataError in project teku by ConsenSys.
the class SyncCommitteeProductionDutyTest method shouldReportPartialFailureWhenBeaconNodeRejectsSomeMessages.
@Test
void shouldReportPartialFailureWhenBeaconNodeRejectsSomeMessages() {
final UInt64 slot = UInt64.valueOf(48);
final int validatorIndex1 = 11;
final int validatorIndex2 = 22;
final Validator validator2 = createValidator();
final BLSSignature signature1 = dataStructureUtil.randomSignature();
final BLSSignature signature2 = dataStructureUtil.randomSignature();
final SyncCommitteeProductionDuty duties = createDuty(committeeAssignment(validator, validatorIndex1, 1, 2, 3), committeeAssignment(validator2, validatorIndex2, 1, 5));
when(validator.getSigner().signSyncCommitteeMessage(slot, blockRoot, forkInfo)).thenReturn(SafeFuture.completedFuture(signature1));
when(validator2.getSigner().signSyncCommitteeMessage(slot, blockRoot, forkInfo)).thenReturn(SafeFuture.completedFuture(signature2));
when(validatorApiChannel.sendSyncCommitteeMessages(any())).thenReturn(SafeFuture.completedFuture(List.of(new SubmitDataError(UInt64.ZERO, "API Rejected"))));
produceMessagesAndReport(duties, slot);
assertSentMessages(createMessage(slot, blockRoot, validatorIndex1, signature1), createMessage(slot, blockRoot, validatorIndex2, signature2));
verify(validatorLogger).dutyCompleted(MESSAGE_TYPE, slot, 1, Set.of(blockRoot));
verify(validatorLogger).dutyFailed(eq(MESSAGE_TYPE), eq(slot), eq(Set.of(validator.getPublicKey().toAbbreviatedString())), argThat(error -> error.getMessage().equals("API Rejected")));
}
use of tech.pegasys.teku.validator.api.SubmitDataError 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.validator.api.SubmitDataError 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.validator.api.SubmitDataError in project teku by ConsenSys.
the class ValidatorApiHandlerTest method sendSignedAttestations_shouldNotAddToDutyMetricsAndPerformanceTrackerWhenInvalid.
@Test
void sendSignedAttestations_shouldNotAddToDutyMetricsAndPerformanceTrackerWhenInvalid() {
final Attestation attestation = dataStructureUtil.randomAttestation();
when(attestationManager.onAttestation(any(ValidateableAttestation.class))).thenReturn(completedFuture(AttestationProcessingResult.invalid("Bad juju")));
final SafeFuture<List<SubmitDataError>> result = validatorApiHandler.sendSignedAttestations(List.of(attestation));
assertThat(result).isCompletedWithValue(List.of(new SubmitDataError(ZERO, "Bad juju")));
verify(dutyMetrics, never()).onAttestationPublished(attestation.getData().getSlot());
verify(performanceTracker, never()).saveProducedAttestation(attestation);
}
use of tech.pegasys.teku.validator.api.SubmitDataError 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);
}
Aggregations