Skip to content

Commit

Permalink
chore(blockifier): refactor feature contract path getters for differe…
Browse files Browse the repository at this point in the history
…nt paths
  • Loading branch information
dorimedini-starkware committed Jul 29, 2024
1 parent c60f856 commit b304c0e
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions crates/blockifier/src/test_utils/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ const SECURITY_TEST_CONTRACT_NAME: &str = "security_tests_contract";
const TEST_CONTRACT_NAME: &str = "test_contract";

// ERC20 contract is in a unique location.
const ERC20_BASE_NAME: &str = "ERC20";
const ERC20_CAIRO0_CONTRACT_SOURCE_PATH: &str =
"./ERC20/ERC20_Cairo0/ERC20_without_some_syscalls/ERC20/ERC20.cairo";
const ERC20_CAIRO0_CONTRACT_PATH: &str = "./ERC20/ERC20_Cairo0/ERC20_without_some_syscalls/ERC20/\
erc20_contract_without_some_syscalls_compiled.json";
const ERC20_CAIRO1_CONTRACT_SOURCE_PATH: &str = "./ERC20/ERC20_Cairo1/ERC20.cairo";
const ERC20_CAIRO1_CONTRACT_PATH: &str = "./ERC20/ERC20_Cairo1/erc20.casm.json";

/// Enum representing all feature contracts.
Expand Down Expand Up @@ -186,24 +190,52 @@ impl FeatureContract {
}
}

pub fn get_compiled_path(&self) -> String {
let cairo_version = self.cairo_version();
let contract_name = match self {
fn contract_base_name(&self) -> &str {
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,
Self::ERC20(_) => ERC20_BASE_NAME,
}
}

pub fn get_source_path(&self) -> String {
match self {
// Special case: ERC20 contract in a different location.
Self::ERC20(cairo_version) => match cairo_version {
CairoVersion::Cairo0 => ERC20_CAIRO0_CONTRACT_SOURCE_PATH,
CairoVersion::Cairo1 => ERC20_CAIRO1_CONTRACT_SOURCE_PATH,
}
.into(),
_not_erc20 => format!(
"feature_contracts/cairo{}/{}.cairo",
match self.cairo_version() {
CairoVersion::Cairo0 => "0",
CairoVersion::Cairo1 => "1",
},
self.contract_base_name()
),
}
}

pub fn get_compiled_path(&self) -> String {
let cairo_version = self.cairo_version();
let contract_name = match self {
// ERC20 is a special case - not in the feature_contracts directory.
Self::ERC20(_) => {
Self::ERC20(cairo_version) => {
return match cairo_version {
CairoVersion::Cairo0 => ERC20_CAIRO0_CONTRACT_PATH.into(),
CairoVersion::Cairo1 => ERC20_CAIRO1_CONTRACT_PATH.into(),
};
CairoVersion::Cairo0 => ERC20_CAIRO0_CONTRACT_PATH,
CairoVersion::Cairo1 => ERC20_CAIRO1_CONTRACT_PATH,
}
.into();
}
_not_erc20 => self.contract_base_name(),
};

format!(
"feature_contracts/cairo{}/compiled/{}{}.json",
match cairo_version {
Expand Down

0 comments on commit b304c0e

Please sign in to comment.