Skip to content

Commit

Permalink
Pull in main
Browse files Browse the repository at this point in the history
Refactor get_client to support both ws and http

Add helper functions to config
  • Loading branch information
tbraun96 committed Oct 30, 2024
2 parents 239fce0 + 33a95cf commit 4713d4f
Show file tree
Hide file tree
Showing 70 changed files with 3,280 additions and 1,701 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
blueprint-manager,
gadget-context-derive,
gadget-blueprint-proc-macro,
gadget-blueprint-proc-macro-playground,
gadget-blueprint-proc-macro-playground
]
steps:
- name: checkout code
Expand Down
8 changes: 7 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@
[submodule "blueprints/ecdsa-threshold-mpc/contracts/lib/tnt-core"]
path = blueprints/ecdsa-threshold-mpc/contracts/lib/tnt-core
url = https://github.com/tangle-network/tnt-core
branch = main
branch = main
[submodule "blueprints/incredible-squaring-symbiotic/contracts/lib/forge-std"]
path = blueprints/incredible-squaring-symbiotic/contracts/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "blueprints/incredible-squaring-symbiotic/contracts/lib/core"]
path = blueprints/incredible-squaring-symbiotic/contracts/lib/core
url = https://github.com/symbioticfi/core
56 changes: 56 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"blueprint-metadata",
"blueprints/incredible-squaring",
"blueprints/incredible-squaring-eigenlayer",
"blueprints/incredible-squaring-symbiotic",
"blueprints/periodic-web-poller",
"blueprints/tangle-raw-event-listener",
"cli",
Expand Down Expand Up @@ -46,7 +47,9 @@ blueprint-manager = { version = "0.1.1", path = "./blueprint-manager" }
blueprint-test-utils = { path = "./blueprint-test-utils" }
gadget-sdk = { path = "./sdk", default-features = false, version = "0.2.3" }

incredible-squaring-blueprint = { path = "./blueprints/incredible-squaring", default-features = false, version = "0.1.1" }
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" }
Expand Down Expand Up @@ -181,6 +184,9 @@ secp256k1 = "0.29.1"
eigensdk = { version = "0.1.0", features = ["full", "utils", "types"] }
testcontainers = { version = "0.20.1" }

# Symbiotic
symbiotic-rs = { version = "0.1.0" }

# Config for 'cargo dist'
[workspace.metadata.dist]
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
Expand Down
2 changes: 1 addition & 1 deletion blueprint-manager/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct BlueprintManagerConfig {
/// The directory in which all gadgets will store their data
#[arg(long, short = 'd', default_value = "./data")]
pub data_dir: PathBuf,
/// The verbosity level, can be used multiple times
/// The verbosity level, can be used multiple times to increase verbosity
#[arg(long, short = 'v', action = clap::ArgAction::Count)]
pub verbose: u8,
/// Whether to use pretty logging
Expand Down
2 changes: 2 additions & 0 deletions blueprint-manager/src/sources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ 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!("--verbose={}", opt.verbose),
format!("--pretty={}", opt.pretty),
format!("--blueprint-id={}", blueprint_id),
format!("--service-id={}", service_id),
format!("--protocol={}", protocol),
Expand Down
53 changes: 11 additions & 42 deletions blueprint-manager/src/sources/testing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::sources::BinarySourceFetcher;
use async_trait::async_trait;
use color_eyre::Report;
use gadget_sdk::{info, trace};
use gadget_sdk::trace;
use std::path::PathBuf;
use tangle_subxt::tangle_testnet_runtime::api::runtime_types::tangle_primitives::services::TestFetcher;

Expand All @@ -26,52 +26,21 @@ impl BinarySourceFetcher for TestSourceFetcher {
.map_err(|err| Report::msg(format!("Failed to parse `base_path`: {:?}", err)))?;
let git_repo_root = get_git_repo_root_path().await?;

let profile = if cfg!(debug_assertions) {
"debug"
} else {
"release"
};
let base_path = std::path::absolute(git_repo_root.join(&base_path_str))?;
let binary_path = git_repo_root.join(&base_path).join("bin").join(&cargo_bin);
let binary_path = git_repo_root
.join(&base_path)
.join("target")
.join(profile)
.join(&cargo_bin);
let binary_path = std::path::absolute(&binary_path)?;

trace!("Base Path: {}", base_path.display());
trace!("Binary Path: {}", binary_path.display());
info!("Building binary...");

let env = std::env::vars().collect::<Vec<(String, String)>>();

// Note: even if multiple gadgets are built, only the leader will actually build
// while the followers will just hang on the Cargo.lock file and then instantly
// finish compilation
let tokio_build_process = tokio::process::Command::new("cargo")
.arg("install")
.arg("--path")
.arg(&base_path)
// .arg("--bin")
// .arg(cargo_bin)
.arg("--root")
.arg(&base_path)
.stdout(std::process::Stdio::inherit()) // Inherit the stdout of this process
.stderr(std::process::Stdio::inherit()) // Inherit the stderr of this process
.stdin(std::process::Stdio::null())
.current_dir(&std::env::current_dir()?)
.envs(env)
.output()
.await
.map_err(|err| Report::msg(format!("Failed to run `cargo install`: {:?}", err)))?;

if !tokio_build_process.status.success() {
return Err(Report::msg(format!(
"Failed to build binary: {:?}",
tokio_build_process
)));
}

if !binary_path.exists() {
return Err(Report::msg(format!(
"Binary not found at path: {}",
binary_path.display()
)));
}

info!("Successfully built binary to {}", binary_path.display());

Ok(binary_path)
}

Expand Down
1 change: 1 addition & 0 deletions blueprint-test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ alloy-contract = { workspace = true }
alloy-rpc-types-eth = { workspace = true }
alloy-node-bindings = { workspace = true }
thiserror = { workspace = true }
lazy_static = { workspace = true }

eigensdk = { workspace = true }
testcontainers = { workspace = true }
Expand Down
113 changes: 113 additions & 0 deletions blueprint-test-utils/src/eigenlayer_test_env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
use alloy_primitives::{address, Address};
use alloy_provider::Provider;
use gadget_sdk::info;
use gadget_sdk::{
config::protocol::EigenlayerContractAddresses, events_watcher::evm::get_provider_http,
};

use crate::helpers::get_receipt;

alloy_sol_types::sol!(
#[allow(missing_docs)]
#[sol(rpc)]
#[derive(Debug)]
IncredibleSquaringTaskManager,
"./../blueprints/incredible-squaring-eigenlayer/contracts/out/IncredibleSquaringTaskManager.sol/IncredibleSquaringTaskManager.json"
);

alloy_sol_types::sol!(
#[allow(missing_docs)]
#[sol(rpc)]
#[derive(Debug)]
PauserRegistry,
"./../blueprints/incredible-squaring-eigenlayer/contracts/out/IPauserRegistry.sol/IPauserRegistry.json"
);

alloy_sol_types::sol!(
#[allow(missing_docs, clippy::too_many_arguments)]
#[sol(rpc)]
#[derive(Debug)]
RegistryCoordinator,
"./../blueprints/incredible-squaring-eigenlayer/contracts/out/RegistryCoordinator.sol/RegistryCoordinator.json"
);

pub struct EigenlayerTestEnvironment {
pub http_endpoint: String,
pub ws_endpoint: String,
pub accounts: Vec<Address>,
pub eigenlayer_contract_addresses: EigenlayerContractAddresses,
pub pauser_registry_address: Address,
}

pub async fn setup_eigenlayer_test_environment(
http_endpoint: &str,
ws_endpoint: &str,
) -> EigenlayerTestEnvironment {
let provider = get_provider_http(http_endpoint);

let accounts = provider.get_accounts().await.unwrap();

let registry_coordinator_address = address!("c3e53f4d16ae77db1c982e75a937b9f60fe63690");
std::env::set_var(
"REGISTRY_COORDINATOR_ADDR",
registry_coordinator_address.to_string(),
);
let operator_state_retriever_address = address!("1613beb3b2c4f22ee086b2b38c1476a3ce7f78e8");
std::env::set_var(
"OPERATOR_STATE_RETRIEVER_ADDR",
operator_state_retriever_address.to_string(),
);
let delegation_manager_address = address!("dc64a140aa3e981100a9beca4e685f962f0cf6c9");
std::env::set_var(
"DELEGATION_MANAGER_ADDR",
delegation_manager_address.to_string(),
);
let strategy_manager_address = address!("5fc8d32690cc91d4c39d9d3abcbd16989f875707");
std::env::set_var(
"STRATEGY_MANAGER_ADDR",
strategy_manager_address.to_string(),
);
let erc20_mock_address = address!("7969c5ed335650692bc04293b07f5bf2e7a673c0");
std::env::set_var("ERC20_MOCK_ADDR", erc20_mock_address.to_string());

let pauser_registry = PauserRegistry::deploy(provider.clone()).await.unwrap();
let pauser_registry_address = *pauser_registry.address();

let registry_coordinator =
RegistryCoordinator::new(registry_coordinator_address, provider.clone());

let operator_set_params = RegistryCoordinator::OperatorSetParam {
maxOperatorCount: 10,
kickBIPsOfOperatorStake: 100,
kickBIPsOfTotalStake: 1000,
};
let strategy_params = RegistryCoordinator::StrategyParams {
strategy: erc20_mock_address,
multiplier: 1,
};

info!("Creating Quorum");
let _receipt = get_receipt(registry_coordinator.createQuorum(
operator_set_params,
0,
vec![strategy_params],
))
.await
.unwrap();

info!("Setup Eigenlayer test environment");

EigenlayerTestEnvironment {
http_endpoint: http_endpoint.to_string(),
ws_endpoint: ws_endpoint.to_string(),
accounts,
eigenlayer_contract_addresses: EigenlayerContractAddresses {
registry_coordinator_address,
operator_state_retriever_address,
delegation_manager_address,
strategy_manager_address,
avs_directory_address: Default::default(),
},
pauser_registry_address,
}
}
Loading

0 comments on commit 4713d4f

Please sign in to comment.