Skip to content

Commit 021abe4

Browse files
feat(apollo_starknet_os_program): add fixer for OS constants test
1 parent 1b132cd commit 021abe4

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

crates/apollo_starknet_os_program/src/constants_test.rs

Lines changed: 18 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::SyscallSelector;
47
use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector};
@@ -220,8 +223,22 @@ fn generate_constants_file() -> String {
220223
cairo0_format(&unformatted)
221224
}
222225

226+
/// Test that the generated constants file matches the expected contents.
227+
/// To fix this test, run:
228+
/// ```bash
229+
/// FIX_OS_CONSTANTS=1 cargo test -p apollo_starknet_os_program test_os_constants
230+
/// ```
223231
#[test]
224232
fn test_os_constants() {
225233
verify_cairo0_compiler_deps();
226-
assert_eq!(CONSTANTS_CONTENTS, generate_constants_file());
234+
let generated = generate_constants_file();
235+
let fix = std::env::var("FIX_OS_CONSTANTS").is_ok();
236+
if fix {
237+
// Write the generated contents to the file.
238+
let path = PathBuf::from(compile_time_cargo_manifest_dir!())
239+
.join("src/cairo/starkware/starknet/core/os/constants.cairo");
240+
std::fs::write(path, &generated).expect("Failed to write generated constants file.");
241+
} else {
242+
assert_eq!(CONSTANTS_CONTENTS, generated);
243+
}
227244
}

0 commit comments

Comments
 (0)