Skip to content

Commit

Permalink
test: add test for cast send (#6176)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Oct 31, 2023
1 parent 94ae897 commit 30ae702
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
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"
);
});

0 comments on commit 30ae702

Please sign in to comment.