use of tech.pegasys.teku.validator.api.SubmitDataError in project teku by ConsenSys.
the class ValidatorApiHandlerTest method sendSignedAttestations_shouldProcessMixOfValidAndInvalidAttestations.
@Test
void sendSignedAttestations_shouldProcessMixOfValidAndInvalidAttestations() {
final Attestation invalidAttestation = dataStructureUtil.randomAttestation();
final Attestation validAttestation = dataStructureUtil.randomAttestation();
when(attestationManager.onAttestation(validatableAttestationOf(invalidAttestation))).thenReturn(completedFuture(AttestationProcessingResult.invalid("Bad juju")));
when(attestationManager.onAttestation(validatableAttestationOf(validAttestation))).thenReturn(completedFuture(SUCCESSFUL));
final SafeFuture<List<SubmitDataError>> result = validatorApiHandler.sendSignedAttestations(List.of(invalidAttestation, validAttestation));
assertThat(result).isCompletedWithValue(List.of(new SubmitDataError(ZERO, "Bad juju")));
verify(dutyMetrics, never()).onAttestationPublished(invalidAttestation.getData().getSlot());
verify(dutyMetrics).onAttestationPublished(validAttestation.getData().getSlot());
verify(performanceTracker, never()).saveProducedAttestation(invalidAttestation);
verify(performanceTracker).saveProducedAttestation(validAttestation);
}
use of tech.pegasys.teku.validator.api.SubmitDataError in project teku by ConsenSys.
the class ValidatorApiHandlerTest method sendSyncCommitteeMessages_shouldRaiseErrors.
@Test
void sendSyncCommitteeMessages_shouldRaiseErrors() {
final SyncCommitteeMessage message = dataStructureUtil.randomSyncCommitteeMessage();
final List<SyncCommitteeMessage> messages = List.of(message);
when(syncCommitteeMessagePool.add(any())).thenReturn(SafeFuture.completedFuture(InternalValidationResult.create(ValidationResultCode.REJECT, "Rejected")));
final SafeFuture<List<SubmitDataError>> result = validatorApiHandler.sendSyncCommitteeMessages(messages);
assertThat(result).isCompletedWithValue(List.of(new SubmitDataError(UInt64.ZERO, "Rejected")));
verify(performanceTracker, never()).saveProducedSyncCommitteeMessage(message);
}
use of tech.pegasys.teku.validator.api.SubmitDataError in project teku by ConsenSys.
the class ValidatorApiHandlerTest method sendAggregateAndProofs_shouldProcessMixOfValidAndInvalidAggregates.
@Test
void sendAggregateAndProofs_shouldProcessMixOfValidAndInvalidAggregates() {
final SignedAggregateAndProof invalidAggregate = dataStructureUtil.randomSignedAggregateAndProof();
final SignedAggregateAndProof validAggregate = dataStructureUtil.randomSignedAggregateAndProof();
when(attestationManager.onAttestation(ValidateableAttestation.aggregateFromValidator(spec, invalidAggregate))).thenReturn(completedFuture(AttestationProcessingResult.invalid("Bad juju")));
when(attestationManager.onAttestation(ValidateableAttestation.aggregateFromValidator(spec, validAggregate))).thenReturn(completedFuture(SUCCESSFUL));
final SafeFuture<List<SubmitDataError>> result = validatorApiHandler.sendAggregateAndProofs(List.of(invalidAggregate, validAggregate));
assertThat(result).isCompletedWithValue(List.of(new SubmitDataError(ZERO, "Bad juju")));
// Should send both to the attestation manager.
verify(attestationManager).onAttestation(argThat(validatableAttestation -> validatableAttestation.getSignedAggregateAndProof().equals(validAggregate)));
verify(attestationManager).onAttestation(argThat(validatableAttestation -> validatableAttestation.getSignedAggregateAndProof().equals(invalidAggregate)));
}
use of tech.pegasys.teku.validator.api.SubmitDataError in project teku by ConsenSys.
the class MetricRecordingValidatorApiChannelTest method getSendDataArguments.
public static Stream<Arguments> getSendDataArguments() {
final DataStructureUtil dataStructureUtil = new DataStructureUtil(TestSpecFactory.createMinimalAltair());
final List<SubmitDataError> submissionErrors = List.of(new SubmitDataError(UInt64.ZERO, "Nope"));
final List<Attestation> attestations = List.of(dataStructureUtil.randomAttestation());
final List<SyncCommitteeMessage> syncCommitteeMessages = List.of(dataStructureUtil.randomSyncCommitteeMessage());
final List<SignedAggregateAndProof> aggregateAndProofs = List.of(dataStructureUtil.randomSignedAggregateAndProof());
return Stream.of(sendDataTest("sendSignedAttestations", channel -> channel.sendSignedAttestations(attestations), MetricRecordingValidatorApiChannel.PUBLISHED_ATTESTATION_COUNTER_NAME, submissionErrors), sendDataTest("sendSyncCommitteeMessages", channel -> channel.sendSyncCommitteeMessages(syncCommitteeMessages), MetricRecordingValidatorApiChannel.SYNC_COMMITTEE_SEND_MESSAGES_NAME, submissionErrors), sendDataTest("sendAggregateAndProofs", channel -> channel.sendAggregateAndProofs(aggregateAndProofs), MetricRecordingValidatorApiChannel.PUBLISHED_AGGREGATE_COUNTER_NAME, submissionErrors));
}
use of tech.pegasys.teku.validator.api.SubmitDataError in project teku by ConsenSys.
the class AttestationProductionDutyTest method shouldReportFailureWhenAttestationIsInvalid.
@Test
void shouldReportFailureWhenAttestationIsInvalid() {
final int committeeIndex = 3;
final int committeePosition = 6;
final int committeeSize = 22;
final Validator validator = createValidator();
final AttestationData attestationData = expectCreateAttestationData(committeeIndex);
final Attestation expectedAttestation = expectSignAttestation(validator, committeePosition, committeeSize, attestationData);
when(validatorApiChannel.sendSignedAttestations(List.of(expectedAttestation))).thenReturn(SafeFuture.completedFuture(List.of(new SubmitDataError(UInt64.ZERO, "Naughty attestation"))));
final SafeFuture<Optional<AttestationData>> attestationResult = duty.addValidator(validator, committeeIndex, committeePosition, 10, committeeSize);
performAndReportDuty();
assertThat(attestationResult).isCompletedWithValue(Optional.of(attestationData));
verify(validatorApiChannel).sendSignedAttestations(List.of(expectedAttestation));
verify(validatorLogger).dutyFailed(eq(TYPE), eq(SLOT), eq(Set.of(validator.getPublicKey().toAbbreviatedString())), argThat(error -> error instanceof RestApiReportedException && error.getMessage().equals("Naughty attestation")));
verifyNoMoreInteractions(validatorLogger);
}
Aggregations