Skip to content

Commit c1aae23

Browse files
feat(apollo_starknet_os_program): add fixer for OS constants test
1 parent 0f85e49 commit c1aae23

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

crates/apollo_starknet_os_program/src/constants_test.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
use std::path::PathBuf;
2+
13
use apollo_infra_utils::cairo0_compiler::{cairo0_format, verify_cairo0_compiler_deps};
4+
use apollo_infra_utils::compile_time_cargo_manifest_dir;
25
use blockifier::blockifier_versioned_constants::{OsConstants, VersionedConstants};
36
use blockifier::execution::syscalls::vm_syscall_utils::SyscallSelector;
47
use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector};
@@ -205,8 +208,27 @@ fn generate_constants_file() -> String {
205208
cairo0_format(&unformatted)
206209
}
207210

211+
/// Test that the generated constants file matches the expected contents.
212+
/// To fix this test, run:
213+
/// ```bash
214+
/// FIX_OS_CONSTANTS=1 cargo test -p apollo_starknet_os_program test_os_constants
215+
/// ```
208216
#[test]
209217
fn test_os_constants() {
210218
verify_cairo0_compiler_deps();
211-
assert_eq!(CONSTANTS_CONTENTS, generate_constants_file());
219+
let generated = generate_constants_file();
220+
let fix = std::env::var("FIX_OS_CONSTANTS").is_ok();
221+
if fix {
222+
// Write the generated contents to the file.
223+
let path = PathBuf::from(compile_time_cargo_manifest_dir!())
224+
.join("src/cairo/starkware/starknet/core/os/constants.cairo");
225+
std::fs::write(path, &generated).expect("Failed to write generated constants file.");
226+
} else {
227+
assert_eq!(
228+
CONSTANTS_CONTENTS, generated,
229+
"Generated constants file does not match the expected contents. Please run \
230+
`FIX_OS_CONSTANTS=1 cargo test -p apollo_starknet_os_program test_os_constants` to \
231+
fix the test."
232+
);
233+
}
212234
}

0 commit comments

Comments
 (0)