Skip to content

Commit

Permalink
Adding a test that proves this works now
Browse files Browse the repository at this point in the history
  • Loading branch information
MBerguer committed Jan 24, 2025
1 parent ba1e537 commit d6401ec
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 4 deletions.
2 changes: 0 additions & 2 deletions crates/config/src/zksync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,6 @@ mod tests {
use foundry_compilers::solc::SolcCompiler;
use semver::Version;

use crate::Config;

use super::*;

#[test]
Expand Down
17 changes: 17 additions & 0 deletions crates/forge/tests/it/zk/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// test that checks that you have to recompile the project if the zksolc version changes (the
// cache is invalidated)
#[test]
fn zksync_project_has_zksync_solc_when_solc_req_is_a_version_and_zksolc_version_changes() {
let zk_config = zk_config();

let config =
Config { zksolc: Some(SolcReq::Version(Version::new(0, 8, 26))), ..Default::default() };
let project = config_create_project(&config, false, true).unwrap();
let solc_compiler = project.compiler.solc;
if let SolcCompiler::Specific(path) = solc_compiler {
let version = get_solc_version_info(&path.solc).unwrap();
assert!(version.zksync_version.is_some());
} else {
panic!("Expected SolcCompiler::Specific");
}
}
49 changes: 47 additions & 2 deletions crates/forge/tests/it/zk/linking.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use foundry_test_utils::{forgetest_async, util, TestProject};

use crate::test_helpers::{deploy_zk_contract, run_zk_script_test};
use foundry_test_utils::{forgetest_async, util, TestProject};

// TODO(zk): add test that actually does the deployment
// of the unlinked contract via script, once recursive linking is supported
Expand Down Expand Up @@ -53,3 +52,49 @@ fn setup_libs_prj(prj: &mut TestProject) {
)
.unwrap();
}

// test that checks that you have to recompile the project if the zksolc version changes (the
// cache is invalidated)
// step 1, create a config with a specific zksolc version i.e 1.5.6
// step 2, create a project with the config
// compile the project
// check that output contains the zksolc version 1.5.6
// step 3, create a new config with a different zksolc version i.e 1.5.7
// step 4, create a project with the new config
// compile the project
// check that output contains the zksolc version 1.5.7 (demonstrating that the cache was
// invalidated, and the project was recompiled) compile the project again,
// check the output once more it should say that the cache is ok
// forgetest_async!(
// zksync_project_has_zksync_solc_when_solc_req_is_a_version_and_zksolc_version_changes,
// |prj, cmd| {
// let mut zk_config = ForgeTestProfile::Default.zk_config();

// let project = config_create_project(&zk_config, false, true).unwrap();

// let version = get_solc_version_info(&path.solc).unwrap();
// assert!(version.zksync_version.is_some());
// assert_eq!(version.zksync_version.unwrap(), Version::new(1, 5, 6));

// zk_config.zksync.zksolc = Some(SolcReq::Version(Version::new(1, 5, 7)));
// let project = config_create_project(&zk_config, false, true).unwrap();
// let solc_compiler = project.compiler.solc;
// if let SolcCompiler::Specific(path) = solc_compiler {
// let version = get_solc_version_info(&path.solc).unwrap();
// assert!(version.zksync_version.is_some());
// assert_eq!(version.zksync_version.unwrap(), Version::new(1, 5, 7));
// } else {
// panic!("Expected SolcCompiler::Specific");
// }

// let project = config_create_project(&zk_config, false, true).unwrap();
// let solc_compiler = project.compiler.solc;
// if let SolcCompiler::Specific(path) = solc_compiler {
// let version = get_solc_version_info(&path.solc).unwrap();
// assert!(version.zksync_version.is_some());
// assert_eq!(version.zksync_version.unwrap(), Version::new(1, 5, 7));
// } else {
// panic!("Expected SolcCompiler::Specific");
// }
// }
// );
58 changes: 58 additions & 0 deletions crates/zksync/compilers/tests/zksync_tests.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use core::{assert_eq, assert_ne};
use std::{
collections::{HashMap, HashSet},
fs,
path::PathBuf,
str::FromStr,
};

use foundry_compilers::solc::Solc;
use foundry_compilers_artifacts_solc::Remapping;
use foundry_test_utils::foundry_compilers::{
buildinfo::BuildInfo, cache::CompilerCache, project_util::*, resolver::parse::SolData,
Expand Down Expand Up @@ -654,3 +656,59 @@ fn zksync_can_compile_yul_sample() {

assert!(!yul_bytecode.is_empty(), "SimpleStore bytecode is empty");
}

// Test that checks that you have to recompile the project if the zksolc version changes (the
// cache is invalidated)
#[test]
fn zksync_detects_change_on_cache_if_zksolc_version_changes() {
let mut project = TempProject::<ZkSolcCompiler, ZkArtifactOutput>::dapptools().unwrap();
let solc =
Solc::find_or_install(&semver::Version::new(0, 8, 19)).expect("could not install solc");

project.project_mut().build_info = true;
project
.add_source(
"A",
r#"
pragma solidity ^0.8.10;
import "./B.sol";
contract A { }
"#,
)
.unwrap();

project
.add_source(
"B",
r"
pragma solidity ^0.8.10;
contract B { }
",
)
.unwrap();

let config_1_5_6 = ZkSolcCompiler {
zksolc: ZkSolc::get_path_for_version(&semver::Version::new(1, 5, 0)).unwrap(),
solc: foundry_compilers::solc::SolcCompiler::Specific(solc),
};
project.project_mut().compiler = config_1_5_6;

let compiled_1 = project.compile().unwrap();
compiled_1.assert_success();

let cache = CompilerCache::<ZkSolcSettings>::read(project.cache_path()).unwrap();

let config_1_5_7 = ZkSolcCompiler {
zksolc: ZkSolc::get_path_for_version(&semver::Version::new(1, 5, 10)).unwrap(),
solc: Default::default(),
};
project.project_mut().compiler = config_1_5_7;

let compiled_2 = project.compile().unwrap();

assert!(!compiled_2.is_unchanged());

let latest_cache = CompilerCache::<ZkSolcSettings>::read(project.cache_path()).unwrap();

assert_ne!(cache, latest_cache);
}

0 comments on commit d6401ec

Please sign in to comment.