Skip to content

Commit 62577cc

Browse files
feat(apollo_starknet_os_program): add fixer for OS constants test
1 parent 84d3238 commit 62577cc

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};
@@ -190,8 +193,22 @@ fn generate_constants_file() -> String {
190193
cairo0_format(&unformatted)
191194
}
192195

196+
/// Test that the generated constants file matches the expected contents.
197+
/// To fix this test, run:
198+
/// ```bash
199+
/// FIX_OS_CONSTANTS=1 cargo test -p apollo_starknet_os_program test_os_constants
200+
/// ```
193201
#[test]
194202
fn test_os_constants() {
195203
verify_cairo0_compiler_deps();
196-
assert_eq!(CONSTANTS_CONTENTS, generate_constants_file());
204+
let generated = generate_constants_file();
205+
let fix = std::env::var("FIX_OS_CONSTANTS").is_ok();
206+
if fix {
207+
// Write the generated contents to the file.
208+
let path = PathBuf::from(compile_time_cargo_manifest_dir!())
209+
.join("src/cairo/starkware/starknet/core/os/constants.cairo");
210+
std::fs::write(path, &generated).expect("Failed to write generated constants file.");
211+
} else {
212+
assert_eq!(CONSTANTS_CONTENTS, generated);
213+
}
197214
}

0 commit comments

Comments
 (0)