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

test: add forge create test #6137

Merged
merged 1 commit into from
Oct 27, 2023
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
53 changes: 53 additions & 0 deletions crates/forge/tests/cli/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,56 @@ forgetest_async!(
);
}
);

// tests that we can deploy with constructor args
forgetest_async!(
#[serial_test::serial]
can_create_with_constructor_args,
|prj: TestProject, mut cmd: TestCommand| async move {
let (_api, handle) = spawn(NodeConfig::test()).await;
let rpc = handle.http_endpoint();
let wallet = handle.dev_wallets().next().unwrap();
let pk = hex::encode(wallet.signer().to_bytes());
cmd.args(["init", "--force"]);
cmd.assert_non_empty_stdout();

// explicitly byte code hash for consistent checks
let config = Config { bytecode_hash: BytecodeHash::None, ..Default::default() };
prj.write_config(config);

prj.inner()
.add_source(
"ConstructorContract",
r#"
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract ConstructorContract {
string public name;

constructor(string memory _name) {
name = _name;
}
}
"#,
)
.unwrap();

cmd.forge_fuse().args([
"create",
"./src/ConstructorContract.sol:ConstructorContract",
"--use",
"solc:0.8.15",
"--rpc-url",
rpc.as_str(),
"--private-key",
pk.as_str(),
"--constructor-args",
"My Constructor",
]);

cmd.unchecked_output().stdout_matches_path(
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures/can_create_with_constructor_args.stdout"),
);
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Compiling 23 files with 0.8.15
Solc 0.8.15 finished in 2.82s
Compiler run successful!
Deployer: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
Deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3
Transaction hash: 0x294df85109c991ec2760cd51e5ddc869bf5dc3b249b296305ffcd1a0563b2eea