Skip to content

Commit

Permalink
Renaming + fixing test
Browse files Browse the repository at this point in the history
Rename it back so the compiler understand
fixing the test to assert for the missing library
  • Loading branch information
MBerguer committed Jan 7, 2025
1 parent 0d09b88 commit 35edefe
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 19 deletions.
2 changes: 1 addition & 1 deletion crates/config/src/zksync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl ZkSyncConfig {
via_ir: Some(via_ir),
// Set in project paths.
remappings: Vec::new(),
zk_detect_missing_libraries: self.zk_detect_missing_libraries,
detect_missing_libraries: self.zk_detect_missing_libraries,
enable_eravm_extensions: self.enable_eravm_extensions,
force_evmla: self.force_evmla,
llvm_options: self.llvm_options.clone(),
Expand Down
16 changes: 10 additions & 6 deletions crates/forge/bin/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use foundry_config::{
value::{Dict, Map, Value},
Metadata, Profile, Provider,
},
zksync::config_create_project,
Config,
};
use serde::Serialize;
Expand Down Expand Up @@ -90,10 +91,6 @@ impl BuildArgs {
config = self.load_config();
}

if self.zk_detect_missing_libraries {
config.zksync.zk_detect_missing_libraries = true;
}

if !config.zksync.should_compile() {
let project = config.project()?;

Expand Down Expand Up @@ -130,8 +127,15 @@ impl BuildArgs {
// no way to return a default from either branch. Ok(output)
Ok(())
} else {
let zk_project =
foundry_config::zksync::config_create_project(&config, config.cache, false)?;
let mut zk_project = config_create_project(&config, config.cache, false)?;

// Note: This is to pass the zk_detect_missing_libraries flag to the zk compiler only
// while building.
zk_project.settings.settings.detect_missing_libraries =
self.zk_detect_missing_libraries;

// sh_print!("Compiling ZK contracts...")?;
// sh_println!("zk_project.settings.settings: {:?}", zk_project.settings.settings)?;

// Collect sources to compile if build subdirectories specified.
let mut files = vec![];
Expand Down
45 changes: 37 additions & 8 deletions crates/forge/tests/cli/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::utils::generate_large_contract;
use foundry_config::{zksync::ZkSyncConfig, Config};

Check failure on line 2 in crates/forge/tests/cli/build.rs

View workflow job for this annotation

GitHub Actions / zk-cargo-test

unused import: `zksync::ZkSyncConfig`
use foundry_test_utils::{forgetest, snapbox::IntoData, str};
use foundry_test_utils::{forgetest, snapbox::IntoData, str, util::OutputExt};

Check failure on line 3 in crates/forge/tests/cli/build.rs

View workflow job for this annotation

GitHub Actions / zk-cargo-test

unused import: `util::OutputExt`
use globset::Glob;
use std::fs;

Check failure on line 5 in crates/forge/tests/cli/build.rs

View workflow job for this annotation

GitHub Actions / zk-cargo-test

unused import: `std::fs`

forgetest_init!(can_parse_build_filters, |prj, cmd| {
prj.clear();
Expand Down Expand Up @@ -209,14 +210,42 @@ contract ValidContract {}
cmd.args(["build"]).assert_success();
});

forgetest_init!(test_zk_build_missing_libraries_as_arg, |prj, cmd| {
cmd.args(["build", "--zksync", "--zk-detect-missing-libraries"]).assert_success();
});
forgetest!(test_zk_build_with_missing_libraries_as_arg, |prj, cmd| {
prj.add_source(
"Foo",
r#"
library Foo {
function get_something() external returns (uint256 c) {}
}
"#,
)
.unwrap();

forgetest_init!(test_zk_build_missing_libraries_as_config, |prj, cmd| {
let zk = ZkSyncConfig { zk_detect_missing_libraries: true, ..Default::default() };
prj.write_config(Config { zksync: zk, ..Default::default() });
cmd.args(["build", "--zksync", "--zk-detect-missing-libraries"]).assert_success();
prj.add_source(
"UsesFoo",
r#"
import "./Foo.sol";
contract UsesFoo {
uint256 something;
constructor() {
something = Foo.get_something();
}
}
"#,
)
.unwrap();

// cmd.args(["build", "--zksync", "--zk-detect-missing-libraries", "--json"]).assert_success();
cmd.args(["build", "--zksync", "--zk-detect-missing-libraries", "--json", "--force"])
.assert_success()
.stdout_eq(str![[r#"
...
"missingLibraries": [
"src/Foo.sol:Foo"
]
...
"#]]);
});

forgetest_init!(test_zk_missing_libraries_param_only_on_build, |prj, cmd| {
Expand Down
8 changes: 4 additions & 4 deletions crates/zksync/compilers/src/compilers/zksolc/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub struct ZkSettings {
/// Switch to missing deployable libraries detection mode.
/// Contracts are not compiled in this mode, and all compilation artifacts are not included.
#[serde(default, rename = "detectMissingLibraries")]
pub zk_detect_missing_libraries: bool,
pub detect_missing_libraries: bool,
// zksolc arguments
/// A flag indicating whether to enable the system contract compilation mode.
/// Whether to enable EraVM extensions.
Expand Down Expand Up @@ -204,7 +204,7 @@ impl Default for ZkSettings {
via_ir: None,
libraries: Default::default(),
remappings: Default::default(),
zk_detect_missing_libraries: false,
detect_missing_libraries: false,
enable_eravm_extensions: false,
llvm_options: Default::default(),
force_evmla: false,
Expand Down Expand Up @@ -244,7 +244,7 @@ impl CompilerSettings for ZkSolcSettings {
optimizer,
metadata,
libraries,
zk_detect_missing_libraries,
detect_missing_libraries,
enable_eravm_extensions,
llvm_options,
force_evmla,
Expand All @@ -262,7 +262,7 @@ impl CompilerSettings for ZkSolcSettings {
*optimizer == other.settings.optimizer &&
*metadata == other.settings.metadata &&
*libraries == other.settings.libraries &&
*zk_detect_missing_libraries == other.settings.zk_detect_missing_libraries &&
*detect_missing_libraries == other.settings.detect_missing_libraries &&
*enable_eravm_extensions == other.settings.enable_eravm_extensions &&
*llvm_options == other.settings.llvm_options &&
*force_evmla == other.settings.force_evmla &&
Expand Down

0 comments on commit 35edefe

Please sign in to comment.