diff --git a/.github/workflows/validate_pr.yml b/.github/workflows/validate_pr.yml index cb49f5f..710a727 100644 --- a/.github/workflows/validate_pr.yml +++ b/.github/workflows/validate_pr.yml @@ -16,6 +16,34 @@ env: CARGO_TERM_COLOR: always jobs: + forge: + name: Forge + runs-on: macos-latest + steps: + - name: Install Foundry + run: | + curl -L https://foundry.paradigm.xyz | bash + foundryup + + - name: Verify Forge installation + run: forge --version + + - name: Set up Foundry cache + run: | + forge install + + - name: Run build script + run: | + chmod +x ./test-utils/scripts/build.sh + ./test-utils/scripts/build.sh + + - name: Upload Build Artifacts + if: success() + uses: actions/upload-artifact@v3 + with: + name: build-artifacts + path: ./out/ + formatting: name: Rustfmt runs-on: ubuntu-latest diff --git a/test-utils/Cargo.toml b/test-utils/Cargo.toml index 81e41b1..e5d19ed 100644 --- a/test-utils/Cargo.toml +++ b/test-utils/Cargo.toml @@ -7,13 +7,17 @@ license.workspace = true homepage.workspace = true repository.workspace = true -#[lib] -#name = "test_utils" -#path = "src/lib.rs" -# -#[[bin]] -#name = "incredible_squaring" -#path = "src/incredible_squaring.rs" +[lib] +name = "test_utils" +path = "src/lib.rs" + +[[bin]] +name = "incredible_squaring" +path = "src/bin/incredible_squaring.rs" + +[[bin]] +name = "tangle" +path = "src/bin/tangle.rs" [dependencies] alloy-abi.workspace = true diff --git a/test-utils/README.md b/test-utils/README.md new file mode 100644 index 0000000..dbef63e --- /dev/null +++ b/test-utils/README.md @@ -0,0 +1,75 @@ +# EigenSDK-RS Test Utilities + +[![Validate PR](https://github.com/webb-tools/eigensdk-rs/actions/workflows/validate_pr.yml/badge.svg)](https://github.com/webb-tools/eigensdk-rs/actions/workflows/validate_pr.yml) +[![Rust Version](https://img.shields.io/badge/rust-1.74.0%2B-blue.svg)](https://www.rust-lang.org) +--- + +## Overview + +Utilities designed to streamline and enhance the testing process of EigenSDK-RS and any projects that utilize it. + +## Getting Started + +To use `test-utils` in your own workspace, add it as a dev-dependency. Using these tools in EigenSDK-RS work out-of-the-box: + +```toml +[dev-dependencies] +test-utils = { path = "https://github.com/webb-tools/eigensdk-rs/tree/main/test-utils" } +``` +## Features + +--- +### Scripts + +To automatically set the Environment variables required for testing: +```bash +. ./scripts/env_setup.sh +``` + +If you are building your own AVS, you may be frequently rebuilding your Contracts. You can automatically clean and rebuild the contracts in `/contracts` with: +```bash +./scripts/rebuild_contracts.sh +``` +To rebuild the contracts in the AVS directory: +```bash +./scripts/rebuild_contracts.sh +``` + +--- + +### Test Binaries + +To run the included Testnets as binaries, build the project and then run the testnet you need: +```bash +cargo build -r +./target/release/incredible-squaring +``` +or +```bash +cargo build -r +./target/release/tangle +``` + +--- + +### Cargo tests + +To run the tests for the included AVSs (from the test-utils directory): + +#### Tangle +```bash +# To just run the deployment test, running the Testnet +cargo test test_tangle_deployment + +# To run the testnet and test connecting an Operator to it +cargo test test_full_tangle +``` + +#### Incredible Squaring +```bash +# To just run the deployment test, running the Testnet +cargo test test_incredible_squaring_deployment + +# To run the testnet and test connecting an Operator to it +cargo test test_full_incredible_squaring +``` diff --git a/test-utils/scripts/build.sh b/test-utils/scripts/build.sh new file mode 100644 index 0000000..4ea3fcc --- /dev/null +++ b/test-utils/scripts/build.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Define the directories +DIR1="./../contracts/lib/eigenlayer-middleware" +DIR2="./../contracts" +DIR3="./../avs/incredible-squaring-avs/contracts" +DIR4="./../avs/tangle-avs/contract" + +# Function to run forge commands in a directory +run_forge_commands() { + local dir=$1 + echo "Running forge commands in $dir" + cd "$dir" || exit + forge build + cd - || exit +} + +# Run forge commands in both directories +run_forge_commands "$DIR1" +run_forge_commands "$DIR2" +run_forge_commands "$DIR3" +run_forge_commands "$DIR4" \ No newline at end of file diff --git a/test-utils/src/anvil/testnet/mod.rs b/test-utils/src/anvil/testnet/mod.rs index e859aa4..07d8149 100644 --- a/test-utils/src/anvil/testnet/mod.rs +++ b/test-utils/src/anvil/testnet/mod.rs @@ -1,2 +1,2 @@ pub mod incredible_squaring; -pub(crate) mod tangle; +pub mod tangle; diff --git a/test-utils/src/incredible_squaring.rs b/test-utils/src/bin/incredible_squaring.rs similarity index 93% rename from test-utils/src/incredible_squaring.rs rename to test-utils/src/bin/incredible_squaring.rs index 00f8021..3ac0c2e 100644 --- a/test-utils/src/incredible_squaring.rs +++ b/test-utils/src/bin/incredible_squaring.rs @@ -1,5 +1,4 @@ #![allow(dead_code)] -use crate::anvil::testnet::incredible_squaring::*; use alloy_provider::Provider; use alloy_provider::ProviderBuilder; use alloy_signer_local::PrivateKeySigner; @@ -7,6 +6,7 @@ use alloy_transport_ws::WsConnect; use incredible_squaring_avs::operator::*; use k256::ecdsa::SigningKey; use k256::elliptic_curve::SecretKey; +use test_utils::anvil::testnet::incredible_squaring::*; #[tokio::main] async fn main() { @@ -107,16 +107,16 @@ mod tests { use k256::elliptic_curve::SecretKey; use std::env; - // #[tokio::test] - // async fn test_full_incredible_squaring() { - // if env::var("RUST_LOG").is_err() { - // env::set_var("RUST_LOG", "info"); - // } - // env::set_var("BLS_PASSWORD", "BLS_PASSWORD"); - // env::set_var("ECDSA_PASSWORD", "ECDSA_PASSWORD"); - // env_logger::init(); - // run_full_incredible_squaring_test().await; - // } + #[tokio::test] + async fn test_full_incredible_squaring() { + if env::var("RUST_LOG").is_err() { + env::set_var("RUST_LOG", "info"); + } + env::set_var("BLS_PASSWORD", "BLS_PASSWORD"); + env::set_var("ECDSA_PASSWORD", "ECDSA_PASSWORD"); + env_logger::init(); + run_full_incredible_squaring_test().await; + } #[tokio::test] async fn test_incredible_squaring_deployment() { diff --git a/test-utils/src/tangle.rs b/test-utils/src/bin/tangle.rs similarity index 94% rename from test-utils/src/tangle.rs rename to test-utils/src/bin/tangle.rs index e5d7d71..774d4b8 100644 --- a/test-utils/src/tangle.rs +++ b/test-utils/src/bin/tangle.rs @@ -1,5 +1,4 @@ #![allow(dead_code)] -use crate::anvil::testnet::tangle::*; use alloy_provider::Provider; use alloy_provider::ProviderBuilder; use alloy_signer_local::PrivateKeySigner; @@ -7,6 +6,7 @@ use alloy_transport_ws::WsConnect; use k256::ecdsa::SigningKey; use k256::elliptic_curve::SecretKey; use tangle_avs::operator::*; +use test_utils::anvil::testnet::tangle::*; #[tokio::main] async fn main() { @@ -101,16 +101,16 @@ mod tests { use k256::elliptic_curve::SecretKey; use std::env; - // #[tokio::test] - // async fn test_full_tangle() { - // if env::var("RUST_LOG").is_err() { - // env::set_var("RUST_LOG", "info"); - // } - // env::set_var("BLS_PASSWORD", "BLS_PASSWORD"); - // env::set_var("ECDSA_PASSWORD", "ECDSA_PASSWORD"); - // env_logger::init(); - // run_full_tangle_test().await; - // } + #[tokio::test] + async fn test_full_tangle() { + if env::var("RUST_LOG").is_err() { + env::set_var("RUST_LOG", "info"); + } + env::set_var("BLS_PASSWORD", "BLS_PASSWORD"); + env::set_var("ECDSA_PASSWORD", "ECDSA_PASSWORD"); + env_logger::init(); + run_full_tangle_test().await; + } #[tokio::test] async fn test_tangle_deployment() { diff --git a/test-utils/src/lib.rs b/test-utils/src/lib.rs index d621112..ff59a3b 100644 --- a/test-utils/src/lib.rs +++ b/test-utils/src/lib.rs @@ -1,3 +1 @@ pub mod anvil; -pub mod incredible_squaring; -pub mod tangle;