Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(blockifier): clean runnable contract class code #1745

Merged
merged 1 commit into from
Nov 6, 2024
Merged
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
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() })
}
Loading