Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion crates/apollo_starknet_os_program/src/constants_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::path::PathBuf;

use apollo_infra_utils::cairo0_compiler::{cairo0_format, verify_cairo0_compiler_deps};
use apollo_infra_utils::compile_time_cargo_manifest_dir;
use blockifier::blockifier_versioned_constants::{OsConstants, VersionedConstants};
use blockifier::execution::syscalls::vm_syscall_utils::SyscallSelector;
use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector};
Expand Down Expand Up @@ -205,8 +208,28 @@ fn generate_constants_file() -> String {
cairo0_format(&unformatted)
}

/// Test that `constants.cairo` generated from the values in the versioned constants matches the
/// existing file. To fix this test, run:
/// ```bash
/// FIX_OS_CONSTANTS=1 cargo test -p apollo_starknet_os_program test_os_constants
/// ```
#[test]
fn test_os_constants() {
verify_cairo0_compiler_deps();
assert_eq!(CONSTANTS_CONTENTS, generate_constants_file());
// Generate `constants.cairo` from the current OS constants.
let generated = generate_constants_file();
let fix = std::env::var("FIX_OS_CONSTANTS").is_ok();
if fix {
// Write the generated contents to the file.
let path = PathBuf::from(compile_time_cargo_manifest_dir!())
.join("src/cairo/starkware/starknet/core/os/constants.cairo");
std::fs::write(path, &generated).expect("Failed to write generated constants file.");
} else {
assert_eq!(
CONSTANTS_CONTENTS, generated,
"Generated constants file does not match the expected contents. Please run \
`FIX_OS_CONSTANTS=1 cargo test -p apollo_starknet_os_program test_os_constants` to \
fix the test."
);
}
}
Loading