diff --git a/Cargo.lock b/Cargo.lock index b990e505..19ee2d5d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5613,6 +5613,7 @@ dependencies = [ "serde", "serde_json", "starknet_api", + "test_utils", "thiserror", ] diff --git a/crates/starknet_sierra_compile/Cargo.toml b/crates/starknet_sierra_compile/Cargo.toml index 1925ae2c..e5d9e244 100644 --- a/crates/starknet_sierra_compile/Cargo.toml +++ b/crates/starknet_sierra_compile/Cargo.toml @@ -20,3 +20,4 @@ thiserror.workspace = true [dev-dependencies] assert_matches.workspace = true +test_utils = {path = "../test_utils"} diff --git a/crates/starknet_sierra_compile/src/compile_test.rs b/crates/starknet_sierra_compile/src/compile_test.rs index 37d1f373..1dec4714 100644 --- a/crates/starknet_sierra_compile/src/compile_test.rs +++ b/crates/starknet_sierra_compile/src/compile_test.rs @@ -1,17 +1,17 @@ +use std::env; use std::path::Path; use assert_matches::assert_matches; use cairo_lang_starknet_classes::allowed_libfuncs::AllowedLibfuncsError; +use test_utils::{get_absolute_path, FAULTY_ACCOUNT_CLASS_FILE, TEST_FILES_FOLDER}; use crate::compile::{compile_sierra_to_casm, CompilationUtilError}; use crate::test_utils::contract_class_from_file; -const FAULTY_ACCOUNT_SIERRA_FILE: &str = "account_faulty.sierra.json"; -const TEST_FILES_FOLDER: &str = "./tests/fixtures"; - #[test] fn test_compile_sierra_to_casm() { - let sierra_path = &Path::new(TEST_FILES_FOLDER).join(FAULTY_ACCOUNT_SIERRA_FILE); + env::set_current_dir(get_absolute_path(TEST_FILES_FOLDER)).expect("Failed to set current dir."); + let sierra_path = Path::new(FAULTY_ACCOUNT_CLASS_FILE); let expected_casm_contract_length = 72304; let contract_class = contract_class_from_file(sierra_path); @@ -24,7 +24,8 @@ fn test_compile_sierra_to_casm() { // TODO(Arni, 1/5/2024): Add a test for panic result test. #[test] fn test_negative_flow_compile_sierra_to_casm() { - let sierra_path = &Path::new(TEST_FILES_FOLDER).join(FAULTY_ACCOUNT_SIERRA_FILE); + env::set_current_dir(get_absolute_path(TEST_FILES_FOLDER)).expect("Failed to set current dir."); + let sierra_path = Path::new(FAULTY_ACCOUNT_CLASS_FILE); let mut contract_class = contract_class_from_file(sierra_path); // Truncate the sierra program to trigger an error. diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index 571ec7f3..89d13f90 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs @@ -5,6 +5,7 @@ pub const TEST_FILES_FOLDER: &str = "crates/test_utils/test_files"; pub const CONTRACT_CLASS_FILE: &str = "contract_class.json"; pub const COMPILED_CLASS_HASH_OF_CONTRACT_CLASS: &str = "0x01e4f1248860f32c336f93f2595099aaa4959be515e40b75472709ef5243ae17"; +pub const FAULTY_ACCOUNT_CLASS_FILE: &str = "faulty_account.sierra.json"; /// Returns the absolute path from the project root. pub fn get_absolute_path(relative_path: &str) -> PathBuf { diff --git a/crates/starknet_sierra_compile/tests/fixtures/account_faulty.sierra.json b/crates/test_utils/test_files/faulty_account.sierra.json similarity index 100% rename from crates/starknet_sierra_compile/tests/fixtures/account_faulty.sierra.json rename to crates/test_utils/test_files/faulty_account.sierra.json