Skip to content

Commit

Permalink
Add happy path tests when data is below high watermark
Browse files Browse the repository at this point in the history
  • Loading branch information
siladu committed Sep 11, 2023
1 parent 7d3f859 commit 4669b66
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ public void blockCannotSignWhenSlotIsAtOrBeyondHighWatermark() {
verify(signedBlocksDao, never()).insertBlockProposal(any(), refEq(signedBlock));
}

@Test
public void blockCanSignWhenSlotIsAtOrBeyondHighWatermark() {
final SignedBlock signedBlock = new SignedBlock(VALIDATOR_ID, SLOT, SIGNING_ROOT);
when(metadataDao.findHighWatermark(any()))
.thenReturn(Optional.of(new HighWatermark(SLOT.add(1L), null)));

assertThat(dbSlashingProtection.maySignBlock(PUBLIC_KEY1, SIGNING_ROOT, SLOT, GVR)).isTrue();

verify(signedBlocksDao).insertBlockProposal(any(), refEq(signedBlock));
}

@Test
public void blockCannotSignWhenNoRegisteredValidator(final Jdbi jdbi) {
final DbSlashingProtection dbSlashingProtection =
Expand Down Expand Up @@ -298,6 +309,36 @@ public void cannotSignAttestationWhenTargetIsAtOrBeyondHighWatermark() {
verify(signedAttestationsDao, never()).insertAttestation(any(), refEq(attestation));
}

@Test
public void attestationCanSignWhenSourceIsBelowHighWatermark() {
final SignedAttestation attestation =
new SignedAttestation(VALIDATOR_ID, SOURCE_EPOCH, SOURCE_EPOCH, SIGNING_ROOT);
when(metadataDao.findHighWatermark(any()))
.thenReturn(Optional.of(new HighWatermark(null, SOURCE_EPOCH.add(1L))));

assertThat(
dbSlashingProtection.maySignAttestation(
PUBLIC_KEY1, SIGNING_ROOT, SOURCE_EPOCH, SOURCE_EPOCH, GVR))
.isTrue();

verify(signedAttestationsDao).insertAttestation(any(), refEq(attestation));
}

@Test
public void attestationCanSignWhenTargetIsBelowHighWatermark() {
final SignedAttestation attestation =
new SignedAttestation(VALIDATOR_ID, SOURCE_EPOCH, TARGET_EPOCH, SIGNING_ROOT);
when(metadataDao.findHighWatermark(any()))
.thenReturn(Optional.of(new HighWatermark(null, TARGET_EPOCH.add(1L))));

assertThat(
dbSlashingProtection.maySignAttestation(
PUBLIC_KEY1, SIGNING_ROOT, SOURCE_EPOCH, TARGET_EPOCH, GVR))
.isTrue();

verify(signedAttestationsDao).insertAttestation(any(), refEq(attestation));
}

@Test
public void attestationCannotSignWhenPreviousIsSurroundingAttestation() {
final SignedAttestation attestation =
Expand Down

0 comments on commit 4669b66

Please sign in to comment.