Skip to content

Commit 8b6e56f

Browse files
chore(blockifier_test_utils): delete tag-and-toolchain related code
1 parent 456f44a commit 8b6e56f

3 files changed

Lines changed: 27 additions & 83 deletions

File tree

crates/blockifier_test_utils/src/cairo_compile.rs

Lines changed: 5 additions & 42 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};
44
use std::{env, fs};
55

@@ -9,16 +9,16 @@ use apollo_infra_utils::path::project_path;
99
use tempfile::NamedTempFile;
1010
use tracing::info;
1111

12+
use crate::contracts::CairoVersionString;
13+
1214
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";
1515

1616
pub enum CompilationArtifacts {
1717
Cairo0 { casm: Vec<u8> },
1818
Cairo1 { casm: Vec<u8>, sierra: Vec<u8> },
1919
}
2020

21-
fn cairo1_compiler_version_for_feature_contracts() -> String {
21+
pub fn cairo1_compiler_version_for_feature_contracts() -> CairoVersionString {
2222
// TODO(lior): Uncomment the following line it and remove the rest of the code, once the
2323
// Cairo compiler version is updated to 2.11.0 in the toml file.
2424
// If the compiler version is updated in the toml to a version < 2.11.0,
@@ -28,23 +28,6 @@ fn cairo1_compiler_version_for_feature_contracts() -> String {
2828
"2.11.0-dev.2".into()
2929
}
3030

31-
pub fn cairo1_compiler_tag() -> String {
32-
format!("v{}", cairo1_compiler_version_for_feature_contracts())
33-
}
34-
35-
/// Returns the path to the local Cairo1 compiler repository.
36-
/// Returns <sequencer_repo_root>/<RELATIVE_PATH_TO_CAIRO_REPO>, where the relative path can be
37-
/// overridden by the environment variable (otherwise, the default is used).
38-
fn local_cairo1_compiler_repo_path() -> PathBuf {
39-
// Location of blockifier's Cargo.toml.
40-
let manifest_dir = compile_time_cargo_manifest_dir!();
41-
42-
Path::new(&manifest_dir).join(
43-
env::var(CAIRO1_REPO_RELATIVE_PATH_OVERRIDE_ENV_VAR)
44-
.unwrap_or_else(|_| DEFAULT_CAIRO1_REPO_RELATIVE_PATH.into()),
45-
)
46-
}
47-
4831
/// Path to local compiler package directory, of the specified version.
4932
fn cairo1_package_dir(version: &String) -> PathBuf {
5033
project_path().unwrap().join(format!("target/bin/cairo_package__{version}"))
@@ -128,13 +111,7 @@ pub fn cairo0_compile(
128111
}
129112

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

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

crates/blockifier_test_utils/src/contracts.rs

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ use starknet_types_core::felt::Felt;
1313
use strum::IntoEnumIterator;
1414
use strum_macros::EnumIter;
1515

16-
use crate::cairo_compile::{cairo0_compile, cairo1_compile, CompilationArtifacts};
16+
use crate::cairo_compile::{
17+
cairo0_compile,
18+
cairo1_compile,
19+
cairo1_compiler_version_for_feature_contracts,
20+
CompilationArtifacts,
21+
};
1722
use crate::cairo_versions::{CairoVersion, RunnableCairo1};
1823

1924
pub const CAIRO1_FEATURE_CONTRACTS_DIR: &str = "resources/feature_contracts/cairo1";
@@ -77,16 +82,12 @@ const ERC20_CAIRO1_CONTRACT_SOURCE_PATH: &str = "./resources/ERC20/ERC20_Cairo1/
7782
const ERC20_SIERRA_CONTRACT_PATH: &str = "./resources/ERC20/ERC20_Cairo1/erc20.sierra.json";
7883
const ERC20_CAIRO1_CONTRACT_PATH: &str = "./resources/ERC20/ERC20_Cairo1/erc20.casm.json";
7984

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";
85+
// The following contracts are compiled with a fixed version of the compiler.
86+
const LEGACY_CONTRACT_COMPILER_VERSION: &str = "2.1.0";
87+
const CAIRO_STEPS_TEST_CONTRACT_COMPILER_VERSION: &str = "2.7.0";
8488

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>>;
89+
pub type CairoVersionString = String;
90+
pub type VersionToContractsMapping = HashMap<CairoVersionString, Vec<FeatureContract>>;
9091

9192
/// Enum representing all feature contracts.
9293
/// The contracts that are implemented in both Cairo versions include a version field.
@@ -193,19 +194,12 @@ impl FeatureContract {
193194
}
194195

195196
/// 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 {
197+
/// specific (old) compiler version.
198+
pub fn fixed_version(&self) -> CairoVersionString {
199199
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),
200+
Self::LegacyTestContract => LEGACY_CONTRACT_COMPILER_VERSION.into(),
201+
Self::CairoStepsTestContract => CAIRO_STEPS_TEST_CONTRACT_COMPILER_VERSION.into(),
202+
_ => cairo1_compiler_version_for_feature_contracts(),
209203
}
210204
}
211205

@@ -338,10 +332,7 @@ impl FeatureContract {
338332
};
339333
cairo0_compile(self.get_source_path(), extra_arg, false)
340334
}
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-
}
335+
CairoVersion::Cairo1(_) => cairo1_compile(self.get_source_path(), self.fixed_version()),
345336
}
346337
}
347338

@@ -405,10 +396,10 @@ impl FeatureContract {
405396
Self::all_contracts().filter(|contract| !matches!(contract, Self::ERC20(_)))
406397
}
407398

408-
pub fn cairo1_feature_contracts_by_tag() -> TagToContractsMapping {
399+
pub fn cairo1_feature_contracts_by_version() -> VersionToContractsMapping {
409400
Self::all_feature_contracts()
410401
.filter(|contract| contract.cairo_version() != CairoVersion::Cairo0)
411-
.map(|contract| (contract.fixed_tag_and_rust_toolchain(), contract))
402+
.map(|contract| (contract.fixed_version(), contract))
412403
.into_group_map()
413404
}
414405
}

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)