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

Add warnings while using common arguments #2573

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Cast

#### Added

- Warning is displayed when using common arguments that will be deprecated in the future.

#### Changed

- Short option for `--accounts-file` flag has been removed.
Expand Down
37 changes: 37 additions & 0 deletions crates/sncast/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ enum Commands {
fn main() -> Result<()> {
let cli = Cli::parse();

check_deprecated_arguments(&cli);

let numbers_format = NumbersFormat::from_flags(cli.hex_format, cli.int_format);
let output_format = OutputFormat::from_flag(cli.json);

Expand Down Expand Up @@ -603,3 +605,38 @@ fn update_cast_config(config: &mut CastConfig, cli: &Cli) {
clone_or_else!(cli.wait_timeout, config.wait_params.get_timeout()),
);
}

fn check_deprecated_arguments(cli: &Cli) {
let mut warnings = Vec::new();
let warning_lhs = "In the upcoming version the";
let warning_rhs = "option will be removed as common argument and relocated to be an argument for a specific subcommand";

franciszekjob marked this conversation as resolved.
Show resolved Hide resolved
if cli.profile.is_some() {
warnings.push(format!("{warning_lhs} '--profile' {warning_rhs}"));
}
if cli.account.is_some() {
warnings.push(format!("{warning_lhs} '--account' {warning_rhs}"));
}
if cli.accounts_file_path.is_some() {
warnings.push(format!("{warning_lhs} '--accounts-file' {warning_rhs}"));
}
if cli.keystore.is_some() {
warnings.push(format!("{warning_lhs} '--keystore' {warning_rhs}"));
}
if cli.wait {
warnings.push(format!("{warning_lhs} '--wait' {warning_rhs}"));
}
if cli.wait_timeout.is_some() {
warnings.push(format!("{warning_lhs} '--wait-timeout' {warning_rhs}"));
}
if cli.wait_retry_interval.is_some() {
warnings.push(format!(
"{warning_lhs} '--wait-retry-interval' {warning_rhs}",
));
}

for warning in warnings {
//colors the warning message in yellow
eprintln!("\x1b[33mWarning: {warning}\x1b[0m");
}
}
27 changes: 21 additions & 6 deletions crates/sncast/tests/e2e/account/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,15 @@ pub async fn test_existent_account_address_and_incorrect_class_hash() {

let snapbox = runner(&args).current_dir(tempdir.path());

snapbox.assert().stderr_matches(formatdoc! {r"
// TODO(#2552)
let output = snapbox.assert().success();
assert_stderr_contains(
output,
formatdoc! {r"
command: account add
error: Incorrect class hash {} for account address {}
", DEVNET_OZ_CLASS_HASH_CAIRO_0, DEVNET_PREDEPLOYED_ACCOUNT_ADDRESS});
", DEVNET_OZ_CLASS_HASH_CAIRO_0, DEVNET_PREDEPLOYED_ACCOUNT_ADDRESS},
);
}

#[tokio::test]
Expand Down Expand Up @@ -175,10 +180,15 @@ pub async fn test_nonexistent_account_address_and_nonexistent_class_hash() {

let snapbox = runner(&args).current_dir(tempdir.path());

snapbox.assert().stderr_matches(indoc! {r"
// TODO(#2552)
let output = snapbox.assert().success();
assert_stderr_contains(
output,
indoc! {r"
command: account add
error: Class with hash 0x101 is not declared, try using --class-hash with a hash of the declared class
"});
"},
);
}

#[tokio::test]
Expand All @@ -205,10 +215,15 @@ pub async fn test_nonexistent_account_address() {

let snapbox = runner(&args).current_dir(tempdir.path());

snapbox.assert().stderr_matches(indoc! {r"
// TODO(#2552)
let output = snapbox.assert().success();
assert_stderr_contains(
output,
indoc! {r"
command: account add
error: There is no contract at the specified address
"});
"},
);
}

#[tokio::test]
Expand Down
5 changes: 3 additions & 2 deletions crates/sncast/tests/e2e/account/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::helpers::constants::ACCOUNT_FILE_PATH;
use crate::helpers::runner::runner;
use crate::{e2e::account::helpers::create_tempdir_with_accounts_file, helpers::constants::URL};
use indoc::indoc;
use shared::test_utils::output_assert::{assert_stderr_contains, AsOutput};
use shared::test_utils::output_assert::assert_stderr_contains;

#[test]
pub fn test_no_accounts_in_network() {
Expand Down Expand Up @@ -159,7 +159,8 @@ pub fn test_happy_case_with_yes_flag() {
let snapbox = runner(&args).current_dir(temp_dir.path());
let output = snapbox.assert().success();

assert!(output.as_stderr().is_empty());
// TODO(#2552)
// assert!(output.as_stderr().is_empty());
output.stdout_matches(indoc! {r"
command: account delete
result: Account successfully removed
Expand Down
24 changes: 16 additions & 8 deletions crates/sncast/tests/e2e/account/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ fn test_happy_case() {
let snapbox = runner(&args).current_dir(temp_dir.path());
let output = snapbox.assert().success();

assert!(output.as_stderr().is_empty());
// TODO(#2552)
// assert!(output.as_stderr().is_empty());

let expected = formatdoc!(
"
Expand Down Expand Up @@ -75,7 +76,8 @@ fn test_happy_case_with_private_keys() {
let snapbox = runner(&args).current_dir(temp_dir.path());
let output = snapbox.assert().success();

assert!(output.as_stderr().is_empty());
// TODO(#2552)
// assert!(output.as_stderr().is_empty());

let expected = formatdoc!(
"
Expand Down Expand Up @@ -130,7 +132,8 @@ fn test_happy_case_hex_format() {
let snapbox = runner(&args).current_dir(temp_dir.path());
let output = snapbox.assert().success();

assert!(output.as_stderr().is_empty());
// TODO(#2552)
// assert!(output.as_stderr().is_empty());

let expected = formatdoc!(
"
Expand Down Expand Up @@ -185,7 +188,8 @@ fn test_happy_case_int_format() {
let snapbox = runner(&args).current_dir(temp_dir.path());
let output = snapbox.assert().success();

assert!(output.as_stderr().is_empty());
// TODO(#2552)
// assert!(output.as_stderr().is_empty());

let expected = formatdoc!(
"
Expand Down Expand Up @@ -233,7 +237,8 @@ fn test_happy_case_json() {
let snapbox = runner(&args).current_dir(temp_dir.path());
let output = snapbox.assert().success();

assert!(output.as_stderr().is_empty());
// TODO(#2552)
// assert!(output.as_stderr().is_empty());

let output_plain = output.as_stdout().to_string();
let output_parsed: Value = serde_json::from_str(&output_plain)
Expand Down Expand Up @@ -283,7 +288,8 @@ fn test_happy_case_with_private_keys_json() {
let snapbox = runner(&args).current_dir(temp_dir.path());
let output = snapbox.assert().success();

assert!(output.as_stderr().is_empty());
// TODO(#2552)
// assert!(output.as_stderr().is_empty());

let output_plain = output.as_stdout().to_string();
let output_parsed: Value = serde_json::from_str(&output_plain)
Expand Down Expand Up @@ -337,7 +343,8 @@ fn test_happy_case_with_private_keys_json_int_format() {
let snapbox = runner(&args).current_dir(temp_dir.path());
let output = snapbox.assert().success();

assert!(output.as_stderr().is_empty());
// TODO(#2552)
// assert!(output.as_stderr().is_empty());

let output_plain = output.as_stdout().to_string();
let output_parsed: Value = serde_json::from_str(&output_plain)
Expand Down Expand Up @@ -409,7 +416,8 @@ fn test_no_accounts_available() {
let snapbox = runner(&args).current_dir(temp_dir.path());
let output = snapbox.assert().success();

assert!(output.as_stderr().is_empty());
// TODO(#2552)
// assert!(output.as_stderr().is_empty());
assert_stdout_contains(
output,
format!(
Expand Down
3 changes: 2 additions & 1 deletion crates/sncast/tests/e2e/main_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,5 +318,6 @@ async fn test_keystore_declare() {
env::set_var(KEYSTORE_PASSWORD_ENV_VAR, "123");
let snapbox = runner(&args).current_dir(contract_path.path());

assert!(snapbox.assert().success().get_output().stderr.is_empty());
// TODO(#2552)
assert!(!snapbox.assert().success().get_output().stderr.is_empty());
}
22 changes: 12 additions & 10 deletions crates/sncast/tests/e2e/multicall/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ async fn test_happy_case(account: &str) {
let snapbox = runner(&args);
let output = snapbox.assert();

let stderr_str = output.as_stderr();
assert!(
stderr_str.is_empty(),
"Multicall error, stderr: \n{stderr_str}",
);
// TODO(#2552)
// let stderr_str = output.as_stderr();
// assert!(
// stderr_str.is_empty(),
// "Multicall error, stderr: \n{stderr_str}",
// );

output.stdout_matches(indoc! {r"
command: multicall run
Expand Down Expand Up @@ -77,11 +78,12 @@ async fn test_calldata_ids() {
let snapbox = runner(&args);
let output = snapbox.assert();

let stderr_str = output.as_stderr();
assert!(
stderr_str.is_empty(),
"Multicall error, stderr: \n{stderr_str}",
);
// TODO(#2552)
// let stderr_str = output.as_stderr();
// assert!(
// stderr_str.is_empty(),
// "Multicall error, stderr: \n{stderr_str}",
// );

output.stdout_matches(indoc! {r"
command: multicall run
Expand Down
Loading