|
1 | 1 | use std::collections::HashSet; |
2 | 2 |
|
| 3 | +use apollo_starknet_os_program::{AGGREGATOR_PROGRAM, OS_PROGRAM}; |
3 | 4 | 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; |
4 | 9 | use strum::IntoEnumIterator; |
5 | 10 |
|
6 | 11 | use crate::hints::enum_definition::{AllHints, DeprecatedSyscallHint}; |
7 | 12 | use crate::hints::types::HintEnum; |
8 | 13 |
|
| 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 | + |
9 | 36 | #[test] |
10 | 37 | fn test_hint_strings_are_unique() { |
11 | 38 | let all_hints = AllHints::all_iter().map(|hint| hint.to_str()).collect::<Vec<_>>(); |
@@ -34,3 +61,17 @@ fn test_syscall_compatibility_with_blockifier() { |
34 | 61 | the implementation." |
35 | 62 | ); |
36 | 63 | } |
| 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