From 30ae702a31e175ca9c2c23bba71ee9d8520c8e45 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 31 Oct 2023 01:34:30 +0100 Subject: [PATCH] test: add test for cast send (#6176) --- crates/cast/bin/cmd/send.rs | 14 ++++++++------ crates/cast/tests/cli/main.rs | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/crates/cast/bin/cmd/send.rs b/crates/cast/bin/cmd/send.rs index 512a3ea1e25d..25d8a1a0f9c8 100644 --- a/crates/cast/bin/cmd/send.rs +++ b/crates/cast/bin/cmd/send.rs @@ -89,12 +89,8 @@ impl SendTxArgs { command, unlocked, } = self; - let config = Config::from(ð); - 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, @@ -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(ð); + 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 diff --git a/crates/cast/tests/cli/main.rs b/crates/cast/tests/cli/main.rs index 7b752e1ee618..76506d8d41c9 100644 --- a/crates/cast/tests/cli/main.rs +++ b/crates/cast/tests/cli/main.rs @@ -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" + ); +});