Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(replayTest): parametric #1273

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 @@ -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<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();
}
}
Loading