Skip to content
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
20 changes: 20 additions & 0 deletions crates/blockifier/src/execution/contract_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,26 @@ impl From<CasmContractEntryPoints> for EntryPointsByType<EntryPointV1> {
}
}

impl From<&EntryPointV1> for CasmContractEntryPoint {
fn from(ep: &EntryPointV1) -> Self {
CasmContractEntryPoint {
selector: ep.selector.0.to_biguint(),
offset: ep.offset.0,
builtins: ep.builtins.iter().map(|b| b.to_str().to_string()).collect(),
}
}
}

impl From<&EntryPointsByType<EntryPointV1>> for CasmContractEntryPoints {
fn from(entry_points: &EntryPointsByType<EntryPointV1>) -> Self {
CasmContractEntryPoints {
external: entry_points.external.iter().map(Into::into).collect(),
l1_handler: entry_points.l1_handler.iter().map(Into::into).collect(),
constructor: entry_points.constructor.iter().map(Into::into).collect(),
}
}
}

impl<EP: Clone + HasSelector> EntryPointsByType<EP> {
pub fn get_entry_point(
&self,
Expand Down
52 changes: 52 additions & 0 deletions crates/blockifier/src/execution/contract_class_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ use std::sync::Arc;
use assert_matches::assert_matches;
use blockifier_test_utils::cairo_versions::{CairoVersion, RunnableCairo1};
use blockifier_test_utils::contracts::FeatureContract;
use cairo_lang_starknet_classes::casm_contract_class::{
CasmContractEntryPoint,
CasmContractEntryPoints,
};
use cairo_lang_starknet_classes::NestedIntList;
use cairo_lang_utils::bigint::BigUintAsHex;
use num_bigint::BigUint;
use rstest::rstest;
use starknet_api::contract_class::compiled_class_hash::{HashVersion, HashableCompiledClass};
use starknet_api::contract_class::ContractClass;
Expand All @@ -16,6 +21,8 @@ use starknet_types_core::hash::Blake2Felt252;
use crate::execution::contract_class::{
CompiledClassV1,
ContractClassV1Inner,
EntryPointV1,
EntryPointsByType,
FeltSizeCount,
NestedFeltCounts,
RunnableCompiledClass,
Expand Down Expand Up @@ -184,3 +191,48 @@ fn test_encoded_u32_len(#[case] test_data: &[Felt]) {

assert_eq!(actual_u32_len, estimated_u32_len);
}

#[rstest]
#[case::empty(CasmContractEntryPoints::default())]
#[case::single_external(CasmContractEntryPoints {
external: vec![CasmContractEntryPoint {
selector: BigUint::from(123u64),
offset: 42,
builtins: vec!["range_check".to_string(), "pedersen".to_string()],
}],
l1_handler: vec![],
constructor: vec![],
})]
#[case::all_types(CasmContractEntryPoints {
external: vec![
CasmContractEntryPoint {
selector: BigUint::from(100u64),
offset: 10,
builtins: vec!["range_check".to_string()],
},
CasmContractEntryPoint {
selector: BigUint::from(200u64),
offset: 20,
builtins: vec![],
},
],
l1_handler: vec![CasmContractEntryPoint {
selector: BigUint::from(300u64),
offset: 30,
builtins: vec!["pedersen".to_string()],
}],
constructor: vec![CasmContractEntryPoint {
selector: BigUint::from(400u64),
offset: 40,
builtins: vec!["range_check".to_string(), "bitwise".to_string()],
}],
})]
fn test_entry_points_round_trip(#[case] original: CasmContractEntryPoints) {
// Convert CasmContractEntryPoints -> EntryPointsByType<EntryPointV1>.
let entry_points_by_type: EntryPointsByType<EntryPointV1> = (&original).into();

// Convert back: EntryPointsByType<EntryPointV1> -> CasmContractEntryPoints.
let round_tripped: CasmContractEntryPoints = (&entry_points_by_type).into();

assert_eq!(round_tripped, original);
}
Loading