Skip to content

Commit adbdd11

Browse files
chore(blockifier_test_utils): delete tag-and-toolchain related code
1 parent 807de22 commit adbdd11

3 files changed

Lines changed: 19 additions & 77 deletions

File tree

crates/blockifier_test_utils/src/cairo_compile.rs

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::io::Write;
2-
use std::path::{Path, PathBuf};
2+
use std::path::PathBuf;
33
use std::process::{Command, Output, Stdio};
44
use std::{env, fs};
55

@@ -10,8 +10,6 @@ use tempfile::NamedTempFile;
1010
use tracing::info;
1111

1212
const CAIRO0_PIP_REQUIREMENTS_FILE: &str = "tests/requirements.txt";
13-
const CAIRO1_REPO_RELATIVE_PATH_OVERRIDE_ENV_VAR: &str = "CAIRO1_REPO_RELATIVE_PATH";
14-
const DEFAULT_CAIRO1_REPO_RELATIVE_PATH: &str = "../../../cairo";
1513

1614
pub enum CompilationArtifacts {
1715
Cairo0 { casm: Vec<u8> },
@@ -22,19 +20,6 @@ pub fn cairo1_compiler_tag() -> String {
2220
format!("v{}", cairo1_compiler_version())
2321
}
2422

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

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

137116
let sierra_output = starknet_compile(path, &version);
@@ -196,17 +175,3 @@ fn verify_cairo0_compiler_deps() {
196175
CAIRO0_PIP_REQUIREMENTS_FILE
197176
);
198177
}
199-
200-
fn get_tag_and_repo_file_path(git_tag_override: Option<String>) -> (String, PathBuf) {
201-
let tag = git_tag_override.unwrap_or(cairo1_compiler_tag());
202-
let cairo_repo_path = local_cairo1_compiler_repo_path();
203-
// Check if the path is a directory.
204-
assert!(
205-
cairo_repo_path.is_dir(),
206-
"Cannot verify Cairo1 contracts, Cairo repo not found at {0}.\nPlease run:\n\
207-
git clone https://github.com/starkware-libs/cairo {0}\nThen rerun the test.",
208-
cairo_repo_path.to_string_lossy(),
209-
);
210-
211-
(tag, cairo_repo_path)
212-
}

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.
@@ -193,19 +190,12 @@ impl FeatureContract {
193190
}
194191

195192
/// Some contracts are designed to test behavior of code compiled with a
196-
/// specific (old) compiler tag. To run the (old) compiler, older rust
197-
/// version is required.
198-
pub fn fixed_tag_and_rust_toolchain(&self) -> TagAndToolchain {
193+
/// specific (old) compiler version.
194+
pub fn fixed_version(&self) -> CairoVersionString {
199195
match self {
200-
Self::LegacyTestContract => (
201-
Some(LEGACY_CONTRACT_COMPILER_TAG.into()),
202-
Some(LEGACY_CONTRACT_RUST_TOOLCHAIN.into()),
203-
),
204-
Self::CairoStepsTestContract => (
205-
Some(CAIRO_STEPS_TEST_CONTRACT_COMPILER_TAG.into()),
206-
Some(CAIRO_STEPS_TEST_CONTRACT_RUST_TOOLCHAIN.into()),
207-
),
208-
_ => (None, None),
196+
Self::LegacyTestContract => LEGACY_CONTRACT_COMPILER_VERSION.into(),
197+
Self::CairoStepsTestContract => CAIRO_STEPS_TEST_CONTRACT_COMPILER_VERSION.into(),
198+
_ => cairo1_compiler_version(),
209199
}
210200
}
211201

@@ -338,10 +328,7 @@ impl FeatureContract {
338328
};
339329
cairo0_compile(self.get_source_path(), extra_arg, false)
340330
}
341-
CairoVersion::Cairo1(_) => {
342-
let (tag_override, cargo_nightly_arg) = self.fixed_tag_and_rust_toolchain();
343-
cairo1_compile(self.get_source_path(), tag_override, cargo_nightly_arg)
344-
}
331+
CairoVersion::Cairo1(_) => cairo1_compile(self.get_source_path(), self.fixed_version()),
345332
}
346333
}
347334

@@ -405,10 +392,10 @@ impl FeatureContract {
405392
Self::all_contracts().filter(|contract| !matches!(contract, Self::ERC20(_)))
406393
}
407394

408-
pub fn cairo1_feature_contracts_by_tag() -> TagToContractsMapping {
395+
pub fn cairo1_feature_contracts_by_version() -> VersionToContractsMapping {
409396
Self::all_feature_contracts()
410397
.filter(|contract| contract.cairo_version() != CairoVersion::Cairo0)
411-
.map(|contract| (contract.fixed_tag_and_rust_toolchain(), contract))
398+
.map(|contract| (contract.fixed_version(), contract))
412399
.into_group_map()
413400
}
414401
}

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)