use of tech.pegasys.web3signer.slashingprotection.dao.SignedAttestation in project web3signer by ConsenSys.
the class DbSlashingProtectionTest method attestationCanSignWhenNoSurroundingOrSurroundedByAttestation.
@Test
public void attestationCanSignWhenNoSurroundingOrSurroundedByAttestation() {
final SignedAttestation attestation = new SignedAttestation(VALIDATOR_ID, SOURCE_EPOCH, TARGET_EPOCH, SIGNING_ROOT);
when(signedAttestationsDao.findAttestationsForEpochWithDifferentSigningRoot(any(), anyInt(), any(), any())).thenReturn(emptyList());
when(signedAttestationsDao.findSurroundingAttestations(any(), anyInt(), any(), any())).thenReturn(emptyList());
when(signedAttestationsDao.findSurroundedAttestations(any(), anyInt(), any(), any())).thenReturn(emptyList());
assertThat(dbSlashingProtection.maySignAttestation(PUBLIC_KEY1, SIGNING_ROOT, SOURCE_EPOCH, TARGET_EPOCH, GVR)).isTrue();
verify(signedAttestationsDao).findAttestationsForEpochWithDifferentSigningRoot(any(), eq(VALIDATOR_ID), eq(TARGET_EPOCH), eq(SIGNING_ROOT));
verify(signedAttestationsDao).findSurroundingAttestations(any(), eq(VALIDATOR_ID), eq(SOURCE_EPOCH), eq(TARGET_EPOCH));
verify(signedAttestationsDao).findSurroundedAttestations(any(), eq(VALIDATOR_ID), eq(SOURCE_EPOCH), eq(TARGET_EPOCH));
verify(signedAttestationsDao).insertAttestation(any(), refEq(attestation));
}
use of tech.pegasys.web3signer.slashingprotection.dao.SignedAttestation in project web3signer by ConsenSys.
the class DbSlashingProtectionTest method attestationCannotSignWhenPreviousIsSurroundingAttestation.
@Test
public void attestationCannotSignWhenPreviousIsSurroundingAttestation() {
final SignedAttestation attestation = new SignedAttestation(VALIDATOR_ID, SOURCE_EPOCH, TARGET_EPOCH, SIGNING_ROOT);
when(signedAttestationsDao.findAttestationsForEpochWithDifferentSigningRoot(any(), anyInt(), any(), any())).thenReturn(emptyList());
final SignedAttestation surroundingAttestation = new SignedAttestation(VALIDATOR_ID, SOURCE_EPOCH.subtract(1), TARGET_EPOCH.subtract(1), SIGNING_ROOT);
when(signedAttestationsDao.findSurroundingAttestations(any(), anyInt(), any(), any())).thenReturn(List.of(surroundingAttestation));
assertThat(dbSlashingProtection.maySignAttestation(PUBLIC_KEY1, SIGNING_ROOT, SOURCE_EPOCH, TARGET_EPOCH, GVR)).isFalse();
verify(signedAttestationsDao).findAttestationsForEpochWithDifferentSigningRoot(any(), eq(VALIDATOR_ID), eq(TARGET_EPOCH), eq(SIGNING_ROOT));
verify(signedAttestationsDao).findSurroundingAttestations(any(), eq(VALIDATOR_ID), eq(SOURCE_EPOCH), eq(TARGET_EPOCH));
verify(signedAttestationsDao, never()).insertAttestation(any(), refEq(attestation));
}
use of tech.pegasys.web3signer.slashingprotection.dao.SignedAttestation in project web3signer by ConsenSys.
the class DbSlashingProtectionTest method attestationCanBeSignedWithSourceEpochEqualToMin.
@Test
public void attestationCanBeSignedWithSourceEpochEqualToMin() {
when(lowWatermarkDao.findLowWatermarkForValidator(any(), anyInt())).thenReturn(Optional.of(new SigningWatermark(1, null, SOURCE_EPOCH, UInt64.valueOf(3))));
assertThat(dbSlashingProtection.maySignAttestation(PUBLIC_KEY1, SIGNING_ROOT, SOURCE_EPOCH, TARGET_EPOCH, GVR)).isTrue();
verify(lowWatermarkDao).findLowWatermarkForValidator(any(), eq(VALIDATOR_ID));
final SignedAttestation attestation = new SignedAttestation(VALIDATOR_ID, SOURCE_EPOCH, TARGET_EPOCH, SIGNING_ROOT);
verify(signedAttestationsDao).insertAttestation(any(), refEq(attestation));
}
use of tech.pegasys.web3signer.slashingprotection.dao.SignedAttestation in project web3signer by ConsenSys.
the class DbSlashingProtectionTest method attestationCannotSignWhenPreviousIsSurroundedByAttestation.
@Test
public void attestationCannotSignWhenPreviousIsSurroundedByAttestation() {
final SignedAttestation attestation = new SignedAttestation(VALIDATOR_ID, SOURCE_EPOCH, TARGET_EPOCH, SIGNING_ROOT);
when(signedAttestationsDao.findAttestationsForEpochWithDifferentSigningRoot(any(), anyInt(), any(), any())).thenReturn(emptyList());
when(signedAttestationsDao.findSurroundingAttestations(any(), anyInt(), any(), any())).thenReturn(emptyList());
final SignedAttestation surroundedAttestation = new SignedAttestation(VALIDATOR_ID, SOURCE_EPOCH.add(1), TARGET_EPOCH.add(1), SIGNING_ROOT);
when(signedAttestationsDao.findSurroundedAttestations(any(), anyInt(), any(), any())).thenReturn(List.of(surroundedAttestation));
assertThat(dbSlashingProtection.maySignAttestation(PUBLIC_KEY1, SIGNING_ROOT, SOURCE_EPOCH, TARGET_EPOCH, GVR)).isFalse();
verify(signedAttestationsDao).findAttestationsForEpochWithDifferentSigningRoot(any(), eq(VALIDATOR_ID), eq(TARGET_EPOCH), eq(SIGNING_ROOT));
verify(signedAttestationsDao).findSurroundingAttestations(any(), eq(VALIDATOR_ID), eq(SOURCE_EPOCH), eq(TARGET_EPOCH));
verify(signedAttestationsDao).findSurroundedAttestations(any(), eq(VALIDATOR_ID), eq(SOURCE_EPOCH), eq(TARGET_EPOCH));
verify(signedAttestationsDao, never()).insertAttestation(any(), refEq(attestation));
}
use of tech.pegasys.web3signer.slashingprotection.dao.SignedAttestation in project web3signer by ConsenSys.
the class DbSlashingProtectionTest method cannotSignAttestationWhichWasPreviouslySignedButBelowSourceWatermark.
@Test
public void cannotSignAttestationWhichWasPreviouslySignedButBelowSourceWatermark() {
final SignedAttestation attestation = new SignedAttestation(VALIDATOR_ID, SOURCE_EPOCH, TARGET_EPOCH, SIGNING_ROOT);
when(lowWatermarkDao.findLowWatermarkForValidator(any(), anyInt())).thenReturn(Optional.of(new SigningWatermark(VALIDATOR_ID, null, SOURCE_EPOCH.add(1L), TARGET_EPOCH.subtract(1L))));
assertThat(dbSlashingProtection.maySignAttestation(PUBLIC_KEY1, SIGNING_ROOT, SOURCE_EPOCH, TARGET_EPOCH, GVR)).isFalse();
verify(signedAttestationsDao, never()).insertAttestation(any(), refEq(attestation));
verify(lowWatermarkDao).findLowWatermarkForValidator(any(), eq(VALIDATOR_ID));
}
Aggregations