From 9bfedf8c00aaf7716e74ddd412dd23f078e93f92 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Sun, 22 Sep 2024 10:59:49 +0200 Subject: [PATCH 1/4] feat(replayTest): parametric --- .../linea/replaytests/ReplayTests.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) 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 1e65303ed4..c49fd87c3e 100644 --- a/arithmetization/src/test/java/net/consensys/linea/replaytests/ReplayTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/replaytests/ReplayTests.java @@ -18,9 +18,18 @@ 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.ArrayList; +import java.util.List; +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 { @@ -188,4 +197,43 @@ void mainnet1339346ContextRevertTwice() { void legacyTxWithoutChainID() { replay(LINEA_SEPOLIA, "254251.sepolia.json.gz"); } + + static List blockNumbers = new ArrayList<>(); + + @ParameterizedTest + @MethodSource("replayBlockTestSource") + void replayBlockTest(int blockNumber) { + // TODO: fix issue with paths + File file = new File("arithmetization/src/test/resources/replays/" + blockNumber + ".json.gz"); + if (!file.exists()) { + String command = "./scripts/capture.pl --start " + blockNumber; + try { + // Execute the command + Process process = Runtime.getRuntime().exec(command); + process.waitFor(); + } catch (InterruptedException | IOException e) { + e.printStackTrace(); + } + } + // replay(LINEA_MAINNET, blockNumber + ".json.gz"); + System.out.println("Replaying block " + blockNumber); + } + + static Stream replayBlockTestSource() { + // Example of how to add a range + add(2435888, 2435889); + // Example of how to add a single block + add(2435890); + return blockNumbers.stream(); + } + + private static void add(int start, int end) { + for (int i = start; i <= end; i++) { + blockNumbers.add(Arguments.of(i)); + } + } + + private static void add(int start) { + blockNumbers.add(Arguments.of(start)); + } } From 3f9cc121e2578fa47056ea668528e8231466ab20 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Mon, 23 Sep 2024 20:55:24 +0200 Subject: [PATCH 2/4] fix(replayTest): split ranges into independent paramatrised tests --- .../consensys/linea/replaytests/ReplayTests.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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 c49fd87c3e..dc57f83cf2 100644 --- a/arithmetization/src/test/java/net/consensys/linea/replaytests/ReplayTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/replaytests/ReplayTests.java @@ -200,23 +200,24 @@ void legacyTxWithoutChainID() { static List blockNumbers = new ArrayList<>(); + @Disabled @ParameterizedTest @MethodSource("replayBlockTestSource") void replayBlockTest(int blockNumber) { - // TODO: fix issue with paths - File file = new File("arithmetization/src/test/resources/replays/" + blockNumber + ".json.gz"); + File file = + new File("../arithmetization/src/test/resources/replays/" + blockNumber + ".json.gz"); if (!file.exists()) { - String command = "./scripts/capture.pl --start " + blockNumber; + String[] cmd = {"./scripts/capture.pl", "--start", String.valueOf(blockNumber)}; try { - // Execute the command - Process process = Runtime.getRuntime().exec(command); + 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"); - System.out.println("Replaying block " + blockNumber); + replay(LINEA_MAINNET, blockNumber + ".json.gz"); } static Stream replayBlockTestSource() { From 3c6e95ef93bf70fbaa785661cadb45e292cf3ec1 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 25 Sep 2024 13:04:22 +0200 Subject: [PATCH 3/4] spotless --- .../net/consensys/linea/replaytests/ReplayTests.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 2183aafecb..4c8e4ef7eb 100644 --- a/arithmetization/src/test/java/net/consensys/linea/replaytests/ReplayTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/replaytests/ReplayTests.java @@ -198,6 +198,12 @@ void legacyTxWithoutChainID() { replay(LINEA_SEPOLIA, "254251.sepolia.json.gz"); } + @Test + void incorrectCreationCapture() { + replay(LINEA_MAINNET, "4323985.json.gz"); + } + + // Parametrized replay tests static List blockNumbers = new ArrayList<>(); @Disabled @@ -237,9 +243,4 @@ private static void add(int start, int end) { private static void add(int start) { blockNumbers.add(Arguments.of(start)); } - - @Test - void incorrectCreationCapture() { - replay(LINEA_MAINNET, "4323985.json.gz"); - } } From 5f2430780000058f9c5d27690d609bffe60008e0 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 25 Sep 2024 14:56:03 +0200 Subject: [PATCH 4/4] fix(replayTests): move support tools in dedicated class --- .../linea/replaytests/ReplayTestTools.java | 24 +++++++++++++++++++ .../linea/replaytests/ReplayTests.java | 19 +++------------ 2 files changed, 27 insertions(+), 16 deletions(-) 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 4c8e4ef7eb..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,14 +14,14 @@ */ 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.ArrayList; -import java.util.List; import java.util.stream.Stream; import org.junit.jupiter.api.Disabled; @@ -203,9 +203,6 @@ void incorrectCreationCapture() { replay(LINEA_MAINNET, "4323985.json.gz"); } - // Parametrized replay tests - static List blockNumbers = new ArrayList<>(); - @Disabled @ParameterizedTest @MethodSource("replayBlockTestSource") @@ -231,16 +228,6 @@ static Stream replayBlockTestSource() { add(2435888, 2435889); // Example of how to add a single block add(2435890); - return blockNumbers.stream(); - } - - private static void add(int start, int end) { - for (int i = start; i <= end; i++) { - blockNumbers.add(Arguments.of(i)); - } - } - - private static void add(int start) { - blockNumbers.add(Arguments.of(start)); + return BLOCK_NUMBERS.stream(); } }