Skip to content

Commit d6401ec

Browse files
committed
Adding a test that proves this works now
1 parent ba1e537 commit d6401ec

File tree

4 files changed

+122
-4
lines changed

4 files changed

+122
-4
lines changed

crates/config/src/zksync.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,6 @@ mod tests {
347347
use foundry_compilers::solc::SolcCompiler;
348348
use semver::Version;
349349

350-
use crate::Config;
351-
352350
use super::*;
353351

354352
#[test]

crates/forge/tests/it/zk/config.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// test that checks that you have to recompile the project if the zksolc version changes (the
2+
// cache is invalidated)
3+
#[test]
4+
fn zksync_project_has_zksync_solc_when_solc_req_is_a_version_and_zksolc_version_changes() {
5+
let zk_config = zk_config();
6+
7+
let config =
8+
Config { zksolc: Some(SolcReq::Version(Version::new(0, 8, 26))), ..Default::default() };
9+
let project = config_create_project(&config, false, true).unwrap();
10+
let solc_compiler = project.compiler.solc;
11+
if let SolcCompiler::Specific(path) = solc_compiler {
12+
let version = get_solc_version_info(&path.solc).unwrap();
13+
assert!(version.zksync_version.is_some());
14+
} else {
15+
panic!("Expected SolcCompiler::Specific");
16+
}
17+
}

crates/forge/tests/it/zk/linking.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use foundry_test_utils::{forgetest_async, util, TestProject};
2-
31
use crate::test_helpers::{deploy_zk_contract, run_zk_script_test};
2+
use foundry_test_utils::{forgetest_async, util, TestProject};
43

54
// TODO(zk): add test that actually does the deployment
65
// of the unlinked contract via script, once recursive linking is supported
@@ -53,3 +52,49 @@ fn setup_libs_prj(prj: &mut TestProject) {
5352
)
5453
.unwrap();
5554
}
55+
56+
// test that checks that you have to recompile the project if the zksolc version changes (the
57+
// cache is invalidated)
58+
// step 1, create a config with a specific zksolc version i.e 1.5.6
59+
// step 2, create a project with the config
60+
// compile the project
61+
// check that output contains the zksolc version 1.5.6
62+
// step 3, create a new config with a different zksolc version i.e 1.5.7
63+
// step 4, create a project with the new config
64+
// compile the project
65+
// check that output contains the zksolc version 1.5.7 (demonstrating that the cache was
66+
// invalidated, and the project was recompiled) compile the project again,
67+
// check the output once more it should say that the cache is ok
68+
// forgetest_async!(
69+
// zksync_project_has_zksync_solc_when_solc_req_is_a_version_and_zksolc_version_changes,
70+
// |prj, cmd| {
71+
// let mut zk_config = ForgeTestProfile::Default.zk_config();
72+
73+
// let project = config_create_project(&zk_config, false, true).unwrap();
74+
75+
// let version = get_solc_version_info(&path.solc).unwrap();
76+
// assert!(version.zksync_version.is_some());
77+
// assert_eq!(version.zksync_version.unwrap(), Version::new(1, 5, 6));
78+
79+
// zk_config.zksync.zksolc = Some(SolcReq::Version(Version::new(1, 5, 7)));
80+
// let project = config_create_project(&zk_config, false, true).unwrap();
81+
// let solc_compiler = project.compiler.solc;
82+
// if let SolcCompiler::Specific(path) = solc_compiler {
83+
// let version = get_solc_version_info(&path.solc).unwrap();
84+
// assert!(version.zksync_version.is_some());
85+
// assert_eq!(version.zksync_version.unwrap(), Version::new(1, 5, 7));
86+
// } else {
87+
// panic!("Expected SolcCompiler::Specific");
88+
// }
89+
90+
// let project = config_create_project(&zk_config, false, true).unwrap();
91+
// let solc_compiler = project.compiler.solc;
92+
// if let SolcCompiler::Specific(path) = solc_compiler {
93+
// let version = get_solc_version_info(&path.solc).unwrap();
94+
// assert!(version.zksync_version.is_some());
95+
// assert_eq!(version.zksync_version.unwrap(), Version::new(1, 5, 7));
96+
// } else {
97+
// panic!("Expected SolcCompiler::Specific");
98+
// }
99+
// }
100+
// );

crates/zksync/compilers/tests/zksync_tests.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
use core::{assert_eq, assert_ne};
12
use std::{
23
collections::{HashMap, HashSet},
34
fs,
45
path::PathBuf,
56
str::FromStr,
67
};
78

9+
use foundry_compilers::solc::Solc;
810
use foundry_compilers_artifacts_solc::Remapping;
911
use foundry_test_utils::foundry_compilers::{
1012
buildinfo::BuildInfo, cache::CompilerCache, project_util::*, resolver::parse::SolData,
@@ -654,3 +656,59 @@ fn zksync_can_compile_yul_sample() {
654656

655657
assert!(!yul_bytecode.is_empty(), "SimpleStore bytecode is empty");
656658
}
659+
660+
// Test that checks that you have to recompile the project if the zksolc version changes (the
661+
// cache is invalidated)
662+
#[test]
663+
fn zksync_detects_change_on_cache_if_zksolc_version_changes() {
664+
let mut project = TempProject::<ZkSolcCompiler, ZkArtifactOutput>::dapptools().unwrap();
665+
let solc =
666+
Solc::find_or_install(&semver::Version::new(0, 8, 19)).expect("could not install solc");
667+
668+
project.project_mut().build_info = true;
669+
project
670+
.add_source(
671+
"A",
672+
r#"
673+
pragma solidity ^0.8.10;
674+
import "./B.sol";
675+
contract A { }
676+
"#,
677+
)
678+
.unwrap();
679+
680+
project
681+
.add_source(
682+
"B",
683+
r"
684+
pragma solidity ^0.8.10;
685+
contract B { }
686+
",
687+
)
688+
.unwrap();
689+
690+
let config_1_5_6 = ZkSolcCompiler {
691+
zksolc: ZkSolc::get_path_for_version(&semver::Version::new(1, 5, 0)).unwrap(),
692+
solc: foundry_compilers::solc::SolcCompiler::Specific(solc),
693+
};
694+
project.project_mut().compiler = config_1_5_6;
695+
696+
let compiled_1 = project.compile().unwrap();
697+
compiled_1.assert_success();
698+
699+
let cache = CompilerCache::<ZkSolcSettings>::read(project.cache_path()).unwrap();
700+
701+
let config_1_5_7 = ZkSolcCompiler {
702+
zksolc: ZkSolc::get_path_for_version(&semver::Version::new(1, 5, 10)).unwrap(),
703+
solc: Default::default(),
704+
};
705+
project.project_mut().compiler = config_1_5_7;
706+
707+
let compiled_2 = project.compile().unwrap();
708+
709+
assert!(!compiled_2.is_unchanged());
710+
711+
let latest_cache = CompilerCache::<ZkSolcSettings>::read(project.cache_path()).unwrap();
712+
713+
assert_ne!(cache, latest_cache);
714+
}

0 commit comments

Comments
 (0)