Skip to content

Commit 93979e0

Browse files
test(starknet_os): hint consistency test with local program objects
1 parent dca637c commit 93979e0

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

crates/starknet_committer_and_os_cli/src/os_cli/tests/python_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ impl PythonTestRunner for OsPythonTestRunner {
5757
}
5858
}
5959

60+
// TODO(Dori): Delete this test, in favor of the `test_all_hints_are_known` in the `starknet_os`
61+
// crate.
6062
#[allow(clippy::result_large_err)]
6163
fn compare_os_hints(input: &str) -> OsPythonTestResult {
6264
let unfiltered_python_hints: HashSet<String> = serde_json::from_str(input)?;

crates/starknet_os/src/hints/enum_definition_test.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
11
use std::collections::HashSet;
22

3+
use apollo_starknet_os_program::{AGGREGATOR_PROGRAM, OS_PROGRAM};
34
use blockifier::execution::hint_code::SYSCALL_HINTS;
5+
use cairo_vm::hint_processor::builtin_hint_processor::hint_code::HINT_CODES;
6+
use cairo_vm::hint_processor::builtin_hint_processor::kzg_da::WRITE_DIVMOD_SEGMENT;
7+
use cairo_vm::hint_processor::builtin_hint_processor::secp::cairo0_hints::CAIRO0_HINT_CODES;
8+
use cairo_vm::types::program::Program;
49
use strum::IntoEnumIterator;
510

611
use crate::hints::enum_definition::{AllHints, DeprecatedSyscallHint};
712
use crate::hints::types::HintEnum;
813

14+
fn vm_hints() -> HashSet<&'static str> {
15+
let mut vm_hints = HashSet::from([WRITE_DIVMOD_SEGMENT]);
16+
vm_hints.extend(HINT_CODES.values());
17+
vm_hints.extend(CAIRO0_HINT_CODES.values());
18+
vm_hints
19+
}
20+
21+
fn unknown_hints_for_program(program: &Program, filter: &HashSet<&str>) -> HashSet<String> {
22+
program
23+
.shared_program_data
24+
.hints_collection
25+
.iter_hints()
26+
.map(|hint| hint.code.clone())
27+
.filter(|hint_str| !filter.contains(hint_str.as_str()))
28+
.filter_map(
29+
|hint_str| {
30+
if AllHints::from_str(&hint_str).is_err() { Some(hint_str) } else { None }
31+
},
32+
)
33+
.collect()
34+
}
35+
936
#[test]
1037
fn test_hint_strings_are_unique() {
1138
let all_hints = AllHints::all_iter().map(|hint| hint.to_str()).collect::<Vec<_>>();
@@ -34,3 +61,17 @@ fn test_syscall_compatibility_with_blockifier() {
3461
the implementation."
3562
);
3663
}
64+
65+
#[test]
66+
fn test_all_hints_are_known() {
67+
let vm_hints = vm_hints();
68+
let unknown_os_hints = unknown_hints_for_program(&OS_PROGRAM, &vm_hints);
69+
let unknown_aggregator_hints = unknown_hints_for_program(&AGGREGATOR_PROGRAM, &vm_hints);
70+
let unknown_hints: HashSet<String> =
71+
unknown_os_hints.union(&unknown_aggregator_hints).cloned().collect();
72+
73+
assert!(
74+
unknown_hints.is_empty(),
75+
"The following hints are not known in 'starknet_os': {unknown_hints:#?}."
76+
);
77+
}

0 commit comments

Comments
 (0)