Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(chisel): determine proper path to Vm.sol based on proj remappings #9703

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/chisel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ time = { version = "0.3", features = ["formatting"] }
tokio = { workspace = true, features = ["full"] }
yansi.workspace = true
tracing.workspace = true
walkdir.workspace = true

[target.'cfg(unix)'.dependencies]
tikv-jemallocator = { workspace = true, optional = true }
Expand Down
30 changes: 21 additions & 9 deletions crates/chisel/src/session_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use semver::Version;
use serde::{Deserialize, Serialize};
use solang_parser::{diagnostics::Diagnostic, pt};
use std::{fs, path::PathBuf};
use walkdir::WalkDir;
use yansi::Paint;

/// The minimum Solidity version of the `Vm` interface.
Expand Down Expand Up @@ -466,15 +467,26 @@ contract {contract_name} is Script {{
pub fn to_repl_source(&self) -> String {
let Version { major, minor, patch, .. } = self.solc.version;
let Self { contract_name, global_code, top_level_code, run_code, config, .. } = self;

let (vm_import, vm_constant) = if !config.no_vm {
(
"import {Vm} from \"forge-std/Vm.sol\";\n",
"Vm internal constant vm = Vm(address(uint160(uint256(keccak256(\"hevm cheat code\")))));\n"
)
} else {
("", "")
};
let (mut vm_import, mut vm_constant) = (String::new(), String::new());
if !config.no_vm {
// Check if there's any `forge-std` remapping and determine proper path to it by
// searching remapping path.
if let Some(remapping) = config
.foundry_config
.remappings
.iter()
.find(|remapping| remapping.name == "forge-std/")
{
if let Some(vm_path) = WalkDir::new(&remapping.path.path)
.into_iter()
.filter_map(|e| e.ok())
.find(|e| e.file_name() == "Vm.sol")
{
vm_import = format!("import {{Vm}} from \"{}\";\n", vm_path.path().display());
vm_constant = "Vm internal constant vm = Vm(address(uint160(uint256(keccak256(\"hevm cheat code\")))));\n".to_string();
}
}
}

format!(
r#"
Expand Down
Loading