Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

chore: make FeatureContract::cairo_version public #2002

Merged
merged 1 commit into from
Jun 25, 2024
Merged
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
100 changes: 50 additions & 50 deletions crates/blockifier/src/test_utils/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub enum FeatureContract {
}

impl FeatureContract {
fn cairo_version(&self) -> CairoVersion {
pub fn cairo_version(&self) -> CairoVersion {
match self {
Self::AccountWithLongValidate(version)
| Self::AccountWithoutValidations(version)
Expand All @@ -79,55 +79,6 @@ impl FeatureContract {
}
}

fn get_cairo_version_bit(&self) -> u32 {
match self.cairo_version() {
CairoVersion::Cairo0 => 0,
CairoVersion::Cairo1 => CAIRO1_BIT,
}
}

/// Unique integer representing each unique contract. Used to derive "class hash" and "address".
fn get_integer_base(self) -> u32 {
self.get_cairo_version_bit()
+ match self {
Self::AccountWithLongValidate(_) => ACCOUNT_LONG_VALIDATE_BASE,
Self::AccountWithoutValidations(_) => ACCOUNT_WITHOUT_VALIDATIONS_BASE,
Self::Empty(_) => EMPTY_CONTRACT_BASE,
Self::ERC20 => ERC20_CONTRACT_BASE,
Self::FaultyAccount(_) => FAULTY_ACCOUNT_BASE,
Self::LegacyTestContract => LEGACY_CONTRACT_BASE,
Self::SecurityTests => SECURITY_TEST_CONTRACT_BASE,
Self::TestContract(_) => TEST_CONTRACT_BASE,
}
}

fn get_compiled_path(&self) -> String {
let cairo_version = self.cairo_version();
let contract_name = match self {
Self::AccountWithLongValidate(_) => ACCOUNT_LONG_VALIDATE_NAME,
Self::AccountWithoutValidations(_) => ACCOUNT_WITHOUT_VALIDATIONS_NAME,
Self::Empty(_) => EMPTY_CONTRACT_NAME,
Self::FaultyAccount(_) => FAULTY_ACCOUNT_NAME,
Self::LegacyTestContract => LEGACY_CONTRACT_NAME,
Self::SecurityTests => SECURITY_TEST_CONTRACT_NAME,
Self::TestContract(_) => TEST_CONTRACT_NAME,
// ERC20 is a special case - not in the feature_contracts directory.
Self::ERC20 => return ERC20_CONTRACT_PATH.into(),
};
format!(
"./feature_contracts/cairo{}/compiled/{}{}.json",
match cairo_version {
CairoVersion::Cairo0 => "0",
CairoVersion::Cairo1 => "1",
},
contract_name,
match cairo_version {
CairoVersion::Cairo0 => "_compiled",
CairoVersion::Cairo1 => ".casm",
}
)
}

pub fn set_cairo_version(&mut self, version: CairoVersion) {
match self {
Self::AccountWithLongValidate(v)
Expand Down Expand Up @@ -176,4 +127,53 @@ impl FeatureContract {
pub fn get_raw_class(&self) -> String {
get_raw_contract_class(&self.get_compiled_path())
}

fn get_cairo_version_bit(&self) -> u32 {
match self.cairo_version() {
CairoVersion::Cairo0 => 0,
CairoVersion::Cairo1 => CAIRO1_BIT,
}
}

/// Unique integer representing each unique contract. Used to derive "class hash" and "address".
fn get_integer_base(self) -> u32 {
self.get_cairo_version_bit()
+ match self {
Self::AccountWithLongValidate(_) => ACCOUNT_LONG_VALIDATE_BASE,
Self::AccountWithoutValidations(_) => ACCOUNT_WITHOUT_VALIDATIONS_BASE,
Self::Empty(_) => EMPTY_CONTRACT_BASE,
Self::ERC20 => ERC20_CONTRACT_BASE,
Self::FaultyAccount(_) => FAULTY_ACCOUNT_BASE,
Self::LegacyTestContract => LEGACY_CONTRACT_BASE,
Self::SecurityTests => SECURITY_TEST_CONTRACT_BASE,
Self::TestContract(_) => TEST_CONTRACT_BASE,
}
}

fn get_compiled_path(&self) -> String {
let cairo_version = self.cairo_version();
let contract_name = match self {
Self::AccountWithLongValidate(_) => ACCOUNT_LONG_VALIDATE_NAME,
Self::AccountWithoutValidations(_) => ACCOUNT_WITHOUT_VALIDATIONS_NAME,
Self::Empty(_) => EMPTY_CONTRACT_NAME,
Self::FaultyAccount(_) => FAULTY_ACCOUNT_NAME,
Self::LegacyTestContract => LEGACY_CONTRACT_NAME,
Self::SecurityTests => SECURITY_TEST_CONTRACT_NAME,
Self::TestContract(_) => TEST_CONTRACT_NAME,
// ERC20 is a special case - not in the feature_contracts directory.
Self::ERC20 => return ERC20_CONTRACT_PATH.into(),
};
format!(
"./feature_contracts/cairo{}/compiled/{}{}.json",
match cairo_version {
CairoVersion::Cairo0 => "0",
CairoVersion::Cairo1 => "1",
},
contract_name,
match cairo_version {
CairoVersion::Cairo0 => "_compiled",
CairoVersion::Cairo1 => ".casm",
}
)
}
}
Loading