use of tech.pegasys.teku.validator.client.Validator in project teku by ConsenSys.
the class AttestationProductionDutyTest method shouldCreateAttestationForMultipleValidatorsInDifferentCommittees.
@SuppressWarnings("unchecked")
@Test
public void shouldCreateAttestationForMultipleValidatorsInDifferentCommittees() {
final int committeeIndex1 = 3;
final int committeeIndex2 = 5;
final int committeeSize1 = 15;
final int committeeSize2 = 20;
final int validator1CommitteePosition = 6;
final int validator2CommitteePosition = 2;
final int validator3CommitteePosition = 5;
final Validator validator1 = createValidator();
final Validator validator2 = createValidator();
final Validator validator3 = createValidator();
final AttestationData unsignedAttestation1 = expectCreateAttestationData(committeeIndex1);
final AttestationData unsignedAttestation2 = expectCreateAttestationData(committeeIndex2);
final Attestation expectedAttestation1 = expectSignAttestation(validator1, validator1CommitteePosition, committeeSize1, unsignedAttestation1);
final Attestation expectedAttestation2 = expectSignAttestation(validator2, validator2CommitteePosition, committeeSize2, unsignedAttestation2);
final Attestation expectedAttestation3 = expectSignAttestation(validator3, validator3CommitteePosition, committeeSize1, unsignedAttestation1);
final SafeFuture<Optional<AttestationData>> attestationResult1 = duty.addValidator(validator1, committeeIndex1, validator1CommitteePosition, 10, committeeSize1);
final SafeFuture<Optional<AttestationData>> attestationResult2 = duty.addValidator(validator2, committeeIndex2, validator2CommitteePosition, 10, committeeSize2);
final SafeFuture<Optional<AttestationData>> attestationResult3 = duty.addValidator(validator3, committeeIndex1, validator3CommitteePosition, 10, committeeSize1);
performAndReportDuty();
assertThat(attestationResult1).isCompletedWithValue(Optional.of(unsignedAttestation1));
assertThat(attestationResult2).isCompletedWithValue(Optional.of(unsignedAttestation2));
assertThat(attestationResult3).isCompletedWithValue(Optional.of(unsignedAttestation1));
ArgumentCaptor<List<Attestation>> argumentCaptor = ArgumentCaptor.forClass(List.class);
verify(validatorApiChannel).sendSignedAttestations(argumentCaptor.capture());
assertThat(argumentCaptor.getValue()).containsExactlyInAnyOrder(expectedAttestation1, expectedAttestation2, expectedAttestation3);
// Need to create an unsigned attestation for each committee
verify(validatorApiChannel, times(2)).createAttestationData(any(), anyInt());
verify(validatorLogger).dutyCompleted(TYPE, SLOT, 3, Set.of(unsignedAttestation1.getBeacon_block_root(), unsignedAttestation2.getBeacon_block_root()));
verifyNoMoreInteractions(validatorLogger);
}
use of tech.pegasys.teku.validator.client.Validator 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);
}
use of tech.pegasys.teku.validator.client.Validator in project teku by ConsenSys.
the class AttestationProductionDutyTest method shouldPublishProducedAttestationsWhenSomeUnsignedAttestationsFail.
@Test
public void shouldPublishProducedAttestationsWhenSomeUnsignedAttestationsFail() {
final Validator validator1 = createValidator();
final Validator validator2 = createValidator();
final int validator1CommitteeIndex = 0;
final int validator1CommitteePosition = 5;
final int validator2CommitteeIndex = 1;
final int validator2CommitteePosition = 3;
final int validator2CommitteeSize = 12;
final RuntimeException failure = new RuntimeException("Golly gee");
when(validatorApiChannel.createAttestationData(SLOT, validator1CommitteeIndex)).thenReturn(failedFuture(failure));
final AttestationData attestationData = expectCreateAttestationData(validator2CommitteeIndex);
final Attestation expectedAttestation = expectSignAttestation(validator2, validator2CommitteePosition, validator2CommitteeSize, attestationData);
final SafeFuture<Optional<AttestationData>> attestationResult1 = duty.addValidator(validator1, validator1CommitteeIndex, validator1CommitteePosition, 10, 11);
final SafeFuture<Optional<AttestationData>> attestationResult2 = duty.addValidator(validator2, validator2CommitteeIndex, validator2CommitteePosition, 10, validator2CommitteeSize);
performAndReportDuty();
assertThat(attestationResult1).isCompletedExceptionally();
assertThatThrownBy(attestationResult1::join).hasRootCause(failure);
assertThat(attestationResult2).isCompletedWithValue(Optional.of(attestationData));
verify(validatorApiChannel).sendSignedAttestations(List.of(expectedAttestation));
verify(validatorLogger).dutyCompleted(TYPE, SLOT, 1, Set.of(attestationData.getBeacon_block_root()));
verify(validatorLogger).dutyFailed(TYPE, SLOT, Set.of(validator1.getPublicKey().toAbbreviatedString()), failure);
verifyNoMoreInteractions(validatorLogger);
}
use of tech.pegasys.teku.validator.client.Validator in project teku by ConsenSys.
the class AttestationProductionDutyTest method shouldFailWhenUnsignedAttestationCanNotBeCreated.
@Test
public void shouldFailWhenUnsignedAttestationCanNotBeCreated() {
final Validator validator = createValidator();
when(validatorApiChannel.createAttestationData(SLOT, 0)).thenReturn(completedFuture(Optional.empty()));
final SafeFuture<Optional<AttestationData>> attestationFuture = duty.addValidator(validator, 0, 5, 10, 11);
performAndReportDuty();
assertThat(attestationFuture).isCompletedWithValue(Optional.empty());
verify(validatorLogger).dutyFailed(eq(TYPE), eq(SLOT), eq(Set.of(validator.getPublicKey().toAbbreviatedString())), any(IllegalStateException.class));
verifyNoMoreInteractions(validatorLogger);
}
use of tech.pegasys.teku.validator.client.Validator in project teku by ConsenSys.
the class AttestationProductionDutyTest method shouldPublishProducedAttestationsWhenSignerFailsForSomeAttestations.
@Test
public void shouldPublishProducedAttestationsWhenSignerFailsForSomeAttestations() {
final Validator validator1 = createValidator();
final Validator validator2 = createValidator();
final int committeeIndex = 0;
final int validator1CommitteePosition = 5;
final int validator2CommitteePosition = 3;
final int validator1CommitteeSize = 23;
final int validator2CommitteeSize = 39;
final AttestationData attestationData = expectCreateAttestationData(committeeIndex);
final RuntimeException signingFailure = new RuntimeException("Gosh darn");
when(validator1.getSigner().signAttestationData(attestationData, fork)).thenReturn(failedFuture(signingFailure));
final Attestation expectedAttestation = expectSignAttestation(validator2, validator2CommitteePosition, validator2CommitteeSize, attestationData);
final SafeFuture<Optional<AttestationData>> attestationResult1 = duty.addValidator(validator1, committeeIndex, validator1CommitteePosition, 10, validator1CommitteeSize);
final SafeFuture<Optional<AttestationData>> attestationResult2 = duty.addValidator(validator2, committeeIndex, validator2CommitteePosition, 10, validator2CommitteeSize);
performAndReportDuty();
assertThat(attestationResult1).isCompletedWithValue(Optional.of(attestationData));
assertThat(attestationResult2).isCompletedWithValue(Optional.of(attestationData));
verify(validatorApiChannel).sendSignedAttestations(List.of(expectedAttestation));
verify(validatorLogger).dutyCompleted(TYPE, SLOT, 1, Set.of(attestationData.getBeacon_block_root()));
verify(validatorLogger).dutyFailed(TYPE, SLOT, Set.of(validator1.getPublicKey().toAbbreviatedString()), signingFailure);
verifyNoMoreInteractions(validatorLogger);
}
Aggregations