From f36621ba9d497b65cc73f05397f235dfea3569ec Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 1 Oct 2024 15:31:01 +0200 Subject: [PATCH] feat(replayTest): parametric (#1273) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --------- Co-authored-by: Olivier Bégassat <38285177+OlivierBBB@users.noreply.github.com> --- .../linea/replaytests/ReplayTestTools.java | 24 ++++++++++++ .../linea/replaytests/ReplayTests.java | 37 +++++++++++++++++++ 2 files changed, 61 insertions(+) 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 fed91ae9c3..aed8605f18 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 { @@ -192,4 +201,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(); + } }