Skip to content

chore: move utils to testutils #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: test/integration-rewards-test
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

172 changes: 0 additions & 172 deletions crates/chainio/clients/avsregistry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,175 +17,3 @@ pub mod error;

/// Fake avs registry module
pub mod fake_reader;

#[cfg(test)]
pub(crate) mod test_utils {

use crate::reader::AvsRegistryChainReader;
use crate::writer::AvsRegistryChainWriter;
use alloy::{
primitives::{aliases::U96, Address, Bytes, FixedBytes, U256},
providers::WalletProvider,
sol_types::SolCall,
};
use eigen_common::get_signer;
use eigen_crypto_bls::BlsKeyPair;
use eigen_logging::get_test_logger;
use eigen_testing_utils::anvil_constants::{
get_allocation_manager_address, get_erc20_mock_strategy,
get_operator_state_retriever_address, get_registry_coordinator_address,
get_service_manager_address, FIRST_PRIVATE_KEY,
};
use eigen_testing_utils::transaction::wait_transaction;
use eigen_utils::slashing::{
core::allocationmanager::AllocationManager,
middleware::registrycoordinator::{
ISlashingRegistryCoordinatorTypes::OperatorSetParam,
IStakeRegistryTypes::StrategyParams, RegistryCoordinator,
},
sdk::mockavsservicemanager::MockAvsServiceManager,
};

pub(crate) async fn create_operator_set(http_endpoint: &str, avs_address: Address) {
let allocation_manager_addr =
get_allocation_manager_address(http_endpoint.to_string()).await;
let default_signer = get_signer(FIRST_PRIVATE_KEY, http_endpoint);
let allocation_manager =
AllocationManager::new(allocation_manager_addr, default_signer.clone());
let registry_coordinator_addr =
get_registry_coordinator_address(http_endpoint.to_string()).await;
let service_manager_address = get_service_manager_address(http_endpoint.to_string()).await;
let service_manager =
MockAvsServiceManager::new(service_manager_address, default_signer.clone());
service_manager
.setAppointee(
default_signer.default_signer_address(),
allocation_manager_addr,
alloy::primitives::FixedBytes(AllocationManager::setAVSRegistrarCall::SELECTOR),
)
.send()
.await
.unwrap()
.get_receipt()
.await
.unwrap();
allocation_manager
.setAVSRegistrar(avs_address, registry_coordinator_addr)
.send()
.await
.unwrap()
.get_receipt()
.await
.unwrap();

// Create slashable quorum
let contract_registry_coordinator =
RegistryCoordinator::new(registry_coordinator_addr, default_signer.clone());
let operator_set_params = OperatorSetParam {
maxOperatorCount: 10,
kickBIPsOfOperatorStake: 100,
kickBIPsOfTotalStake: 1000,
};
let strategy = get_erc20_mock_strategy(http_endpoint.to_string()).await;
service_manager
.setAppointee(
registry_coordinator_addr,
allocation_manager_addr,
alloy::primitives::FixedBytes(AllocationManager::createOperatorSetsCall::SELECTOR),
)
.send()
.await
.unwrap()
.get_receipt()
.await
.unwrap();
let strategy_params = StrategyParams {
strategy,
multiplier: U96::from(1),
};

contract_registry_coordinator
.createSlashableStakeQuorum(operator_set_params, U96::from(0), vec![strategy_params], 0)
.send()
.await
.unwrap()
.get_receipt()
.await
.unwrap();
}

pub(crate) async fn build_avs_registry_chain_writer(
http_endpoint: String,
private_key: String,
) -> AvsRegistryChainWriter {
let registry_coordinator_address =
get_registry_coordinator_address(http_endpoint.clone()).await;
let service_manager_addr = get_service_manager_address(http_endpoint.clone()).await;
AvsRegistryChainWriter::build_avs_registry_chain_writer(
get_test_logger(),
http_endpoint,
private_key,
registry_coordinator_address,
service_manager_addr,
)
.await
.unwrap()
}

pub(crate) async fn build_avs_registry_chain_reader(
http_endpoint: String,
) -> AvsRegistryChainReader {
let registry_coordinator_addr =
get_registry_coordinator_address(http_endpoint.clone()).await;
let operator_state_retriever_address =
get_operator_state_retriever_address(http_endpoint.clone()).await;

AvsRegistryChainReader::new(
get_test_logger(),
registry_coordinator_addr,
operator_state_retriever_address,
http_endpoint.to_string(),
)
.await
.unwrap()
}

// this function is called from test_avs_writer_methods
pub(crate) async fn test_register_operator(
avs_writer: &AvsRegistryChainWriter,
private_key_decimal: String,
quorum_nums: Bytes,
http_url: String,
) {
let bls_key_pair = BlsKeyPair::new(private_key_decimal).unwrap();
let digest_hash: FixedBytes<32> = FixedBytes::from([0x02; 32]);

// this is set to U256::MAX so that the registry does not take the signature as expired.
let signature_expiry = U256::MAX;
let tx_hash = avs_writer
.register_operator_in_quorum_with_avs_registry_coordinator(
bls_key_pair,
digest_hash,
signature_expiry,
quorum_nums.clone(),
"".into(),
)
.await
.unwrap();

let tx_status = wait_transaction(&http_url, tx_hash).await.unwrap().status();
assert!(tx_status);
}

// this function is caller from test_avs_writer_methods
pub(crate) async fn test_deregister_operator(
avs_writer: &AvsRegistryChainWriter,
quorum_nums: Bytes,
http_url: String,
) {
let tx_hash = avs_writer.deregister_operator(quorum_nums).await.unwrap();

let tx_status = wait_transaction(&http_url, tx_hash).await.unwrap().status();
assert!(tx_status);
}
}
28 changes: 23 additions & 5 deletions crates/chainio/clients/avsregistry/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,19 +1133,35 @@ impl AvsRegistryChainReader {
mod tests {

use super::*;
use crate::test_utils::{
build_avs_registry_chain_reader, build_avs_registry_chain_writer, test_register_operator,
};
use alloy::primitives::address;
use eigen_crypto_bls::BlsKeyPair;
use eigen_logging::get_test_logger;
use eigen_testing_utils::{
anvil::{start_anvil_container, start_m2_anvil_container},
anvil_constants::{
FIFTH_ADDRESS, FIFTH_PRIVATE_KEY, FIRST_ADDRESS, FIRST_PRIVATE_KEY, OPERATOR_BLS_KEY,
get_operator_state_retriever_address, get_registry_coordinator_address, FIFTH_ADDRESS,
FIFTH_PRIVATE_KEY, FIRST_ADDRESS, FIRST_PRIVATE_KEY, OPERATOR_BLS_KEY,
},
chain_clients::{build_avs_registry_chain_writer, test_register_operator},
transaction::wait_transaction,
};

async fn build_avs_registry_chain_reader(http_endpoint: String) -> AvsRegistryChainReader {
let registry_coordinator_addr =
get_registry_coordinator_address(http_endpoint.clone()).await;
let operator_state_retriever_address =
get_operator_state_retriever_address(http_endpoint.clone()).await;

AvsRegistryChainReader::new(
get_test_logger(),
registry_coordinator_addr,
operator_state_retriever_address,
http_endpoint.to_string(),
)
.await
.unwrap()
}

#[tokio::test]
async fn test_get_quorum_count() {
let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await;
Expand Down Expand Up @@ -1343,9 +1359,11 @@ mod tests {
async fn test_is_operator_registered() {
let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await;
let avs_reader = build_avs_registry_chain_reader(http_endpoint.clone()).await;
let registry_coordinator_addr =
get_registry_coordinator_address(http_endpoint.clone()).await;

let is_registered = avs_reader
.is_operator_registered(avs_reader.registry_coordinator_addr)
.is_operator_registered(registry_coordinator_addr)
.await
.unwrap();
assert!(!is_registered);
Expand Down
100 changes: 77 additions & 23 deletions crates/chainio/clients/avsregistry/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,49 +1042,103 @@ impl AvsRegistryChainWriter {
#[cfg(test)]
mod tests {
use super::AvsRegistryChainWriter;
use crate::test_utils::{
build_avs_registry_chain_reader, build_avs_registry_chain_writer, create_operator_set,
test_deregister_operator, test_register_operator,
};
use alloy::primitives::{address, aliases::U96, Address, Bytes, FixedBytes, U256};
use alloy::sol_types::SolCall;
use eigen_common::{get_provider, get_signer};
use eigen_crypto_bls::BlsKeyPair;
use eigen_logging::get_test_logger;
use eigen_testing_utils::anvil::{start_anvil_container, start_m2_anvil_container};
use eigen_testing_utils::anvil_constants::OPERATOR_BLS_KEY_2;
use eigen_testing_utils::anvil_constants::SECOND_PRIVATE_KEY;
use eigen_testing_utils::anvil_constants::THIRD_ADDRESS;
use eigen_testing_utils::anvil_constants::THIRD_PRIVATE_KEY;
use eigen_testing_utils::anvil_constants::{
get_allocation_manager_address, get_erc20_mock_strategy, get_rewards_coordinator_address,
get_service_manager_address,
get_allocation_manager_address, get_erc20_mock_strategy, get_registry_coordinator_address,
get_rewards_coordinator_address, get_service_manager_address,
};
use eigen_testing_utils::anvil_constants::{
FIFTH_ADDRESS, FIFTH_PRIVATE_KEY, FIRST_ADDRESS, FIRST_PRIVATE_KEY, OPERATOR_BLS_KEY,
SECOND_ADDRESS,
OPERATOR_BLS_KEY_2, SECOND_ADDRESS, SECOND_PRIVATE_KEY, THIRD_ADDRESS, THIRD_PRIVATE_KEY,
};
use eigen_testing_utils::chain_clients::{
build_avs_registry_chain_reader, create_operator_set,
};
use eigen_testing_utils::transaction::wait_transaction;
use eigen_utils::slashing::core::allocationmanager::AllocationManager;
use eigen_utils::slashing::core::irewardscoordinator::IRewardsCoordinator;
use eigen_utils::slashing::middleware::registrycoordinator::{
ISlashingRegistryCoordinatorTypes::OperatorSetParam, RegistryCoordinator,
use eigen_utils::slashing::core::{
allocationmanager::AllocationManager, irewardscoordinator::IRewardsCoordinator,
};
use eigen_utils::slashing::middleware::servicemanagerbase::IRewardsCoordinatorTypes::OperatorDirectedRewardsSubmission;
use eigen_utils::slashing::middleware::servicemanagerbase::IRewardsCoordinatorTypes::OperatorReward;
use eigen_utils::slashing::middleware::servicemanagerbase::{
IRewardsCoordinatorTypes::RewardsSubmission,
IRewardsCoordinatorTypes::StrategyAndMultiplier, ServiceManagerBase,
use eigen_utils::slashing::middleware::{
registrycoordinator::{
ISlashingRegistryCoordinatorTypes::OperatorSetParam, RegistryCoordinator,
},
servicemanagerbase::{
IRewardsCoordinatorTypes::OperatorDirectedRewardsSubmission,
IRewardsCoordinatorTypes::OperatorReward, IRewardsCoordinatorTypes::RewardsSubmission,
IRewardsCoordinatorTypes::StrategyAndMultiplier, ServiceManagerBase,
},
stakeregistry::{IStakeRegistryTypes::StrategyParams, StakeRegistry},
};
use eigen_utils::slashing::middleware::stakeregistry::IStakeRegistryTypes::StrategyParams;
use eigen_utils::slashing::middleware::stakeregistry::StakeRegistry;
use futures_util::StreamExt;

async fn build_avs_registry_chain_writer(
http_endpoint: String,
private_key: String,
) -> AvsRegistryChainWriter {
let registry_coordinator_address =
get_registry_coordinator_address(http_endpoint.clone()).await;
let service_manager_addr = get_service_manager_address(http_endpoint.clone()).await;
AvsRegistryChainWriter::build_avs_registry_chain_writer(
get_test_logger(),
http_endpoint,
private_key,
registry_coordinator_address,
service_manager_addr,
)
.await
.unwrap()
}

/// this function is called from test_avs_writer_methods
async fn test_register_operator(
avs_writer: &AvsRegistryChainWriter,
private_key_decimal: String,
quorum_nums: Bytes,
http_url: String,
) {
let bls_key_pair = BlsKeyPair::new(private_key_decimal).unwrap();
let digest_hash: FixedBytes<32> = FixedBytes::from([0x02; 32]);

// this is set to U256::MAX so that the registry does not take the signature as expired.
let signature_expiry = U256::MAX;
let tx_hash = avs_writer
.register_operator_in_quorum_with_avs_registry_coordinator(
bls_key_pair,
digest_hash,
signature_expiry,
quorum_nums.clone(),
"".into(),
)
.await
.unwrap();

let tx_status = wait_transaction(&http_url, tx_hash).await.unwrap().status();
assert!(tx_status);
}

/// this function is caller from test_avs_writer_methods
async fn test_deregister_operator(
avs_writer: &AvsRegistryChainWriter,
quorum_nums: Bytes,
http_url: String,
) {
let tx_hash = avs_writer.deregister_operator(quorum_nums).await.unwrap();

let tx_status = wait_transaction(&http_url, tx_hash).await.unwrap().status();
assert!(tx_status);
}

#[tokio::test]
async fn test_avs_writer_methods() {
let (_container, http_endpoint, _ws_endpoint) = start_m2_anvil_container().await;
let bls_key = OPERATOR_BLS_KEY.to_string();
let private_key = FIFTH_PRIVATE_KEY.to_string();
let avs_writer =
let avs_writer: AvsRegistryChainWriter =
build_avs_registry_chain_writer(http_endpoint.clone(), private_key.clone()).await;
let operator_addr = FIFTH_ADDRESS;
let quorum_nums = Bytes::from([0]);
Expand Down
Loading
Loading