Search in sources :

Example 1 with SignedAttestation

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));
}
Also used : SignedAttestation(tech.pegasys.web3signer.slashingprotection.dao.SignedAttestation) Test(org.junit.jupiter.api.Test)

Example 2 with SignedAttestation

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));
}
Also used : SignedAttestation(tech.pegasys.web3signer.slashingprotection.dao.SignedAttestation) Test(org.junit.jupiter.api.Test)

Example 3 with SignedAttestation

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));
}
Also used : SigningWatermark(tech.pegasys.web3signer.slashingprotection.dao.SigningWatermark) SignedAttestation(tech.pegasys.web3signer.slashingprotection.dao.SignedAttestation) Test(org.junit.jupiter.api.Test)

Example 4 with SignedAttestation

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));
}
Also used : SignedAttestation(tech.pegasys.web3signer.slashingprotection.dao.SignedAttestation) Test(org.junit.jupiter.api.Test)

Example 5 with SignedAttestation

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));
}
Also used : SigningWatermark(tech.pegasys.web3signer.slashingprotection.dao.SigningWatermark) SignedAttestation(tech.pegasys.web3signer.slashingprotection.dao.SignedAttestation) Test(org.junit.jupiter.api.Test)

Aggregations

SignedAttestation (tech.pegasys.web3signer.slashingprotection.dao.SignedAttestation)16 Test (org.junit.jupiter.api.Test)14 SigningWatermark (tech.pegasys.web3signer.slashingprotection.dao.SigningWatermark)5 URL (java.net.URL)4 TestSlashingProtectionParameters (dsl.TestSlashingProtectionParameters)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 UInt64 (org.apache.tuweni.units.bigints.UInt64)1 CsvSource (org.junit.jupiter.params.provider.CsvSource)1 SignedBlock (tech.pegasys.web3signer.slashingprotection.dao.SignedBlock)1