Search in sources :

Example 1 with ValidatorLogger

use of tech.pegasys.teku.infrastructure.logging.ValidatorLogger 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);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) AttestationSchema(tech.pegasys.teku.spec.datastructures.operations.Attestation.AttestationSchema) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SszBitlist(tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) SafeFuture.completedFuture(tech.pegasys.teku.infrastructure.async.SafeFuture.completedFuture) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) Signer(tech.pegasys.teku.core.signatures.Signer) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) ForkProvider(tech.pegasys.teku.validator.client.ForkProvider) BatchAttestationSendingStrategy(tech.pegasys.teku.validator.client.duties.attestations.BatchAttestationSendingStrategy) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) SafeFuture.failedFuture(tech.pegasys.teku.infrastructure.async.SafeFuture.failedFuture) Spec(tech.pegasys.teku.spec.Spec) FileBackedGraffitiProvider(tech.pegasys.teku.validator.api.FileBackedGraffitiProvider) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) ValidatorLogger(tech.pegasys.teku.infrastructure.logging.ValidatorLogger) BLSSignature(tech.pegasys.teku.bls.BLSSignature) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) AttestationProductionDuty(tech.pegasys.teku.validator.client.duties.attestations.AttestationProductionDuty) List(java.util.List) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Optional(java.util.Optional) Collections(java.util.Collections) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Mockito.mock(org.mockito.Mockito.mock) Validator(tech.pegasys.teku.validator.client.Validator) AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) Optional(java.util.Optional) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Validator(tech.pegasys.teku.validator.client.Validator) Test(org.junit.jupiter.api.Test)

Example 2 with ValidatorLogger

use of tech.pegasys.teku.infrastructure.logging.ValidatorLogger 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")));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) SchemaDefinitionsAltair(tech.pegasys.teku.spec.schemas.SchemaDefinitionsAltair) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) Signer(tech.pegasys.teku.core.signatures.Signer) ArgumentCaptor(org.mockito.ArgumentCaptor) ForkProvider(tech.pegasys.teku.validator.client.ForkProvider) Arrays.asList(java.util.Arrays.asList) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) Spec(tech.pegasys.teku.spec.Spec) Bytes32(org.apache.tuweni.bytes.Bytes32) DutyResult(tech.pegasys.teku.validator.client.duties.DutyResult) ValidatorLogger(tech.pegasys.teku.infrastructure.logging.ValidatorLogger) BLSSignature(tech.pegasys.teku.bls.BLSSignature) Collections.emptyList(java.util.Collections.emptyList) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) List(java.util.List) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) SyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage) IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Optional(java.util.Optional) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Mockito.mock(org.mockito.Mockito.mock) Validator(tech.pegasys.teku.validator.client.Validator) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Validator(tech.pegasys.teku.validator.client.Validator) BLSSignature(tech.pegasys.teku.bls.BLSSignature) Test(org.junit.jupiter.api.Test)

Example 3 with ValidatorLogger

use of tech.pegasys.teku.infrastructure.logging.ValidatorLogger in project teku by ConsenSys.

the class SlashingProtectionLoggerTest method beforeEach.

@BeforeEach
public void beforeEach() throws Exception {
    when(slashingProtector.getSigningRecord(any())).thenReturn(Optional.empty());
    this.asyncRunner = new StubAsyncRunner();
    this.validatorLogger = mock(ValidatorLogger.class);
    this.slashingProtectionLogger = new SlashingProtectionLogger(slashingProtector, spec, asyncRunner, validatorLogger);
    this.slashingProtectionLogger.onSlot(UInt64.ONE);
}
Also used : ValidatorLogger(tech.pegasys.teku.infrastructure.logging.ValidatorLogger) StubAsyncRunner(tech.pegasys.teku.infrastructure.async.StubAsyncRunner) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

BeforeEach (org.junit.jupiter.api.BeforeEach)3 ValidatorLogger (tech.pegasys.teku.infrastructure.logging.ValidatorLogger)3 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Test (org.junit.jupiter.api.Test)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)2 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.verify (org.mockito.Mockito.verify)2 Mockito.verifyNoInteractions (org.mockito.Mockito.verifyNoInteractions)2 Mockito.when (org.mockito.Mockito.when)2 BLSSignature (tech.pegasys.teku.bls.BLSSignature)2 Signer (tech.pegasys.teku.core.signatures.Signer)2 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 Spec (tech.pegasys.teku.spec.Spec)2