Skip to content

Commit 6f89c52

Browse files
blockifier: feature contracts real compiled class hash (#8500)
1 parent be03442 commit 6f89c52

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

crates/blockifier/src/test_utils/contracts.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
55
use starknet_api::abi::abi_utils::selector_from_name;
66
use starknet_api::abi::constants::CONSTRUCTOR_ENTRY_POINT_NAME;
77
use starknet_api::contract_class::{ContractClass, EntryPointType};
8-
use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector};
8+
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, EntryPointSelector};
99
use starknet_api::deprecated_contract_class::{
1010
ContractClass as DeprecatedContractClass,
1111
EntryPointOffset,
@@ -20,6 +20,7 @@ use crate::test_utils::struct_impls::LoadContractFromFile;
2020

2121
pub trait FeatureContractTrait {
2222
fn get_class(&self) -> ContractClass;
23+
fn get_real_compiled_class_hash(&self) -> CompiledClassHash;
2324
fn get_runnable_class(&self) -> RunnableCompiledClass;
2425

2526
/// Fetch PC locations from the compiled contract to compute the expected PC locations in the
@@ -91,6 +92,18 @@ fn get_class_for_feature_contract(feature_contract: FeatureContract) -> Contract
9192
}
9293
}
9394

95+
#[cached]
96+
fn get_real_compiled_class_hash_for_feature_contract(
97+
feature_contract: FeatureContract,
98+
) -> CompiledClassHash {
99+
match get_class_for_feature_contract(feature_contract) {
100+
ContractClass::V0(_) => {
101+
panic!("V0 compiled class hash is not supported.")
102+
}
103+
ContractClass::V1((class, _)) => CompiledClassHash(class.compiled_class_hash()),
104+
}
105+
}
106+
94107
impl FeatureContractTrait for FeatureContract {
95108
fn get_class(&self) -> ContractClass {
96109
get_class_for_feature_contract(*self)
@@ -106,6 +119,10 @@ impl FeatureContractTrait for FeatureContract {
106119

107120
self.get_class().try_into().unwrap()
108121
}
122+
123+
fn get_real_compiled_class_hash(&self) -> CompiledClassHash {
124+
get_real_compiled_class_hash_for_feature_contract(*self)
125+
}
109126
}
110127

111128
/// The information needed to test a [FeatureContract].

crates/starknet_os_flow_tests/src/tests.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ use blockifier_test_utils::cairo_versions::{CairoVersion, RunnableCairo1};
66
use blockifier_test_utils::calldata::create_calldata;
77
use blockifier_test_utils::contracts::FeatureContract;
88
use rstest::rstest;
9-
use starknet_api::contract_class::ContractClass;
10-
use starknet_api::core::CompiledClassHash;
119
use starknet_api::executable_transaction::{DeclareTransaction, InvokeTransaction};
1210
use starknet_api::execution_resources::GasAmount;
1311
use starknet_api::test_utils::declare::declare_tx;
@@ -79,14 +77,8 @@ async fn declare_deploy_scenario(#[values(1, 2)] n_blocks: usize) {
7977
// Declare a test contract.
8078
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm));
8179
let test_contract_sierra = test_contract.get_sierra();
82-
let contract_class = test_contract.get_class();
83-
// TODO(Nimrod): Get the class hash bay adding a method `get_real_class_hash` to feature
84-
// contracts.
8580
let class_hash = test_contract_sierra.calculate_class_hash();
86-
let ContractClass::V1((test_contract_casm, _)) = contract_class else {
87-
panic!("Expected a V1 contract class.");
88-
};
89-
let compiled_class_hash = CompiledClassHash(test_contract_casm.compiled_class_hash());
81+
let compiled_class_hash = test_contract.get_real_compiled_class_hash();
9082
let declare_tx_args = declare_tx_args! {
9183
sender_address: *FUNDED_ACCOUNT_ADDRESS,
9284
class_hash,

crates/starknet_os_flow_tests/src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ pub(crate) fn create_cairo1_bootstrap_declare_tx(
148148
panic!("Expected a Cairo 1 contract class.");
149149
};
150150
let class_hash = sierra.calculate_class_hash();
151-
let compiled_class_hash = starknet_api::core::CompiledClassHash(casm.compiled_class_hash());
152-
execution_contracts.add_cairo1_contract(casm.clone(), &sierra);
151+
let compiled_class_hash = feature_contract.get_real_compiled_class_hash();
152+
execution_contracts.add_cairo1_contract(casm, &sierra);
153153
let declare_tx_args = declare_tx_args! {
154154
sender_address: DeclareTransaction::bootstrap_address(),
155155
class_hash,

0 commit comments

Comments
 (0)