-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: atlantic test now use mock server
- Loading branch information
mohiiit
committed
Nov 14, 2024
1 parent
a93afe0
commit 751517d
Showing
2 changed files
with
22 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |