From 751517d56d7fb13ab711923529d757a2151f4f98 Mon Sep 17 00:00:00 2001 From: mohiiit Date: Thu, 14 Nov 2024 17:37:54 +0530 Subject: [PATCH] refactor: atlantic test now use mock server --- .../atlantic-service/src/lib.rs | 2 ++ .../atlantic-service/tests/lib.rs | 36 ++++++++++--------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/crates/prover-clients/atlantic-service/src/lib.rs b/crates/prover-clients/atlantic-service/src/lib.rs index c0cbbb19..0d60e08f 100644 --- a/crates/prover-clients/atlantic-service/src/lib.rs +++ b/crates/prover-clients/atlantic-service/src/lib.rs @@ -42,6 +42,8 @@ impl ProverClient for AtlanticProverService { // sleep for 2 seconds to make sure the job is submitted tokio::time::sleep(tokio::time::Duration::from_secs(2)).await; let atlantic_job_response = self.atlantic_client.add_job(pie_file_path, proof_layout).await?; + // sleep for 2 seconds to make sure the job is submitted + tokio::time::sleep(tokio::time::Duration::from_secs(2)).await; log::debug!("Successfully submitted task to atlantic: {:?}", atlantic_job_response); // The temporary file will be automatically deleted when `temp_file` goes out of scope Ok(atlantic_job_response.sharp_query_id) diff --git a/crates/prover-clients/atlantic-service/tests/lib.rs b/crates/prover-clients/atlantic-service/tests/lib.rs index e28f690f..6cac6725 100644 --- a/crates/prover-clients/atlantic-service/tests/lib.rs +++ b/crates/prover-clients/atlantic-service/tests/lib.rs @@ -1,8 +1,8 @@ use atlantic_service::AtlanticProverService; use cairo_vm::types::layout_name::LayoutName; use cairo_vm::vm::runners::cairo_pie::CairoPie; +use httpmock::MockServer; use prover_client_interface::{ProverClient, Task}; -use rstest::rstest; use utils::settings::env::EnvSettingsProvider; use crate::constants::CAIRO_PIE_PATH; @@ -10,27 +10,31 @@ use crate::constants::CAIRO_PIE_PATH; mod constants; #[tokio::test] -#[rstest] -async fn atlantic_client_submit_task_works() { +async fn atlantic_client_submit_task_calls_correct_endpoint() { let _ = env_logger::try_init(); color_eyre::install().expect("Unable to install color_eyre"); dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); - let atlantic_service = AtlanticProverService::new_with_settings(&EnvSettingsProvider {}); - let cairo_pie_path = env!("CARGO_MANIFEST_DIR").to_string() + CAIRO_PIE_PATH; + // Start a mock server + let mock_server = MockServer::start(); + + // Create a mock for the submit endpoint + let submit_mock = mock_server.mock(|when, then| { + when.method("POST").path("/l1/atlantic-query/proof-generation-verification"); + then.status(200).header("content-type", "application/json").json_body(serde_json::json!({ + "sharpQueryId": "mock_query_id_123" + })); + }); + // Configure the service to use mock server + let settings = EnvSettingsProvider {}; + let atlantic_service = AtlanticProverService::with_test_settings(&settings, mock_server.port()); + + let cairo_pie_path = env!("CARGO_MANIFEST_DIR").to_string() + CAIRO_PIE_PATH; let cairo_pie = CairoPie::read_zip_file(cairo_pie_path.as_ref()).expect("failed to read cairo pie zip"); + let task_result = atlantic_service.submit_task(Task::CairoPie(Box::new(cairo_pie)), LayoutName::dynamic).await; - log::info!("Task result from atlantic service: {:?}", task_result); - assert!(task_result.is_ok()); - let query_id = task_result.expect("Failed to submit task"); - // let query_id = "01JA7X1R3HH2BXJ6B7NC814ERP"; - log::info!("Task submitted with query id: {:?}", query_id); - let status = atlantic_service - .atlantic_client - .get_job_status(query_id.as_ref()) - .await - .expect("Failed to get status from atlantic"); - log::info!("Got status from atlantic {:?}", status); + assert!(task_result.is_ok()); + submit_mock.assert(); }