|
| 1 | +use std::path::PathBuf; |
| 2 | + |
1 | 3 | use apollo_infra_utils::cairo0_compiler::{cairo0_format, verify_cairo0_compiler_deps}; |
| 4 | +use apollo_infra_utils::compile_time_cargo_manifest_dir; |
2 | 5 | use blockifier::blockifier_versioned_constants::{OsConstants, VersionedConstants}; |
3 | 6 | use blockifier::execution::syscalls::vm_syscall_utils::SyscallSelector; |
4 | 7 | use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector}; |
@@ -205,8 +208,27 @@ fn generate_constants_file() -> String { |
205 | 208 | cairo0_format(&unformatted) |
206 | 209 | } |
207 | 210 |
|
| 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 | +/// ``` |
208 | 216 | #[test] |
209 | 217 | fn test_os_constants() { |
210 | 218 | 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 | + } |
212 | 234 | } |
0 commit comments