Skip to content

Commit

Permalink
refactor(starknet_api): use const in sierra version (#2477)
Browse files Browse the repository at this point in the history
  • Loading branch information
AvivYossef-starkware authored Dec 5, 2024
1 parent 7698524 commit 3cc89a5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
4 changes: 2 additions & 2 deletions crates/blockifier/src/transaction/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ pub fn create_all_resource_bounds(

pub fn calculate_class_info_for_testing(contract_class: ContractClass) -> ClassInfo {
let (sierra_program_length, sierra_version) = match contract_class {
ContractClass::V0(_) => (0, SierraVersion::zero()),
ContractClass::V1(_) => (100, SierraVersion::latest()),
ContractClass::V0(_) => (0, SierraVersion::DEPRECATED),
ContractClass::V1(_) => (100, SierraVersion::LATEST),
};
ClassInfo::new(&contract_class, sierra_program_length, 100, sierra_version).unwrap()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub trait ReexecutionStateReader {
&legacy_to_contract_class_v0(legacy)?,
DEPRECATED_CONTRACT_SIERRA_SIZE,
abi_length,
SierraVersion::zero(),
SierraVersion::DEPRECATED,
)?)
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/papyrus_execution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ fn to_blockifier_tx(
&deprecated_class.into(),
DEPRECATED_CONTRACT_SIERRA_SIZE,
abi_length,
SierraVersion::zero(),
SierraVersion::DEPRECATED,
)
.map_err(|err| ExecutionError::BadDeclareTransaction {
tx: DeclareTransaction::V0(declare_tx.clone()),
Expand All @@ -862,7 +862,7 @@ fn to_blockifier_tx(
&deprecated_class.into(),
DEPRECATED_CONTRACT_SIERRA_SIZE,
abi_length,
SierraVersion::zero(),
SierraVersion::DEPRECATED,
)
.map_err(|err| ExecutionError::BadDeclareTransaction {
tx: DeclareTransaction::V1(declare_tx.clone()),
Expand Down
2 changes: 1 addition & 1 deletion crates/papyrus_execution/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl TxsScenarioBuilder {
DUMMY_SIERRA_SIZE,
0,
false,
SierraVersion::latest(),
SierraVersion::LATEST,
);
self.txs.push(tx);
self
Expand Down
18 changes: 7 additions & 11 deletions crates/starknet_api/src/contract_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,15 @@ impl ContractClass {
pub struct SierraVersion(Version);

impl SierraVersion {
pub fn new(major: u64, minor: u64, patch: u64) -> Self {
Self(Version::new(major, minor, patch))
}

/// Version of deprecated contract class.
pub fn zero() -> Self {
Self(Version::new(0, 0, 0))
}
/// Version of deprecated contract class (Cairo 0).
pub const DEPRECATED: Self = Self(Version::new(0, 0, 0));

// TODO(Aviv): Implement logic to fetch the latest version dynamically from Cargo.toml and write
// tests to ensure that it matches the value returned by this function.
pub fn latest() -> Self {
Self::new(2, 8, 4)
pub const LATEST: Self = Self(Version::new(2, 8, 4));

pub fn new(major: u64, minor: u64, patch: u64) -> Self {
Self(Version::new(major, minor, patch))
}

/// Converts a sierra program to a SierraVersion.
Expand Down Expand Up @@ -105,7 +101,7 @@ impl SierraVersion {

impl Default for SierraVersion {
fn default() -> Self {
Self::latest()
Self::LATEST
}
}

Expand Down

0 comments on commit 3cc89a5

Please sign in to comment.