Skip to content

Commit

Permalink
refactor: deserialize input in deserialize function
Browse files Browse the repository at this point in the history
  • Loading branch information
aner-starkware committed Jul 9, 2024
1 parent 09c320e commit 9e72961
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions crates/committer_cli/src/tests/benchmark_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct CommitterRegressionInput {
struct TreeRegressionInput {
tree_flow_input: TreeFlowInput,
expected_hash: String,
expected_storage_changes: String,
expected_storage_changes: Map<String, Value>,
}

// TODO(Aner, 9/8/24): remove this impl and use the Deserialize derive, by changing the input format.
Expand All @@ -41,20 +41,24 @@ impl<'de> Deserialize<'de> for TreeRegressionInput {
Ok(Self {
tree_flow_input: parse_input_single_storage_tree_flow_test(&map),
expected_hash: map.get("expected_hash").unwrap().to_string(),
expected_storage_changes: map.get("expected_storage_changes").unwrap().to_string(),
expected_storage_changes: serde_json::from_str(
map.get("expected_storage_changes").unwrap(),
)
.unwrap(),
})
}
}

#[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() {
let input: TreeRegressionInput = serde_json::from_str(SINGLE_TREE_FLOW_INPUT).unwrap();
let tree_regression_input: TreeRegressionInput =
serde_json::from_str(SINGLE_TREE_FLOW_INPUT).unwrap();
let TreeFlowInput {
leaf_modifications,
storage,
root_hash,
} = input.tree_flow_input;
} = tree_regression_input.tree_flow_input;

let start = std::time::Instant::now();
// Benchmark the single tree flow test.
Expand All @@ -65,16 +69,15 @@ pub async fn test_benchmark_single_tree() {
// TODO(Aner, 8/7/2024): use structs for deserialization.
let output_map: HashMap<&str, Value> = serde_json::from_str(&output).unwrap();
let output_hash = output_map.get("root_hash").unwrap();
let expected_hash = input.expected_hash;
let expected_hash = tree_regression_input.expected_hash;
assert_eq!(output_hash.as_str().unwrap(), expected_hash);

// Assert the storage changes.
let Value::Object(storage_changes) = output_map.get("storage_changes").unwrap() else {
panic!("Expected storage changes object to be an object.");
};
let expected_storage_changes: Map<String, Value> =
serde_json::from_str(&input.expected_storage_changes).unwrap();
assert_eq!(storage_changes, &expected_storage_changes);
let expected_storage_changes = &tree_regression_input.expected_storage_changes;
assert_eq!(storage_changes, expected_storage_changes);

// 4. Assert the execution time does not exceed the threshold.
assert!(execution_time.as_secs_f64() < MAX_TIME_FOR_SINGLE_TREE_BECHMARK_TEST);
Expand Down

0 comments on commit 9e72961

Please sign in to comment.