Skip to content

Commit f8f23d8

Browse files
feat(blockifier): recompile Cairo1 in the CI
1 parent 1c94532 commit f8f23d8

File tree

3 files changed

+43
-29
lines changed

3 files changed

+43
-29
lines changed

.github/workflows/blockifier_compiled_cairo.yml

+34-5
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,26 @@ 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/feature_contracts_compatibility_test.rs'
15+
- 'crates/blockifier/tests/requirements.txt'
1216
pull_request:
1317
types:
1418
- opened
1519
- reopened
1620
- synchronize
1721
paths:
1822
- '.github/workflows/blockifier_compiled_cairo.yml'
19-
- 'crates/blockifier/feature_contracts/cairo0/**'
23+
- 'crates/blockifier/feature_contracts/**'
24+
- 'crates/blockifier/src/test_utils/cairo_compile.rs'
25+
- 'crates/blockifier/tests/feature_contracts_compatibility_test.rs'
26+
- 'crates/blockifier/tests/requirements.txt'
2027

2128
jobs:
2229
verify_cairo_file_dependencies:
@@ -39,6 +46,28 @@ jobs:
3946
LD_LIBRARY_PATH: ${{ env.Python3_ROOT_DIR }}/bin
4047
run: echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
4148

42-
- run:
43-
pip install -r crates/blockifier/tests/requirements.txt;
44-
cargo test verify_feature_contracts -- --include-ignored
49+
# Checkout sequencer into a dedicated directory - technical requirement in order to be able to checkout `cairo` in a sibling directory.
50+
- name: checkout sequencer into `sequencer` directory.
51+
uses: actions/checkout@v4
52+
with:
53+
repository: 'starkware-libs/sequencer'
54+
path: 'sequencer'
55+
56+
- name: checkout cairo1 repo in order to compile cairo1 contracts.
57+
uses: actions/checkout@v4
58+
with:
59+
repository: 'starkware-libs/cairo'
60+
fetch-depth: 0
61+
fetch-tags: true
62+
path: 'cairo'
63+
64+
- name: install toolchain for legacy contract compilation (old compiler tag)
65+
uses: actions-rs/toolchain@master
66+
with:
67+
toolchain: nightly-2023-07-05
68+
69+
- name: Verify cairo contract recompilation (both cairo versions).
70+
run:
71+
cd sequencer &&
72+
pip install -r crates/blockifier/tests/requirements.txt &&
73+
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
@@ -190,7 +190,6 @@ fn prepare_cairo1_compiler_deps(git_tag_override: Option<String>) {
190190
// Checkout the required version in the compiler repo.
191191
run_and_verify_output(Command::new("git").args([
192192
"-C",
193-
// TODO(Dori, 1/6/2024): Handle CI case (repo path will be different).
194193
cairo_repo_path.to_str().unwrap(),
195194
"checkout",
196195
&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 fix 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)