diff --git a/arithmetization/src/test/java/net/consensys/linea/replaytests/ReplayTestTools.java b/arithmetization/src/test/java/net/consensys/linea/replaytests/ReplayTestTools.java index f72c1e6bcd..83ab4bae4c 100644 --- a/arithmetization/src/test/java/net/consensys/linea/replaytests/ReplayTestTools.java +++ b/arithmetization/src/test/java/net/consensys/linea/replaytests/ReplayTestTools.java @@ -34,6 +34,7 @@ import lombok.extern.slf4j.Slf4j; import net.consensys.linea.testing.ReplayExecutionEnvironment; +import org.junit.jupiter.params.provider.Arguments; /** * Replays are captured on a fully (not snapshot) synchronized Besu node running the plugin: @@ -53,6 +54,8 @@ */ @Slf4j public class ReplayTestTools { + /** A list of block numbers used for testing purposes in {@link ReplayTests}. */ + static List BLOCK_NUMBERS = new ArrayList<>(); /** * Loads a .json or .json.gz replay file generated by the {@link @@ -181,4 +184,25 @@ public static void bulkReplay(BigInteger chainId, String directory) { } } } + + /** + * Adds a range of block numbers to the BLOCK_NUMBERS list. + * + * @param start the starting block number (inclusive) + * @param end the ending block number (inclusive) + */ + static void add(int start, int end) { + for (int i = start; i <= end; i++) { + BLOCK_NUMBERS.add(Arguments.of(i)); + } + } + + /** + * Adds a single block number to the BLOCK_NUMBERS list. + * + * @param start the block number to add + */ + static void add(int start) { + BLOCK_NUMBERS.add(Arguments.of(start)); + } } diff --git a/arithmetization/src/test/java/net/consensys/linea/replaytests/ReplayTests.java b/arithmetization/src/test/java/net/consensys/linea/replaytests/ReplayTests.java index 3584392db9..2b5a5cf862 100644 --- a/arithmetization/src/test/java/net/consensys/linea/replaytests/ReplayTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/replaytests/ReplayTests.java @@ -14,13 +14,22 @@ */ package net.consensys.linea.replaytests; +import static net.consensys.linea.replaytests.ReplayTestTools.BLOCK_NUMBERS; +import static net.consensys.linea.replaytests.ReplayTestTools.add; import static net.consensys.linea.replaytests.ReplayTestTools.replay; import static net.consensys.linea.testing.ReplayExecutionEnvironment.LINEA_MAINNET; import static net.consensys.linea.testing.ReplayExecutionEnvironment.LINEA_SEPOLIA; +import java.io.File; +import java.io.IOException; +import java.util.stream.Stream; + import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; @Tag("replay") public class ReplayTests { @@ -193,4 +202,32 @@ void legacyTxWithoutChainID() { void incorrectCreationCapture() { replay(LINEA_MAINNET, "4323985.json.gz"); } + + @Disabled + @ParameterizedTest + @MethodSource("replayBlockTestSource") + void replayBlockTest(int blockNumber) { + File file = + new File("../arithmetization/src/test/resources/replays/" + blockNumber + ".json.gz"); + if (!file.exists()) { + String[] cmd = {"./scripts/capture.pl", "--start", String.valueOf(blockNumber)}; + try { + ProcessBuilder processBuilder = new ProcessBuilder(cmd); + processBuilder.directory(new File("../")); + Process process = processBuilder.start(); + process.waitFor(); + } catch (InterruptedException | IOException e) { + e.printStackTrace(); + } + } + replay(LINEA_MAINNET, blockNumber + ".json.gz"); + } + + static Stream replayBlockTestSource() { + // Example of how to add a range + add(2435888, 2435889); + // Example of how to add a single block + add(2435890); + return BLOCK_NUMBERS.stream(); + } }