Skip to content

Commit

Permalink
feat(blockifier): recompile Cairo1 in the CI
Browse files Browse the repository at this point in the history
  • Loading branch information
dorimedini-starkware committed Aug 11, 2024
1 parent 1c94532 commit feb2d27
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 29 deletions.
39 changes: 34 additions & 5 deletions .github/workflows/blockifier_compiled_cairo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@ on:
push:
branches:
- main
- main-v[0-9].**
tags:
- v[0-9].**
paths:
- 'crates/blockifier/feature_contracts/cairo0/**'
- '.github/workflows/blockifier_compiled_cairo.yml'
- 'crates/blockifier/feature_contracts/**'
- 'crates/blockifier/src/test_utils/cairo_compile.rs'
- 'crates/blockifier/tests/feature_contracts_compatibility_test.rs'
- 'crates/blockifier/tests/requirements.txt'
pull_request:
types:
- opened
- reopened
- synchronize
paths:
- '.github/workflows/blockifier_compiled_cairo.yml'
- 'crates/blockifier/feature_contracts/cairo0/**'
- 'crates/blockifier/feature_contracts/**'
- 'crates/blockifier/src/test_utils/cairo_compile.rs'
- 'crates/blockifier/tests/feature_contracts_compatibility_test.rs'
- 'crates/blockifier/tests/requirements.txt'

jobs:
verify_cairo_file_dependencies:
Expand All @@ -39,6 +46,28 @@ jobs:
LD_LIBRARY_PATH: ${{ env.Python3_ROOT_DIR }}/bin
run: echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV

- run:
pip install -r crates/blockifier/tests/requirements.txt;
cargo test verify_feature_contracts -- --include-ignored
# Checkout sequencer into a dedicated directory - technical requirement in order to be able to checkout `cairo` in a sibling directory.
- name: checkout sequencer into `sequencer` directory.
uses: actions/checkout@v4
with:
repository: 'starkware-libs/sequencer'
path: 'sequencer'

- name: checkout cairo1 repo in order to compile cairo1 contracts.
uses: actions/checkout@v4
with:
repository: 'starkware-libs/cairo'
fetch-depth: 1
fetch-tags: true
path: 'cairo'

- name: install toolchain for legacy contract compilation (old compiler tag)
uses: actions-rs/toolchain@master
with:
toolchain: nightly-2023-07-05

- name: Verify cairo contract recompilation (both cairo versions).
run:
cd sequencer &&
pip install -r crates/blockifier/tests/requirements.txt &&
cargo test -p blockifier --test feature_contracts_compatibility_test --features testing -- --include-ignored
1 change: 0 additions & 1 deletion crates/blockifier/src/test_utils/cairo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ fn prepare_cairo1_compiler_deps(git_tag_override: Option<String>) {
// Checkout the required version in the compiler repo.
run_and_verify_output(Command::new("git").args([
"-C",
// TODO(Dori, 1/6/2024): Handle CI case (repo path will be different).
cairo_repo_path.to_str().unwrap(),
"checkout",
&tag,
Expand Down
32 changes: 9 additions & 23 deletions crates/blockifier/tests/feature_contracts_compatibility_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use rstest::rstest;
const CAIRO0_FEATURE_CONTRACTS_DIR: &str = "feature_contracts/cairo0";
const CAIRO1_FEATURE_CONTRACTS_DIR: &str = "feature_contracts/cairo1";
const COMPILED_CONTRACTS_SUBDIR: &str = "compiled";
const FIX_COMMAND: &str = "FIX_FEATURE_TEST=1 cargo test -- --ignored";
const FIX_COMMAND: &str = "FIX_FEATURE_TEST=1 cargo test -p blockifier --test \
feature_contracts_compatibility_test --features testing -- \
--include-ignored";

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

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

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

0 comments on commit feb2d27

Please sign in to comment.