Skip to content

Commit

Permalink
address foundry-rs#7244
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Mar 2, 2024
1 parent 2a8f624 commit 6b09401
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
12 changes: 9 additions & 3 deletions crates/forge/bin/cmd/script/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use foundry_common::{
ContractsByArtifact,
};
use foundry_compilers::{
artifacts::{ContractBytecode, ContractBytecodeSome, Libraries},
artifacts::{BytecodeObject, ContractBytecode, ContractBytecodeSome, Libraries},
cache::SolFilesCache,
contracts::ArtifactContracts,
info::ContractInfo,
Expand Down Expand Up @@ -81,8 +81,14 @@ impl PreprocessedState {
if id.name != *name {
continue;
}
} else if !contract.bytecode.as_ref().map_or(false, |b| b.object.bytes_len() > 0) {
// Ignore contracts with empty/missing bytecode, e.g. interfaces.
} else if contract.abi.as_ref().map_or(true, |abi| abi.is_empty()) ||
contract.bytecode.as_ref().map_or(true, |b| match &b.object {
BytecodeObject::Bytecode(b) => b.is_empty(),
BytecodeObject::Unlinked(_) => false,
})
{
// Ignore contracts with empty abi or linked bytecode of length 0 which are
// interfaces/abstract contracts/libraries.
continue;
}

Expand Down
5 changes: 3 additions & 2 deletions crates/forge/bin/cmd/script/simulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ use std::{
};

impl PreSimulationState {
/// If simulation is enabled, simulates transactions against fork and fills gas estimation and metadata.
/// Otherwise, metadata (e.g. additional contracts, created contract names) is left empty.
/// If simulation is enabled, simulates transactions against fork and fills gas estimation and
/// metadata. Otherwise, metadata (e.g. additional contracts, created contract names) is
/// left empty.
pub async fn fill_metadata(self) -> Result<FilledTransactionsState> {
let transactions = if let Some(txs) = self.execution_result.transactions.as_ref() {
if self.args.skip_simulation {
Expand Down
22 changes: 22 additions & 0 deletions crates/forge/tests/cli/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,28 @@ interface Interface {}
assert!(cmd.stdout_lossy().contains("Script ran successfully."));
});

forgetest_async!(assert_can_detect_unlinked_target_with_libraries, |prj, cmd| {
let script = prj
.add_script(
"ScriptWithExtLib.s.sol",
r#"
library Lib {
function f() public {}
}
contract Script {
function run() external {
Lib.f();
}
}
"#,
)
.unwrap();

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

forgetest_async!(assert_can_resume_with_additional_contracts, |prj, cmd| {
let (_api, handle) = spawn(NodeConfig::test()).await;
let mut tester = ScriptTester::new_broadcast(cmd, &handle.http_endpoint(), prj.root());
Expand Down

0 comments on commit 6b09401

Please sign in to comment.