Skip to content

Commit

Permalink
Workflow, testing readme, and build script
Browse files Browse the repository at this point in the history
  • Loading branch information
Tjemmmic committed Aug 14, 2024
1 parent 3c7f124 commit 165c457
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 32 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/validate_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
75 changes: 75 additions & 0 deletions test-utils/README.md
Original file line number Diff line number Diff line change
@@ -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
```
22 changes: 22 additions & 0 deletions test-utils/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion test-utils/src/anvil/testnet/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod incredible_squaring;
pub(crate) mod tangle;
pub mod tangle;
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#![allow(dead_code)]
use crate::anvil::testnet::incredible_squaring::*;
use alloy_provider::Provider;
use alloy_provider::ProviderBuilder;
use alloy_signer_local::PrivateKeySigner;
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() {
Expand Down Expand Up @@ -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() {
Expand Down
22 changes: 11 additions & 11 deletions test-utils/src/tangle.rs → test-utils/src/bin/tangle.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#![allow(dead_code)]
use crate::anvil::testnet::tangle::*;
use alloy_provider::Provider;
use alloy_provider::ProviderBuilder;
use alloy_signer_local::PrivateKeySigner;
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() {
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 0 additions & 2 deletions test-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
pub mod anvil;
pub mod incredible_squaring;
pub mod tangle;

0 comments on commit 165c457

Please sign in to comment.