Skip to content

Commit

Permalink
move tests location
Browse files Browse the repository at this point in the history
  • Loading branch information
juan518munoz committed Jan 7, 2025
1 parent aa57afc commit 66e8260
Show file tree
Hide file tree
Showing 5 changed files with 1,029 additions and 1,029 deletions.
217 changes: 217 additions & 0 deletions core/node/da_clients/src/eigen/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,220 @@ impl DataAvailabilityClient for EigenClient {
Some(RawEigenClient::blob_size_limit())
}
}

/// 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 std::{str::FromStr, sync::Arc, time::Duration};

use backon::{ConstantBuilder, Retryable};
use serial_test::file_serial;
use zksync_config::{configs::da_client::eigen::EigenSecrets, EigenConfig};
use zksync_da_client::{
types::{DAError, DispatchResponse},
DataAvailabilityClient,
};
use zksync_types::secrets::PrivateKey;

use crate::eigen::{blob_info::BlobInfo, EigenClient, GetBlobData};

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

async fn get_commitment(&self, blob_id: &str) -> anyhow::Result<Option<BlobInfo>> {
self.client.get_commitment(blob_id).await
}
}

const STATUS_QUERY_TIMEOUT: u64 = 1800000; // 30 minutes
const STATUS_QUERY_INTERVAL: u64 = 5; // 5 ms

async fn get_blob_info(
client: &EigenClient,
result: &DispatchResponse,
) -> anyhow::Result<BlobInfo> {
let blob_info = (|| async {
let blob_info = client.get_commitment(&result.blob_id).await?;
if blob_info.is_none() {
return Err(anyhow::anyhow!("Blob not found"));
}
Ok(blob_info.unwrap())
})
.retry(
&ConstantBuilder::default()
.with_delay(Duration::from_millis(STATUS_QUERY_INTERVAL))
.with_max_times((STATUS_QUERY_TIMEOUT / STATUS_QUERY_INTERVAL) as usize),
)
.when(|e| e.to_string().contains("Blob not found"))
.await?;

Ok(blob_info)
}

#[derive(Debug, Clone)]
struct MockGetBlobData;

#[async_trait::async_trait]
impl GetBlobData for MockGetBlobData {
async fn get_blob_data(&self, _input: &'_ str) -> anyhow::Result<Option<Vec<u8>>> {
Ok(None)
}
}

fn test_secrets() -> EigenSecrets {
EigenSecrets {
private_key: PrivateKey::from_str(
"d08aa7ae1bb5ddd46c3c2d8cdb5894ab9f54dec467233686ca42629e826ac4c6",
)
.unwrap(),
}
}

#[ignore = "depends on external RPC"]
#[tokio::test]
#[file_serial]
async fn test_non_auth_dispersal() {
let config = EigenConfig::default();
let secrets = test_secrets();
let client = EigenClient::new(config.clone(), secrets, Arc::new(MockGetBlobData))
.await
.unwrap();
let data = vec![1; 20];
let result = client.dispatch_blob(0, data.clone()).await.unwrap();

let blob_info = get_blob_info(&client, &result).await.unwrap();
let expected_inclusion_data = blob_info.clone().blob_verification_proof.inclusion_proof;
let actual_inclusion_data = client
.get_inclusion_data(&result.blob_id)
.await
.unwrap()
.unwrap()
.data;
assert_eq!(expected_inclusion_data, actual_inclusion_data);
let retrieved_data = client.get_blob_data(blob_info).await.unwrap();
assert_eq!(retrieved_data.unwrap(), data);
}

#[ignore = "depends on external RPC"]
#[tokio::test]
#[file_serial]
async fn test_auth_dispersal() {
let config = EigenConfig {
authenticated: true,
..EigenConfig::default()
};
let secrets = test_secrets();
let client = EigenClient::new(config.clone(), secrets, Arc::new(MockGetBlobData))
.await
.unwrap();
let data = vec![1; 20];
let result = client.dispatch_blob(0, data.clone()).await.unwrap();
let blob_info = get_blob_info(&client, &result).await.unwrap();

let expected_inclusion_data = blob_info.clone().blob_verification_proof.inclusion_proof;
let actual_inclusion_data = client
.get_inclusion_data(&result.blob_id)
.await
.unwrap()
.unwrap()
.data;
assert_eq!(expected_inclusion_data, actual_inclusion_data);
let retrieved_data = client.get_blob_data(blob_info).await.unwrap();
assert_eq!(retrieved_data.unwrap(), data);
}

#[ignore = "depends on external RPC"]
#[tokio::test]
#[file_serial]
async fn test_wait_for_finalization() {
let config = EigenConfig {
wait_for_finalization: true,
authenticated: true,
..EigenConfig::default()
};
let secrets = test_secrets();

let client = EigenClient::new(config.clone(), secrets, Arc::new(MockGetBlobData))
.await
.unwrap();
let data = vec![1; 20];
let result = client.dispatch_blob(0, data.clone()).await.unwrap();
let blob_info = get_blob_info(&client, &result).await.unwrap();

let expected_inclusion_data = blob_info.clone().blob_verification_proof.inclusion_proof;
let actual_inclusion_data = client
.get_inclusion_data(&result.blob_id)
.await
.unwrap()
.unwrap()
.data;
assert_eq!(expected_inclusion_data, actual_inclusion_data);
let retrieved_data = client.get_blob_data(blob_info).await.unwrap();
assert_eq!(retrieved_data.unwrap(), data);
}

#[ignore = "depends on external RPC"]
#[tokio::test]
#[file_serial]
async fn test_settlement_layer_confirmation_depth() {
let config = EigenConfig {
settlement_layer_confirmation_depth: 5,
..EigenConfig::default()
};
let secrets = test_secrets();
let client = EigenClient::new(config.clone(), secrets, Arc::new(MockGetBlobData))
.await
.unwrap();
let data = vec![1; 20];
let result = client.dispatch_blob(0, data.clone()).await.unwrap();
let blob_info = get_blob_info(&client, &result).await.unwrap();

let expected_inclusion_data = blob_info.clone().blob_verification_proof.inclusion_proof;
let actual_inclusion_data = client
.get_inclusion_data(&result.blob_id)
.await
.unwrap()
.unwrap()
.data;
assert_eq!(expected_inclusion_data, actual_inclusion_data);
let retrieved_data = client.get_blob_data(blob_info).await.unwrap();
assert_eq!(retrieved_data.unwrap(), data);
}

#[ignore = "depends on external RPC"]
#[tokio::test]
#[file_serial]
async fn test_auth_dispersal_settlement_layer_confirmation_depth() {
let config = EigenConfig {
settlement_layer_confirmation_depth: 5,
authenticated: true,
..EigenConfig::default()
};
let secrets = test_secrets();
let client = EigenClient::new(config.clone(), secrets, Arc::new(MockGetBlobData))
.await
.unwrap();
let data = vec![1; 20];
let result = client.dispatch_blob(0, data.clone()).await.unwrap();
let blob_info = get_blob_info(&client, &result).await.unwrap();

let expected_inclusion_data = blob_info.clone().blob_verification_proof.inclusion_proof;
let actual_inclusion_data = client
.get_inclusion_data(&result.blob_id)
.await
.unwrap()
.unwrap()
.data;
assert_eq!(expected_inclusion_data, actual_inclusion_data);
let retrieved_data = client.get_blob_data(blob_info).await.unwrap();
assert_eq!(retrieved_data.unwrap(), data);
}
}
Loading

0 comments on commit 66e8260

Please sign in to comment.