Skip to content

Commit

Permalink
WEB3-113: chore: CI coverage of examples (#229)
Browse files Browse the repository at this point in the history
Inspired by #227 this PR runs `cargo fmt` `cargo sort` `cargo clippy`
`cargo test` and `forge tests` for all examples in the CI.
It uses a bash script to find all examples under the `example` folder
instead of manually listing them.

It also addresses all the found linter warnings.

closes WEB3-109
closes Web3-110
  • Loading branch information
Wollac committed Oct 7, 2024
1 parent cbb0819 commit 5e5dada
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 16 deletions.
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
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/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"

0 comments on commit 5e5dada

Please sign in to comment.