Skip to content

Commit

Permalink
Tests/ethereum (#1012)
Browse files Browse the repository at this point in the history
* add workflow

* Create gradle-ethereum-test.yml

* remove duplicate

* remove duplicate

* change order of modules

* change order of modules

* change order of modules

* Revert "change order of modules"

This reverts commit 7c38a26.

* change order of modules

* remove build

* make zkevm

* make zkevm

* adding logs

* adding logs

* adding logs

* adding logs

* adding logs

* trigger on schedule

* spotless

* remove redundent steps.

* Fix GeneralStateReferenceTest template import

* Make tests run in parallel

---------

Co-authored-by: Gaurav Ahuja <gauravahuja9@gmail.com>
  • Loading branch information
FlorianHuc and gauravahuja authored Aug 29, 2024
1 parent a69c91e commit e096543
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 5 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/gradle-ethereum-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: gradle

on:
schedule:
- cron: "0 23 * * *"

env:
CARGO_NET_GIT_FETCH_WITH_CLI: true

jobs:
ethereum-tests:
runs-on: ubuntu-latest-128
steps:
- uses: webfactory/ssh-agent@v0.7.0
with:
ssh-private-key: |
${{ secrets.CONSTRAINTS_SSH_KEY }}
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive

- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: 21
distribution: temurin

- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1

# The asset URL for the latest release can be found with:
# curl -L -H "Accept: application/vnd.github+json" \
# -H "Authorization: Bearer YOUR_GH_API_TOKEN" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# https://api.github.com/repos/ConsenSys/corset/releases/latest
# | jq '.assets[] | select(.name|endswith("x86_64-unknown-linux-musl.tar.gz")) | .url'
- name: Install Corset
run: RUSTFLAGS=-Awarnings cargo install --git ssh://git@github.com/ConsenSys/corset --tag v9.7.13 --locked --force
# run: |
# curl -L \
# -H "Accept: application/octet-stream" \
# -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# -o corset.tar.gz \
# https://api.github.com/repos/Consensys/corset/releases/assets/151396061
# tar xzf corset.tar.gz
# mv corset $HOME
# echo $HOME >> $GITHUB_PATH

- name: Generate block chain reference tests
run: ./gradlew :reference-tests:generateBlockchainReferenceTests -Dorg.gradle.parallel=true -Dorg.gradle.caching=true
env:
JAVA_OPTS: -Dorg.gradle.daemon=false -DZKEVM_BIN_ORIGINAL_PATH="zkevm-constraints/zkevm.bin"
CORSET_FLAGS: fields,expand,expand,expand

- name: generate zkevm.bin
run: cd ./zkevm-constraints; make zkevm.bin -B; cd ..

- name: Run general reference tests
run: ./gradlew referenceGeneralStateTests
env:
JAVA_OPTS: -Dorg.gradle.daemon=false
CORSET_FLAGS: fields,expand,expand,expand

6 changes: 6 additions & 0 deletions docs/get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ ______________________________________________________________________
# Run only acceptance tests
./gradlew clean acceptanceTests

# Generate EVM test suite BlockchainTests
./gradlew :reference-tests:generateBlockchainReferenceTests

# Run EVM test suite BlockchainTests
./gradlew clean referenceBlockchainTests

# Generate EVM test suite GeneralStateTests
./gradlew :reference-tests:generateGeneralStateReferenceTests

# Run EVM test suite GeneralStateTests
./gradlew clean referenceGeneralStateTests

Expand Down
2 changes: 2 additions & 0 deletions gradle/tests.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ apply plugin: 'com.adarshr.test-logger'
test {
minHeapSize = "4g"
maxHeapSize = "8g"
maxParallelForks = Runtime.getRuntime().availableProcessors().intdiv(2) ?: 1
jvmArgs = [
'-XX:-UseGCOverheadLimit',
// Mockito and jackson-databind do some strange reflection during tests.
Expand Down Expand Up @@ -120,6 +121,7 @@ tasks.register('unitTests', Test) {

minHeapSize = "4g"
maxHeapSize = "8g"
maxParallelForks = Runtime.getRuntime().availableProcessors().intdiv(2) ?: 1

useJUnitPlatform {
excludeTags("AcceptanceTest")
Expand Down
2 changes: 2 additions & 0 deletions reference-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ tasks.register('referenceBlockchainTests', Test) {

minHeapSize = "4g"
maxHeapSize = "20g"
maxParallelForks = Runtime.getRuntime().availableProcessors().intdiv(2) ?: 1

useJUnitPlatform {
includeTags("BlockchainReferenceTest")
Expand All @@ -62,6 +63,7 @@ tasks.register('referenceGeneralStateTests', Test) {

minHeapSize = "4g"
maxHeapSize = "20g"
maxParallelForks = Runtime.getRuntime().availableProcessors().intdiv(2) ?: 1

useJUnitPlatform {
includeTags("GeneralStateReferenceTest")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Collection;
import java.util.List;

import lombok.extern.slf4j.Slf4j;
import net.consensys.linea.corset.CorsetValidator;
import net.consensys.linea.zktracer.ZkTracer;
import org.hyperledger.besu.ethereum.MainnetBlockValidator;
Expand All @@ -40,6 +41,7 @@
import org.hyperledger.besu.ethereum.rlp.RLPException;
import org.hyperledger.besu.testutil.JsonTestParameters;

@Slf4j
public class BlockchainReferenceTestTools {
private static final ReferenceTestProtocolSchedules REFERENCE_TEST_PROTOCOL_SCHEDULES =
ReferenceTestProtocolSchedules.create();
Expand Down Expand Up @@ -88,6 +90,7 @@ private BlockchainReferenceTestTools() {
}

public static Collection<Object[]> generateTestParametersForConfig(final String[] filePath) {
Arrays.stream(filePath).forEach(f -> log.info("checking file: {}", f));
return PARAMS.generate(
Arrays.stream(filePath)
.map(f -> Paths.get("src/test/resources/ethereum-tests/" + f).toFile())
Expand All @@ -100,6 +103,8 @@ public static void executeTest(final BlockchainReferenceTestCaseSpec spec) {
spec.getWorldStateArchive()
.getMutable(genesisBlockHeader.getStateRoot(), genesisBlockHeader.getHash())
.get();
log.info(
"checking roothash {} is {}", worldState.rootHash(), genesisBlockHeader.getStateRoot());
assertThat(worldState.rootHash()).isEqualTo(genesisBlockHeader.getStateRoot());

final ProtocolSchedule schedule =
Expand Down Expand Up @@ -130,13 +135,18 @@ public static void executeTest(final BlockchainReferenceTestCaseSpec spec) {

final BlockImportResult importResult =
blockImporter.importBlock(context, block, validationMode, validationMode);

log.info(
"checking block is imported {} equals {}",
importResult.isImported(),
candidateBlock.isValid());
assertThat(importResult.isImported()).isEqualTo(candidateBlock.isValid());
} catch (final RLPException e) {
log.info("caugh RLP exception, checking it's invalid {}", candidateBlock.isValid());
assertThat(candidateBlock.isValid()).isFalse();
}

assertThat(corsetValidator.validate(zkTracer.writeToTmpFile()).isValid()).isTrue();
CorsetValidator.Result corsetResult = corsetValidator.validate(zkTracer.writeToTmpFile());
log.info("Corset result {}", corsetResult);
assertThat(corsetResult.isValid()).isTrue();
}

assertThat(blockchain.getChainHeadHash()).isEqualTo(spec.getLastBlockHash());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

package net.consensys.linea.generated.generalstate;

import static net.consensys.linea.testing.GeneralStateReferenceTestTools.executeTest;
import static net.consensys.linea.testing.GeneralStateReferenceTestTools.generateTestParametersForConfig;
import static net.consensys.linea.GeneralStateReferenceTestTools.executeTest;
import static net.consensys.linea.GeneralStateReferenceTestTools.generateTestParametersForConfig;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.util.stream.Stream;
Expand Down

0 comments on commit e096543

Please # to comment.