Skip to content

Commit

Permalink
simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr committed Dec 13, 2024
1 parent c2cad07 commit e13c529
Showing 1 changed file with 25 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,7 @@ void shouldVerifyValidAvailableBlobs() throws Exception {
.thenReturn(true);

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);
runAvailabilityCheck();

assertAvailable(availabilityCheckResult);
}
Expand All @@ -113,20 +100,7 @@ void shouldVerifyInvalidBlobsDueToWrongBlockHeader() throws Exception {
.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);
runAvailabilityCheck();

assertInvalid(
availabilityCheckResult,
Expand All @@ -144,20 +118,7 @@ void shouldVerifyInvalidBlobsDueToWrongKzg() throws Exception {
.thenReturn(true);

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);
runAvailabilityCheck();

assertInvalid(availabilityCheckResult, blobSidecarsComplete, Optional.empty());
}
Expand All @@ -171,20 +132,7 @@ void shouldVerifyInvalidBlobsWhenKzgValidationThrows() throws Exception {
when(miscHelpers.verifyBlobKzgProofBatch(any(), any())).thenThrow(error);

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);
runAvailabilityCheck();

assertInvalid(availabilityCheckResult, blobSidecarsComplete, Optional.of(error));
}
Expand All @@ -201,20 +149,7 @@ void shouldVerifyInvalidBlobsWhenCompletenessValidationThrows() throws Exception
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);
runAvailabilityCheck();

assertInvalid(availabilityCheckResult, blobSidecarsComplete, Optional.of(error));
}
Expand Down Expand Up @@ -270,6 +205,26 @@ void shouldReturnNotRequiredWhenBlockIsOutsideAvailabilityWindow() throws Except
assertNotRequired(availabilityCheckResult);
}

private SafeFuture<BlobSidecarsAndValidationResult> runAvailabilityCheck() throws Exception {
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);

return availabilityCheckResult;
}

private void assertInvalid(
final SafeFuture<BlobSidecarsAndValidationResult> availabilityOrValidityCheck,
final List<BlobSidecar> invalidBlobs,
Expand Down

0 comments on commit e13c529

Please sign in to comment.