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 test for cast send #6176

Merged
merged 1 commit into from
Oct 31, 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
14 changes: 8 additions & 6 deletions crates/cast/bin/cmd/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,8 @@ impl SendTxArgs {
command,
unlocked,
} = self;
let config = Config::from(&eth);
let provider = utils::get_provider(&config)?;
let chain = utils::get_chain(config.chain_id, &provider).await?;
let api_key = config.get_etherscan_api_key(Some(chain));
let mut sig = sig.unwrap_or_default();

let mut sig = sig.unwrap_or_default();
let code = if let Some(SendTxSubcommands::Create {
code,
sig: constructor_sig,
Expand All @@ -108,10 +104,16 @@ impl SendTxArgs {
None
};

// ensure mandatory fields are provided
if code.is_none() && to.is_none() {
eyre::bail!("Must specify a destination or contract code to deploy");
eyre::bail!("Must specify a recipient address or contract code to deploy");
}

let config = Config::from(&eth);
let provider = utils::get_provider(&config)?;
let chain = utils::get_chain(config.chain_id, &provider).await?;
let api_key = config.get_etherscan_api_key(Some(chain));

// Case 1:
// Default to sending via eth_sendTransaction if the --unlocked flag is passed.
// This should be the only way this RPC method is used as it requires a local node
Expand Down
14 changes: 14 additions & 0 deletions crates/cast/tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,17 @@ casttest!(cast_tx_raw, |_: TestProject, mut cmd: TestCommand| {
let output2 = cmd.stdout_lossy();
assert_eq!(output, output2);
});

// ensure receipt or code is required
casttest!(cast_send_requires_to, |_: TestProject, mut cmd: TestCommand| {
cmd.args([
"send",
"--private-key",
"0x0000000000000000000000000000000000000000000000000000000000000001",
]);
let output = cmd.stderr_lossy();
assert_eq!(
output.trim(),
"Error: \nMust specify a recipient address or contract code to deploy"
);
});