Skip to content

Commit

Permalink
Merge pull request #25 from Moonsong-Labs/test-add-compilation-of-yul…
Browse files Browse the repository at this point in the history
…-sample

test: Add test for compilation of yul sample file
  • Loading branch information
Jrigada authored Aug 28, 2024
2 parents 904fb13 + 7368260 commit daf5ffb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/zksync-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/rust-toolchain@1.80.0
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
Expand All @@ -36,10 +36,9 @@ jobs:
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@clippy
- uses: Swatinem/rust-cache@v2
- uses: dtolnay/[email protected]
with:
cache-on-failure: true
components: clippy
- run: cargo clippy --workspace --all-targets --all-features
env:
RUSTFLAGS: -Dwarnings
Expand All @@ -52,7 +51,7 @@ jobs:
uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
uses: dtolnay/rust-toolchain@1.80.0
with:
components: rustfmt

Expand All @@ -68,10 +67,7 @@ jobs:
with:
submodules: recursive
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions-rust-lang/setup-rust-toolchain@v1
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- uses: dtolnay/[email protected]
- name: Run tests
run: cargo test zk
env:
Expand Down
37 changes: 37 additions & 0 deletions crates/compilers/tests/zksync.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{collections::HashMap, fs, path::PathBuf, str::FromStr};

use alloy_primitives::Bytes;
use foundry_compilers::{
buildinfo::BuildInfo,
cache::CompilerCache,
Expand Down Expand Up @@ -299,3 +300,39 @@ contract B { }

assert!(!project.project().build_info_path().exists());
}

#[test]
fn zksync_can_compile_yul_sample() {
let _ = tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.try_init()
.ok();
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../test-data/zksync/yul-sample");
let paths = ProjectPathsConfig::builder().sources(root);
let project = TempProject::<ZkSolcCompiler, ZkArtifactOutput>::new(paths).unwrap();

let compiled = zksync::project_compile(project.project()).unwrap();
compiled.assert_success();

let simple_store_artifact = compiled
.compiled_artifacts
.values()
.find_map(|contracts| {
contracts
.iter()
.find(|(name, _)| name.ends_with("SimpleStore.yul"))
.and_then(|(_, artifacts)| artifacts.first())
})
.expect("SimpleStore.yul artifact not found")
.artifact
.bytecode
.clone()
.unwrap();

let yul_bytecode = simple_store_artifact.object.as_bytes().unwrap();

let expected_bytecode = Bytes::from_str("00000001002001900000000c0000c13d000000002101043c0000000000100435000000200100043d0000000701100197000000000202043b0000000802200197000000000112019f000000200010043f0000000001000019000000000001042d000000240000043f0000002001000039000001000010044300000120000004430000000601000041000000130001042e0000001200000432000000130001042e0000001400010430000000000000000000000000000000000000000000000000000000020000000000000000000000000000004000000100000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007e29ac13118f5fe419367dc363d30b339540f7ac9ff1faccec3e73526efd43e7").unwrap();

// Assert bytecode equality
assert_eq!(*yul_bytecode, expected_bytecode, "SimpleStore.yul bytecode mismatch");
}
11 changes: 11 additions & 0 deletions test-data/zksync/yul-sample/SimpleStore.yul
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
object "SimpleStore" {
code {
datacopy(0, dataoffset("SimpleStore_deployed"), datasize("SimpleStore_deployed"))
return(0, datasize("SimpleStore_deployed"))
}
object "SimpleStore_deployed" {
code {
calldatacopy(0, 0, 36) // write calldata to memory
}
}
}

0 comments on commit daf5ffb

Please sign in to comment.