Skip to content

Commit

Permalink
Continue Improving Event Flows (#399)
Browse files Browse the repository at this point in the history
* wip: generalize tangle

* Add stopper for tangle

* Generalize TangleResult<Ty>, reduce macro code

* Update macros/blueprint-proc-macro/src/job.rs

Co-authored-by: Alex <[email protected]>

* Update sdk/src/event_listener/tangle/mod.rs

Co-authored-by: Alex <[email protected]>

* wip: Reduce EVM related code, add reliable/ordered protocol

* Incredible squaring eigen test working

* Add incredible-squaring-eigen test

* Adjust test name

---------

Co-authored-by: drewstone <[email protected]>
Co-authored-by: Alex <[email protected]>
  • Loading branch information
3 people authored Oct 30, 2024
1 parent 33a95cf commit ee6addc
Show file tree
Hide file tree
Showing 65 changed files with 1,159 additions and 641 deletions.
57 changes: 56 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
run: forge update && cd blueprints/incredible-squaring-eigenlayer && forge build --root ./contracts

- name: Run Clippy
run: cargo clippy --tests -- -D warnings
run: cargo clippy --tests --examples -- -D warnings

testing:
timeout-minutes: 90
Expand Down Expand Up @@ -122,3 +122,58 @@ jobs:

- name: tests
run: cargo nextest run --nocapture --package ${{ matrix.package }} ${{ matrix.package == 'gadget-sdk' && '--features getrandom,std' || '' }}

integration-test-eigenlayer:
timeout-minutes: 90
runs-on: macos-latest
steps:
- name: checkout code
uses: actions/checkout@v2

- name: Install Foundry
run: |
curl -L https://foundry.paradigm.xyz | bash
source /Users/runner/.bashrc
foundryup
- name: Add Foundry to PATH
run: echo "${HOME}/.foundry/bin" >> $GITHUB_PATH

- name: Forge build
run: forge update && cd blueprints/incredible-squaring-eigenlayer && forge build --root ./contracts && cd ../../

- name: setup-docker
run: brew install docker

- name: Verify Forge and Docker installation
run: forge --version && docker --version

- name: Run anvil in background
run: anvil --version && anvil &

- name: install rust
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: stable

- uses: swatinem/rust-cache@v2
with:
cache-on-failure: "true"

- name: install protobuf
run: brew install protobuf gmp

- name: Set Relevant M1 env vars
run: |
export LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/lib
export INCLUDE_PATH=$INCLUDE_PATH:/opt/homebrew/include
- name: install cargo-nextest
run: cargo install cargo-nextest --locked

- name: Build (release) integration test
run: cargo build --release -p incredible-squaring-blueprint-eigenlayer

- name: tests
run: RUST_LOG=gadget=trace cargo test --package blueprint-test-utils test_eigenlayer_incredible_squaring_blueprint -- --nocapture

11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"blueprints/incredible-squaring-eigenlayer",
"blueprints/incredible-squaring-symbiotic",
"blueprints/periodic-web-poller",
"blueprints/tangle-raw-event-listener",
"cli",
"gadget-io",
"blueprint-test-utils",
Expand All @@ -15,6 +16,7 @@ members = [
"macros/blueprint-proc-macro-core",
"macros/playground",
"macros/context-derive",

]
exclude = ["tangle-test-utils", "example"]

Expand Down Expand Up @@ -49,6 +51,7 @@ incredible-squaring-blueprint = { path = "./blueprints/incredible-squaring", def
incredible-squaring-blueprint-eigenlayer = { path = "./blueprints/incredible-squaring-eigenlayer", default-features = false, version = "0.1.1" }
incredible-squaring-blueprint-symbiotic = { path = "./blueprints/incredible-squaring-symbiotic", default-features = false, version = "0.1.1" }
periodic-web-poller-blueprint = { path = "./blueprints/periodic-web-poller", default-features = false, version = "0.1.1" }
tangle-raw-event-listener-blueprint = { path = "./blueprints/tangle-raw-event-listener", default-features = false, version = "0.1.1" }
gadget-blueprint-proc-macro = { path = "./macros/blueprint-proc-macro", default-features = false, version = "0.2.3" }
gadget-blueprint-proc-macro-core = { path = "./macros/blueprint-proc-macro-core", default-features = false, version = "0.1.5" }
gadget-context-derive = { path = "./macros/context-derive", default-features = false, version = "0.1.3" }
Expand Down
6 changes: 5 additions & 1 deletion blueprint-manager/src/sources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ pub fn generate_process_arguments(
format!("--ws-rpc-url={}", gadget_config.ws_rpc_url),
format!("--keystore-uri={}", gadget_config.keystore_uri),
format!("--chain={}", gadget_config.chain),
format!("-{}", "v".repeat(gadget_config.verbose as usize)),
format!("--blueprint-id={}", blueprint_id),
format!("--service-id={}", service_id),
format!("--protocol={}", protocol),
Expand All @@ -173,5 +172,10 @@ pub fn generate_process_arguments(
arguments.push(format!("--keystore-password={}", keystore_password));
}

// Uses occurrences of clap short -v
if opt.verbose > 0 {
arguments.push(format!("-{}", "v".repeat(opt.verbose as usize)));
}

Ok(arguments)
}
8 changes: 2 additions & 6 deletions blueprint-test-utils/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ impl BlueprintProcessManager {
format!("--ws-rpc-url={}", Url::parse(ws_endpoint).unwrap()),
format!("--keystore-uri={}", keystore_uri_str.clone()),
format!("--chain={}", SupportedChains::LocalTestnet),
format!("--vvv"),
format!("--pretty"),
"-vvv".to_string(),
"--pretty".to_string(),
format!("--blueprint-id={}", instance_id),
format!("--service-id={}", instance_id),
format!("--protocol={}", protocol),
Expand Down Expand Up @@ -168,10 +168,6 @@ impl BlueprintProcessManager {
"--strategy-manager={}",
EigenlayerContractAddresses::default().strategy_manager_address
));
arguments.push(format!(
"--avs-directory={}",
EigenlayerContractAddresses::default().avs_directory_address
));
}
Protocol::Symbiotic => {
arguments.push(format!(
Expand Down
69 changes: 40 additions & 29 deletions blueprint-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,24 +313,6 @@ pub async fn request_service(
Ok(())
}

/// Approves a service request. This is meant for testing, and will always approve the request.
pub async fn approve_service(
client: &TestClient,
caller: &TanglePairSigner<sp_core::sr25519::Pair>,
request_id: u64,
restaking_percent: u8,
) -> Result<(), Box<dyn Error>> {
let call = api::tx()
.services()
.approve(request_id, Percent(restaking_percent));
let res = client
.tx()
.sign_and_submit_then_watch_default(&call, caller)
.await?;
wait_for_in_block_success(res).await?;
Ok(())
}

pub async fn wait_for_in_block_success(
mut res: TxProgress<TangleConfig, TestClient>,
) -> Result<(), Box<dyn Error>> {
Expand Down Expand Up @@ -410,6 +392,39 @@ pub async fn get_next_call_id(client: &TestClient) -> Result<u64, Box<dyn Error>
Ok(res)
}

/// Approves a service request. This is meant for testing, and will always approve the request.
pub async fn approve_service(
client: &TestClient,
caller: &TanglePairSigner<sp_core::sr25519::Pair>,
request_id: u64,
restaking_percent: u8,
) -> Result<(), Box<dyn Error>> {
gadget_sdk::info!("Approving service request ...");
let call = api::tx()
.services()
.approve(request_id, Percent(restaking_percent));
let res = client
.tx()
.sign_and_submit_then_watch_default(&call, caller)
.await?;
res.wait_for_finalized_success().await?;
Ok(())
}

pub async fn get_next_request_id(client: &TestClient) -> Result<u64, Box<dyn Error>> {
gadget_sdk::info!("Fetching next request ID ...");
let next_request_id_addr = api::storage().services().next_service_request_id();
let next_request_id = client
.storage()
.at_latest()
.await
.expect("Failed to fetch latest block")
.fetch_or_default(&next_request_id_addr)
.await
.expect("Failed to fetch next request ID");
Ok(next_request_id)
}

#[macro_export]
macro_rules! test_blueprint {
(
Expand All @@ -420,7 +435,7 @@ macro_rules! test_blueprint {
[$($expected_output:expr),+]
) => {
use $crate::{
get_next_call_id, get_next_service_id, run_test_blueprint_manager,
get_next_call_id, run_test_blueprint_manager,
submit_job, wait_for_completion_of_tangle_job, Opts, setup_log,
};

Expand Down Expand Up @@ -457,11 +472,10 @@ macro_rules! test_blueprint {
run_test_blueprint_manager,
)
.await
.execute_with_async(move |client, handles| async move {
.execute_with_async(move |client, handles, blueprint| async move {
let keypair = handles[0].sr25519_id().clone();
let service_id = get_next_service_id(client)
.await
.expect("Failed to get next service id");
let selected_service = &blueprint.services[0];
let service_id = selected_service.id;
let call_id = get_next_call_id(client)
.await
.expect("Failed to get next job id");
Expand Down Expand Up @@ -570,17 +584,14 @@ mod tests_standard {

new_test_ext_blueprint_manager::<5, 1, (), _, _>((), opts, run_test_blueprint_manager)
.await
.execute_with_async(move |client, handles| async move {
.execute_with_async(move |client, handles, blueprint| async move {
// At this point, blueprint has been deployed, every node has registered
// as an operator for the relevant services, and, all gadgets are running

// What's left: Submit a job, wait for the job to finish, then assert the job results
let keypair = handles[0].sr25519_id().clone();

let service_id = get_next_service_id(client)
.await
.expect("Failed to get next service id")
.saturating_sub(1);
let selected_service = &blueprint.services[0];
let service_id = selected_service.id;
let call_id = get_next_call_id(client)
.await
.expect("Failed to get next job id")
Expand Down
Loading

0 comments on commit ee6addc

Please sign in to comment.