Skip to content

Commit

Permalink
Makefile testing targets improvements (#1828)
Browse files Browse the repository at this point in the history
  • Loading branch information
rakanalh authored Feb 7, 2025
1 parent f9b0c3f commit f6eb357
Show file tree
Hide file tree
Showing 58 changed files with 190 additions and 126 deletions.
86 changes: 65 additions & 21 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Build citrea
run: make build-release

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
Expand All @@ -107,6 +106,43 @@ jobs:
target/release/**/methods.rs
retention-days: 1

build-test:
name: build-tests
runs-on: ubicloud-standard-30
timeout-minutes: 60
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v4
- uses: rui314/setup-mold@v1
- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
version: "23.2"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Toolchain
uses: dtolnay/rust-toolchain@nightly
- name: Rust Cache
uses: ubicloud/rust-cache@v2
- name: Install risc0
uses: ./.github/actions/install-risc0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Cache ethereum-tests
uses: actions/cache@v4
with:
key: "eth-tests-1c23e3c"
path: crates/evm/ethereum-tests
- name: Build citrea
run: make build-test
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: citrea-test-build
path: |
target/debug/citrea
target/debug/**/methods.rs
retention-days: 1

check:
name: check
runs-on: ubicloud-standard-16
Expand Down Expand Up @@ -185,7 +221,9 @@ jobs:
command: check

coverage:
needs: docker-setup
needs:
- docker-setup
- build-test
runs-on: ubicloud-standard-16
if: github.event.pull_request.draft == false
steps:
Expand All @@ -195,7 +233,6 @@ jobs:
components: llvm-tools-preview
- name: Rust Cache
uses: ubicloud/rust-cache@v2

- name: Setup env
if: ${{ github.event.inputs.RUST_LOG != '' }}
run: echo "RUST_LOG=${{ github.event.inputs.RUST_LOG }}" >> $GITHUB_ENV
Expand All @@ -210,33 +247,35 @@ jobs:
with:
key: "eth-tests-1c23e3c"
path: crates/evm/ethereum-tests

- name: Restore cached Docker image
uses: actions/cache@v4
with:
path: /tmp/docker
key: ${{ runner.os }}-docker-${{ env.TEST_BITCOIN_DOCKER }}

- name: Load Docker image
run: docker load < /tmp/docker/bitcoin.tar

- name: Download artifact
uses: actions/download-artifact@v4
with:
name: citrea-test-build
path: target/debug
- name: Make citrea executable
run: chmod +x target/debug/citrea
- name: Run coverage
run: make coverage
run: make coverage-ci
env:
RUST_BACKTRACE: 1
TEST_BITCOIN_DOCKER: 1
RISC0_DEV_MODE: 1 # This is needed to generate mock proofs and verify them
CITREA_E2E_TEST_BINARY: ${{ github.workspace }}/target/debug/citrea
PARALLEL_PROOF_LIMIT: 1
TEST_OUT_DIR: ${{ runner.temp }}/coverage

- name: Upload e2e test dir
if: failure() || cancelled()
uses: actions/upload-artifact@v4
with:
name: e2e-test-dir-coverage
path: ${{ runner.temp }}/coverage

- name: Upload coverage
uses: codecov/codecov-action@v4
with:
Expand All @@ -261,15 +300,15 @@ jobs:
- name: Make citrea executable
run: chmod +x target/release/citrea
- name: Install node dependencies
working-directory: ./bin/citrea/tests/evm/uniswap
working-directory: ./bin/citrea/tests/mock/evm/uniswap
run: npm install
- name: Run uniswap tests
run: |
RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/sequencer_rollup_config.toml --sequencer resources/configs/mock/sequencer_config.toml --genesis-paths resources/genesis/mock/ --dev &
sleep 2
RUST_LOG=off ./target/release/citrea --rollup-config-path resources/configs/mock/rollup_config.toml --genesis-paths resources/genesis/mock/ --dev &
sleep 2
cd ./bin/citrea/tests/evm/uniswap
cd ./bin/citrea/tests/mock/evm/uniswap
npx hardhat run --network citrea scripts/01_deploy.js
npx hardhat run --network citrea scripts/02_swap.js
seqnHeight=$(curl -s 0.0.0.0:12345/ -H "Content-Type: application/json" --data '{"method":"eth_getBlockByNumber","params":["latest"],"id":1,"jsonrpc":"2.0"}' | jq -e .result.number) || (echo "Couldn't get sequencer block"; exit 1)
Expand Down Expand Up @@ -304,15 +343,15 @@ jobs:
- name: Make citrea executable
run: chmod +x target/release/citrea
- name: Install dependencies
working-directory: ./bin/citrea/tests/evm/web3_py
working-directory: ./bin/citrea/tests/mock/evm/web3_py
run: pip install -r requirements.txt
- name: Run web3.py tests
run: |
RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/sequencer_rollup_config.toml --sequencer resources/configs/mock/sequencer_config.toml --genesis-paths resources/genesis/mock/ --dev &
sleep 2
RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/rollup_config.toml --genesis-paths resources/genesis/mock/ --dev &
sleep 2
cd ./bin/citrea/tests/evm/web3_py
cd ./bin/citrea/tests/mock/evm/web3_py
python test.py
ethers_js:
Expand All @@ -332,15 +371,15 @@ jobs:
- name: Make citrea executable
run: chmod +x target/release/citrea
- name: Install node dependencies
working-directory: ./bin/citrea/tests/evm/ethers_js
working-directory: ./bin/citrea/tests/mock/evm/ethers_js
run: npm install
- name: Run ethers_js tests
run: |
RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/sequencer_rollup_config.toml --sequencer resources/configs/mock/sequencer_config.toml --genesis-paths resources/genesis/mock/ --dev &
sleep 2
RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/rollup_config.toml --genesis-paths resources/genesis/mock/ --dev &
sleep 2
cd ./bin/citrea/tests/evm/ethers_js
cd ./bin/citrea/tests/mock/evm/ethers_js
npm install
npx mocha test.js
cd ../../../../..
Expand Down Expand Up @@ -371,7 +410,9 @@ jobs:
run: make check-no-std

nextest:
needs: docker-setup
needs:
- docker-setup
- build-test
name: nextest
runs-on: ubicloud-standard-16
timeout-minutes: 60
Expand Down Expand Up @@ -402,26 +443,29 @@ jobs:
with:
key: "eth-tests-1c23e3c"
path: crates/evm/ethereum-tests

- name: Restore cached Docker image
uses: actions/cache@v4
with:
path: /tmp/docker
key: ${{ runner.os }}-docker-${{ env.TEST_BITCOIN_DOCKER }}

- name: Load Docker image
run: docker load < /tmp/docker/bitcoin.tar

- name: Download artifact
uses: actions/download-artifact@v4
with:
name: citrea-test-build
path: target/debug
- name: Make citrea executable
run: chmod +x target/debug/citrea
- name: Run nextest
run: make test
run: make test-ci
env:
RUST_BACKTRACE: 1
RISC0_DEV_MODE: 1 # This is needed to generate mock proofs and verify them
TEST_BITCOIN_DOCKER: 1
CITREA_E2E_TEST_BINARY: ${{ github.workspace }}/target/debug/citrea
PARALLEL_PROOF_LIMIT: 1
TEST_OUT_DIR: ${{ runner.temp }}/test

- name: Upload e2e test dir
if: failure() || cancelled()
uses: actions/upload-artifact@v4
Expand Down
22 changes: 13 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ build: ## Build the project
@cargo build

.PHONY: build-test
build-test: ## Build the project
build-test: $(EF_TESTS_DIR) ## Build the project
@cargo build $(TEST_FEATURES)

build-reproducible: build-risc0-docker build-sp1 ## Build the project in release mode with reproducible guest builds
Expand Down Expand Up @@ -55,8 +55,18 @@ clean-all: clean clean-node clean-txs
test-legacy: ## Runs test suite with output from tests printed
@cargo test -- --nocapture -Zunstable-options --report-time

test: build-test $(EF_TESTS_DIR) ## Runs test suite using next test
RISC0_DEV_MODE=1 cargo nextest run --workspace --all-features --no-fail-fast $(filter-out $@,$(MAKECMDGOALS))
test-ci:
RISC0_DEV_MODE=1 PARALLEL_PROOF_LIMIT=1 cargo nextest run --workspace --all-features --no-fail-fast $(filter-out $@,$(MAKECMDGOALS))

coverage-ci:
RISC0_DEV_MODE=1 PARALLEL_PROOF_LIMIT=1 cargo llvm-cov --locked --lcov --output-path lcov.info nextest --workspace --all-features

test: build-test test-ci ## Runs test suite using next test

coverage: build-test coverage-ci ## Coverage in lcov format

coverage-html: ## Coverage in HTML format
cargo llvm-cov --locked --all-features --html nextest --workspace --all-features

install-dev-tools: ## Installs all necessary cargo helpers
cargo install --locked dprint
Expand Down Expand Up @@ -105,12 +115,6 @@ find-unused-deps: ## Prints unused dependencies for project. Note: requires nigh
find-flaky-tests: ## Runs tests over and over to find if there's flaky tests
flaky-finder -j16 -r320 --continue "cargo test -- --nocapture"

coverage: build-test $(EF_TESTS_DIR) ## Coverage in lcov format
cargo llvm-cov --locked --lcov --output-path lcov.info nextest --workspace --all-features

coverage-html: ## Coverage in HTML format
cargo llvm-cov --locked --all-features --html nextest --workspace --all-features

docs: ## Generates documentation locally
cargo doc --open

Expand Down
5 changes: 5 additions & 0 deletions bin/citrea/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mock-e2e:
cargo nextest run --all-features --no-fail-fast --test mock_e2e

bitcoin-e2e:
cargo nextest run --all-features --no-fail-fast --test bitcoin_e2e
14 changes: 0 additions & 14 deletions bin/citrea/tests/all_tests.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use sov_rollup_interface::Network;
use tokio::time::sleep;

use super::get_citrea_path;
use crate::evm::make_test_client;
use crate::common::make_test_client;

pub async fn wait_for_zkproofs(
full_node: &FullNode,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use citrea_e2e::Result;
use reth_primitives::BlockNumberOrTag;

use super::get_citrea_path;
use crate::evm::make_test_client;
use crate::common::make_test_client;

/// Full node receives transaction from RPC.
/// Sends it to the sequencer.
Expand Down
2 changes: 2 additions & 0 deletions bin/citrea/tests/bitcoin_e2e.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod bitcoin;
mod common;
File renamed without changes.
3 changes: 3 additions & 0 deletions bin/citrea/tests/common/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub const TEST_SEND_NO_COMMITMENT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT: u64 = 1000;
pub const DEFAULT_PROOF_WAIT_DURATION: u64 = 600; // 10 minutes
pub const TEST_DATA_GENESIS_PATH: &str = "../../resources/test-data/integration-tests";
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ use tokio::sync::oneshot;
use tokio::time::sleep;
use tracing::{debug, info_span, instrument, warn, Instrument};

use crate::test_client::TestClient;
use crate::DEFAULT_PROOF_WAIT_DURATION;
use crate::common::client::TestClient;
use crate::common::DEFAULT_PROOF_WAIT_DURATION;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NodeMode {
Expand Down
29 changes: 29 additions & 0 deletions bin/citrea/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#![allow(dead_code)]
use std::net::SocketAddr;
use std::str::FromStr;

use alloy::signers::local::PrivateKeySigner;
use alloy::signers::Signer;
use alloy_primitives::Address;

use crate::common::client::TestClient;
pub use crate::common::constants::*;

pub mod client;
pub mod constants;
pub mod helpers;

#[allow(clippy::borrowed_box)]
pub async fn make_test_client(rpc_address: SocketAddr) -> anyhow::Result<Box<TestClient>> {
let chain_id: u64 = 5655;
let key = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
.parse::<PrivateKeySigner>()
.unwrap()
.with_chain_id(Some(chain_id));

let from_addr = Address::from_str("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266").unwrap();

Ok(Box::new(
TestClient::new(chain_id, key, from_addr, rpc_address).await?,
))
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use citrea_stf::genesis_config::GenesisPaths;
use reth_primitives::{BlockId, BlockNumberOrTag};
use tokio::time::sleep;

use crate::evm::init_test_rollup;
use crate::test_client::TestClient;
use crate::test_helpers::{
use super::init_test_rollup;
use crate::common::client::TestClient;
use crate::common::helpers::{
create_default_rollup_config, start_rollup, tempdir_with_children, wait_for_l2_block, NodeMode,
};
use crate::TEST_DATA_GENESIS_PATH;
use crate::common::TEST_DATA_GENESIS_PATH;

#[tokio::test(flavor = "multi_thread")]
async fn test_archival_state() -> Result<(), anyhow::Error> {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use citrea_common::SequencerConfig;
use citrea_stf::genesis_config::GenesisPaths;
use reth_primitives::BlockNumberOrTag;

use crate::evm::init_test_rollup;
use crate::test_helpers::{
use super::init_test_rollup;
use crate::common::helpers::{
create_default_rollup_config, start_rollup, tempdir_with_children, wait_for_l2_block, NodeMode,
};
use crate::TEST_DATA_GENESIS_PATH;
use crate::common::TEST_DATA_GENESIS_PATH;

#[tokio::test(flavor = "multi_thread")]
async fn test_minimum_base_fee() -> Result<(), anyhow::Error> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use citrea_evm::smart_contracts::SimpleStorageContract;
use citrea_stf::genesis_config::GenesisPaths;
use reth_primitives::BlockNumberOrTag;

use crate::evm::init_test_rollup;
use crate::test_client::TestClient;
use crate::test_helpers::{
use super::init_test_rollup;
use crate::common::client::TestClient;
use crate::common::helpers::{
create_default_rollup_config, start_rollup, tempdir_with_children, wait_for_l2_block, NodeMode,
};
use crate::TEST_DATA_GENESIS_PATH;
use crate::common::TEST_DATA_GENESIS_PATH;

#[tokio::test(flavor = "multi_thread")]
async fn test_gas_price_increase() -> Result<(), anyhow::Error> {
Expand Down
Loading

0 comments on commit f6eb357

Please sign in to comment.