Skip to content

Commit

Permalink
Adding the right test
Browse files Browse the repository at this point in the history
  • Loading branch information
MBerguer committed Jan 24, 2025
1 parent d6401ec commit 5fc3aab
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 120 deletions.
71 changes: 71 additions & 0 deletions crates/forge/tests/cli/zk_build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use foundry_common::fs;
use foundry_test_utils::util::OutputExt;
use regex::Regex;

Expand All @@ -11,3 +12,73 @@ forgetest_init!(test_zk_build_sizes, |prj, cmd| {

assert!(pattern.is_match(&stdout), "Unexpected size output:\n{stdout}");
});

// tests build output is as expected in zksync mode
forgetest_init!(test_zk_cache, |prj, cmd| {
let zk_toml = r#"[profile.default]
src = 'src'
out = 'out'
libs = ['lib']
solc = '0.8.26'
[profile.default.zksync]
zksolc = '1.5.6'
"#;

fs::write(prj.root().join("foundry.toml"), zk_toml).unwrap();

cmd.args(["build", "--zksync"]);
let stdout_1 = cmd.assert_success().get_output().stdout_lossy();
let pattern_1 = Regex::new(r"Compiler run successful").unwrap();

let stdout_2 = cmd.assert_success().get_output().stdout_lossy();
let pattern_2 = Regex::new(r"No files changed, compilation skipped").unwrap();

assert!(pattern_1.is_match(&stdout_1));
assert!(pattern_2.is_match(&stdout_2));

// assert!(pattern.is_match(&stdout), "Unexpected size output:\n{stdout}");
});

// tests build output is as expected in zksync mode
forgetest_init!(test_zk_cache_invalid_on_version_changed, |prj, cmd| {
let template_toml = r#"[profile.default]
src = 'src'
out = 'out'
libs = ['lib']
solc = '0.8.26'
[profile.default.zksync]
"#;

let toml_156 = format!(
r#"{}
zksolc = '1.5.6'
"#,
template_toml
);

let toml_157 = format!(
r#"{}
zksolc = '1.5.7'
"#,
template_toml
);

fs::write(prj.root().join("foundry.toml"), toml_156).unwrap();

cmd.args(["build", "--zksync"]);
let stdout_1 = cmd.assert_success().get_output().stdout_lossy();
let pattern_1 = Regex::new(r"Compiler run successful").unwrap();

fs::remove_file(prj.root().join("foundry.toml")).unwrap();
fs::write(prj.root().join("foundry.toml"), toml_157).unwrap();

let stdout_2 = cmd.assert_success().get_output().stdout_lossy();
let pattern_2 = Regex::new(r"Compiler run successful!").unwrap(); // if we see this, means the cache was invalidated

assert!(pattern_1.is_match(&stdout_1));
assert!(pattern_2.is_match(&stdout_2));

// assert!(pattern.is_match(&stdout), "Unexpected size output:\n{stdout}");
});
17 changes: 0 additions & 17 deletions crates/forge/tests/it/zk/config.rs

This file was deleted.

46 changes: 0 additions & 46 deletions crates/forge/tests/it/zk/linking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,49 +52,3 @@ 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");
// }
// }
// );
57 changes: 0 additions & 57 deletions crates/zksync/compilers/tests/zksync_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::{
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 @@ -656,59 +655,3 @@ 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 5fc3aab

Please sign in to comment.