From 35b2af0d5267feb5be60e9c30f2ae4b5878b2588 Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Wed, 13 Mar 2024 17:00:00 +0100 Subject: [PATCH 1/4] Add test coverage for get_constant_from_var_name --- .../builtin_hint_processor/hint_utils.rs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs b/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs index 3a1808b5a0..971c5d4b8c 100644 --- a/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs +++ b/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs @@ -277,4 +277,46 @@ mod tests { Err(HintError::IdentifierNotInteger(bx)) if *bx == ("value".to_string(), (1,0).into()) ); } + + #[test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn test_get_constant_from_var_name_with_point() { + let ids_data = HashMap::from([ + ("value".to_string(), Felt252::from(2)), + ("ids.MAX_LOW".to_string(), Felt252::from(20)), + ]); + + assert_eq!( + *get_constant_from_var_name("MAX_LOW", &ids_data).unwrap(), + Felt252::from(20) + ); + } + + #[test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn test_get_constant_from_var_name_without_point() { + let ids_data = HashMap::from([ + ("value".to_string(), Felt252::from(2)), + ("ids.MAX_LOW".to_string(), Felt252::from(20)), + ]); + + assert_eq!( + *get_constant_from_var_name("value", &ids_data).unwrap(), + Felt252::from(2) + ); + } + + #[test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn test_get_constant_from_var_name_invalid() { + let ids_data = HashMap::from([ + ("value".to_string(), Felt252::from(2)), + ("ids.MAX_LOW".to_string(), Felt252::from(20)), + ]); + + assert_matches!( + get_constant_from_var_name("MAX_HIGH", &ids_data), + Err(HintError::MissingConstant(bx)) if *bx == "MAX_HIGH".to_string() + ); + } } From 72ddc240be05f5d747a3c1d376bef823c5422add Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Wed, 13 Mar 2024 22:18:50 +0100 Subject: [PATCH 2/4] Update vm/src/hint_processor/builtin_hint_processor/hint_utils.rs --- vm/src/hint_processor/builtin_hint_processor/hint_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs b/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs index 971c5d4b8c..3e46ef8145 100644 --- a/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs +++ b/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs @@ -281,7 +281,7 @@ mod tests { #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_get_constant_from_var_name_with_point() { - let ids_data = HashMap::from([ + let constants = HashMap::from([ ("value".to_string(), Felt252::from(2)), ("ids.MAX_LOW".to_string(), Felt252::from(20)), ]); From f3202be446e1135e98dad24cc4c181e78eab9425 Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Wed, 13 Mar 2024 22:18:56 +0100 Subject: [PATCH 3/4] Update vm/src/hint_processor/builtin_hint_processor/hint_utils.rs --- vm/src/hint_processor/builtin_hint_processor/hint_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs b/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs index 3e46ef8145..327396b3e6 100644 --- a/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs +++ b/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs @@ -309,7 +309,7 @@ mod tests { #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_get_constant_from_var_name_invalid() { - let ids_data = HashMap::from([ + let constants = HashMap::from([ ("value".to_string(), Felt252::from(2)), ("ids.MAX_LOW".to_string(), Felt252::from(20)), ]); From c560c6870d1fc15221640c489db1c69438392e1e Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Wed, 13 Mar 2024 22:19:02 +0100 Subject: [PATCH 4/4] Update vm/src/hint_processor/builtin_hint_processor/hint_utils.rs --- vm/src/hint_processor/builtin_hint_processor/hint_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs b/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs index 327396b3e6..a35d8d9f84 100644 --- a/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs +++ b/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs @@ -295,7 +295,7 @@ mod tests { #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_get_constant_from_var_name_without_point() { - let ids_data = HashMap::from([ + let constants = HashMap::from([ ("value".to_string(), Felt252::from(2)), ("ids.MAX_LOW".to_string(), Felt252::from(20)), ]);