Skip to content

Commit 4ffc4b2

Browse files
chore(blockifier_test_utils): delete tag-and-toolchain related code
1 parent 00aa036 commit 4ffc4b2

3 files changed

Lines changed: 20 additions & 79 deletions

File tree

crates/blockifier_test_utils/src/cairo_compile.rs

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1+
use std::fs;
12
use std::io::Write;
2-
use std::path::{Path, PathBuf};
3+
use std::path::PathBuf;
34
use std::process::{Command, Output, Stdio};
45
use std::sync::LazyLock;
5-
use std::{env, fs};
66

77
use apollo_infra_utils::cairo_compiler_version::cairo1_compiler_version;
8-
use apollo_infra_utils::compile_time_cargo_manifest_dir;
98
use apollo_infra_utils::path::{project_path, resolve_project_relative_path};
109
use tempfile::NamedTempFile;
1110
use tracing::info;
1211

1312
static CAIRO0_PIP_REQUIREMENTS_FILE: LazyLock<PathBuf> =
1413
LazyLock::new(|| resolve_project_relative_path("scripts/requirements.txt").unwrap());
15-
const CAIRO1_REPO_RELATIVE_PATH_OVERRIDE_ENV_VAR: &str = "CAIRO1_REPO_RELATIVE_PATH";
16-
const DEFAULT_CAIRO1_REPO_RELATIVE_PATH: &str = "../../../cairo";
1714

1815
pub enum CompilationArtifacts {
1916
Cairo0 { casm: Vec<u8> },
@@ -24,19 +21,6 @@ pub fn cairo1_compiler_tag() -> String {
2421
format!("v{}", cairo1_compiler_version())
2522
}
2623

27-
/// Returns the path to the local Cairo1 compiler repository.
28-
/// Returns <sequencer_repo_root>/<RELATIVE_PATH_TO_CAIRO_REPO>, where the relative path can be
29-
/// overridden by the environment variable (otherwise, the default is used).
30-
fn local_cairo1_compiler_repo_path() -> PathBuf {
31-
// Location of blockifier's Cargo.toml.
32-
let manifest_dir = compile_time_cargo_manifest_dir!();
33-
34-
Path::new(&manifest_dir).join(
35-
env::var(CAIRO1_REPO_RELATIVE_PATH_OVERRIDE_ENV_VAR)
36-
.unwrap_or_else(|_| DEFAULT_CAIRO1_REPO_RELATIVE_PATH.into()),
37-
)
38-
}
39-
4024
/// Path to local compiler package directory, of the specified version.
4125
fn cairo1_package_dir(version: &String) -> PathBuf {
4226
project_path().unwrap().join(format!("target/bin/cairo_package__{version}"))
@@ -127,13 +111,7 @@ pub fn cairo0_compile(
127111
}
128112

129113
/// Compiles a Cairo1 program using the compiler version set in the Cargo.toml.
130-
pub fn cairo1_compile(
131-
path: String,
132-
git_tag_override: Option<String>,
133-
_cargo_nightly_arg: Option<String>,
134-
) -> CompilationArtifacts {
135-
let (tag, _cairo_repo_path) = get_tag_and_repo_file_path(git_tag_override);
136-
let version = tag.strip_prefix("v").unwrap().to_string();
114+
pub fn cairo1_compile(path: String, version: String) -> CompilationArtifacts {
137115
assert!(cairo1_package_exists(&version));
138116

139117
let sierra_output = starknet_compile(path, &version);
@@ -202,17 +180,3 @@ fn verify_cairo0_compiler_deps() {
202180
*CAIRO0_PIP_REQUIREMENTS_FILE
203181
);
204182
}
205-
206-
fn get_tag_and_repo_file_path(git_tag_override: Option<String>) -> (String, PathBuf) {
207-
let tag = git_tag_override.unwrap_or(cairo1_compiler_tag());
208-
let cairo_repo_path = local_cairo1_compiler_repo_path();
209-
// Check if the path is a directory.
210-
assert!(
211-
cairo_repo_path.is_dir(),
212-
"Cannot verify Cairo1 contracts, Cairo repo not found at {0}.\nPlease run:\n\
213-
git clone https://github.com/starkware-libs/cairo {0}\nThen rerun the test.",
214-
cairo_repo_path.to_string_lossy(),
215-
);
216-
217-
(tag, cairo_repo_path)
218-
}

crates/blockifier_test_utils/src/contracts.rs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::collections::HashMap;
22
use std::fs;
33
use std::path::PathBuf;
44

5+
use apollo_infra_utils::cairo_compiler_version::cairo1_compiler_version;
56
use apollo_infra_utils::compile_time_cargo_manifest_dir;
67
use cairo_lang_starknet_classes::contract_class::ContractClass as CairoLangContractClass;
78
use itertools::Itertools;
@@ -77,16 +78,12 @@ const ERC20_CAIRO1_CONTRACT_SOURCE_PATH: &str = "./resources/ERC20/ERC20_Cairo1/
7778
const ERC20_SIERRA_CONTRACT_PATH: &str = "./resources/ERC20/ERC20_Cairo1/erc20.sierra.json";
7879
const ERC20_CAIRO1_CONTRACT_PATH: &str = "./resources/ERC20/ERC20_Cairo1/erc20.casm.json";
7980

80-
// The following contracts are compiled with a fixed version of the compiler. This compiler version
81-
// no longer compiles with stable rust, so the toolchain is also fixed.
82-
const LEGACY_CONTRACT_COMPILER_TAG: &str = "v2.1.0";
83-
const LEGACY_CONTRACT_RUST_TOOLCHAIN: &str = "2023-07-05";
81+
// The following contracts are compiled with a fixed version of the compiler.
82+
const LEGACY_CONTRACT_COMPILER_VERSION: &str = "2.1.0";
83+
const CAIRO_STEPS_TEST_CONTRACT_COMPILER_VERSION: &str = "2.7.0";
8484

85-
const CAIRO_STEPS_TEST_CONTRACT_COMPILER_TAG: &str = "v2.7.0";
86-
const CAIRO_STEPS_TEST_CONTRACT_RUST_TOOLCHAIN: &str = "2024-04-29";
87-
88-
pub type TagAndToolchain = (Option<String>, Option<String>);
89-
pub type TagToContractsMapping = HashMap<TagAndToolchain, Vec<FeatureContract>>;
85+
pub type CairoVersionString = String;
86+
pub type VersionToContractsMapping = HashMap<CairoVersionString, Vec<FeatureContract>>;
9087

9188
/// Enum representing all feature contracts.
9289
/// The contracts that are implemented in both Cairo versions include a version field.
@@ -198,19 +195,12 @@ impl FeatureContract {
198195
}
199196

200197
/// Some contracts are designed to test behavior of code compiled with a
201-
/// specific (old) compiler tag. To run the (old) compiler, older rust
202-
/// version is required.
203-
pub fn fixed_tag_and_rust_toolchain(&self) -> TagAndToolchain {
198+
/// specific (old) compiler version.
199+
pub fn fixed_version(&self) -> CairoVersionString {
204200
match self {
205-
Self::LegacyTestContract => (
206-
Some(LEGACY_CONTRACT_COMPILER_TAG.into()),
207-
Some(LEGACY_CONTRACT_RUST_TOOLCHAIN.into()),
208-
),
209-
Self::CairoStepsTestContract => (
210-
Some(CAIRO_STEPS_TEST_CONTRACT_COMPILER_TAG.into()),
211-
Some(CAIRO_STEPS_TEST_CONTRACT_RUST_TOOLCHAIN.into()),
212-
),
213-
_ => (None, None),
201+
Self::LegacyTestContract => LEGACY_CONTRACT_COMPILER_VERSION.into(),
202+
Self::CairoStepsTestContract => CAIRO_STEPS_TEST_CONTRACT_COMPILER_VERSION.into(),
203+
_ => cairo1_compiler_version(),
214204
}
215205
}
216206

@@ -343,10 +333,7 @@ impl FeatureContract {
343333
};
344334
cairo0_compile(self.get_source_path(), extra_arg, false)
345335
}
346-
CairoVersion::Cairo1(_) => {
347-
let (tag_override, cargo_nightly_arg) = self.fixed_tag_and_rust_toolchain();
348-
cairo1_compile(self.get_source_path(), tag_override, cargo_nightly_arg)
349-
}
336+
CairoVersion::Cairo1(_) => cairo1_compile(self.get_source_path(), self.fixed_version()),
350337
}
351338
}
352339

@@ -410,10 +397,10 @@ impl FeatureContract {
410397
Self::all_contracts().filter(|contract| !matches!(contract, Self::ERC20(_)))
411398
}
412399

413-
pub fn cairo1_feature_contracts_by_tag() -> TagToContractsMapping {
400+
pub fn cairo1_feature_contracts_by_version() -> VersionToContractsMapping {
414401
Self::all_feature_contracts()
415402
.filter(|contract| contract.cairo_version() != CairoVersion::Cairo0)
416-
.map(|contract| (contract.fixed_tag_and_rust_toolchain(), contract))
403+
.map(|contract| (contract.fixed_version(), contract))
417404
.into_group_map()
418405
}
419406
}

crates/blockifier_test_utils/tests/feature_contracts_compatibility_test.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
use std::fs;
22

3-
use blockifier_test_utils::cairo_compile::{
4-
cairo1_compiler_tag,
5-
verify_cairo1_package,
6-
CompilationArtifacts,
7-
};
3+
use blockifier_test_utils::cairo_compile::{verify_cairo1_package, CompilationArtifacts};
84
use blockifier_test_utils::cairo_versions::{CairoVersion, RunnableCairo1};
95
use blockifier_test_utils::contracts::{
106
FeatureContract,
@@ -86,15 +82,9 @@ async fn verify_feature_contracts_compatibility(fix: bool, cairo_version: CairoV
8682
}
8783
}
8884
CairoVersion::Cairo1(RunnableCairo1::Casm) => {
89-
for (tag_and_tool_chain, feature_contracts) in
90-
FeatureContract::cairo1_feature_contracts_by_tag()
85+
for (version, feature_contracts) in
86+
FeatureContract::cairo1_feature_contracts_by_version()
9187
{
92-
let version = tag_and_tool_chain
93-
.0
94-
.unwrap_or(cairo1_compiler_tag())
95-
.strip_prefix("v")
96-
.unwrap()
97-
.to_string();
9888
verify_cairo1_package(&version).await;
9989

10090
let mut task_set = tokio::task::JoinSet::new();

0 commit comments

Comments
 (0)