From 4618bce56aa8abdd254241ae9f4e7e83181b5ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Mon, 6 Jan 2025 16:28:35 -0300 Subject: [PATCH] refactor: move `get_distribution_roots_length` to reader --- crates/chainio/clients/elcontracts/src/lib.rs | 133 +++++++ .../chainio/clients/elcontracts/src/reader.rs | 81 +++-- .../chainio/clients/elcontracts/src/writer.rs | 338 ++++++------------ 3 files changed, 293 insertions(+), 259 deletions(-) diff --git a/crates/chainio/clients/elcontracts/src/lib.rs b/crates/chainio/clients/elcontracts/src/lib.rs index d433d9f3..6893a160 100644 --- a/crates/chainio/clients/elcontracts/src/lib.rs +++ b/crates/chainio/clients/elcontracts/src/lib.rs @@ -9,3 +9,136 @@ pub mod error; pub mod reader; pub mod writer; + +#[cfg(test)] +pub(crate) mod test_utils { + use alloy::hex::FromHex; + use alloy_primitives::{address, Address, Bytes, FixedBytes, U256}; + use eigen_logging::get_test_logger; + use eigen_testing_utils::anvil_constants::{ + get_allocation_manager_address, get_avs_directory_address, get_delegation_manager_address, + get_registry_coordinator_address, get_rewards_coordinator_address, + get_strategy_manager_address, + }; + use eigen_utils::{ + delegationmanager::DelegationManager, + get_provider, get_signer, + irewardscoordinator::{ + IRewardsCoordinator, + IRewardsCoordinatorTypes::{ + EarnerTreeMerkleLeaf, RewardsMerkleClaim, TokenTreeMerkleLeaf, + }, + }, + }; + use std::str::FromStr; + + use crate::{reader::ELChainReader, writer::ELChainWriter}; + + pub const OPERATOR_ADDRESS: Address = address!("70997970C51812dc3A010C7d01b50e0d17dc79C8"); + + pub async fn build_el_chain_reader(http_endpoint: String) -> ELChainReader { + let delegation_manager_address = + get_delegation_manager_address(http_endpoint.clone()).await; + let avs_directory_address = get_avs_directory_address(http_endpoint.clone()).await; + let rewards_coordinator = get_rewards_coordinator_address(http_endpoint.clone()).await; + + ELChainReader::build( + get_test_logger().clone(), + delegation_manager_address, + avs_directory_address, + rewards_coordinator, + &http_endpoint, + ) + .await + .unwrap() + } + + pub const ANVIL_FIRST_ADDRESS: Address = address!("f39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + pub const ANVIL_FIRST_PRIVATE_KEY: &str = + "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; + + pub async fn new_test_writer(http_endpoint: String, private_key: String) -> ELChainWriter { + let el_chain_reader = build_el_chain_reader(http_endpoint.clone()).await; + let strategy_manager = get_strategy_manager_address(http_endpoint.clone()).await; + let rewards_coordinator = get_rewards_coordinator_address(http_endpoint.clone()).await; + let delegation_manager = get_delegation_manager_address(http_endpoint.clone()).await; + let allocation_manager = get_allocation_manager_address(http_endpoint.clone()).await; + let contract_delegation_manager = + DelegationManager::new(delegation_manager, get_provider(&http_endpoint)); + let permission_controller = contract_delegation_manager + .permissionController() + .call() + .await + .unwrap() + ._0; + let registry_coordinator = get_registry_coordinator_address(http_endpoint.clone()).await; + + ELChainWriter::new( + delegation_manager, + strategy_manager, + rewards_coordinator, + permission_controller, + allocation_manager, + registry_coordinator, + el_chain_reader, + http_endpoint.clone(), + private_key, + ) + } + + pub async fn new_claim(http_endpoint: &str) -> (FixedBytes<32>, RewardsMerkleClaim) { + let el_chain_writer = new_test_writer( + http_endpoint.to_string(), + ANVIL_FIRST_PRIVATE_KEY.to_string(), + ) + .await; + + let earner_address = address!("25a1b7322f9796b26a4bec125913b34c292b28d6"); + let claim = RewardsMerkleClaim { + rootIndex: 0, + earnerIndex: 7, + earnerTreeProof: Bytes::from_hex("4bf5e16eaabbc36964f1e1639808669420f55d60e51adb7e9695b77145c479fd6777be59643947bb24d78e69d6605bf369c515b479f3a8967dd68a97c5bb4a4a262b28002eeb6cbbffb7e79e5741bf2be189a6073440a62fabcd8af4dbda94e3").unwrap(), + earnerLeaf: EarnerTreeMerkleLeaf { + earner: earner_address, + earnerTokenRoot: FixedBytes::from_hex( + "f8e7e20b32aae1d818dcb593b98982841e9a0ed12c161ad603e3ee3948746cba", + ) + .unwrap(), + }, + tokenIndices: vec![7], + tokenTreeProofs: vec![ + Bytes::from_hex("3cd04e8fc6f23812c570fe12292a30bb9e105e00f5913ac4b4938f23e65d8d10e6b1403d58c9d5450952e7d96c81305dad9fb966e8a27d3a42058e3958a0d30033148e91b455542d05deb81b8305b672e742cd3145f7022a0089bad2e6af9173").unwrap(), + ], + tokenLeaves: vec![TokenTreeMerkleLeaf { + token: address!("7fbfdd1dfd80730385aee232cc9f79b8ae12a654"), + cumulativeEarnings: U256::from_str("3000000000000000000").unwrap(), + }], + }; + + // Using test data taken from + // https://github.com/Layr-Labs/eigenlayer-contracts/blob/a888a1cd1479438dda4b138245a69177b125a973/src/test/test-data/rewardsCoordinator/processClaimProofs_MaxEarnerAndLeafIndices.json + let root = FixedBytes::from_hex( + "37550707c80f3d8907c467999730e52127ab89be3f17a5017a3f1ffb73a1445f", + ) + .unwrap(); + + let key = "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; + let rewards_coordinator = IRewardsCoordinator::new( + get_rewards_coordinator_address(http_endpoint.to_string()).await, + get_signer(key, http_endpoint), + ); + let curr_rewards_calculation_end_timestamp = el_chain_writer + .get_curr_rewards_calculation_end_timestamp() + .await + .unwrap(); + let submit_tx = rewards_coordinator + .submitRoot(root, curr_rewards_calculation_end_timestamp + 1) + .send() + .await + .unwrap(); + let submit_status = submit_tx.get_receipt().await.unwrap().status(); + assert!(submit_status); + + (root, claim) + } +} diff --git a/crates/chainio/clients/elcontracts/src/reader.rs b/crates/chainio/clients/elcontracts/src/reader.rs index d7143803..8444b593 100644 --- a/crates/chainio/clients/elcontracts/src/reader.rs +++ b/crates/chainio/clients/elcontracts/src/reader.rs @@ -11,6 +11,7 @@ use eigen_utils::{ delegationmanager::DelegationManager, erc20::ERC20::{self, ERC20Instance}, get_provider, + irewardscoordinator::IRewardsCoordinator, istrategy::IStrategy::{self, IStrategyInstance}, permissioncontroller::PermissionController, SdkProvider, @@ -199,6 +200,35 @@ impl ELChainReader { Ok(avs_hash) } + /// Get the length of the distribution roots. + /// + /// # Returns + /// + /// * `Result` - The length of the distribution roots if the call is successful, + /// otherwise an error. + /// + /// # Errors + /// + /// * `ElContractsError` - if the call to the contract fails. + pub async fn get_distribution_roots_length(&self) -> Result { + let provider = get_provider(&self.provider); + + let contract_rewards_coordinator = + IRewardsCoordinator::new(self.rewards_coordinator, &provider); + + let distribution_roots_lenght_call = contract_rewards_coordinator + .getDistributionRootsLength() + .call() + .await + .map_err(ElContractsError::AlloyContractError)?; + + let IRewardsCoordinator::getDistributionRootsLengthReturn { + _0: distribution_roots_length, + } = distribution_roots_lenght_call; + + Ok(distribution_roots_length) + } + /// Get the operator's shares in a strategy /// /// # Arguments @@ -1122,14 +1152,11 @@ pub struct AllocationInfo { #[cfg(test)] mod tests { use super::*; + use crate::test_utils::{build_el_chain_reader, OPERATOR_ADDRESS}; use alloy::providers::Provider; use alloy::{eips::eip1898::BlockNumberOrTag::Number, rpc::types::BlockTransactionsKind}; use alloy_primitives::{address, keccak256, Address, FixedBytes, U256}; - use eigen_logging::get_test_logger; - use eigen_testing_utils::anvil_constants::{ - get_allocation_manager_address, get_avs_directory_address, get_erc20_mock_strategy, - get_rewards_coordinator_address, - }; + use eigen_testing_utils::anvil_constants::get_erc20_mock_strategy; use eigen_testing_utils::{ anvil::start_anvil_container, anvil_constants::get_delegation_manager_address, }; @@ -1140,37 +1167,6 @@ mod tests { delegationmanager::DelegationManager::calculateDelegationApprovalDigestHashReturn, }; - const OPERATOR_ADDRESS: Address = address!("70997970C51812dc3A010C7d01b50e0d17dc79C8"); - - async fn build_el_chain_reader(http_endpoint: String) -> ELChainReader { - let delegation_manager_address = - get_delegation_manager_address(http_endpoint.clone()).await; - let allocation_manager_address = - get_allocation_manager_address(http_endpoint.clone()).await; - let avs_directory_address = get_avs_directory_address(http_endpoint.clone()).await; - let rewards_coordinator_address = - get_rewards_coordinator_address(http_endpoint.clone()).await; - - let delegation_manager_contract = - DelegationManager::new(delegation_manager_address, get_provider(&http_endpoint)); - let permission_controller_address = delegation_manager_contract - .permissionController() - .call() - .await - .unwrap() - ._0; - - ELChainReader::new( - get_test_logger(), - allocation_manager_address, - delegation_manager_address, - rewards_coordinator_address, - avs_directory_address, - permission_controller_address, - http_endpoint, - ) - } - #[tokio::test] async fn test_calculate_delegation_approval_digest_hash() { let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; @@ -1262,6 +1258,19 @@ mod tests { assert_eq!(hash, operator_hash); } + #[tokio::test] + async fn test_get_distribution_roots_length() { + let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; + let el_chain_reader = build_el_chain_reader(http_endpoint.clone()).await; + + let distribution_roots_length_ret = el_chain_reader + .get_distribution_roots_length() + .await + .unwrap(); + + assert_eq!(distribution_roots_length_ret, U256::from(1)); + } + #[tokio::test] async fn test_is_operator_registered() { let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; diff --git a/crates/chainio/clients/elcontracts/src/writer.rs b/crates/chainio/clients/elcontracts/src/writer.rs index b1b83c52..e80468fe 100644 --- a/crates/chainio/clients/elcontracts/src/writer.rs +++ b/crates/chainio/clients/elcontracts/src/writer.rs @@ -292,35 +292,6 @@ impl ELChainWriter { Ok(cumulative_claimed_for_root_ret) } - /// Get the length of the distribution roots. - /// - /// # Returns - /// - /// * `Result` - The length of the distribution roots if the call is successful, - /// otherwise an error. - /// - /// # Errors - /// - /// * `ElContractsError` - if the call to the contract fails. - pub async fn get_distribution_roots_length(&self) -> Result { - let provider = get_signer(&self.signer, &self.provider); - - let contract_rewards_coordinator = - IRewardsCoordinator::new(self.rewards_coordinator, &provider); - - let distribution_roots_lenght_call = contract_rewards_coordinator - .getDistributionRootsLength() - .call() - .await - .map_err(ElContractsError::AlloyContractError)?; - - let IRewardsCoordinator::getDistributionRootsLengthReturn { - _0: distribution_roots_length, - } = distribution_roots_lenght_call; - - Ok(distribution_roots_length) - } - /// Get the current rewards calculation end timestamp (the timestamp until which rewards have been calculated). /// /// # Returns @@ -811,21 +782,23 @@ impl ELChainWriter { } } +#[cfg(test)] +mod test_utils {} + #[cfg(test)] mod tests { - use super::ELChainWriter; - use crate::reader::ELChainReader; - use alloy::{hex::FromHex, providers::Provider}; - use alloy_primitives::{address, aliases::U96, Address, Bytes, FixedBytes, U256}; + use crate::test_utils::{ + build_el_chain_reader, new_claim, new_test_writer, ANVIL_FIRST_ADDRESS, + ANVIL_FIRST_PRIVATE_KEY, + }; + use alloy::providers::Provider; + use alloy_primitives::{address, aliases::U96, Address, U256}; use eigen_crypto_bls::BlsKeyPair; - use eigen_logging::get_test_logger; use eigen_testing_utils::{ anvil::{mine_anvil_blocks, set_account_balance, start_anvil_container}, anvil_constants::{ - get_allocation_manager_address, get_avs_directory_address, - get_delegation_manager_address, get_erc20_mock_strategy, - get_registry_coordinator_address, get_rewards_coordinator_address, - get_strategy_manager_address, + get_allocation_manager_address, get_erc20_mock_strategy, + get_registry_coordinator_address, }, transaction::wait_transaction, }; @@ -835,14 +808,7 @@ mod tests { AllocationManager::{self, OperatorSet}, IAllocationManagerTypes, }, - delegationmanager::DelegationManager, get_provider, get_signer, - irewardscoordinator::{ - IRewardsCoordinator, - IRewardsCoordinatorTypes::{ - EarnerTreeMerkleLeaf, RewardsMerkleClaim, TokenTreeMerkleLeaf, - }, - }, registrycoordinator::{ IRegistryCoordinator::OperatorSetParam, IStakeRegistry::StrategyParams, RegistryCoordinator, @@ -850,121 +816,20 @@ mod tests { }; use std::str::FromStr; - const OPERATOR_ADDRESS: Address = address!("f39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - const OPERATOR_PRIVATE_KEY: &str = - "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; - - /// Returns a new instance of ELChainWriter - async fn setup_el_chain_reader(http_endpoint: String) -> ELChainReader { - let delegation_manager_address = - get_delegation_manager_address(http_endpoint.clone()).await; - let avs_directory_address = get_avs_directory_address(http_endpoint.clone()).await; - let rewards_coordinator = get_rewards_coordinator_address(http_endpoint.clone()).await; - - ELChainReader::build( - get_test_logger().clone(), - delegation_manager_address, - avs_directory_address, - rewards_coordinator, - &http_endpoint, - ) - .await - .unwrap() - } - - async fn new_test_writer(http_endpoint: String, private_key: String) -> ELChainWriter { - let el_chain_reader = setup_el_chain_reader(http_endpoint.clone()).await; - let strategy_manager = get_strategy_manager_address(http_endpoint.clone()).await; - let rewards_coordinator = get_rewards_coordinator_address(http_endpoint.clone()).await; - let delegation_manager = get_delegation_manager_address(http_endpoint.clone()).await; - let allocation_manager = get_allocation_manager_address(http_endpoint.clone()).await; - let contract_delegation_manager = - DelegationManager::new(delegation_manager, get_provider(&http_endpoint)); - let permission_controller = contract_delegation_manager - .permissionController() - .call() - .await - .unwrap() - ._0; - let registry_coordinator = get_registry_coordinator_address(http_endpoint.clone()).await; - - ELChainWriter::new( - delegation_manager, - strategy_manager, - rewards_coordinator, - permission_controller, - allocation_manager, - registry_coordinator, - el_chain_reader, - http_endpoint.clone(), - private_key, - ) - } - - async fn new_claim(http_endpoint: &str) -> (FixedBytes<32>, RewardsMerkleClaim) { - let el_chain_writer = - new_test_writer(http_endpoint.to_string(), OPERATOR_PRIVATE_KEY.to_string()).await; - - let earner_address = address!("25a1b7322f9796b26a4bec125913b34c292b28d6"); - let claim = RewardsMerkleClaim { - rootIndex: 0, - earnerIndex: 7, - earnerTreeProof: Bytes::from_hex("4bf5e16eaabbc36964f1e1639808669420f55d60e51adb7e9695b77145c479fd6777be59643947bb24d78e69d6605bf369c515b479f3a8967dd68a97c5bb4a4a262b28002eeb6cbbffb7e79e5741bf2be189a6073440a62fabcd8af4dbda94e3").unwrap(), - earnerLeaf: EarnerTreeMerkleLeaf { - earner: earner_address, - earnerTokenRoot: FixedBytes::from_hex( - "f8e7e20b32aae1d818dcb593b98982841e9a0ed12c161ad603e3ee3948746cba", - ) - .unwrap(), - }, - tokenIndices: vec![7], - tokenTreeProofs: vec![ - Bytes::from_hex("3cd04e8fc6f23812c570fe12292a30bb9e105e00f5913ac4b4938f23e65d8d10e6b1403d58c9d5450952e7d96c81305dad9fb966e8a27d3a42058e3958a0d30033148e91b455542d05deb81b8305b672e742cd3145f7022a0089bad2e6af9173").unwrap(), - ], - tokenLeaves: vec![TokenTreeMerkleLeaf { - token: address!("7fbfdd1dfd80730385aee232cc9f79b8ae12a654"), - cumulativeEarnings: U256::from_str("3000000000000000000").unwrap(), - }], - }; - - // Using test data taken from - // https://github.com/Layr-Labs/eigenlayer-contracts/blob/a888a1cd1479438dda4b138245a69177b125a973/src/test/test-data/rewardsCoordinator/processClaimProofs_MaxEarnerAndLeafIndices.json - let root = FixedBytes::from_hex( - "37550707c80f3d8907c467999730e52127ab89be3f17a5017a3f1ffb73a1445f", - ) - .unwrap(); - - let key = "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; - let rewards_coordinator = IRewardsCoordinator::new( - get_rewards_coordinator_address(http_endpoint.to_string()).await, - get_signer(key, http_endpoint), - ); - let curr_rewards_calculation_end_timestamp = el_chain_writer - .get_curr_rewards_calculation_end_timestamp() - .await - .unwrap(); - let submit_tx = rewards_coordinator - .submitRoot(root, curr_rewards_calculation_end_timestamp + 1) - .send() - .await - .unwrap(); - let submit_status = submit_tx.get_receipt().await.unwrap().status(); - assert!(submit_status); - - (root, claim) - } - #[tokio::test] async fn test_register_operator() { let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; - let el_chain_reader = setup_el_chain_reader(http_endpoint.clone()).await; - let el_chain_writer = - new_test_writer(http_endpoint.to_string(), OPERATOR_PRIVATE_KEY.to_string()).await; + let el_chain_reader = build_el_chain_reader(http_endpoint.clone()).await; + let el_chain_writer = new_test_writer( + http_endpoint.to_string(), + ANVIL_FIRST_PRIVATE_KEY.to_string(), + ) + .await; let operator = Operator { - address: OPERATOR_ADDRESS, // can only register the address corresponding to the signer used in the writer + address: ANVIL_FIRST_ADDRESS, // can only register the address corresponding to the signer used in the writer staker_opt_out_window_blocks: 3, - delegation_approver_address: OPERATOR_ADDRESS, + delegation_approver_address: ANVIL_FIRST_ADDRESS, metadata_url: Some("metadata_uri".to_string()), allocation_delay: 1, }; @@ -974,7 +839,7 @@ mod tests { .unwrap(); let is_registered = el_chain_reader - .is_operator_registered(OPERATOR_ADDRESS) + .is_operator_registered(ANVIL_FIRST_ADDRESS) .await .unwrap(); assert!(is_registered); @@ -1030,8 +895,11 @@ mod tests { #[tokio::test] async fn test_deposit_erc20_into_strategy() { let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; - let el_chain_writer = - new_test_writer(http_endpoint.to_string(), OPERATOR_PRIVATE_KEY.to_string()).await; + let el_chain_writer = new_test_writer( + http_endpoint.to_string(), + ANVIL_FIRST_PRIVATE_KEY.to_string(), + ) + .await; let amount = U256::from_str("100").unwrap(); let strategy_addr = get_erc20_mock_strategy(http_endpoint.clone()).await; @@ -1047,8 +915,11 @@ mod tests { #[tokio::test] async fn test_set_claimer_for() { let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; - let el_chain_writer = - new_test_writer(http_endpoint.to_string(), OPERATOR_PRIVATE_KEY.to_string()).await; + let el_chain_writer = new_test_writer( + http_endpoint.to_string(), + ANVIL_FIRST_PRIVATE_KEY.to_string(), + ) + .await; let claimer = address!("5eb15C0992734B5e77c888D713b4FC67b3D679A2"); @@ -1061,41 +932,26 @@ mod tests { #[tokio::test] async fn test_check_claim() { let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; - let el_chain_writer = - new_test_writer(http_endpoint.to_string(), OPERATOR_PRIVATE_KEY.to_string()).await; + let el_chain_writer = new_test_writer( + http_endpoint.to_string(), + ANVIL_FIRST_PRIVATE_KEY.to_string(), + ) + .await; let (_, claim) = new_claim(&http_endpoint).await; - let distribution_roots_length = el_chain_writer - .get_distribution_roots_length() - .await - .unwrap(); - assert_eq!(distribution_roots_length, U256::from(1)); - let valid_claim = el_chain_writer.check_claim(claim.clone()).await.unwrap(); assert!(valid_claim); } - #[tokio::test] - async fn test_get_distribution_roots_length() { - let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; - let el_chain_writer = - new_test_writer(http_endpoint.to_string(), OPERATOR_PRIVATE_KEY.to_string()).await; - new_claim(&http_endpoint).await; - - let distribution_roots_length_ret = el_chain_writer - .get_distribution_roots_length() - .await - .unwrap(); - - assert_eq!(distribution_roots_length_ret, U256::from(1)); - } - #[tokio::test] async fn test_get_root_index_from_hash() { let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; - let el_chain_writer = - new_test_writer(http_endpoint.to_string(), OPERATOR_PRIVATE_KEY.to_string()).await; + let el_chain_writer = new_test_writer( + http_endpoint.to_string(), + ANVIL_FIRST_PRIVATE_KEY.to_string(), + ) + .await; let (root, _) = new_claim(&http_endpoint).await; let index = el_chain_writer @@ -1109,8 +965,11 @@ mod tests { #[tokio::test] async fn test_get_cumulative_claimed() { let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; - let el_chain_writer = - new_test_writer(http_endpoint.to_string(), OPERATOR_PRIVATE_KEY.to_string()).await; + let el_chain_writer = new_test_writer( + http_endpoint.to_string(), + ANVIL_FIRST_PRIVATE_KEY.to_string(), + ) + .await; let earner_address = address!("F2288D736d27C1584Ebf7be5f52f9E4d47251AeE"); let (_, _, token_address) = el_chain_writer @@ -1133,8 +992,11 @@ mod tests { #[tokio::test] async fn test_get_cumulative_claimed_for_root() { let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; - let el_chain_writer = - new_test_writer(http_endpoint.to_string(), OPERATOR_PRIVATE_KEY.to_string()).await; + let el_chain_writer = new_test_writer( + http_endpoint.to_string(), + ANVIL_FIRST_PRIVATE_KEY.to_string(), + ) + .await; let (root, _) = new_claim(&http_endpoint).await; let distribution_root = el_chain_writer @@ -1148,32 +1010,35 @@ mod tests { #[tokio::test] async fn test_add_and_remove_pending_admin() { let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; - let el_chain_writer = - new_test_writer(http_endpoint.to_string(), OPERATOR_PRIVATE_KEY.to_string()).await; + let el_chain_writer = new_test_writer( + http_endpoint.to_string(), + ANVIL_FIRST_PRIVATE_KEY.to_string(), + ) + .await; let pending_admin = address!("009440d62dc85c73dbf889b7ad1f4da8b231d2ef"); let tx_hash = el_chain_writer - .add_pending_admin(OPERATOR_ADDRESS, pending_admin) + .add_pending_admin(ANVIL_FIRST_ADDRESS, pending_admin) .await .unwrap(); wait_transaction(&http_endpoint, tx_hash).await.unwrap(); let is_pending_admin = el_chain_writer .el_chain_reader - .is_pending_admin(OPERATOR_ADDRESS, pending_admin) + .is_pending_admin(ANVIL_FIRST_ADDRESS, pending_admin) .await .unwrap(); assert!(is_pending_admin); let tx_hash = el_chain_writer - .remove_pending_admin(OPERATOR_ADDRESS, pending_admin) + .remove_pending_admin(ANVIL_FIRST_ADDRESS, pending_admin) .await .unwrap(); wait_transaction(&http_endpoint, tx_hash).await.unwrap(); let is_admin = el_chain_writer .el_chain_reader - .is_pending_admin(OPERATOR_ADDRESS, pending_admin) + .is_pending_admin(ANVIL_FIRST_ADDRESS, pending_admin) .await .unwrap(); assert!(!is_admin); @@ -1182,26 +1047,32 @@ mod tests { #[tokio::test] async fn test_accept_admin() { let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; - let account_writer = - new_test_writer(http_endpoint.to_string(), OPERATOR_PRIVATE_KEY.to_string()).await; + let account_writer = new_test_writer( + http_endpoint.to_string(), + ANVIL_FIRST_PRIVATE_KEY.to_string(), + ) + .await; let pending_admin = address!("14dC79964da2C08b23698B3D3cc7Ca32193d9955"); let pending_admin_key = "0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356"; account_writer - .add_pending_admin(OPERATOR_ADDRESS, pending_admin) + .add_pending_admin(ANVIL_FIRST_ADDRESS, pending_admin) .await .unwrap(); let admin_writer = new_test_writer(http_endpoint.to_string(), pending_admin_key.to_string()).await; - admin_writer.accept_admin(OPERATOR_ADDRESS).await.unwrap(); + admin_writer + .accept_admin(ANVIL_FIRST_ADDRESS) + .await + .unwrap(); let is_admin = admin_writer .el_chain_reader - .is_admin(OPERATOR_ADDRESS, pending_admin) + .is_admin(ANVIL_FIRST_ADDRESS, pending_admin) .await .unwrap(); assert!(is_admin); @@ -1210,8 +1081,11 @@ mod tests { #[tokio::test] async fn test_remove_admin() { let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; - let el_chain_writer = - new_test_writer(http_endpoint.to_string(), OPERATOR_PRIVATE_KEY.to_string()).await; + let el_chain_writer = new_test_writer( + http_endpoint.to_string(), + ANVIL_FIRST_PRIVATE_KEY.to_string(), + ) + .await; let pending_admin_1 = address!("14dC79964da2C08b23698B3D3cc7Ca32193d9955"); let pending_admin_1_key = @@ -1223,29 +1097,35 @@ mod tests { // Adding two admins and removing one. Cannot remove the last admin, so one must remain el_chain_writer - .add_pending_admin(OPERATOR_ADDRESS, pending_admin_1) + .add_pending_admin(ANVIL_FIRST_ADDRESS, pending_admin_1) .await .unwrap(); el_chain_writer - .add_pending_admin(OPERATOR_ADDRESS, pending_admin_2) + .add_pending_admin(ANVIL_FIRST_ADDRESS, pending_admin_2) .await .unwrap(); let admin_1_writer = new_test_writer(http_endpoint.to_string(), pending_admin_1_key.to_string()).await; - admin_1_writer.accept_admin(OPERATOR_ADDRESS).await.unwrap(); + admin_1_writer + .accept_admin(ANVIL_FIRST_ADDRESS) + .await + .unwrap(); let admin_2_writer = new_test_writer(http_endpoint.to_string(), pending_admin_2_key.to_string()).await; - admin_2_writer.accept_admin(OPERATOR_ADDRESS).await.unwrap(); + admin_2_writer + .accept_admin(ANVIL_FIRST_ADDRESS) + .await + .unwrap(); admin_1_writer - .remove_admin(OPERATOR_ADDRESS, pending_admin_2) + .remove_admin(ANVIL_FIRST_ADDRESS, pending_admin_2) .await .unwrap(); let is_admin = el_chain_writer .el_chain_reader - .is_admin(OPERATOR_ADDRESS, pending_admin_2) + .is_admin(ANVIL_FIRST_ADDRESS, pending_admin_2) .await .unwrap(); assert!(!is_admin); @@ -1254,15 +1134,18 @@ mod tests { #[tokio::test] async fn test_set_and_remove_permission() { let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; - let account_address = OPERATOR_ADDRESS; + let account_address = ANVIL_FIRST_ADDRESS; let appointee_address = address!("009440d62dc85c73dbf889b7ad1f4da8b231d2ef"); let appointee_key = "6b35c6d8110c888de06575b45181bf3f9e6c73451fa5cde812c95a6b31e66ddf"; let target = address!("14dC79964da2C08b23698B3D3cc7Ca32193d9955"); let selector = [0, 1, 2, 3].into(); // add an admin - let account_writer = - new_test_writer(http_endpoint.to_string(), OPERATOR_PRIVATE_KEY.to_string()).await; + let account_writer = new_test_writer( + http_endpoint.to_string(), + ANVIL_FIRST_PRIVATE_KEY.to_string(), + ) + .await; // set permission let tx_hash = account_writer @@ -1283,8 +1166,11 @@ mod tests { assert!(can_call); // test remove permission - let el_chain_writer = - new_test_writer(http_endpoint.to_string(), OPERATOR_PRIVATE_KEY.to_string()).await; + let el_chain_writer = new_test_writer( + http_endpoint.to_string(), + ANVIL_FIRST_PRIVATE_KEY.to_string(), + ) + .await; let tx_hash = el_chain_writer .remove_permission(account_address, appointee_address, target, selector) @@ -1298,7 +1184,7 @@ mod tests { async fn create_operator_set(http_endpoint: &str, avs_address: Address, operator_set_id: u32) { let allocation_manager_addr = get_allocation_manager_address(http_endpoint.to_string()).await; - let signer = get_signer(OPERATOR_PRIVATE_KEY, http_endpoint); + let signer = get_signer(ANVIL_FIRST_PRIVATE_KEY, http_endpoint); let allocation_manager = AllocationManager::new(allocation_manager_addr, signer.clone()); let registry_coordinator_addr = get_registry_coordinator_address(http_endpoint.to_string()).await; @@ -1365,7 +1251,7 @@ mod tests { async fn test_register_for_operator_sets() { let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; - let avs_address = OPERATOR_ADDRESS; + let avs_address = ANVIL_FIRST_ADDRESS; let operator_set_id = 1; create_operator_set(http_endpoint.as_str(), avs_address, operator_set_id).await; @@ -1405,13 +1291,16 @@ mod tests { #[tokio::test] async fn test_set_allocation_delay() { let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; - let el_chain_writer = - new_test_writer(http_endpoint.to_string(), OPERATOR_PRIVATE_KEY.to_string()).await; + let el_chain_writer = new_test_writer( + http_endpoint.to_string(), + ANVIL_FIRST_PRIVATE_KEY.to_string(), + ) + .await; let delay = 10; let tx_hash = el_chain_writer - .set_allocation_delay(OPERATOR_ADDRESS, delay) + .set_allocation_delay(ANVIL_FIRST_ADDRESS, delay) .await .unwrap(); let receipt = wait_transaction(&http_endpoint, tx_hash).await.unwrap(); @@ -1419,7 +1308,7 @@ mod tests { let allocation_delay = el_chain_writer .el_chain_reader - .get_allocation_delay(OPERATOR_ADDRESS) + .get_allocation_delay(ANVIL_FIRST_ADDRESS) .await .unwrap(); @@ -1429,13 +1318,16 @@ mod tests { #[tokio::test] async fn test_modify_allocations() { let (container, http_endpoint, _ws_endpoint) = start_anvil_container().await; - let el_chain_writer = - new_test_writer(http_endpoint.to_string(), OPERATOR_PRIVATE_KEY.to_string()).await; + let el_chain_writer = new_test_writer( + http_endpoint.to_string(), + ANVIL_FIRST_PRIVATE_KEY.to_string(), + ) + .await; - let operator_address = OPERATOR_ADDRESS; + let operator_address = ANVIL_FIRST_ADDRESS; let strategy_addr = get_erc20_mock_strategy(http_endpoint.clone()).await; - let avs_address = OPERATOR_ADDRESS; + let avs_address = ANVIL_FIRST_ADDRESS; let operator_set_id = 1; create_operator_set(http_endpoint.as_str(), avs_address, operator_set_id).await; @@ -1466,7 +1358,7 @@ mod tests { let allocation_delay = el_chain_writer .el_chain_reader - .get_allocation_delay(OPERATOR_ADDRESS) + .get_allocation_delay(ANVIL_FIRST_ADDRESS) .await .unwrap(); mine_anvil_blocks(&container, allocation_delay).await;