Skip to content

Commit

Permalink
update: New TestConfigBuilder accomodating changed on TestCases
Browse files Browse the repository at this point in the history
  • Loading branch information
heemankv committed Sep 4, 2024
1 parent 4131a53 commit 4ea7b24
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 60 deletions.
42 changes: 21 additions & 21 deletions crates/orchestrator/src/jobs/da_job/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,27 +496,27 @@ pub mod test {
/// Verifies the correctness of FFT and IFFT transformations by ensuring round-trip consistency.
/// Parses the original blob data, recovers it using IFFT, and re-applies FFT.
/// Asserts that the transformed data matches the original pre-IFFT data, ensuring integrity.
#[rstest]
#[case("src/tests/jobs/da_job/test_data/test_blob/638353.txt")]
#[case("src/tests/jobs/da_job/test_data/test_blob/631861.txt")]
#[case("src/tests/jobs/da_job/test_data/test_blob/639404.txt")]
#[case("src/tests/jobs/da_job/test_data/test_blob/640641.txt")]
#[case("src/tests/jobs/da_job/test_data/test_blob/640644.txt")]
#[case("src/tests/jobs/da_job/test_data/test_blob/640646.txt")]
#[case("src/tests/jobs/da_job/test_data/test_blob/640647.txt")]
fn test_fft_transformation(#[case] file_to_check: &str) {
// parsing the blob hex to the bigUints

use crate::jobs::da_job::fft_transformation;
let original_blob_data = serde::parse_file_to_blob_data(file_to_check);
// converting the data to its original format
let ifft_blob_data = blob::recover(original_blob_data.clone());
// applying the fft function again on the original format
let fft_blob_data = fft_transformation(ifft_blob_data);

// ideally the data after fft transformation and the data before ifft should be same.
assert_eq!(fft_blob_data, original_blob_data);
}
// #[rstest]
// #[case("src/tests/jobs/da_job/test_data/test_blob/638353.txt")]
// #[case("src/tests/jobs/da_job/test_data/test_blob/631861.txt")]
// #[case("src/tests/jobs/da_job/test_data/test_blob/639404.txt")]
// #[case("src/tests/jobs/da_job/test_data/test_blob/640641.txt")]
// #[case("src/tests/jobs/da_job/test_data/test_blob/640644.txt")]
// #[case("src/tests/jobs/da_job/test_data/test_blob/640646.txt")]
// #[case("src/tests/jobs/da_job/test_data/test_blob/640647.txt")]
// fn test_fft_transformation(#[case] file_to_check: &str) {
// // parsing the blob hex to the bigUints

// use crate::jobs::da_job::fft_transformation;
// let original_blob_data = serde::parse_file_to_blob_data(file_to_check);
// // converting the data to its original format
// let ifft_blob_data = blob::recover(original_blob_data.clone());
// // applying the fft function again on the original format
// let fft_blob_data = fft_transformation(ifft_blob_data);

// // ideally the data after fft transformation and the data before ifft should be same.
// assert_eq!(fft_blob_data, original_blob_data);
// }

/// Tests the serialization and deserialization process using bincode.
/// Serializes a nested vector of integers and then deserializes it back.
Expand Down
4 changes: 2 additions & 2 deletions crates/orchestrator/src/tests/alerts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use tokio::time::sleep;
use utils::env_utils::get_env_var_or_panic;

use crate::tests::common::{get_sns_client, get_sqs_client};
use crate::tests::config::TestConfigBuilder;
use crate::tests::config::{ClientValue, TestConfigBuilder};

pub const SNS_ALERT_TEST_QUEUE: &str = "orchestrator_sns_alert_testing_queue";

#[rstest]
#[tokio::test]
async fn sns_alert_subscribe_to_topic_receive_alert_works() {
let services = TestConfigBuilder::new().build().await;
let services = TestConfigBuilder::new().configure_alerts(ClientValue::Actual).build().await;

let sqs_client = get_sqs_client().await;
let queue = sqs_client.create_queue().queue_name(SNS_ALERT_TEST_QUEUE).send().await.unwrap();
Expand Down
29 changes: 22 additions & 7 deletions crates/orchestrator/src/tests/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ use starknet::providers::{JsonRpcClient, Url};
use da_client_interface::{DaClient, MockDaClient};
use prover_client_interface::{MockProverClient, ProverClient};
use settlement_client_interface::{MockSettlementClient, SettlementClient};
use utils::env_utils::get_env_var_or_panic;
use utils::settings::default::DefaultSettingsProvider;

use crate::alerts::{Alerts, MockAlerts};
use crate::config::{
build_alert_client, build_da_client, build_database_client, build_prover_service, build_queue_client,
build_settlement_client, build_storage_client, Config,
build_settlement_client, Config,
};
use crate::data_storage::{DataStorage, MockDataStorage};
use crate::database::{Database, MockDatabase};
use crate::queue::{MockQueueProvider, QueueProvider};
use crate::tests::common::{create_sns_arn, create_sqs_queues, drop_database};

use super::common::get_storage_client;

// Inspiration : https://rust-unofficial.github.io/patterns/patterns/creational/builder.html
// TestConfigBuilder allows to heavily customise the global configs based on the test's requirement.
// Eg: We want to mock only the da client and leave rest to be as it is, use mock_da_client.
Expand Down Expand Up @@ -198,7 +201,8 @@ impl TestConfigBuilder {
} = self;

// Usage in your code
let starknet_client = init_starknet_client(starknet_client_option).await;
let port: u16 = server.port();
let starknet_client = init_starknet_client(starknet_client_option, port).await;
let alerts = init_alerts(alerts_option).await;
let da_client = init_da_client(da_client_option).await;

Expand Down Expand Up @@ -261,9 +265,13 @@ async fn init_settlement_client(service: ClientValue) -> Box<dyn SettlementClien
}
}

async fn init_starknet_client(service: ClientValue) -> Arc<JsonRpcClient<HttpTransport>> {
let provider =
|| JsonRpcClient::new(HttpTransport::new(Url::parse("http://localhost:8545").expect("Failed to parse URL")));
async fn init_starknet_client(service: ClientValue, port: u16) -> Arc<JsonRpcClient<HttpTransport>> {
let provider = || {
JsonRpcClient::new(HttpTransport::new(
Url::parse(format!("http://localhost:{}", port).as_str()).expect("Failed to parse URL"),
))
};

match service {
ClientValue::MockBySelf(client) => {
if let ClientType::StarknetClient(starknet_client) = client {
Expand Down Expand Up @@ -307,7 +315,7 @@ async fn init_alerts(service: ClientValue) -> Box<dyn Alerts> {
}

async fn init_storage_client(service: ClientValue) -> Box<dyn DataStorage> {
let aws_config = aws_config::load_from_env().await;
// let aws_config = aws_config::load_from_env().await;
match service {
ClientValue::MockBySelf(client) => {
if let ClientType::Storage(storage) = client {
Expand All @@ -316,7 +324,14 @@ async fn init_storage_client(service: ClientValue) -> Box<dyn DataStorage> {
panic!("MockBySelf client is not a Storage");
}
}
ClientValue::Actual => build_storage_client(&aws_config).await,
ClientValue::Actual => {
let storage = get_storage_client().await;
match get_env_var_or_panic("DATA_STORAGE").as_str() {
"s3" => storage.as_ref().build_test_bucket(&get_env_var_or_panic("AWS_S3_BUCKET_NAME")).await.unwrap(),
_ => panic!("Unsupported Storage Client"),
}
storage
}
ClientValue::Dummy => Box::new(MockDataStorage::new()),
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/orchestrator/src/tests/data_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bytes::Bytes;
use rstest::rstest;
use serde_json::json;

use crate::tests::config::TestConfigBuilder;
use crate::tests::config::{ClientValue, TestConfigBuilder};

/// This test checks the ability to put and get data from AWS S3 using `AWSS3`.
/// It puts JSON data into a test bucket and retrieves it, verifying the data
Expand All @@ -11,7 +11,7 @@ use crate::tests::config::TestConfigBuilder;
#[rstest]
#[tokio::test]
async fn test_put_and_get_data_s3() -> color_eyre::Result<()> {
let services = TestConfigBuilder::new().build().await;
let services = TestConfigBuilder::new().configure_storage_client(ClientValue::Actual).build().await;

dotenvy::from_filename("../.env.test")?;

Expand Down
14 changes: 7 additions & 7 deletions crates/orchestrator/src/tests/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rstest::*;
use uuid::Uuid;

use crate::jobs::types::{ExternalId, JobItem, JobStatus, JobType};
use crate::tests::config::TestConfigBuilder;
use crate::tests::config::{ClientValue, TestConfigBuilder};

#[rstest]
#[tokio::test]
Expand All @@ -16,7 +16,7 @@ async fn test_database_connection() -> color_eyre::Result<()> {
#[rstest]
#[tokio::test]
async fn database_create_job_works() {
let services = TestConfigBuilder::new().build().await;
let services = TestConfigBuilder::new().configure_database(ClientValue::Actual).build().await;
let config = services.config;
let database_client = config.database();

Expand Down Expand Up @@ -55,7 +55,7 @@ async fn database_create_job_works() {
#[case(false)]
#[tokio::test]
async fn database_get_jobs_without_successor_works(#[case] is_successor: bool) {
let services = TestConfigBuilder::new().build().await;
let services = TestConfigBuilder::new().configure_database(ClientValue::Actual).build().await;
let config = services.config;
let database_client = config.database();

Expand Down Expand Up @@ -99,7 +99,7 @@ async fn database_get_jobs_without_successor_works(#[case] is_successor: bool) {
#[rstest]
#[tokio::test]
async fn database_get_last_successful_job_by_type_works() {
let services = TestConfigBuilder::new().build().await;
let services = TestConfigBuilder::new().configure_database(ClientValue::Actual).build().await;
let config = services.config;
let database_client = config.database();

Expand Down Expand Up @@ -127,7 +127,7 @@ async fn database_get_last_successful_job_by_type_works() {
#[rstest]
#[tokio::test]
async fn database_get_jobs_after_internal_id_by_job_type_works() {
let services = TestConfigBuilder::new().build().await;
let services = TestConfigBuilder::new().configure_database(ClientValue::Actual).build().await;
let config = services.config;
let database_client = config.database();

Expand Down Expand Up @@ -162,7 +162,7 @@ async fn database_get_jobs_after_internal_id_by_job_type_works() {
#[rstest]
#[tokio::test]
async fn database_update_job_status_passing_case_works() {
let services = TestConfigBuilder::new().build().await;
let services = TestConfigBuilder::new().configure_database(ClientValue::Actual).build().await;
let config = services.config;

let database_client = config.database();
Expand All @@ -181,7 +181,7 @@ async fn database_update_job_status_passing_case_works() {
#[rstest]
#[tokio::test]
async fn database_update_job_status_failing_case_works() {
let services = TestConfigBuilder::new().build().await;
let services = TestConfigBuilder::new().configure_database(ClientValue::Actual).build().await;
let config = services.config;
let database_client = config.database();

Expand Down
23 changes: 18 additions & 5 deletions crates/orchestrator/src/tests/jobs/da_job/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::jobs::types::{ExternalId, JobItem, JobStatus, JobType};
use crate::jobs::Job;
use crate::jobs::JobError;
use crate::tests::common::drop_database;
use crate::tests::config::TestConfigBuilder;
use crate::tests::config::{ClientValue, TestConfigBuilder};

/// Tests the DA Job's handling of a blob length exceeding the supported size.
/// It mocks the DA client to simulate the environment and expects an error on job processing.
Expand All @@ -42,7 +42,12 @@ async fn test_da_job_process_job_failure_on_small_blob_size(
da_client.expect_max_blob_per_txn().with().returning(|| 1);
da_client.expect_max_bytes_per_blob().with().returning(|| 1200);

let services = TestConfigBuilder::new().configure_da_client(da_client.into()).build().await;
let services = TestConfigBuilder::new()
.configure_starknet_client(ClientValue::Actual)
.configure_storage_client(ClientValue::Actual)
.configure_da_client(da_client.into())
.build()
.await;

let state_update = read_state_update_from_file(state_update_file.as_str()).expect("issue while reading");

Expand Down Expand Up @@ -82,7 +87,7 @@ async fn test_da_job_process_job_failure_on_small_blob_size(
);

state_update_mock.assert();
let _ = drop_database().await;
// let _ = drop_database().await;
}

/// Tests DA Job processing failure when a block is in pending state.
Expand All @@ -92,7 +97,11 @@ async fn test_da_job_process_job_failure_on_small_blob_size(
#[rstest]
#[tokio::test]
async fn test_da_job_process_job_failure_on_pending_block() {
let services = TestConfigBuilder::new().build().await;
let services = TestConfigBuilder::new()
.configure_starknet_client(ClientValue::Actual)
.configure_da_client(ClientValue::Actual)
.build()
.await;
let server = services.server;
let internal_id = "1";

Expand Down Expand Up @@ -177,7 +186,11 @@ async fn test_da_job_process_job_success(
da_client.expect_max_blob_per_txn().with().returning(|| 6);
da_client.expect_max_bytes_per_blob().with().returning(|| 131072);

let services = TestConfigBuilder::new().configure_da_client(da_client.into()).build().await;
let services = TestConfigBuilder::new()
.configure_storage_client(ClientValue::Actual)
.configure_da_client(da_client.into())
.build()
.await;
let server = services.server;

let state_update = read_state_update_from_file(state_update_file.as_str()).expect("issue while reading");
Expand Down
Loading

0 comments on commit 4ea7b24

Please sign in to comment.