diff --git a/crates/common/src/preprocessor/data.rs b/crates/common/src/preprocessor/data.rs index f7a31686e030a..78fe1098fcc56 100644 --- a/crates/common/src/preprocessor/data.rs +++ b/crates/common/src/preprocessor/data.rs @@ -141,13 +141,13 @@ impl ContractData { /// import "lib/openzeppelin-contracts/contracts/token/ERC20.sol"; /// /// abstract contract DeployHelper335 is ERC20 { - /// struct ConstructorArgs { + /// struct FoundryPpConstructorArgs { /// string name; /// string symbol; /// } /// } /// - /// function encodeArgs335(DeployHelper335.ConstructorArgs memory args) pure returns (bytes memory) { + /// function encodeArgs335(DeployHelper335.FoundryPpConstructorArgs memory args) pure returns (bytes memory) { /// return abi.encode(args.name, args.symbol); /// } /// ``` @@ -158,7 +158,7 @@ impl ContractData { /// ``` /// becomes /// ```solidity - /// vm.deployCode("artifact path", encodeArgs335(DeployHelper335.ConstructorArgs(name, symbol))) + /// vm.deployCode("artifact path", encodeArgs335(DeployHelper335.FoundryPpConstructorArgs(name, symbol))) /// ``` /// With named arguments: /// ```solidity @@ -166,7 +166,7 @@ impl ContractData { /// ``` /// becomes /// ```solidity - /// vm.deployCode("artifact path", encodeArgs335(DeployHelper335.ConstructorArgs({name: name, symbol: symbol}))) + /// vm.deployCode("artifact path", encodeArgs335(DeployHelper335.FoundryPpConstructorArgs({name: name, symbol: symbol}))) /// ``` pub fn build_helper(&self) -> Option { let Self { contract_id, path, name, constructor_data, artifact: _ } = self; @@ -183,12 +183,12 @@ pragma solidity >=0.4.0; import "{path}"; abstract contract DeployHelper{contract_id} is {name} {{ - struct ConstructorArgs {{ + struct FoundryPpConstructorArgs {{ {struct_fields}; }} }} -function encodeArgs{contract_id}(DeployHelper{contract_id}.ConstructorArgs memory args) pure returns (bytes memory) {{ +function encodeArgs{contract_id}(DeployHelper{contract_id}.FoundryPpConstructorArgs memory args) pure returns (bytes memory) {{ return abi.encode({abi_encode_args}); }} "#, diff --git a/crates/common/src/preprocessor/deps.rs b/crates/common/src/preprocessor/deps.rs index 2af9d76ba61af..e15e21798e9af 100644 --- a/crates/common/src/preprocessor/deps.rs +++ b/crates/common/src/preprocessor/deps.rs @@ -320,7 +320,7 @@ pub(crate) fn remove_bytecode_dependencies( update.push_str(", "); update.push_str(&format!( - "_args: encodeArgs{id}(DeployHelper{id}.ConstructorArgs", + "_args: encodeArgs{id}(DeployHelper{id}.FoundryPpConstructorArgs", id = dep.referenced_contract.get() )); if *call_args_offset > 0 { diff --git a/crates/forge/tests/cli/test_optimizer.rs b/crates/forge/tests/cli/test_optimizer.rs index ec95aa12c7cac..f5938aeda4873 100644 --- a/crates/forge/tests/cli/test_optimizer.rs +++ b/crates/forge/tests/cli/test_optimizer.rs @@ -1300,3 +1300,48 @@ Compiling 1 files with [..] "#]]); }); + +// +forgetest_init!(preprocess_contract_with_constructor_args_struct, |prj, cmd| { + prj.wipe_contracts(); + prj.update_config(|config| { + config.dynamic_test_linking = true; + }); + + prj.add_source( + "Counter.sol", + r#" +contract Counter { + struct ConstructorArgs { + uint256 _number; + } + + constructor(uint256 no) { + } +} + "#, + ) + .unwrap(); + + prj.add_test( + "Counter.t.sol", + r#" +import {Test} from "forge-std/Test.sol"; +import {Counter} from "../src/Counter.sol"; + +contract CounterTest is Test { + function test_assert_constructor_revert() public { + Counter counter = new Counter(1); + } +} + "#, + ) + .unwrap(); + // All 20 files should properly compile. + cmd.args(["test"]).with_no_redact().assert_success().stdout_eq(str![[r#" +... +Compiling 20 files with [..] +... + +"#]]); +});