Skip to content

Commit

Permalink
fix: makes use of zksolc_manager during test cmd to download compil…
Browse files Browse the repository at this point in the history
…er if not present (#185)
  • Loading branch information
dutterbutter authored and Deniallugo committed Dec 8, 2023
1 parent d507122 commit cf104db
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
30 changes: 20 additions & 10 deletions crates/common/src/zksolc_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,24 +423,34 @@ impl fmt::Display for ZkSolcManager {
/// The function returns the `ZkSolcManager` if all steps are successful, or an error if any
/// step fails.
pub fn setup_zksolc_manager(zksolc_version: String) -> eyre::Result<ZkSolcManager> {
let zksolc_manager_opts = ZkSolcManagerOpts::new(zksolc_version);
let zksolc_manager_opts = ZkSolcManagerOpts::new(zksolc_version.clone());
let zksolc_manager_builder = ZkSolcManagerBuilder::new(zksolc_manager_opts);
let zksolc_manager = zksolc_manager_builder
.build()
.map_err(|e| eyre::eyre!("Error building zksolc_manager: {}", e))?;
let zksolc_manager = zksolc_manager_builder.build().map_err(|e| {
eyre::eyre!("Error initializing ZkSolcManager for version '{}': {}", zksolc_version, e)
})?;

if let Err(err) = zksolc_manager.check_setup_compilers_dir() {
eyre::bail!("Failed to setup compilers directory: {}", err);
eyre::bail!("Failed to set up or access the ZkSolc compilers directory: {}", err);
}

if !zksolc_manager.exists() {
let download_url = zksolc_manager
.get_full_download_url()
.map(|url| url.to_string())
.unwrap_or_else(|_| "unknown URL".to_string());

println!(
"Downloading zksolc compiler from {:?}",
zksolc_manager.get_full_download_url().unwrap().to_string()
"zksolc not found in `.zksync` directory. Downloading zksolc compiler from {}",
download_url
);
zksolc_manager
.download()
.map_err(|err| eyre::eyre!("Failed to download the file: {}", err))?;
zksolc_manager.download().map_err(|err| {
eyre::eyre!(
"Failed to download zksolc version '{}' from {}: {}",
zksolc_version,
download_url,
err
)
})?;
}

Ok(zksolc_manager)
Expand Down
12 changes: 6 additions & 6 deletions crates/zkforge/bin/cmd/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use foundry_common::{
evm::EvmArgs,
get_contract_name, get_file_name, shell,
zk_compile::{ZkSolc, ZkSolcOpts},
zksolc_manager::{ZkSolcManagerBuilder, ZkSolcManagerOpts, DEFAULT_ZKSOLC_VERSION},
zksolc_manager::{setup_zksolc_manager, DEFAULT_ZKSOLC_VERSION},
};
use foundry_config::{
figment,
Expand Down Expand Up @@ -167,10 +167,7 @@ impl TestArgs {
let toml = config.get_config_path();
let profiles = get_available_profiles(toml)?;

let zksolc_manager =
ZkSolcManagerBuilder::new(ZkSolcManagerOpts::new(DEFAULT_ZKSOLC_VERSION.to_owned()))
.build()
.unwrap();
let zksolc_manager = setup_zksolc_manager(DEFAULT_ZKSOLC_VERSION.to_owned())?;

let zksolc_opts = ZkSolcOpts {
compiler_path: zksolc_manager.get_full_compiler_path(),
Expand All @@ -180,7 +177,10 @@ impl TestArgs {
};

let mut zksolc = ZkSolc::new(zksolc_opts, project);
let output = zksolc.compile().unwrap();
let output = match zksolc.compile() {
Ok(compiled) => compiled,
Err(e) => return Err(eyre::eyre!("Failed to compile with zksolc: {}", e)),
};

let test_options: TestOptions = TestOptionsBuilder::default()
.fuzz(config.fuzz)
Expand Down

0 comments on commit cf104db

Please sign in to comment.