diff --git a/crates/committer_cli/src/tests/benchmark_tests.rs b/crates/committer_cli/src/tests/benchmark_tests.rs index cd20e306..3bc67b10 100644 --- a/crates/committer_cli/src/tests/benchmark_tests.rs +++ b/crates/committer_cli/src/tests/benchmark_tests.rs @@ -1,23 +1,30 @@ use std::collections::HashMap; use committer::patricia_merkle_tree::external_test_utils::single_tree_flow_test; +use serde::Deserialize; use serde_json::{Map, Value}; use crate::{ commands::commit, tests::utils::parse_from_python::parse_input_single_storage_tree_flow_test, }; -//TODO(Aner, 20/06/2024): this test needs to be fixed to be run correctly in the CI: +//TODO(Aner, 20/06/2024): these tests needs to be fixed to be run correctly in the CI: //1. Fix the test to measure cpu_time and not wall_time. //2. Fix the max time threshold to be the expected time for the benchmark test. const MAX_TIME_FOR_SINGLE_TREE_BECHMARK_TEST: f64 = 5.0; const MAX_TIME_FOR_COMMITTER_FLOW_BECHMARK_TEST: f64 = 5.0; const SINGLE_TREE_FLOW_INPUT: &str = include_str!("../../benches/tree_flow_inputs.json"); -//TODO(Aner, 20/06/2024): modify the committer_flow_inputs.json file to be from pseudo-real data -// and to include the expected output. const FLOW_TEST_INPUT: &str = include_str!("../../benches/committer_flow_inputs.json"); const OUTPUT_PATH: &str = "benchmark_output.txt"; +#[derive(Deserialize)] +struct CommitterRegressionInput { + committer_input: String, + contract_states_root: String, + contract_classes_root: String, + expected_facts: String, +} + #[ignore = "To avoid running the benchmark test in Coverage or without the --release flag."] #[tokio::test(flavor = "multi_thread")] pub async fn test_benchmark_single_tree() { @@ -52,13 +59,11 @@ pub async fn test_benchmark_single_tree() { #[ignore = "To avoid running the benchmark test in Coverage or without the --release flag."] #[tokio::test(flavor = "multi_thread")] pub async fn test_benchmark_committer_flow() { - // TODO(Aner, 8/7/2024): use structs for deserialization. - let input: HashMap = serde_json::from_str(FLOW_TEST_INPUT).unwrap(); - let committer_input = input.get("committer_input").unwrap(); + let regression_input: CommitterRegressionInput = serde_json::from_str(FLOW_TEST_INPUT).unwrap(); let start = std::time::Instant::now(); // Benchmark the committer flow test. - commit(committer_input, OUTPUT_PATH.to_owned()).await; + commit(®ression_input.committer_input, OUTPUT_PATH.to_owned()).await; let execution_time = std::time::Instant::now() - start; // Assert the output of the committer flow test. @@ -69,18 +74,14 @@ pub async fn test_benchmark_committer_flow() { let contract_storage_root_hash = committer_output.get("contract_storage_root_hash").unwrap(); let compiled_class_root_hash = committer_output.get("compiled_class_root_hash").unwrap(); - let expected_contract_storage_root_hash = input.get("contract_states_root").unwrap(); - let expected_compiled_class_root_hash = input.get("contract_classes_root").unwrap(); - assert_eq!( contract_storage_root_hash.as_str().unwrap(), - expected_contract_storage_root_hash + regression_input.contract_states_root ); assert_eq!( compiled_class_root_hash.as_str().unwrap(), - expected_compiled_class_root_hash + regression_input.contract_classes_root ); - // Assert the storage changes. // TODO(Aner, 8/7/2024): use structs for deserialization. let Value::Object(storage_changes) = committer_output @@ -92,9 +93,9 @@ pub async fn test_benchmark_committer_flow() { panic!("Expected the storage to be an object."); }; - // TODO(Aner, 8/7/2024): use structs for deserialization. + // TODO(Aner, 8/7/2024): fix to deserialize automatically. let expected_storage_changes: Map = - serde_json::from_str(input.get("expected_facts").unwrap()).unwrap(); + serde_json::from_str(®ression_input.expected_facts).unwrap(); assert_eq!(storage_changes, &expected_storage_changes);