From c04d49e145a3924eb7305b115b90a28b3c2d8a87 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:45:16 +0100 Subject: [PATCH 1/4] test: manually add install commands --- crates/forge/tests/cli/ext_integration.rs | 15 +++- crates/test-utils/src/util.rs | 101 +++++++++------------- 2 files changed, 54 insertions(+), 62 deletions(-) diff --git a/crates/forge/tests/cli/ext_integration.rs b/crates/forge/tests/cli/ext_integration.rs index f0044848a198..25fbfc3598af 100644 --- a/crates/forge/tests/cli/ext_integration.rs +++ b/crates/forge/tests/cli/ext_integration.rs @@ -8,13 +8,17 @@ fn solmate() { #[test] #[cfg_attr(windows, ignore = "Windows cannot find installed programs")] fn prb_math() { - ExtTester::new("PaulRBerg", "prb-math", "5b6279a0cf7c1b1b6a5cc96082811f7ef620cf60").run(); + ExtTester::new("PaulRBerg", "prb-math", "5b6279a0cf7c1b1b6a5cc96082811f7ef620cf60") + .install_command(&["bun", "install", "--prefer-offline"]) + .run(); } #[test] #[cfg_attr(windows, ignore = "Windows cannot find installed programs")] fn prb_proxy() { - ExtTester::new("PaulRBerg", "prb-proxy", "fa13cf09fbf544a2d575b45884b8e94a79a02c06").run(); + ExtTester::new("PaulRBerg", "prb-proxy", "fa13cf09fbf544a2d575b45884b8e94a79a02c06") + .install_command(&["bun", "install", "--prefer-offline"]) + .run(); } #[test] @@ -25,6 +29,7 @@ fn sablier_v2() { .args(["--nmc", "Fork"]) // run tests without optimizations .env("FOUNDRY_PROFILE", "lite") + .install_command(&["bun", "install", "--prefer-offline"]) .run(); } @@ -49,7 +54,9 @@ fn stringutils() { #[test] fn lootloose() { - ExtTester::new("gakonst", "lootloose", "7b639efe97836155a6a6fc626bf1018d4f8b2495").run(); + ExtTester::new("gakonst", "lootloose", "7b639efe97836155a6a6fc626bf1018d4f8b2495") + .install_command(&["make", "install"]) + .run(); } #[test] @@ -93,7 +100,7 @@ fn gunilev() { } #[test] -fn convex() { +fn convex_shutdown_simulation() { ExtTester::new( "mds1", "convex-shutdown-simulation", diff --git a/crates/test-utils/src/util.rs b/crates/test-utils/src/util.rs index beed4498b8b0..eddbe8f33aa2 100644 --- a/crates/test-utils/src/util.rs +++ b/crates/test-utils/src/util.rs @@ -60,6 +60,7 @@ pub struct ExtTester { pub fork_block: Option, pub args: Vec, pub envs: Vec<(String, String)>, + pub install_command: Vec, } impl ExtTester { @@ -73,6 +74,7 @@ impl ExtTester { fork_block: None, args: vec![], envs: vec![], + install_command: vec![], } } @@ -121,6 +123,15 @@ impl ExtTester { self } + /// Adds a command to run after the project is cloned. + /// + /// Note that the command is run in the project's root directory, and it won't fail the test if + /// it fails. + pub fn install_command(mut self, command: &[&str]) -> Self { + self.install_command.extend(command.iter().map(|s| s.to_string())); + self + } + /// Runs the test. pub fn run(&self) { // Skip fork tests if the RPC url is not set. @@ -129,7 +140,7 @@ impl ExtTester { return; } - let (prj, mut cmd) = setup_forge(self.name, self.style.clone()); + let (prj, mut test_cmd) = setup_forge(self.name, self.style.clone()); // Wipe the default structure. prj.wipe(); @@ -141,10 +152,10 @@ impl ExtTester { // Checkout the revision. if self.rev.is_empty() { - let mut cmd = Command::new("git"); - cmd.current_dir(root).args(["log", "-n", "1"]); - eprintln!("$ {cmd:?}"); - let output = cmd.output().unwrap(); + let mut git = Command::new("git"); + git.current_dir(root).args(["log", "-n", "1"]); + eprintln!("$ {git:?}"); + let output = git.output().unwrap(); if !output.status.success() { panic!("git log failed: {output:?}"); } @@ -152,31 +163,44 @@ impl ExtTester { let commit = stdout.lines().next().unwrap().split_whitespace().nth(1).unwrap(); panic!("pin to latest commit: {commit}"); } else { - let mut cmd = Command::new("git"); - cmd.current_dir(root).args(["checkout", self.rev]); - eprintln!("$ {cmd:?}"); - let status = cmd.status().unwrap(); + let mut git = Command::new("git"); + git.current_dir(root).args(["checkout", self.rev]); + eprintln!("$ {git:?}"); + let status = git.status().unwrap(); if !status.success() { panic!("git checkout failed: {status}"); } } - // Run common installation commands. - run_install_commands(prj.root()); + // Run installation command. + if !self.install_command.is_empty() { + let mut install_cmd = Command::new(&self.install_command[0]); + install_cmd.args(&self.install_command[1..]).current_dir(root); + eprintln!("cd {root}; {install_cmd:?}"); + match install_cmd.status() { + Ok(s) => { + eprintln!("\n\n{install_cmd:?}: {s}"); + } + Err(e) => { + eprintln!("\n\n{install_cmd:?}: {e}"); + } + } + } // Run the tests. - cmd.arg("test"); - cmd.args(&self.args); - cmd.args(["--fuzz-runs=256", "--ffi", "-vvvvv"]); + test_cmd.arg("test"); + test_cmd.args(&self.args); + test_cmd.args(["--fuzz-runs=256", "--ffi", "-vvvvv"]); - cmd.envs(self.envs.iter().map(|(k, v)| (k, v))); - cmd.env("FOUNDRY_FUZZ_RUNS", "1"); + test_cmd.envs(self.envs.iter().map(|(k, v)| (k, v))); + test_cmd.env("FOUNDRY_FUZZ_RUNS", "1"); if let Some(fork_block) = self.fork_block { - cmd.env("FOUNDRY_ETH_RPC_URL", foundry_common::rpc::next_http_archive_rpc_endpoint()); - cmd.env("FOUNDRY_FORK_BLOCK_NUMBER", fork_block.to_string()); + test_cmd + .env("FOUNDRY_ETH_RPC_URL", foundry_common::rpc::next_http_archive_rpc_endpoint()); + test_cmd.env("FOUNDRY_FORK_BLOCK_NUMBER", fork_block.to_string()); } - cmd.assert_non_empty_stdout(); + test_cmd.assert_non_empty_stdout(); } } @@ -252,45 +276,6 @@ pub fn clone_remote(repo_url: &str, target_dir: &str) { eprintln!(); } -/// Runs common installation commands, such as `make` and `npm`. Continues if any command fails. -pub fn run_install_commands(root: &Path) { - let root_files = - std::fs::read_dir(root).unwrap().flatten().map(|x| x.path()).collect::>(); - let contains = |path: &str| root_files.iter().any(|p| p.to_str().unwrap().contains(path)); - let run = |args: &[&str]| { - let mut cmd = Command::new(args[0]); - cmd.args(&args[1..]).current_dir(root); - eprintln!("cd {}; {cmd:?}", root.display()); - match cmd.status() { - Ok(s) => { - eprintln!("\n\n{cmd:?}: {s}"); - s.success() - } - Err(e) => { - eprintln!("\n\n{cmd:?}: {e}"); - false - } - } - }; - let maybe_run = |path: &str, args: &[&str]| { - if contains(path) { - run(args) - } else { - false - } - }; - - maybe_run("Makefile", &["make", "install"]); - - // Only run one of these for `node_modules`. - let mut nm = false; - nm = nm || maybe_run("bun.lockb", &["bun", "install", "--prefer-offline"]); - nm = nm || maybe_run("pnpm-lock.yaml", &["pnpm", "install", "--prefer-offline"]); - nm = nm || maybe_run("yarn.lock", &["yarn", "install", "--prefer-offline"]); - nm = nm || maybe_run("package.json", &["npm", "install", "--prefer-offline"]); - let _ = nm; -} - /// Setup an empty test project and return a command pointing to the forge /// executable whose CWD is set to the project's root. /// From 5d77ca05dad6d60036875d561628bda6764a406c Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:56:17 +0100 Subject: [PATCH 2/4] test: npm i in snekmate --- crates/forge/tests/cli/ext_integration.rs | 6 +++++- crates/test-utils/src/util.rs | 17 ++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/crates/forge/tests/cli/ext_integration.rs b/crates/forge/tests/cli/ext_integration.rs index 25fbfc3598af..94cf5f548733 100644 --- a/crates/forge/tests/cli/ext_integration.rs +++ b/crates/forge/tests/cli/ext_integration.rs @@ -67,7 +67,11 @@ fn lil_web3() { #[test] #[cfg_attr(windows, ignore = "Windows cannot find installed programs")] fn snekmate() { - ExtTester::new("pcaversaccio", "snekmate", "ed49a0454393673cdf9a4250dd7051c28e6ac35f").run(); + ExtTester::new("pcaversaccio", "snekmate", "ed49a0454393673cdf9a4250dd7051c28e6ac35f") + .install_command(&["pnpm", "install", "--prefer-offline"]) + // Try npm if pnpm fails / is not installed + .install_command(&["npm", "install", "--prefer-offline"]) + .run(); } #[test] diff --git a/crates/test-utils/src/util.rs b/crates/test-utils/src/util.rs index eddbe8f33aa2..20790743041d 100644 --- a/crates/test-utils/src/util.rs +++ b/crates/test-utils/src/util.rs @@ -60,7 +60,7 @@ pub struct ExtTester { pub fork_block: Option, pub args: Vec, pub envs: Vec<(String, String)>, - pub install_command: Vec, + pub install_commands: Vec>, } impl ExtTester { @@ -74,7 +74,7 @@ impl ExtTester { fork_block: None, args: vec![], envs: vec![], - install_command: vec![], + install_commands: vec![], } } @@ -128,7 +128,7 @@ impl ExtTester { /// Note that the command is run in the project's root directory, and it won't fail the test if /// it fails. pub fn install_command(mut self, command: &[&str]) -> Self { - self.install_command.extend(command.iter().map(|s| s.to_string())); + self.install_commands.push(command.iter().map(|s| s.to_string()).collect()); self } @@ -173,16 +173,19 @@ impl ExtTester { } // Run installation command. - if !self.install_command.is_empty() { - let mut install_cmd = Command::new(&self.install_command[0]); - install_cmd.args(&self.install_command[1..]).current_dir(root); + for install_command in &self.install_commands { + let mut install_cmd = Command::new(&install_command[0]); + install_cmd.args(&install_command[1..]).current_dir(root); eprintln!("cd {root}; {install_cmd:?}"); match install_cmd.status() { Ok(s) => { eprintln!("\n\n{install_cmd:?}: {s}"); + if s.success() { + break; + } } Err(e) => { - eprintln!("\n\n{install_cmd:?}: {e}"); + eprintln!("\n\n{install_cmd:?}: {e}") } } } From 941b0e6eeac045ee2b7a086987a77d5047de2e53 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:58:21 +0100 Subject: [PATCH 3/4] test: npm if bun is not installed --- crates/forge/tests/cli/ext_integration.rs | 6 ++++++ crates/test-utils/src/util.rs | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/forge/tests/cli/ext_integration.rs b/crates/forge/tests/cli/ext_integration.rs index 94cf5f548733..8ea33bf98974 100644 --- a/crates/forge/tests/cli/ext_integration.rs +++ b/crates/forge/tests/cli/ext_integration.rs @@ -10,6 +10,8 @@ fn solmate() { fn prb_math() { ExtTester::new("PaulRBerg", "prb-math", "5b6279a0cf7c1b1b6a5cc96082811f7ef620cf60") .install_command(&["bun", "install", "--prefer-offline"]) + // Try npm if bun fails / is not installed + .install_command(&["npm", "install", "--prefer-offline"]) .run(); } @@ -18,6 +20,8 @@ fn prb_math() { fn prb_proxy() { ExtTester::new("PaulRBerg", "prb-proxy", "fa13cf09fbf544a2d575b45884b8e94a79a02c06") .install_command(&["bun", "install", "--prefer-offline"]) + // Try npm if bun fails / is not installed + .install_command(&["npm", "install", "--prefer-offline"]) .run(); } @@ -30,6 +34,8 @@ fn sablier_v2() { // run tests without optimizations .env("FOUNDRY_PROFILE", "lite") .install_command(&["bun", "install", "--prefer-offline"]) + // Try npm if bun fails / is not installed + .install_command(&["npm", "install", "--prefer-offline"]) .run(); } diff --git a/crates/test-utils/src/util.rs b/crates/test-utils/src/util.rs index 20790743041d..785fa133dd88 100644 --- a/crates/test-utils/src/util.rs +++ b/crates/test-utils/src/util.rs @@ -184,9 +184,7 @@ impl ExtTester { break; } } - Err(e) => { - eprintln!("\n\n{install_cmd:?}: {e}") - } + Err(e) => eprintln!("\n\n{install_cmd:?}: {e}"), } } From 247f81581ecf0f46cbcf3939b8f7c786003d1f2b Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Mon, 12 Feb 2024 20:39:23 +0100 Subject: [PATCH 4/4] updatesomestuff --- crates/forge/tests/cli/ext_integration.rs | 16 +++++++--------- crates/test-utils/src/util.rs | 9 +++++---- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/crates/forge/tests/cli/ext_integration.rs b/crates/forge/tests/cli/ext_integration.rs index 8ea33bf98974..76c497837be3 100644 --- a/crates/forge/tests/cli/ext_integration.rs +++ b/crates/forge/tests/cli/ext_integration.rs @@ -10,7 +10,7 @@ fn solmate() { fn prb_math() { ExtTester::new("PaulRBerg", "prb-math", "5b6279a0cf7c1b1b6a5cc96082811f7ef620cf60") .install_command(&["bun", "install", "--prefer-offline"]) - // Try npm if bun fails / is not installed + // Try npm if bun fails / is not installed. .install_command(&["npm", "install", "--prefer-offline"]) .run(); } @@ -20,7 +20,7 @@ fn prb_math() { fn prb_proxy() { ExtTester::new("PaulRBerg", "prb-proxy", "fa13cf09fbf544a2d575b45884b8e94a79a02c06") .install_command(&["bun", "install", "--prefer-offline"]) - // Try npm if bun fails / is not installed + // Try npm if bun fails / is not installed. .install_command(&["npm", "install", "--prefer-offline"]) .run(); } @@ -29,12 +29,12 @@ fn prb_proxy() { #[cfg_attr(windows, ignore = "Windows cannot find installed programs")] fn sablier_v2() { ExtTester::new("sablier-labs", "v2-core", "84758a40077bf3ccb1c8f7bb8d00278e672fbfef") - // skip fork tests + // Skip fork tests. .args(["--nmc", "Fork"]) - // run tests without optimizations + // Run tests without optimizations. .env("FOUNDRY_PROFILE", "lite") .install_command(&["bun", "install", "--prefer-offline"]) - // Try npm if bun fails / is not installed + // Try npm if bun fails / is not installed. .install_command(&["npm", "install", "--prefer-offline"]) .run(); } @@ -75,16 +75,14 @@ fn lil_web3() { fn snekmate() { ExtTester::new("pcaversaccio", "snekmate", "ed49a0454393673cdf9a4250dd7051c28e6ac35f") .install_command(&["pnpm", "install", "--prefer-offline"]) - // Try npm if pnpm fails / is not installed + // Try npm if pnpm fails / is not installed. .install_command(&["npm", "install", "--prefer-offline"]) .run(); } #[test] fn makerdao_multicall() { - ExtTester::new("makerdao", "multicall", "103a8a28e4e372d582d6539b30031bda4cd48e21") - .args(["--block-number", "1"]) - .run(); + ExtTester::new("makerdao", "multicall", "103a8a28e4e372d582d6539b30031bda4cd48e21").run(); } #[test] diff --git a/crates/test-utils/src/util.rs b/crates/test-utils/src/util.rs index 785fa133dd88..ec54b1ef6c65 100644 --- a/crates/test-utils/src/util.rs +++ b/crates/test-utils/src/util.rs @@ -191,10 +191,9 @@ impl ExtTester { // Run the tests. test_cmd.arg("test"); test_cmd.args(&self.args); - test_cmd.args(["--fuzz-runs=256", "--ffi", "-vvvvv"]); + test_cmd.args(["--fuzz-runs=32", "--ffi", "-vvvvv"]); test_cmd.envs(self.envs.iter().map(|(k, v)| (k, v))); - test_cmd.env("FOUNDRY_FUZZ_RUNS", "1"); if let Some(fork_block) = self.fork_block { test_cmd .env("FOUNDRY_ETH_RPC_URL", foundry_common::rpc::next_http_archive_rpc_endpoint()); @@ -614,7 +613,8 @@ impl TestProject { /// Returns the path to the forge executable. pub fn forge_bin(&self) -> Command { - let forge = self.exe_root.join(format!("../forge{}", env::consts::EXE_SUFFIX)); + let forge = self.exe_root.join("../forge").with_extension(env::consts::EXE_SUFFIX); + let forge = forge.canonicalize().unwrap(); let mut cmd = Command::new(forge); cmd.current_dir(self.inner.root()); // disable color output for comparisons @@ -624,7 +624,8 @@ impl TestProject { /// Returns the path to the cast executable. pub fn cast_bin(&self) -> Command { - let cast = self.exe_root.join(format!("../cast{}", env::consts::EXE_SUFFIX)); + let cast = self.exe_root.join("../cast").with_extension(env::consts::EXE_SUFFIX); + let cast = cast.canonicalize().unwrap(); let mut cmd = Command::new(cast); // disable color output for comparisons cmd.env("NO_COLOR", "1");