Skip to content

Commit

Permalink
tests and other tiny things
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr committed Dec 12, 2024
1 parent fb44215 commit f8d4eb3
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ private BlobSidecarsAndValidationResult validateCompletedBlobSidecars() {
if (!miscHelpers.verifyBlobKzgProofBatch(kzg, blobSidecars)) {
return BlobSidecarsAndValidationResult.invalidResult(blobSidecars);
}

miscHelpers.verifyBlobSidecarCompleteness(blobSidecars, block);
} catch (final Exception ex) {
return BlobSidecarsAndValidationResult.invalidResult(blobSidecars, ex);
}
Expand All @@ -116,8 +118,6 @@ private BlobSidecarsAndValidationResult validateCompletedBlobSidecars() {
new IllegalStateException("Blob sidecars block header does not match signed block"));
}

miscHelpers.verifyBlobSidecarCompleteness(blobSidecars, block);

return BlobSidecarsAndValidationResult.validResult(blobSidecars);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -76,10 +78,12 @@ void setUp() {
}

@Test
void shouldVerifyAvailableBlobs() throws Exception {
void shouldVerifyValidAvailableBlobs() throws Exception {
prepareInitialAvailability();

when(miscHelpers.verifyBlobKzgProofBatch(any(), any())).thenReturn(true);
when(miscHelpers.verifyBlobSidecarBlockHeaderSignatureViaValidatedSignedBlock(anyList(), any()))
.thenReturn(true);

final SafeFuture<BlobSidecarsAndValidationResult> availabilityCheckResult =
blobSidecarsAvailabilityChecker.getAvailabilityCheckResult();
Expand All @@ -101,10 +105,43 @@ void shouldVerifyAvailableBlobs() throws Exception {
}

@Test
void shouldVerifyInvalidBlobs() throws Exception {
void shouldVerifyInvalidBlobsDueToWrongBlockHeader() throws Exception {
prepareInitialAvailability();

when(miscHelpers.verifyBlobKzgProofBatch(any(), any())).thenReturn(true);
when(miscHelpers.verifyBlobSidecarBlockHeaderSignatureViaValidatedSignedBlock(anyList(), any()))
.thenReturn(false);

final SafeFuture<BlobSidecarsAndValidationResult> availabilityCheckResult =
blobSidecarsAvailabilityChecker.getAvailabilityCheckResult();

assertThatSafeFuture(availabilityCheckResult).isNotCompleted();

// initiate availability check
assertThat(blobSidecarsAvailabilityChecker.initiateDataAvailabilityCheck()).isTrue();

assertThatSafeFuture(availabilityCheckResult).isNotCompleted();
verify(blockBlobSidecarsTracker, never()).getBlobSidecars();

// let the tracker complete with all blobSidecars
completeTrackerWith(blobSidecarsComplete);

Waiter.waitFor(availabilityCheckResult);

assertInvalid(
availabilityCheckResult,
blobSidecarsComplete,
Optional.of(
new IllegalStateException("Blob sidecars block header does not match signed block")));
}

@Test
void shouldVerifyInvalidBlobsDueToWrongKzg() throws Exception {
prepareInitialAvailability();

when(miscHelpers.verifyBlobKzgProofBatch(any(), any())).thenReturn(false);
when(miscHelpers.verifyBlobSidecarBlockHeaderSignatureViaValidatedSignedBlock(anyList(), any()))
.thenReturn(true);

final SafeFuture<BlobSidecarsAndValidationResult> availabilityCheckResult =
blobSidecarsAvailabilityChecker.getAvailabilityCheckResult();
Expand All @@ -126,7 +163,7 @@ void shouldVerifyInvalidBlobs() throws Exception {
}

@Test
void shouldVerifyInvalidBlobsWhenValidationThrows() throws Exception {
void shouldVerifyInvalidBlobsWhenKzgValidationThrows() throws Exception {
prepareInitialAvailability();

final RuntimeException error = new RuntimeException("oops");
Expand All @@ -152,6 +189,36 @@ void shouldVerifyInvalidBlobsWhenValidationThrows() throws Exception {
assertInvalid(availabilityCheckResult, blobSidecarsComplete, Optional.of(error));
}

@Test
void shouldVerifyInvalidBlobsWhenCompletenessValidationThrows() throws Exception {
prepareInitialAvailability();

final RuntimeException error = new RuntimeException("oops");

when(miscHelpers.verifyBlobKzgProofBatch(any(), any())).thenReturn(true);
when(miscHelpers.verifyBlobSidecarBlockHeaderSignatureViaValidatedSignedBlock(anyList(), any()))
.thenReturn(true);
doThrow(error).when(miscHelpers).verifyBlobSidecarCompleteness(anyList(), any());

final SafeFuture<BlobSidecarsAndValidationResult> availabilityCheckResult =
blobSidecarsAvailabilityChecker.getAvailabilityCheckResult();

assertThatSafeFuture(availabilityCheckResult).isNotCompleted();

// initiate availability check
assertThat(blobSidecarsAvailabilityChecker.initiateDataAvailabilityCheck()).isTrue();

assertThatSafeFuture(availabilityCheckResult).isNotCompleted();
verify(blockBlobSidecarsTracker, never()).getBlobSidecars();

// let the tracker complete with all blobSidecars
completeTrackerWith(blobSidecarsComplete);

Waiter.waitFor(availabilityCheckResult);

assertInvalid(availabilityCheckResult, blobSidecarsComplete, Optional.of(error));
}

@Test
void shouldFailIfTrackerCompletesWithFailure() {
prepareInitialAvailability();
Expand Down

0 comments on commit f8d4eb3

Please sign in to comment.