Skip to content

Commit 5b2776c

Browse files
feat(blockifier_test_utils): make compiler download async
1 parent dc79548 commit 5b2776c

3 files changed

Lines changed: 17 additions & 15 deletions

File tree

crates/blockifier_test_utils/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ cairo-lang-starknet-classes.workspace = true
1515
flate2.workspace = true
1616
itertools.workspace = true
1717
pretty_assertions.workspace = true
18-
reqwest = { workspace = true, features = ["blocking"] }
18+
reqwest.workspace = true
1919
rstest.workspace = true
2020
serde_json = { workspace = true, features = ["arbitrary_precision"] }
2121
starknet-types-core.workspace = true

crates/blockifier_test_utils/src/cairo_compile.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,24 @@ fn starknet_sierra_compile_binary_path(version: &String) -> PathBuf {
4545

4646
/// Downloads the cairo package to the local directory.
4747
/// Creates the directory if it does not exist.
48-
fn download_cairo_package(version: &String) {
48+
async fn download_cairo_package(version: &String) {
4949
let directory = cairo1_package_dir(version);
5050
info!("Downloading Cairo package to {directory:?}.");
5151
std::fs::create_dir_all(&directory).unwrap();
5252

5353
// Download the artifact.
54-
let client = reqwest::blocking::Client::new();
54+
let client = reqwest::Client::new();
5555
let filename = "release-x86_64-unknown-linux-musl.tar.gz";
5656
let package_url =
5757
format!("https://github.com/starkware-libs/cairo/releases/download/v{version}/{filename}");
58-
let response = client.get(package_url).send().unwrap();
58+
let response = client.get(package_url).send().await.unwrap();
5959
assert!(response.status().is_success(), "Failed to download the package: {response:?}.");
6060

6161
// Write the response to a file.
6262
info!("Writing and extracting package.");
6363
let tar_gz_path = Path::new(&directory).join(filename);
6464
let mut file = std::fs::File::create(&tar_gz_path).unwrap();
65-
file.write_all(&response.bytes().unwrap()).unwrap();
65+
file.write_all(&response.bytes().await.unwrap()).unwrap();
6666

6767
// Extract the tar.gz file.
6868
let tar_gz = std::fs::File::open(&tar_gz_path).unwrap();
@@ -73,15 +73,19 @@ fn download_cairo_package(version: &String) {
7373
info!("Done.");
7474
}
7575

76-
/// Verifies that the Cairo1 package (of the given version) is available.
77-
pub fn verify_cairo1_package(version: &String, download_if_missing: bool) {
76+
fn cairo1_package_exists(version: &String) -> bool {
7877
let cairo_compiler_path = starknet_compile_binary_path(version);
7978
let sierra_compiler_path = starknet_sierra_compile_binary_path(version);
80-
if download_if_missing && (!cairo_compiler_path.exists() || !sierra_compiler_path.exists()) {
81-
download_cairo_package(version);
79+
cairo_compiler_path.exists() && sierra_compiler_path.exists()
80+
}
81+
82+
/// Verifies that the Cairo1 package (of the given version) is available.
83+
/// Attempts to download it if not.
84+
pub async fn verify_cairo1_package(version: &String) {
85+
if !cairo1_package_exists(version) {
86+
download_cairo_package(version).await;
8287
}
83-
assert!(cairo_compiler_path.exists(), "Cairo compiler not found at {cairo_compiler_path:?}");
84-
assert!(sierra_compiler_path.exists(), "Sierra compiler not found at {sierra_compiler_path:?}");
88+
assert!(cairo1_package_exists(version));
8589
}
8690

8791
/// Runs a command. If it has succeeded, it returns the command's output; otherwise, it panics with
@@ -118,8 +122,7 @@ pub fn cairo0_compile(
118122

119123
/// Compiles a Cairo1 program using the compiler version set in the Cargo.toml.
120124
pub fn cairo1_compile(path: String, version: String) -> CompilationArtifacts {
121-
let download_if_missing = false;
122-
verify_cairo1_package(&version, download_if_missing);
125+
assert!(cairo1_package_exists(&version));
123126

124127
let sierra_output = starknet_compile(path, &version);
125128

crates/blockifier_test_utils/tests/feature_contracts_compatibility_test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ async fn verify_feature_contracts_compatibility(fix: bool, cairo_version: CairoV
8585
for (version, feature_contracts) in
8686
FeatureContract::cairo1_feature_contracts_by_version()
8787
{
88-
let download_if_missing = true;
89-
verify_cairo1_package(&version, download_if_missing);
88+
verify_cairo1_package(&version).await;
9089

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

0 commit comments

Comments
 (0)