Skip to content

Commit

Permalink
refactor: atlantic test now use mock server
Browse files Browse the repository at this point in the history
  • Loading branch information
mohiiit committed Nov 14, 2024
1 parent a93afe0 commit 751517d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
2 changes: 2 additions & 0 deletions crates/prover-clients/atlantic-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 20 additions & 16 deletions crates/prover-clients/atlantic-service/tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
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;

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();
}

0 comments on commit 751517d

Please sign in to comment.