Skip to content

Commit

Permalink
test(starknet_os): test hint strings are unique
Browse files Browse the repository at this point in the history
  • Loading branch information
dorimedini-starkware committed Jan 29, 2025
1 parent 30d2866 commit 3972cb7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions crates/starknet_os/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ license.workspace = true
license-file.workspace = true
description = "The Starknet OS."

[features]
testing = ["dep:strum", "dep:strum_macros"]

[dependencies]
cairo-vm.workspace = true
indoc.workspace = true
starknet-types-core.workspace = true
strum = { workspace = true, optional = true }
strum_macros = { workspace = true, optional = true }
thiserror.workspace = true

[dev-dependencies]
strum.workspace = true
strum_macros.workspace = true

[lints]
workspace = true
4 changes: 4 additions & 0 deletions crates/starknet_os/src/hints/enum_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ use crate::hints::transaction_hash::{additional_data_new_segment, data_to_hash_n
use crate::hints::types::{HintEnum, HintExtensionImplementation, HintImplementation};
use crate::{define_hint_enum, define_hint_extension_enum};

#[cfg(test)]
#[path = "enum_definition_test.rs"]
pub mod test;

define_hint_enum!(
Hint,
(
Expand Down
24 changes: 24 additions & 0 deletions crates/starknet_os/src/hints/enum_definition_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::collections::HashSet;

use strum::IntoEnumIterator;

use super::{Hint, HintExtension};
use crate::hints::types::HintEnum;

#[test]
fn test_hint_strings_are_unique() {
let hint_strings = Hint::iter().map(|hint| hint.to_str()).collect::<Vec<_>>();
let hint_extension_strings =
HintExtension::iter().map(|hint| hint.to_str()).collect::<Vec<_>>();
let hint_strings_set: HashSet<&&str> = HashSet::from_iter(hint_strings.iter());
let hint_extension_strings_set = HashSet::from_iter(hint_extension_strings.iter());
assert_eq!(hint_strings.len(), hint_strings_set.len(), "Duplicate hint strings.");
assert_eq!(
hint_extension_strings.len(),
hint_extension_strings_set.len(),
"Duplicate hint extension strings."
);
let ambiguous_strings =
hint_strings_set.intersection(&hint_extension_strings_set).collect::<Vec<_>>();
assert!(ambiguous_strings.is_empty(), "Ambiguous hint strings: {ambiguous_strings:?}");
}
1 change: 1 addition & 0 deletions crates/starknet_os/src/hints/enum_generation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[macro_export]
macro_rules! define_hint_enum_base {
($enum_name:ident, $(($hint_name:ident, $hint_str:expr)),+ $(,)?) => {
#[cfg_attr(any(test, feature = "testing"), derive(strum_macros::EnumIter))]
pub enum $enum_name {
$($hint_name),+
}
Expand Down

0 comments on commit 3972cb7

Please sign in to comment.