Skip to content

Commit

Permalink
refactor(blockifier): clean runnable contract class code
Browse files Browse the repository at this point in the history
  • Loading branch information
noaov1 committed Nov 6, 2024
1 parent a9f3df7 commit 425e5bb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 31 deletions.
12 changes: 0 additions & 12 deletions crates/blockifier/src/execution/contract_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,18 +285,6 @@ impl ContractClassV1 {

Ok(contract_class)
}

/// Returns an empty contract class for testing purposes.
#[cfg(any(feature = "testing", test))]
pub fn empty_for_testing() -> Self {
Self(Arc::new(ContractClassV1Inner {
program: Default::default(),
entry_points_by_type: Default::default(),
hints: Default::default(),
compiler_version: Default::default(),
bytecode_segment_lengths: NestedIntList::Leaf(0),
}))
}
}

/// Returns the estimated VM resources required for computing Casm hash (for Cairo 1 contracts).
Expand Down
15 changes: 0 additions & 15 deletions crates/blockifier/src/test_utils/struct_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::bouncer::{BouncerConfig, BouncerWeights, BuiltinCount};
use crate::context::{BlockContext, ChainInfo, FeeTokenAddresses, TransactionContext};
use crate::execution::call_info::{CallExecution, CallInfo, Retdata};
use crate::execution::common_hints::ExecutionMode;
use crate::execution::contract_class::{ContractClassV0, ContractClassV1};
use crate::execution::entry_point::{
CallEntryPoint,
EntryPointExecutionContext,
Expand Down Expand Up @@ -223,20 +222,6 @@ pub trait LoadContractFromFile: serde::de::DeserializeOwned {
impl LoadContractFromFile for CasmContractClass {}
impl LoadContractFromFile for DeprecatedContractClass {}

impl ContractClassV0 {
pub fn from_file(contract_path: &str) -> Self {
let raw_contract_class = get_raw_contract_class(contract_path);
Self::try_from_json_string(&raw_contract_class).unwrap()
}
}

impl ContractClassV1 {
pub fn from_file(contract_path: &str) -> Self {
let raw_contract_class = get_raw_contract_class(contract_path);
Self::try_from_json_string(&raw_contract_class).unwrap()
}
}

impl BouncerWeights {
pub fn create_for_testing(builtin_count: BuiltinCount) -> Self {
Self { builtin_count, ..Self::empty() }
Expand Down
10 changes: 6 additions & 4 deletions crates/native_blockifier/src/py_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use std::collections::HashMap;
use blockifier::execution::contract_class::ContractClassV0;
use blockifier::state::cached_state::CachedState;
use blockifier::test_utils::dict_state_reader::DictStateReader;
use blockifier::test_utils::struct_impls::LoadContractFromFile;
use starknet_api::class_hash;
use starknet_api::deprecated_contract_class::ContractClass;

pub const TOKEN_FOR_TESTING_CLASS_HASH: &str = "0x30";
// This package is run within the StarkWare repository build directory.
Expand All @@ -12,9 +14,9 @@ pub const TOKEN_FOR_TESTING_CONTRACT_PATH: &str =
starknet/core/test_contract/token_for_testing.json";

pub fn create_py_test_state() -> CachedState<DictStateReader> {
let class_hash_to_class = HashMap::from([(
class_hash!(TOKEN_FOR_TESTING_CLASS_HASH),
ContractClassV0::from_file(TOKEN_FOR_TESTING_CONTRACT_PATH).into(),
)]);
let contract_class: ContractClassV0 =
ContractClass::from_file(TOKEN_FOR_TESTING_CONTRACT_PATH).try_into().unwrap();
let class_hash_to_class =
HashMap::from([(class_hash!(TOKEN_FOR_TESTING_CLASS_HASH), contract_class.into())]);
CachedState::from(DictStateReader { class_hash_to_class, ..Default::default() })
}

0 comments on commit 425e5bb

Please sign in to comment.