Skip to content

Commit

Permalink
fix(script): correctly detect additional contracts (#9207)
Browse files Browse the repository at this point in the history
* add test

* fix(script): correctly detect additional contracts

* fix
  • Loading branch information
klkvr authored Oct 27, 2024
1 parent 3b0c75d commit 513ed69
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
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/forge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ foundry-config.workspace = true
foundry-evm.workspace = true
foundry-wallets.workspace = true
foundry-linking.workspace = true
forge-script-sequence.workspace = true

ethers-contract-abigen = { workspace = true, features = ["providers"] }

Expand Down
48 changes: 48 additions & 0 deletions crates/forge/tests/cli/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::constants::TEMPLATE_CONTRACT;
use alloy_primitives::{hex, Address, Bytes};
use anvil::{spawn, NodeConfig};
use forge_script_sequence::ScriptSequence;
use foundry_test_utils::{
rpc,
util::{OTHER_SOLC_VERSION, SOLC_VERSION},
Expand Down Expand Up @@ -2269,3 +2270,50 @@ backend: failed while inspecting; header validation error: `prevrandao` not set;
"#]]);
});

forgetest_async!(should_detect_additional_contracts, |prj, cmd| {
let (_api, handle) = spawn(NodeConfig::test()).await;

foundry_test_utils::util::initialize(prj.root());
prj.add_source(
"Foo",
r#"
import "forge-std/Script.sol";
contract Simple {}
contract Deployer {
function deploy() public {
new Simple();
}
}
contract ContractScript is Script {
function run() public {
vm.startBroadcast();
Deployer deployer = new Deployer();
deployer.deploy();
}
}
"#,
)
.unwrap();
cmd.arg("script")
.args([
"ContractScript",
"--private-key",
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
"--rpc-url",
&handle.http_endpoint(),
])
.assert_success();

let run_latest = foundry_common::fs::json_files(&prj.root().join("broadcast"))
.find(|file| file.ends_with("run-latest.json"))
.expect("No broadcast artifacts");

let sequence: ScriptSequence = foundry_common::fs::read_json_file(&run_latest).unwrap();

assert_eq!(sequence.transactions.len(), 2);
assert_eq!(sequence.transactions[1].additional_contracts.len(), 1);
});
2 changes: 2 additions & 0 deletions crates/script/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ impl ScriptTransactionBuilder {
self.transaction.contract_address.map_or(true, |addr| addr != contract.address)
});

self.transaction.additional_contracts = created_contracts;

if !self.transaction.is_fixed_gas_limit {
if let Some(unsigned) = self.transaction.transaction.as_unsigned_mut() {
// We inflate the gas used by the user specified percentage
Expand Down

0 comments on commit 513ed69

Please sign in to comment.