Skip to content
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

feat(eigen-client-extra-features): Replace third party dependant tests with mock tests #356

Merged
27 changes: 18 additions & 9 deletions core/node/da_clients/src/eigen/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ use super::{blob_info::BlobInfo, sdk::RawEigenClient};
use crate::utils::to_retriable_da_error;

/// EigenClient is a client for the Eigen DA service.
/// It can be configured to use one of two dispersal methods:
/// - Remote: Dispatch blobs to a remote Eigen service.
/// - Memstore: Stores blobs in memory, used for testing purposes.
#[derive(Debug, Clone)]
pub struct EigenClient {
client: Arc<RawEigenClient>,
Expand Down Expand Up @@ -83,12 +80,10 @@ impl DataAvailabilityClient for EigenClient {
}
}

#[cfg(test)]
impl EigenClient {
pub async fn get_blob_data(&self, blob_id: &str) -> anyhow::Result<Option<Vec<u8>>, DAError> {
self.client.get_blob_data(blob_id).await
}
}
/// EigenDA Client tests are ignored by default, because they require a remote dependency,
/// which may not always be available, causing tests to be flaky.
/// To run these tests, use the following command:
/// `cargo test -p zksync_da_clients -- --ignored`
#[cfg(test)]
mod tests {
use serial_test::serial;
Expand All @@ -98,6 +93,16 @@ mod tests {
use super::*;
use crate::eigen::blob_info::BlobInfo;

impl EigenClient {
pub async fn get_blob_data(
&self,
blob_id: &str,
) -> anyhow::Result<Option<Vec<u8>>, DAError> {
self.client.get_blob_data(blob_id).await
}
}

#[ignore = "depends on external RPC"]
#[tokio::test]
#[serial]
async fn test_non_auth_dispersal() {
Expand Down Expand Up @@ -140,6 +145,7 @@ mod tests {
assert_eq!(retrieved_data.unwrap(), data);
}

#[ignore = "depends on external RPC"]
#[tokio::test]
#[serial]
async fn test_auth_dispersal() {
Expand Down Expand Up @@ -181,6 +187,7 @@ mod tests {
assert_eq!(retrieved_data.unwrap(), data);
}

#[ignore = "depends on external RPC"]
#[tokio::test]
#[serial]
async fn test_wait_for_finalization() {
Expand Down Expand Up @@ -222,6 +229,7 @@ mod tests {
assert_eq!(retrieved_data.unwrap(), data);
}

#[ignore = "depends on external RPC"]
#[tokio::test]
#[serial]
async fn test_settlement_layer_confirmation_depth() {
Expand Down Expand Up @@ -263,6 +271,7 @@ mod tests {
assert_eq!(retrieved_data.unwrap(), data);
}

#[ignore = "depends on external RPC"]
#[tokio::test]
#[serial]
async fn test_auth_dispersal_settlement_layer_confirmation_depth() {
Expand Down
19 changes: 18 additions & 1 deletion core/node/da_clients/src/eigen/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ use tonic::{
};
use zksync_config::EigenConfig;
use zksync_da_client::types::DAError;
use zksync_eth_client::clients::PKSigningClient;
use zksync_types::{url::SensitiveUrl, K256PrivateKey, SLChainId, H160};
use zksync_web3_decl::client::{Client, DynClient, L1};

use super::{
blob_info::BlobInfo,
Expand Down Expand Up @@ -58,7 +61,21 @@ impl RawEigenClient {
private_key: hex::encode(private_key.secret_bytes()),
chain_id: config.chain_id,
};
let verifier = Verifier::new(verifier_config)

let url = SensitiveUrl::from_str(&verifier_config.rpc_url)?;
let query_client: Client<L1> = Client::http(url)?.build();
let query_client = Box::new(query_client) as Box<DynClient<L1>>;
let signing_client = PKSigningClient::new_raw(
K256PrivateKey::from_bytes(zksync_types::H256::from_str(
&verifier_config.private_key,
)?)?,
H160::from_str(&verifier_config.svc_manager_addr)?,
Verifier::DEFAULT_PRIORITY_FEE_PER_GAS,
SLChainId(verifier_config.chain_id),
query_client,
);

let verifier = Verifier::new(verifier_config, signing_client)
.await
.map_err(|e| anyhow::anyhow!(format!("Failed to create verifier {:?}", e)))?;
Ok(RawEigenClient {
Expand Down
Loading
Loading