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

🚸 script: ignore interfaces when inferring target #6246

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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,
}
{
cruzdanilo marked this conversation as resolved.
Show resolved Hide resolved
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."));
});
Loading