Skip to content

Commit b87f63b

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

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

crates/apollo_starknet_os_program/src/constants_test.rs

Lines changed: 24 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,28 @@ fn generate_constants_file() -> String {
205208
cairo0_format(&unformatted)
206209
}
207210

211+
/// Test that `constants.cairo` generated from the values in the versioned constants matches the
212+
/// existing file. 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+
// Generate `constants.cairo` from the current OS constants.
220+
let generated = generate_constants_file();
221+
let fix = std::env::var("FIX_OS_CONSTANTS").is_ok();
222+
if fix {
223+
// Write the generated contents to the file.
224+
let path = PathBuf::from(compile_time_cargo_manifest_dir!())
225+
.join("src/cairo/starkware/starknet/core/os/constants.cairo");
226+
std::fs::write(path, &generated).expect("Failed to write generated constants file.");
227+
} else {
228+
assert_eq!(
229+
CONSTANTS_CONTENTS, generated,
230+
"Generated constants file does not match the expected contents. Please run \
231+
`FIX_OS_CONSTANTS=1 cargo test -p apollo_starknet_os_program test_os_constants` to \
232+
fix the test."
233+
);
234+
}
212235
}

0 commit comments

Comments
 (0)