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

WEB3-113: chore: CI coverage of examples #229

Merged
merged 25 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/scripts/cargo-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -e

fmt_sort(){
while read path; do
printf "Project: %s\n" "$path"
cargo fmt --all --check --manifest-path "$path"
(cd "${path%/*}"; cargo sort --workspace --check)
done
}

grep -rl --include "Cargo.toml" '\[workspace\]' | sort -u | fmt_sort
11 changes: 11 additions & 0 deletions .github/scripts/cargo-clippy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

clippy(){
while read path; do
printf "Project: %s\n" "$path"
cargo clippy --workspace --all-targets --all-features --manifest-path "$path"
done
}

grep -rl --include "Cargo.toml" '\[workspace\]' | sort -u | clippy
12 changes: 12 additions & 0 deletions .github/scripts/cargo-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -e

build_test(){
while read path; do
printf "Project: %s\n" "$path"
cargo build --workspace --all-features --manifest-path "$path"
cargo test --workspace --all-features --manifest-path "$path"
done
}

find . -maxdepth 2 -mindepth 2 -name 'Cargo.toml' | sort -u | build_test
11 changes: 11 additions & 0 deletions .github/scripts/forge-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

fmt(){
while read path; do
printf "Project: %s\n" "$path"
(cd "${path%/*}"; forge fmt --check)
done
}

find . -maxdepth 2 -mindepth 2 -name 'foundry.toml' | sort -u | fmt
11 changes: 11 additions & 0 deletions .github/scripts/forge-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

test(){
while read path; do
printf "Project: %s\n" "$path"
(cd "${path%/*}"; forge test -vvvv)
done
}

find . -maxdepth 2 -mindepth 2 -name 'foundry.toml' | sort -u | test
107 changes: 65 additions & 42 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- check
- doc
- docs-rs
- test
- test-risc0-ethereum
runs-on: ubuntu-latest
steps:
- name: Check all job status
Expand All @@ -44,22 +44,26 @@ jobs:
with:
# Full history is required by license-check.py
fetch-depth: 0
submodules: recursive
- uses: risc0/risc0/.github/actions/rustup@main
- name: Install cargo-sort
uses: risc0/cargo-install@b9307573043522ab0d3e3be64a51763b765b52a4
with:
crate: cargo-sort
version: "1.0"
- uses: actions/setup-node@v3
with:
node-version: 18
- name: cargo check risc0-ethereum
run: |
cargo fmt --all --check
cargo sort --workspace --check
- name: cargo check examples
run: ../.github/scripts/cargo-check.sh
working-directory: examples
- uses: risc0/foundry-toolchain@2fe7e70b520f62368a0e3c464f997df07ede420f
- run: cargo fmt --all --check
- run: cargo sort --workspace --check
- run: cargo clippy --workspace
- run: forge fmt --check
- name: forge check risc0-ethereum
run: forge fmt --check
working-directory: contracts
- name: forge check examples
run: ../.github/scripts/forge-check.sh
working-directory: examples
- uses: actions/setup-python@v4
with:
python-version: "3.10"
Expand All @@ -68,7 +72,42 @@ jobs:
run: |
[ "$(grep -re 'DO[_ ]\?NOT[_ ]\?MERGE' $(git ls-tree --full-tree --name-only -r HEAD) | tee /dev/fd/2 | wc -l)" -eq "0" ]

test:
clippy:
runs-on: [self-hosted, prod, "${{ matrix.os }}", "${{ matrix.device }}"]
strategy:
# Run only on Linux with CPU.
matrix:
include:
- os: Linux
feature: default
device: cpu
steps:
# This is a workaround from: https://github.com/actions/checkout/issues/590#issuecomment-970586842
- run: "git checkout -f $(git -c user.name=x -c user.email=x@x commit-tree $(git hash-object -t tree /dev/null) < /dev/null) || :"
- uses: actions/checkout@v4
with:
submodules: recursive
- if: matrix.feature == 'cuda'
uses: risc0/risc0/.github/actions/cuda@main
- uses: risc0/risc0/.github/actions/rustup@main
- uses: risc0/risc0/.github/actions/sccache@main
with:
key: ${{ matrix.os }}-${{ matrix.feature }}
- uses: ./.github/actions/cargo-risczero-install
with:
ref: ${{ env.RISC0_MONOREPO_REF }}
toolchain-version: ${{ env.RISC0_TOOLCHAIN_VERSION }}
features: ${{ matrix.feature }}
- name: cargo clippy risc0-ethereum
run: cargo clippy --workspace --all-targets --all-features
- name: cargo clippy all examples
run: ../.github/scripts/cargo-clippy.sh
working-directory: examples
env:
RISC0_SKIP_BUILD: true
- run: sccache --show-stats

test-risc0-ethereum:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why suffix test with risc0-ethereum, given that we are in the risc0-ethereum repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it only runs cargo test on the main workspace and not examples etc. There is a separate job for that.

runs-on: [self-hosted, prod, "${{ matrix.os }}", "${{ matrix.device }}"]
strategy:
fail-fast: false
Expand Down Expand Up @@ -104,11 +143,12 @@ jobs:
toolchain-version: ${{ env.RISC0_TOOLCHAIN_VERSION }}
features: ${{ matrix.feature }}
- uses: risc0/foundry-toolchain@2fe7e70b520f62368a0e3c464f997df07ede420f
- name: build workspace
run: cargo test --workspace --timings --no-run
- name: test workspace
run: cargo test --workspace --timings
- uses: actions/upload-artifact@v3
- name: cargo build
run: cargo build --workspace --all-features
- name: cargo test
run: cargo test --workspace --all-features --timings
- name: Upload timings artifacts
uses: actions/upload-artifact@v3
with:
name: cargo-timings-${{ matrix.os }}-${{ matrix.device }}
path: target/cargo-timings/
Expand All @@ -120,13 +160,12 @@ jobs:
examples:
runs-on: [self-hosted, prod, "${{ matrix.os }}", "${{ matrix.device }}"]
strategy:
fail-fast: false
# Run only on Linux with GPU. Additional coverage is marginal, and GPU is fastest.
# Run only on Linux with CPU. Additional coverage is marginal.
matrix:
include:
- os: Linux
feature: cuda
device: nvidia_rtx_a5000
feature: default
device: cpu
steps:
# This is a workaround from: https://github.com/actions/checkout/issues/590#issuecomment-970586842
- run: "git checkout -f $(git -c user.name=x -c user.email=x@x commit-tree $(git hash-object -t tree /dev/null) < /dev/null) || :"
Expand All @@ -139,34 +178,18 @@ jobs:
- uses: risc0/risc0/.github/actions/sccache@main
with:
key: ${{ matrix.os }}-${{ matrix.feature }}
- uses: risc0/foundry-toolchain@2fe7e70b520f62368a0e3c464f997df07ede420f
- uses: actions/setup-node@v4
with:
node-version: 18
- uses: ./.github/actions/cargo-risczero-install
with:
ref: ${{ env.RISC0_MONOREPO_REF }}
toolchain-version: ${{ env.RISC0_TOOLCHAIN_VERSION }}
features: ${{ matrix.feature }}
- name: build erc20
run: cargo build
working-directory: examples/erc20
- name: build erc20-Counter
run: cargo build
working-directory: examples/erc20-counter
- name: forge test erc20-Counter
run: forge test
working-directory: examples/erc20-counter
env:
ETH_RPC_URL: https://ethereum-sepolia-rpc.publicnode.com
- name: build token-stats
run: cargo build
working-directory: examples/token-stats
- name: test erc20-Counter
run: ./test-local-deployment.sh
working-directory: examples/erc20-counter
env:
RISC0_DEV_MODE: true
- uses: risc0/foundry-toolchain@2fe7e70b520f62368a0e3c464f997df07ede420f
- name: cargo test all examples
run: ../.github/scripts/cargo-test.sh
working-directory: examples
- name: forge test all examples
run: ../.github/scripts/forge-test.sh
working-directory: examples
- run: sccache --show-stats

doc:
Expand Down
5 changes: 4 additions & 1 deletion examples/erc20-counter/apps/src/bin/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ async fn main() -> Result<()> {
.on_http(args.eth_rpc_url);

// Create an EVM environment from that provider defaulting to the latest block.
let mut env = EthEvmEnv::builder().provider(provider.clone()).build().await?;
let mut env = EthEvmEnv::builder()
.provider(provider.clone())
.build()
.await?;
// The `with_chain_spec` method is used to specify the chain configuration.
env = env.with_chain_spec(&ETH_SEPOLIA_CHAIN_SPEC);

Expand Down
5 changes: 2 additions & 3 deletions examples/erc20-counter/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[toolchain]
channel = "1.79"
channel = "stable"
components = ["clippy", "rustfmt", "rust-src"]
targets = []
profile = "minimal"
profile = "minimal"
1 change: 0 additions & 1 deletion examples/erc20/host/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use clap::Parser;
use erc20_methods::ERC20_GUEST_ELF;
use risc0_steel::{
ethereum::{EthEvmEnv, ETH_SEPOLIA_CHAIN_SPEC},
host::BlockNumberOrTag,
Contract,
};
use risc0_zkvm::{default_executor, ExecutorEnv};
Expand Down
2 changes: 1 addition & 1 deletion examples/erc20/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "stable"
components = ["rustfmt", "rust-src"]
components = ["clippy", "rustfmt", "rust-src"]
profile = "minimal"
3 changes: 2 additions & 1 deletion examples/token-stats/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ alloy-sol-types = { version = "0.8" }
anyhow = "1.0"
clap = { version = "4.4", features = ["derive", "env"] }
log = "0.4"
methods = { path = "methods" }
token-stats-core = { path = "core" }
token-stats-methods = { path = "methods" }
once_cell = "1.19"
rlp = "0.5.2"
serde = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/token-stats/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "core"
name = "token-stats-core"
version = "0.1.0"
edition = "2021"

Expand Down
4 changes: 2 additions & 2 deletions examples/token-stats/host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ edition = "2021"
alloy-sol-types = { workspace = true }
anyhow = { workspace = true }
clap = { workspace = true }
core = { path = "../core" }
methods = { workspace = true }
risc0-steel = { workspace = true, features = ["host"] }
risc0-zkvm = { workspace = true, features = ["client"] }
token-stats-core = { workspace = true }
token-stats-methods = { workspace = true }
tokio = { workspace = true }
tracing-subscriber = { workspace = true }
url = { workspace = true }
4 changes: 2 additions & 2 deletions examples/token-stats/host/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
use alloy_sol_types::{SolCall, SolValue};
use anyhow::{Context, Result};
use clap::Parser;
use core::{APRCommitment, CometMainInterface, CONTRACT};
use methods::TOKEN_STATS_ELF;
use risc0_steel::{
ethereum::{EthEvmEnv, ETH_MAINNET_CHAIN_SPEC},
Contract,
};
use risc0_zkvm::{default_executor, ExecutorEnv};
use token_stats_core::{APRCommitment, CometMainInterface, CONTRACT};
use token_stats_methods::TOKEN_STATS_ELF;
use tracing_subscriber::EnvFilter;
use url::Url;

Expand Down
2 changes: 1 addition & 1 deletion examples/token-stats/methods/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "methods"
name = "token-stats-methods"
version = "0.1.0"
edition = "2021"

Expand Down
2 changes: 1 addition & 1 deletion examples/token-stats/methods/guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ edition = "2021"

[dependencies]
alloy-sol-types = { version = "0.8" }
core = { path = "../../core" }
risc0-steel = { path = "../../../../steel" }
risc0-zkvm = { git = "https://github.com/risc0/risc0", branch = "main", default-features = false, features = ["std"] }
token-stats-core = { path = "../../core" }

[patch.crates-io]
# use optimized risc0 circuit
Expand Down
2 changes: 1 addition & 1 deletion examples/token-stats/methods/guest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
// limitations under the License.

use alloy_sol_types::SolValue;
use core::{APRCommitment, CometMainInterface, CONTRACT};
use risc0_steel::{
ethereum::{EthEvmInput, ETH_MAINNET_CHAIN_SPEC},
Contract,
};
use risc0_zkvm::guest::env;
use token_stats_core::{APRCommitment, CometMainInterface, CONTRACT};

const SECONDS_PER_YEAR: u64 = 60 * 60 * 24 * 365;

Expand Down
4 changes: 2 additions & 2 deletions examples/token-stats/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "stable"
components = ["rustfmt", "rust-src"]
profile = "minimal"
components = ["clippy", "rustfmt", "rust-src"]
profile = "minimal"
Loading