From e13c5292b1df91ec7d29c7e430781627dcfc42e2 Mon Sep 17 00:00:00 2001 From: Enrico Del Fante Date: Fri, 13 Dec 2024 12:32:11 +0100 Subject: [PATCH] simplify tests --- ...ceBlobSidecarsAvailabilityCheckerTest.java | 95 +++++-------------- 1 file changed, 25 insertions(+), 70 deletions(-) diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceBlobSidecarsAvailabilityCheckerTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceBlobSidecarsAvailabilityCheckerTest.java index 7b0d489bfb3..b2406f0e9da 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceBlobSidecarsAvailabilityCheckerTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceBlobSidecarsAvailabilityCheckerTest.java @@ -86,20 +86,7 @@ void shouldVerifyValidAvailableBlobs() throws Exception { .thenReturn(true); final SafeFuture 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); } @@ -113,20 +100,7 @@ void shouldVerifyInvalidBlobsDueToWrongBlockHeader() throws Exception { .thenReturn(false); final SafeFuture 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, @@ -144,20 +118,7 @@ void shouldVerifyInvalidBlobsDueToWrongKzg() throws Exception { .thenReturn(true); final SafeFuture 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()); } @@ -171,20 +132,7 @@ void shouldVerifyInvalidBlobsWhenKzgValidationThrows() throws Exception { when(miscHelpers.verifyBlobKzgProofBatch(any(), any())).thenThrow(error); final SafeFuture 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)); } @@ -201,20 +149,7 @@ void shouldVerifyInvalidBlobsWhenCompletenessValidationThrows() throws Exception doThrow(error).when(miscHelpers).verifyBlobSidecarCompleteness(anyList(), any()); final SafeFuture 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)); } @@ -270,6 +205,26 @@ void shouldReturnNotRequiredWhenBlockIsOutsideAvailabilityWindow() throws Except assertNotRequired(availabilityCheckResult); } + private SafeFuture runAvailabilityCheck() throws Exception { + final SafeFuture 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 availabilityOrValidityCheck, final List invalidBlobs,