Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions crates/common/src/preprocessor/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
/// }
/// ```
Expand All @@ -158,15 +158,15 @@ 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
/// new ERC20({name: name, symbol: symbol})
/// ```
/// 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<String> {
let Self { contract_id, path, name, constructor_data, artifact: _ } = self;
Expand All @@ -183,12 +183,12 @@ pragma solidity >=0.4.0;
import "{path}";

abstract contract DeployHelper{contract_id} is {name} {{
struct ConstructorArgs {{
struct FoundryPpConstructorArgs {{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could've also just added the ID

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, can add FoundryPp{contract_id}ConstructorArgs should I follow up the change?

{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});
}}
"#,
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/preprocessor/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
45 changes: 45 additions & 0 deletions crates/forge/tests/cli/test_optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1300,3 +1300,48 @@ Compiling 1 files with [..]

"#]]);
});

// <https://github.com/foundry-rs/foundry/issues/10312>
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 [..]
...

"#]]);
});
Loading