Skip to content

Commit

Permalink
fix(compilation): do not compile devnet contract artifacts when doing…
Browse files Browse the repository at this point in the history
… `cargo build` (#365)
  • Loading branch information
cchudant authored Oct 25, 2024
1 parent a2f57e6 commit a0fa067
Show file tree
Hide file tree
Showing 34 changed files with 187 additions and 249 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ jobs:
with:
version: nightly
- name: Build
# also build test contracts for js-tests.
run: |
export GIT_COMMIT_HASH=$GITHUB_SHA
cargo build --release --bin madara
cargo build --release -p m-cairo-test-contracts
- name: Generate binary hash
id: binary_hash
run: |
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ jobs:
env:
ETH_FORK_URL: ${{ secrets.ETH_FORK_URL }}
GATEWAY_KEY: ${{ secrets.GITHUB_GATEWAY_KEY || '' }}
PROPTEST_CASES: 10
run: |
source <(cargo llvm-cov show-env --export-prefix)
cargo build --bin madara --profile dev
export COVERAGE_BIN=$(realpath target/debug/madara)
rm -f target/madara-* lcov.info
cargo test --profile dev -- --test-threads=1
cargo test --profile dev --workspace -- --test-threads=1
- name: Generate coverage info
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ jobs:
- name: Run unit tests
run: |
cargo test
cargo test --workspace
env:
PROPTEST_CASES: 2
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target
crates/client/sync/test-data/*.json
cairo-artifacts
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- fix(compilation): devnet contract artifacts are not compiled by `cargo build` anymore
- feat: add fgw get_block_traces
- refactor: use `hyper` & `tower` instead of `reqwest` for feeder client
- fix(namespace): versioning now works for methods without `starknet` namesapce
Expand Down
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ members = [
"crates/primitives/utils",
"crates/proc-macros",
"crates/tests",
"crates/cairo-test-contracts",
]
resolver = "2"
# Everything except test-related packages, so that they are not compiled when doing `cargo build`.
default-members = [
"crates/client/db",
"crates/client/exec",
Expand All @@ -48,7 +50,6 @@ default-members = [
"crates/primitives/chain_config",
"crates/primitives/utils",
"crates/proc-macros",
"crates/tests",
]

[workspace.lints.rust]
Expand Down Expand Up @@ -120,6 +121,9 @@ mc-mempool = { path = "crates/client/mempool" }
mc-block-import = { path = "crates/client/block_import" }
mc-devnet = { path = "crates/client/devnet" }

# Madara misc
m-cairo-test-contracts = { path = "crates/cairo-test-contracts" }

# Starknet dependencies
cairo-vm = "=1.0.1"
starknet-core = "0.11"
Expand Down
11 changes: 1 addition & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,7 @@ WORKDIR /usr/src/madara/
# Copy the source code into the container
COPY Cargo.toml Cargo.lock ./
COPY crates crates
COPY cairo cairo
COPY cairo_0 cairo_0


# Installing scarb, new since devnet integration
ENV SCARB_VERSION="v2.8.2"
ENV SHELL="/bin/bash"
RUN curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- ${SCARB_VERSION}
ENV PATH="/root/.local/bin:${PATH}"
RUN scarb --version
COPY cairo-artifacts cairo-artifacts

# Install runtime dependencies
RUN apt-get -y update && \
Expand Down
26 changes: 26 additions & 0 deletions cairo-artifacts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Cairo artifacts

We commit these artifacts so that the compilation process is easier, as they require different cairo 0 / cairo 1 versions.

The OZ contracts were compiled as to match the [`starkli`'s allowed class hash list](https://github.com/xJonathanLEI/starkli/blob/1bed33383d8f8cec926f7ce97c4a4243b8bbe43b/src/account.rs#L109):
OpenZeppelin v0.13.0 compiled with cairo v2.6.3.

```sh
git clone https://github.com/OpenZeppelin/cairo-contracts
cd cairo-contracts

SCARB_VERSION=2.6.3
OZ_VERSION=0.13.0

git checkout v$OZ_VERSION
asdf install scarb $SCARB_VERSION
asdf shell scarb $SCARB_VERSION
scarb build
starkli class-hash target/dev/openzeppelin_AccountUpgradeable.contract_class.json
```

should always return class hash `0x00e2eb8f5672af4e6a4e8a8f1b44989685e668489b0a25437733756c5a34a1d6`, and
`target/dev/openzeppelin_AccountUpgradeable.contract_class.json` should match the file in this
folder.

`openzeppelin_ERC20Upgradeable.contract_class.json` is compiled using the same scarb and OZ versions.
File renamed without changes.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

55 changes: 0 additions & 55 deletions cairo/src/account.cairo

This file was deleted.

69 changes: 0 additions & 69 deletions cairo/src/erc20.cairo

This file was deleted.

3 changes: 0 additions & 3 deletions cairo/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

pub mod erc20;
pub mod udc;
pub mod account;
pub mod test_account;
pub mod hello;
60 changes: 0 additions & 60 deletions cairo/src/udc.cairo

This file was deleted.

16 changes: 16 additions & 0 deletions crates/cairo-test-contracts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "m-cairo-test-contracts"
authors.workspace = true
homepage.workspace = true
edition.workspace = true
repository.workspace = true
version.workspace = true
license.workspace = true

[lints]
workspace = true

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() {
let cairo_project_dir = "../../../cairo";
let cairo_project_dir = "../../cairo";
println!("cargo::rerun-if-changed={cairo_project_dir}/src");
println!("cargo::rerun-if-changed={cairo_project_dir}/Scarb.toml");
// Note: scarb build updates the Scarb.lock file, and there is no `--locked` arg to avoid
Expand Down
5 changes: 5 additions & 0 deletions crates/cairo-test-contracts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! This crate is used to build the cairo test contracts for tests. Contracts that are not used in
//! tests need to be put in the `cairo-artifacts` folder at the root of the project`.

pub const TEST_CONTRACT_SIERRA: &[u8] =
include_bytes!("../../../cairo/target/dev/madara_contracts_TestContract.contract_class.json");
3 changes: 3 additions & 0 deletions crates/client/devnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ blockifier = { workspace = true, features = ["testing"] }
mockall.workspace = true
assert_matches.workspace = true

# Compile the test contracts in test cfg.
m-cairo-test-contracts.workspace = true

[dependencies]

# Madara
Expand Down
Loading

0 comments on commit a0fa067

Please sign in to comment.