Skip to content

Commit

Permalink
🚸 script: ignore interfaces when inferring target
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzdanilo committed Nov 8, 2023
1 parent 855d005 commit 2802b60
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/forge/bin/cmd/script/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,13 @@ impl ScriptArgs {

// if it's the target contract, grab the info
if extra.no_target_name {
if id.source == std::path::PathBuf::from(&extra.target_fname) {
// Match artifact source, and ignore interfaces
if id.source == std::path::PathBuf::from(&extra.target_fname) &&
match contract.bytecode.as_ref() {
Some(bytecode) => bytecode.object.bytes_len() > 0,
None => false,
}
{
if extra.matched {
eyre::bail!("Multiple contracts in the target path. Please specify the contract name with `--tc ContractName`")
}
Expand Down
21 changes: 21 additions & 0 deletions crates/forge/tests/cli/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,3 +1108,24 @@ contract NestedCreateFail is Script {
cmd.arg("script").arg(script).args(["--tc", "NestedCreateFail"]);
assert!(cmd.stdout_lossy().contains("Script ran successfully."));
});

forgetest_async!(assert_can_detect_target_contract_with_interfaces, |prj, cmd| {
let script = prj
.inner()
.add_script(
"ScriptWithInterface.s.sol",
r#"
pragma solidity ^0.8.22;
contract Script {
function run() external {}
}
interface Interface {}
"#,
)
.unwrap();

cmd.arg("script").arg(script);
assert!(cmd.stdout_lossy().contains("Script ran successfully."));
});

0 comments on commit 2802b60

Please sign in to comment.