Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 2 additions & 4 deletions crates/apollo_class_manager/src/class_manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ fn mock_compile_expectations(
compiler: &mut MockSierraCompilerClient,
class: RawClass,
) -> (RawExecutableClass, CompiledClassHash) {
let compile_output = (
RawExecutableClass::try_from(ContractClass::test_casm_contract_class()).unwrap(),
CompiledClassHash(felt!("0x5678")),
);
let compile_output =
(RawExecutableClass::test_casm_contract_class(), CompiledClassHash(felt!("0x5678")));
let cloned_compiled_output = compile_output.clone();

compiler
Expand Down
18 changes: 6 additions & 12 deletions crates/apollo_class_manager/src/class_storage_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ fn fs_storage() {

// Add new class.
let class = RawClass::try_from(SierraContractClass::default()).unwrap();
let executable_class =
RawExecutableClass::try_from(ContractClass::test_casm_contract_class()).unwrap();
let executable_class = RawExecutableClass::test_casm_contract_class();
let executable_class_hash_v2 = CompiledClassHash(felt!("0x5678"));
storage
.set_class(class_id, class.clone(), executable_class_hash_v2, executable_class.clone())
Expand Down Expand Up @@ -96,8 +95,7 @@ fn fs_storage_deprecated_class_api() {
assert_eq!(storage.get_deprecated_class(class_id), Ok(None));

// Add new class.
let executable_class =
RawExecutableClass::try_from(ContractClass::test_casm_contract_class()).unwrap();
let executable_class = RawExecutableClass::test_casm_contract_class();
storage.set_deprecated_class(class_id, executable_class.clone()).unwrap();

// Get class.
Expand All @@ -123,8 +121,7 @@ fn temp_dir_location_and_atomic_write_layout() {

// Create tmp dir via the atomic writer and ensure it resides under parent_dir.
let class = RawClass::try_from(SierraContractClass::default()).unwrap();
let executable_class =
RawExecutableClass::try_from(ContractClass::test_casm_contract_class()).unwrap();
let executable_class = RawExecutableClass::test_casm_contract_class();
storage.write_class_atomically(class_id, class.clone(), executable_class.clone()).unwrap();

// After atomic write and rename, the persistent dir should exist and contain the files.
Expand All @@ -147,8 +144,7 @@ fn fs_storage_nonexistent_persistent_root_is_created() {
// Write a new class, which should create the persistent root directories as needed.
let class_id = ClassHash(felt!("0x1234"));
let class = RawClass::try_from(SierraContractClass::default()).unwrap();
let executable_class =
RawExecutableClass::try_from(ContractClass::test_casm_contract_class()).unwrap();
let executable_class = RawExecutableClass::test_casm_contract_class();
let executable_class_hash_v2 = CompiledClassHash(felt!("0x5678"));
storage
.set_class(class_id, class.clone(), executable_class_hash_v2, executable_class.clone())
Expand Down Expand Up @@ -192,8 +188,7 @@ fn fs_storage_partial_write_no_atomic_marker() {
// Fully write class files, without atomic marker.
let class_id = ClassHash(felt!("0x1234"));
let class = RawClass::try_from(SierraContractClass::default()).unwrap();
let executable_class =
RawExecutableClass::try_from(ContractClass::test_casm_contract_class()).unwrap();
let executable_class = RawExecutableClass::test_casm_contract_class();
storage.write_class_atomically(class_id, class, executable_class).unwrap();
assert_eq!(storage.get_executable_class_hash_v2(class_id), Ok(None));

Expand Down Expand Up @@ -248,8 +243,7 @@ fn cached_storage_cairo1_get_executable_and_hash() {

let class_id = ClassHash(felt!("0x1111"));
let class = RawClass::try_from(SierraContractClass::default()).unwrap();
let executable_class =
RawExecutableClass::try_from(ContractClass::test_casm_contract_class()).unwrap();
let executable_class = RawExecutableClass::test_casm_contract_class();
let executable_class_hash_v2 = CompiledClassHash(felt!("0x2222"));

fs_storage
Expand Down
3 changes: 2 additions & 1 deletion crates/apollo_compile_to_casm_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ use strum_macros::{AsRefStr, EnumDiscriminants, EnumIter, IntoStaticStr};
use thiserror::Error;

#[cfg(test)]
#[path = "test.rs"]
pub mod test;
#[cfg(any(feature = "testing", test))]
pub mod test_utils;

pub type SierraCompilerResult<T> = Result<T, SierraCompilerError>;
pub type SierraCompilerClientResult<T> = Result<T, SierraCompilerClientError>;
Expand Down
3 changes: 1 addition & 2 deletions crates/apollo_compile_to_casm_types/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ fn compact_serialization() {
const EXPECTED: &str = "{\"V1\":[{\"bytecode\":[\"0x1\",\"0x1\",\"0x1\"],\"compiler_version\":\
\"\",\"entry_points_by_type\":{\"CONSTRUCTOR\":[],\"EXTERNAL\":[],\"\
L1_HANDLER\":[]},\"hints\":[],\"prime\":\"0x0\"},\"1.7.0\"]}";
let raw_executable_class =
RawExecutableClass::try_from(ContractClass::test_casm_contract_class()).unwrap();
let raw_executable_class = RawExecutableClass::test_casm_contract_class();
let serialized = serde_json::to_string(&raw_executable_class.0).unwrap();

assert_eq!(serialized, EXPECTED);
Expand Down
21 changes: 21 additions & 0 deletions crates/apollo_compile_to_casm_types/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::sync::LazyLock;

use starknet_api::contract_class::ContractClass;

use crate::RawExecutableClass;

static TEST_CASM_CONTRACT_CLASS: LazyLock<RawExecutableClass> =
LazyLock::new(|| ContractClass::test_casm_contract_class().try_into().unwrap());

static TEST_DEPRECATED_CASM_CONTRACT_CLASS: LazyLock<RawExecutableClass> =
LazyLock::new(|| ContractClass::test_deprecated_casm_contract_class().try_into().unwrap());

impl RawExecutableClass {
pub fn test_casm_contract_class() -> Self {
TEST_CASM_CONTRACT_CLASS.clone()
}

pub fn test_deprecated_casm_contract_class() -> Self {
TEST_DEPRECATED_CASM_CONTRACT_CLASS.clone()
}
}