Skip to content

Commit

Permalink
fix(cli): alloy 0.7 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
mempirate committed Dec 2, 2024
1 parent ae8f7be commit e6a9c27
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 35 deletions.
63 changes: 32 additions & 31 deletions bolt-cli/src/commands/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,6 @@ impl OperatorsCommand {

#[cfg(test)]
mod tests {
use std::process::{Command, Output};

use crate::{
cli::{
Chain, EigenLayerSubcommand, OperatorsCommand, OperatorsSubcommand, SymbioticSubcommand,
Expand All @@ -364,26 +362,31 @@ mod tests {
};
use alloy::{
network::EthereumWallet,
node_bindings::Anvil,
primitives::{address, keccak256, utils::parse_units, Address, B256, U256},
providers::{ext::AnvilApi, Provider, ProviderBuilder, WalletProvider},
providers::{ext::AnvilApi, ProviderBuilder, WalletProvider},
signers::local::PrivateKeySigner,
sol_types::SolValue,
};
use rand::Rng;
use reqwest::Url;
use std::process::{Command, Output};

#[tokio::test]
async fn test_eigenlayer_flow() {
let _ = tracing_subscriber::fmt().try_init();
let mut rnd = rand::thread_rng();
let secret_key = B256::from(rnd.gen::<[u8; 32]>());
let wallet = PrivateKeySigner::from_bytes(&secret_key).expect("valid private key");
let s1 = PrivateKeySigner::random();
let secret_key = s1.to_bytes();
let s2 = PrivateKeySigner::random();

let mut wallet = EthereumWallet::new(s1);
wallet.register_signer(s2);

let rpc_url = "https://holesky.drpc.org";
let anvil = Anvil::default().fork(rpc_url).spawn();
let anvil_url = Url::parse(&anvil.endpoint()).expect("valid URL");
let provider = ProviderBuilder::new()
.with_recommended_fillers()
.wallet(EthereumWallet::from(wallet))
.on_anvil_with_config(|anvil| anvil.fork(rpc_url));
let anvil_url = provider.client().transport().url();
.wallet(wallet)
.on_http(anvil_url.clone());

let account = provider.default_signer_address();

Expand All @@ -407,7 +410,7 @@ mod tests {
.await
.expect("to set storage");

let random_address = Address::from(rnd.gen::<[u8; 20]>());
let random_address = provider.signer_addresses().nth(1).expect("second signer");

// 1. Register the operator into EigenLayer. This should be done by the operator using the
// EigenLayer CLI, but we do it here for testing purposes.
Expand Down Expand Up @@ -446,7 +449,7 @@ mod tests {
let deposit_into_strategy = OperatorsCommand {
subcommand: OperatorsSubcommand::EigenLayer {
subcommand: EigenLayerSubcommand::Deposit {
rpc_url: anvil_url.parse().expect("valid url"),
rpc_url: anvil_url.clone(),
operator_private_key: secret_key,
strategy: EigenLayerStrategy::WEth,
amount: U256::from(1),
Expand All @@ -461,7 +464,7 @@ mod tests {
let register_operator = OperatorsCommand {
subcommand: OperatorsSubcommand::EigenLayer {
subcommand: EigenLayerSubcommand::Register {
rpc_url: anvil_url.parse().expect("valid url"),
rpc_url: anvil_url.clone(),
operator_private_key: secret_key,
operator_rpc: "https://bolt.chainbound.io/rpc".parse().expect("valid url"),
salt: B256::ZERO,
Expand All @@ -475,10 +478,7 @@ mod tests {
// 4. Check operator registration
let check_operator_registration = OperatorsCommand {
subcommand: OperatorsSubcommand::EigenLayer {
subcommand: EigenLayerSubcommand::Status {
rpc_url: anvil_url.parse().expect("valid url"),
address: account,
},
subcommand: EigenLayerSubcommand::Status { rpc_url: anvil_url, address: account },
},
};

Expand Down Expand Up @@ -513,16 +513,17 @@ mod tests {
#[tokio::test]
#[ignore = "requires Symbiotic CLI installed"]
async fn test_symbiotic_flow() {
let mut rnd = rand::thread_rng();
let secret_key = B256::from(rnd.gen::<[u8; 32]>());
let wallet = PrivateKeySigner::from_bytes(&secret_key).expect("valid private key");
let s1 = PrivateKeySigner::random();
let secret_key = s1.to_bytes();
let wallet = EthereumWallet::new(s1);

let rpc_url = "https://rpc-holesky.bolt.chainbound.io/rpc";
let rpc_url = "https://holesky.drpc.org";
let anvil = Anvil::default().fork(rpc_url).spawn();
let anvil_url = Url::parse(&anvil.endpoint()).expect("valid URL");
let provider = ProviderBuilder::new()
.with_recommended_fillers()
.wallet(EthereumWallet::from(wallet))
.on_anvil_with_config(|anvil| anvil.fork(rpc_url));
let anvil_url = provider.client().transport().url();
.wallet(wallet)
.on_http(anvil_url.clone());

let account = provider.default_signer_address();

Expand Down Expand Up @@ -552,7 +553,7 @@ mod tests {
.arg("--chain")
.arg("holesky")
.arg("--provider")
.arg(anvil_url)
.arg(anvil_url.to_string())
.arg("register-operator")
.arg("--private-key")
.arg(secret_key.to_string())
Expand All @@ -566,7 +567,7 @@ mod tests {
.arg("--chain")
.arg("holesky")
.arg("--provider")
.arg(anvil_url)
.arg(anvil_url.to_string())
.arg("opt-in-network")
.arg("--private-key")
.arg(secret_key.to_string())
Expand All @@ -583,7 +584,7 @@ mod tests {
.arg("--chain")
.arg("holesky")
.arg("--provider")
.arg(anvil_url)
.arg(anvil_url.to_string())
.arg("opt-in-vault")
.arg("--private-key")
.arg(secret_key.to_string())
Expand All @@ -598,7 +599,7 @@ mod tests {
.arg("--chain")
.arg("holesky")
.arg("--provider")
.arg(anvil_url)
.arg(anvil_url.to_string())
.arg("deposit")
.arg("--private-key")
.arg(secret_key.to_string())
Expand All @@ -612,7 +613,7 @@ mod tests {
let register_into_bolt = OperatorsCommand {
subcommand: OperatorsSubcommand::Symbiotic {
subcommand: SymbioticSubcommand::Register {
rpc_url: anvil_url.parse().expect("valid url"),
rpc_url: anvil_url.clone(),
operator_private_key: secret_key,
operator_rpc: "https://bolt.chainbound.io".parse().expect("valid url"),
},
Expand All @@ -624,7 +625,7 @@ mod tests {
let check_status = OperatorsCommand {
subcommand: OperatorsSubcommand::Symbiotic {
subcommand: SymbioticSubcommand::Status {
rpc_url: anvil_url.parse().expect("valid url"),
rpc_url: anvil_url.clone(),
address: account,
},
},
Expand Down
11 changes: 7 additions & 4 deletions bolt-cli/src/commands/validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,21 @@ impl ValidatorsCommand {
#[cfg(test)]
mod tests {
use alloy::{
node_bindings::Anvil,
primitives::{Address, B256, U256},
providers::{ext::AnvilApi, Provider, ProviderBuilder},
providers::{ext::AnvilApi, ProviderBuilder},
signers::k256::ecdsa::SigningKey,
};
use reqwest::Url;

use crate::cli::{ValidatorsCommand, ValidatorsSubcommand};

#[tokio::test]
async fn test_register_validators() {
let rpc_url = "https://holesky.drpc.org";
let provider = ProviderBuilder::new().on_anvil_with_config(|anvil| anvil.fork(rpc_url));
let anvil_url = provider.client().transport().url();
let anvil = Anvil::default().fork(rpc_url).spawn();
let anvil_url = Url::parse(&anvil.endpoint()).expect("valid URL");
let provider = ProviderBuilder::new().on_http(anvil_url.clone());

let mut rnd = rand::thread_rng();
let secret_key = SigningKey::random(&mut rnd);
Expand All @@ -108,7 +111,7 @@ mod tests {
admin_private_key: B256::try_from(secret_key.to_bytes().as_slice()).unwrap(),
authorized_operator: account,
pubkeys_path: "./test_data/pubkeys.json".parse().unwrap(),
rpc_url: anvil_url.parse().unwrap(),
rpc_url: anvil_url,
},
};

Expand Down

0 comments on commit e6a9c27

Please sign in to comment.