Skip to content

Commit

Permalink
avs registry service chain caller tests (Layr-Labs#90)
Browse files Browse the repository at this point in the history
This PR adds unit tests for `AvsRegistryServiceChainCaller` methods

---------

Co-authored-by: tomasarrachea <tomas.arrachea@lambdaclass.com>
Co-authored-by: Pablo Deymonnaz <deymonnaz@gmail.com>
Co-authored-by: Pablo Deymonnaz <pdeymon@fi.uba.ar>
  • Loading branch information
4 people authored Aug 28, 2024
1 parent dfb1022 commit 76971ad
Show file tree
Hide file tree
Showing 20 changed files with 576 additions and 180 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

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

15 changes: 7 additions & 8 deletions crates/chainio/clients/avsregistry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@ alloy-primitives.workspace = true
alloy-provider.workspace = true
alloy-rpc-types.workspace = true
alloy-signer.workspace = true
alloy-signer-local.workspace = true
async-trait.workspace = true
alloy-transport-http.workspace = true
num-bigint = "0.4.4"
reqwest.workspace = true
eigen-types.workspace = true
eigen-crypto-bls.workspace = true
ark-ff.workspace = true
eigen-client-elcontracts.workspace = true
eigen-crypto-bls.workspace = true
eigen-logging.workspace = true
eigen-types.workspace = true
eigen-utils.workspace = true
num-bigint = "0.4.4"
reqwest.workspace = true
eigen-logging.workspace = true
thiserror.workspace = true
tracing.workspace = true
[lints]
workspace = true
alloy-signer-local.workspace = true

[dev-dependencies]
hex = "0.4.3"
Expand Down
4 changes: 4 additions & 0 deletions crates/chainio/clients/avsregistry/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ pub enum AvsRegistryError {
#[error("Get Operator from Id")]
GetOperatorFromId,

/// Get Operator from Id
#[error("Get Operator Info")]
GetOperatorInfo,

/// Get Operator Status
#[error("Get Operator Status")]
GetOperatorStatus,
Expand Down
67 changes: 67 additions & 0 deletions crates/chainio/clients/avsregistry/src/fake_reader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use crate::{error::AvsRegistryError, reader::AvsRegistryReader};
use alloy_primitives::{Address, Bytes, FixedBytes};
use async_trait::async_trait;
use eigen_crypto_bls::BlsKeyPair;
use eigen_types::test::TestOperator;
use eigen_utils::binding::OperatorStateRetriever;

const OPERATOR_STAKE: u128 = 123;

/// This struct is used to test AvsRegistryServiceChainCaller methods.
#[derive(Debug)]
pub struct FakeAvsRegistryReader {
operator_address: Address,
operator_pubkeys: BlsKeyPair,
operator_id: FixedBytes<32>,
}

impl FakeAvsRegistryReader {
/// Creates a FakeAvsRegistryReader
///
/// # Arguments
///
/// * `operator` - A TestOperator.
/// * `operator_address` - The operator address.
///
/// # Returns
///
/// A FakeAvsRegistryReader
pub fn new(operator: TestOperator, operator_address: Address) -> Self {
Self {
operator_address,
operator_id: operator.operator_id,
operator_pubkeys: operator.bls_keypair,
}
}
}

#[async_trait]
impl AvsRegistryReader for FakeAvsRegistryReader {
async fn get_operators_stake_in_quorums_at_block(
&self,
_block_number: u32,
_quorum_numbers: Bytes,
) -> Result<Vec<Vec<OperatorStateRetriever::Operator>>, AvsRegistryError> {
Ok(vec![vec![OperatorStateRetriever::Operator {
operator: self.operator_address,
operatorId: self.operator_id,
stake: OPERATOR_STAKE,
}]])
}

async fn get_check_signatures_indices(
&self,
_reference_block_number: u32,
_quorum_numbers: Vec<u8>,
_non_signer_operator_ids: Vec<FixedBytes<32>>,
) -> Result<OperatorStateRetriever::CheckSignaturesIndices, AvsRegistryError> {
unimplemented!()
}

async fn get_operator_from_id(
&self,
_operator_id: [u8; 32],
) -> Result<Address, AvsRegistryError> {
Ok(self.operator_address)
}
}
4 changes: 4 additions & 0 deletions crates/chainio/clients/avsregistry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ pub mod writer;

/// Avs registry error message
pub mod error;

#[allow(dead_code)]
/// Fake avs registry module
pub mod fake_reader;
Loading

0 comments on commit 76971ad

Please sign in to comment.