Skip to content

Commit

Permalink
test: add forge create test
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Oct 27, 2023
1 parent aa257c2 commit 302218b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
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

0 comments on commit 302218b

Please sign in to comment.