Skip to content

Commit

Permalink
feat(replayTest): parametric (#1273)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Olivier Bégassat <38285177+OlivierBBB@users.noreply.github.com>
  • Loading branch information
lorenzogentile404 and OlivierBBB authored Oct 1, 2024
1 parent fabcb54 commit f36621b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -53,6 +54,8 @@
*/
@Slf4j
public class ReplayTestTools {
/** A list of block numbers used for testing purposes in {@link ReplayTests}. */
static List<Arguments> BLOCK_NUMBERS = new ArrayList<>();

/**
* Loads a .json or .json.gz replay file generated by the {@link
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Arguments> 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();
}
}

0 comments on commit f36621b

Please sign in to comment.