Skip to content

Commit 9e7cac1

Browse files
feat(blockifier): recompile Cairo1 in the CI
1 parent e87bd1c commit 9e7cac1

File tree

3 files changed

+41
-29
lines changed

3 files changed

+41
-29
lines changed

.github/workflows/blockifier_compiled_cairo.yml

+32-5
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,24 @@ on:
44
push:
55
branches:
66
- main
7+
- main-v[0-9].**
78
tags:
89
- v[0-9].**
910
paths:
10-
- 'crates/blockifier/feature_contracts/cairo0/**'
1111
- '.github/workflows/blockifier_compiled_cairo.yml'
12+
- 'crates/blockifier/feature_contracts/**'
13+
- 'crates/blockifier/src/test_utils/cairo_compile.rs'
14+
- 'crates/blockifier/tests/**'
1215
pull_request:
1316
types:
1417
- opened
1518
- reopened
1619
- synchronize
1720
paths:
1821
- '.github/workflows/blockifier_compiled_cairo.yml'
19-
- 'crates/blockifier/feature_contracts/cairo0/**'
22+
- 'crates/blockifier/feature_contracts/**'
23+
- 'crates/blockifier/src/test_utils/cairo_compile.rs'
24+
- 'crates/blockifier/tests/**'
2025

2126
jobs:
2227
verify_cairo_file_dependencies:
@@ -39,6 +44,28 @@ jobs:
3944
LD_LIBRARY_PATH: ${{ env.Python3_ROOT_DIR }}/bin
4045
run: echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
4146

42-
- run:
43-
pip install -r crates/blockifier/tests/requirements.txt;
44-
cargo test verify_feature_contracts -- --include-ignored
47+
# Checkout sequencer into a dedicated directory - technical requirement in order to be able to checkout `cairo` in a sibling directory.
48+
- name: checkout sequencer into `sequencer` directory.
49+
uses: actions/checkout@v4
50+
with:
51+
repository: 'starkware-libs/sequencer'
52+
path: 'sequencer'
53+
54+
- name: checkout cairo1 repo in order to compile cairo1 contracts.
55+
uses: actions/checkout@v4
56+
with:
57+
repository: 'starkware-libs/cairo'
58+
fetch-depth: 0
59+
fetch-tags: true
60+
path: 'cairo'
61+
62+
- name: install toolchain for legacy contract compilation (old compiler tag)
63+
uses: actions-rs/toolchain@master
64+
with:
65+
toolchain: nightly-2023-07-05
66+
67+
- name: Verify cairo contract recompilation (both cairo versions).
68+
run:
69+
cd sequencer &&
70+
pip install -r crates/blockifier/tests/requirements.txt &&
71+
cargo test -p blockifier --test feature_contracts_compatibility_test --features testing -- --include-ignored

crates/blockifier/src/test_utils/cairo_compile.rs

-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ fn verify_cairo1_compiler_deps(git_tag_override: Option<String>) {
189189
// Checkout the required version in the compiler repo.
190190
run_and_verify_output(Command::new("git").args([
191191
"-C",
192-
// TODO(Dori, 1/6/2024): Handle CI case (repo path will be different).
193192
cairo_repo_path.to_str().unwrap(),
194193
"checkout",
195194
&tag,

crates/blockifier/tests/feature_contracts_compatibility_test.rs

+9-23
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use rstest::rstest;
88
const CAIRO0_FEATURE_CONTRACTS_DIR: &str = "feature_contracts/cairo0";
99
const CAIRO1_FEATURE_CONTRACTS_DIR: &str = "feature_contracts/cairo1";
1010
const COMPILED_CONTRACTS_SUBDIR: &str = "compiled";
11-
const FIX_COMMAND: &str = "FIX_FEATURE_TEST=1 cargo test -- --ignored";
11+
const FIX_COMMAND: &str = "FIX_FEATURE_TEST=1 cargo test -p blockifier --test \
12+
feature_contracts_compatibility_test --features testing -- \
13+
--include-ignored";
1214

1315
// To fix Cairo0 feature contracts, first enter a python venv and install the requirements:
1416
// ```
@@ -18,22 +20,12 @@ const FIX_COMMAND: &str = "FIX_FEATURE_TEST=1 cargo test -- --ignored";
1820
// ```
1921
// Then, run the FIX_COMMAND above.
2022

21-
// This test currently doesn't support Cairo1 contracts. To fix them you'll need to compile them one
22-
// by one:
23-
// 1. Clone the [cairo repo](https://github.com/starkware-libs/cairo).
24-
// 2. Checkout the commit defined in [the root Cargo.toml](../../../../Cargo.toml).
25-
// 3. From within the compiler repo root directory, run:
26-
// ```
27-
// PREFIX=~/workspace/blockifier/crates/blockifier/feature_contracts/cairo1
28-
// CONTRACT_NAME=<contract_base_filename>
29-
// cargo run --release --bin starknet-compile -- --single-file \
30-
// $PREFIX/$CONTRACT_NAME.cairo \
31-
// $PREFIX/compiled/$CONTRACT_NAME.sierra.json
32-
// cargo run --release --bin starknet-sierra-compile \
33-
// $PREFIX/compiled/$CONTRACT_NAME.sierra.json \
34-
// $PREFIX/compiled/$CONTRACT_NAME.casm.json
35-
// ```
36-
// TODO(Gilad, 1/1/2024): New year's resolution: support Cairo1 in the test.
23+
// To test Cairo1 feature contracts, first clone the Cairo repo and checkout the required tag.
24+
// The repo should be located next to the sequencer repo:
25+
// <WORKSPACE_DIR>/
26+
// - sequencer/
27+
// - cairo/
28+
// Then, run the FIX_COMMAND above.
3729

3830
// Checks that:
3931
// 1. `TEST_CONTRACTS` dir exists and contains only `.cairo` files and the subdirectory
@@ -130,12 +122,6 @@ fn verify_feature_contracts_match_enum() {
130122
fn verify_feature_contracts(
131123
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion,
132124
) {
133-
// TODO(Dori, 1/9/2024): Support Cairo1 contracts in the CI and remove this `if` statement.
134-
if std::env::var("CI").unwrap_or("false".into()) == "true"
135-
&& matches!(cairo_version, CairoVersion::Cairo1)
136-
{
137-
return;
138-
}
139125
let fix_features = std::env::var("FIX_FEATURE_TEST").is_ok();
140126
verify_feature_contracts_compatibility(fix_features, cairo_version)
141127
}

0 commit comments

Comments
 (0)