Skip to content

Commit

Permalink
Add precompile tests to CI (#255)
Browse files Browse the repository at this point in the history
* initial dockerfile

* add build-node target, light-node dockerfile update

* add compose to ci

* more ci changes

* install solc with apt

* do not build node in dockerfile

* Working CI

* remove redundant step

* add node

* add node-gyp

* dependencies and build in same step

* print compiler cache

* Update compiler version

* Add cache for CI

* Fix ci.yml

* Fix ci.yml

* Update rust cache

* Update rust cache

* Use rust cache in every step

* Update cache and locks

* Revert "Update cache and locks"

This reverts commit 2000689.

* Share cache between cargo test check and tests

* Use nightly everywhere

* Fix rust nightly

* fix rust

* Use cache for rust everywhere

* Require lint before checks

* Properly start node

* Update makefile and names

* Use literal loopback instead of localhost

* Print test node output

* Build node on CI

* Decrease sleep time

* Move everything to compile

* Fix yml

* Remove test-node output on CI

* Send output to era_node.log

* Add missing ampersand

---------

Co-authored-by: Francisco Krause Arnim <[email protected]>
Co-authored-by: Francisco Krause Arnim <[email protected]>
  • Loading branch information
3 people authored Apr 15, 2024
1 parent bb9d399 commit bf19db4
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 36 deletions.
112 changes: 84 additions & 28 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
name: CI
on:
merge_group:
push:
Expand All @@ -11,53 +10,110 @@ concurrency:
cancel-in-progress: true

jobs:
compile:
name: Compile
lint:
name: Lint Tests Code
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Rustup toolchain install
uses: dtolnay/rust-toolchain@stable
- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
with:
toolchain: stable
targets: wasm32-unknown-unknown
workspaces: |
.test-node-subtree
tests
shared-key: "cache"

- name: Run cargo check
run: cd tests && cargo check
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@nightly

lint:
name: Lint
- name: Install rust nightly
run: |
rustup toolchain install nightly
rustup component add rustfmt
rustup component add clippy
- name: Run cargo fmt
run: cd tests && cargo fmt --all -- --check

- name: Run clippy
run: cd tests && cargo clippy --all-targets --all-features -- -D warnings

check-tests:
name: Cargo check for Tests Code
needs: lint
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
with:
toolchain: stable
components: rustfmt, clippy
workspaces: |
.test-node-subtree
tests
shared-key: "cache"

- name: Run cargo fmt
run: cd tests && cargo fmt --all -- --check
- name: Rustup toolchain install
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly
targets: x86_64-unknown-linux-gnu

- name: Run clippy
run: cd tests && cargo clippy --all-targets --all-features -- -D warnings
- name: Install rust nightly
run: rustup toolchain install nightly --profile minimal --no-self-update

- name: Run cargo check for tests
run: cd tests && cargo check

build-precompiles:
name: "Build precompiles"

precompiles:
name: Compile node and run tests
runs-on: ubuntu-latest
needs: [check-tests]
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Clone node
run: cd submodules && git clone https://github.com/lambdaclass/era-test-node.git --branch lambdaclasss_precompiles

- name: Download solc
uses: pontem-network/get-solc@master
- name: Add solc
run: |
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt install solc
- name: Rustup toolchain install
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly
targets: x86_64-unknown-linux-gnu

- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
with:
workspaces: |
.test-node-subtree
tests
shared-key: "cache"

- name: Install rust nightly
run: rustup toolchain install nightly --profile minimal --no-self-update

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 18.18.0

- name: Install dependencies and build node
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: build-essential cmake pkg-config libssl-dev clang
version: 1.0

- name: "Run tests"
run: |
make test-ci
- name: "Build precompiles"
run: make build-precompiles
- name: Print era test node logs
run: |
cat era_node.log
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as fs from "fs";
import { getCompilersDir } from "hardhat/internal/util/global-dir";
import path from "path";

const COMPILER_VERSION = "1.3.22";
const COMPILER_VERSION = "1.4.0";
const IS_COMPILER_PRE_RELEASE = false;

async function compilerLocation(): Promise<string> {
Expand Down
21 changes: 17 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: clean
.PHONY: clean build-node start-reth reth-and-node-ci test-ci

current_dir := ${CURDIR}
era_test_node_base_path := $(current_dir)/.test-node-subtree
Expand All @@ -10,7 +10,9 @@ era_test_node_src_files = $(shell find $(era_test_node_base_path)/src -name "*.r
precompiles_source = $(wildcard $(current_dir)/precompiles/*.yul)
precompiles_dst = $(patsubst $(current_dir)/precompiles/%, $(precompile_dst_path)/%, $(precompiles_source))

run-node: $(era_test_node) $(precompiles_dst)
build-node: $(era_test_node) $(precompiles_dst)

run-node: build-node
$(era_test_node) --show-calls=all --resolve-hashes --show-gas-details=all run

run-node-light: $(era_test_node) $(precompiles_dst)
Expand All @@ -20,7 +22,7 @@ run-node-light: $(era_test_node) $(precompiles_dst)
# source files are obtained just to recompile if there are changes, and located with a find
$(era_test_node): $(era_test_node_makefile) $(era_test_node_src_files) $(precompiles_dst)
cd $(era_test_node_base_path) && make rust-build

## precompile source is added just to avoid recompiling if they haven't changed
$(precompiles_dst): $(precompiles_source)
cp precompiles/*.yul $(precompile_dst_path) && cd $(era_test_node_base_path) && make build-contracts
Expand All @@ -31,10 +33,21 @@ build-precompiles: $(precompiles_dst)
update-node: era_test_node
cd $(era_test_node_base_path) && make rust-build

test:
start-reth:
docker compose down
docker compose up -d --wait reth

test: start-reth
cd tests && \
cargo test ${PRECOMPILE}

reth-and-node-ci: build-node start-reth
$(era_test_node) --show-calls=all --resolve-hashes --show-gas-details=all run > era_node.log &
sleep 1

test-ci: reth-and-node-ci
cd tests && cargo test

docs:
cd docs && mdbook serve --open

Expand Down
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
reth:
restart: always
image: "ghcr.io/paradigmxyz/reth:v0.2.0-beta.2"
volumes:
- type: bind
source: ./tests/reth/chaindata
target: /chaindata

command: node --dev --datadir /rethdata --http --http.addr 0.0.0.0 --http.port 8545 --dev.block-time 300ms --chain /chaindata/reth_config
ports:
- 127.0.0.1:8545:8545
4 changes: 4 additions & 0 deletions tests/light-node-dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM rust:latest
COPY ./ /precompiles
WORKDIR /precompiles
CMD [ "make", "run-node" ]
86 changes: 86 additions & 0 deletions tests/reth/chaindata/reth_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"config": {
"chainId": 9,
"homesteadBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"eip155Block": 0,
"eip158Block": 0,
"daoForkBlock": 0,
"frontierBlock": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"muirGlacierBlock": 0,
"istanbulBlock": 0,
"berlinBlock": 0,
"londonBlock": 0,
"terminalTotalDifficulty": "0x0",
"mergeNetsplitBlock": 0,
"shanghaiTime": 0,
"cancunTime": 0,
"clique": {
"period": 0,
"epoch": 30000
}
},
"nonce": "0x0",
"timestamp": "0x5ca9158b",
"gasLimit": "0x1c9c380",
"difficulty": "0x0",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": {
"0000000000000000000000000000000000000000": {
"balance": "0x1"
},
"8a91dc2d28b689474298d91899f0c1baf62cb85b": {
"balance": "0x4B3B4CA85A86C47A098A224000000000"
},
"de03a0b5963f75f1c8485b355ff6d30f3093bde7": {
"balance": "0x4B3B4CA85A86C47A098A224000000000"
},
"52312AD6f01657413b2eaE9287f6B9ADaD93D5FE": {
"balance": "0x4B3B4CA85A86C47A098A224000000000"
},
"36615Cf349d7F6344891B1e7CA7C72883F5dc049": {
"balance": "0x4B3B4CA85A86C47A098A224000000000"
},
"a61464658AfeAf65CccaaFD3a512b69A83B77618": {
"balance": "0x4B3B4CA85A86C47A098A224000000000"
},
"0D43eB5B8a47bA8900d84AA36656c92024e9772e": {
"balance": "0x4B3B4CA85A86C47A098A224000000000"
},
"A13c10C0D5bd6f79041B9835c63f91de35A15883": {
"balance": "0x4B3B4CA85A86C47A098A224000000000"
},
"8002cD98Cfb563492A6fB3E7C8243b7B9Ad4cc92": {
"balance": "0x4B3B4CA85A86C47A098A224000000000"
},
"4F9133D1d3F50011A6859807C837bdCB31Aaab13": {
"balance": "0x4B3B4CA85A86C47A098A224000000000"
},
"bd29A1B981925B94eEc5c4F1125AF02a2Ec4d1cA": {
"balance": "0x4B3B4CA85A86C47A098A224000000000"
},
"edB6F5B4aab3dD95C7806Af42881FF12BE7e9daa": {
"balance": "0x4B3B4CA85A86C47A098A224000000000"
},
"e706e60ab5Dc512C36A4646D719b889F398cbBcB": {
"balance": "0x4B3B4CA85A86C47A098A224000000000"
},
"E90E12261CCb0F3F7976Ae611A29e84a6A85f424": {
"balance": "0x4B3B4CA85A86C47A098A224000000000"
},
"e706e60ab5dc512c36a4646d719b889f398cbbcb": {
"balance": "0x4B3B4CA85A86C47A098A224000000000"
}
},
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"baseFeePerGas": 1,
"excessBlobGas": "0x0",
"blobGasUsed": 0
}
5 changes: 2 additions & 3 deletions tests/tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ use zksync_web3_rs::{
},
};

static DEFAULT_L1_PROVIDER_URL: &str =
"https://eth-mainnet.alchemyapi.io/v2/Lc7oIGYeL_QvInzI0Wiu_pOZZDEKBrdf";
static DEFAULT_L2_PROVIDER_URL: &str = "http://localhost:8011";
static DEFAULT_L1_PROVIDER_URL: &str = "http://127.0.0.1:8545";
static DEFAULT_L2_PROVIDER_URL: &str = "http://127.0.0.1:8011";

#[allow(dead_code)]
const ERA_IN_MEMORY_NODE_CHAIN_ID: u64 = 260;
Expand Down

0 comments on commit bf19db4

Please sign in to comment.