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 deprecation info of version flag #2834

Merged
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 @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- interactive interface that allows setting created or imported account as the default

#### Deprecated

- `--version` flag


## [0.35.1] - 2024-12-16

Expand Down
1 change: 1 addition & 0 deletions crates/sncast/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pub mod fee;
pub mod interactive;
pub mod rpc;
pub mod scarb_utils;
pub mod version;
34 changes: 34 additions & 0 deletions crates/sncast/src/helpers/version.rs
kkawula marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#[macro_export]
macro_rules! generate_version_parser {
($enum_name:ident, $variant1:ident, $variant2:ident ) => {
use shared::print::print_as_warning;
use anyhow::Error;

impl std::str::FromStr for $enum_name {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let var1 = stringify!($variant1).to_lowercase();
let var2 = stringify!($variant2).to_lowercase();

match s.to_lowercase().as_str() {
v if v == var1 => Ok($enum_name::$variant1),
v if v == var2 => Ok($enum_name::$variant2),
_ => Err(format!(
"Invalid value '{}'. Possible values: {}, {}",
s, var1, var2
)),
}
}
}

pub fn parse_version(s: &str) -> Result<$enum_name, String> {
let deprecation_message = "The '--version' flag is deprecated and will be removed in the future. Version 3 transactions will become the default and only available version.";
kkawula marked this conversation as resolved.
Show resolved Hide resolved
print_as_warning(&Error::msg(deprecation_message));

let parsed_enum = s.parse::<$enum_name>()?;

Ok(parsed_enum)
}
};
}
6 changes: 4 additions & 2 deletions crates/sncast/src/starknet_commands/account/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use sncast::helpers::fee::{FeeArgs, FeeSettings, FeeToken, PayableTransaction};
use sncast::helpers::rpc::RpcArgs;
use sncast::response::structs::InvokeResponse;
use sncast::{
apply_optional, chain_id_to_network_name, check_account_file_exists,
apply_optional, chain_id_to_network_name, check_account_file_exists, generate_version_parser,
get_account_data_from_accounts_file, get_account_data_from_keystore, get_keystore_password,
handle_rpc_error, handle_wait_for_tx, impl_payable_transaction, AccountType, WaitForTx,
};
Expand Down Expand Up @@ -38,7 +38,7 @@ pub struct Deploy {
pub fee_args: FeeArgs,

/// Version of the account deployment (can be inferred from fee token)
#[clap(short, long)]
#[clap(short, long, value_parser = parse_version)]
pub version: Option<AccountDeployVersion>,

#[clap(flatten)]
Expand All @@ -51,6 +51,8 @@ pub enum AccountDeployVersion {
V3,
}

generate_version_parser!(AccountDeployVersion, V1, V3);

impl_payable_transaction!(Deploy, token_not_supported_for_deployment,
AccountDeployVersion::V1 => FeeToken::Eth,
AccountDeployVersion::V3 => FeeToken::Strk
Expand Down
9 changes: 7 additions & 2 deletions crates/sncast/src/starknet_commands/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use sncast::response::errors::StarknetCommandError;
use sncast::response::structs::{
AlreadyDeclaredResponse, DeclareResponse, DeclareTransactionResponse,
};
use sncast::{apply_optional, handle_wait_for_tx, impl_payable_transaction, ErrorData, WaitForTx};
use sncast::{
apply_optional, generate_version_parser, handle_wait_for_tx, impl_payable_transaction,
ErrorData, WaitForTx,
};
use starknet::accounts::AccountError::Provider;
use starknet::accounts::{ConnectedAccount, DeclarationV2, DeclarationV3};
use starknet::core::types::{DeclareTransactionResult, StarknetError};
Expand Down Expand Up @@ -44,7 +47,7 @@ pub struct Declare {
pub package: Option<String>,

/// Version of the declaration (can be inferred from fee token)
#[clap(short, long)]
#[clap(short, long, value_parser = parse_version)]
pub version: Option<DeclareVersion>,

#[clap(flatten)]
Expand All @@ -57,6 +60,8 @@ pub enum DeclareVersion {
V3,
}

generate_version_parser!(DeclareVersion, V2, V3);

impl_payable_transaction!(Declare, token_not_supported_for_declaration,
DeclareVersion::V2 => FeeToken::Eth,
DeclareVersion::V3 => FeeToken::Strk
Expand Down
8 changes: 6 additions & 2 deletions crates/sncast/src/starknet_commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use sncast::helpers::fee::{FeeArgs, FeeSettings, FeeToken, PayableTransaction};
use sncast::helpers::rpc::RpcArgs;
use sncast::response::errors::StarknetCommandError;
use sncast::response::structs::DeployResponse;
use sncast::{extract_or_generate_salt, impl_payable_transaction, udc_uniqueness};
use sncast::{
extract_or_generate_salt, generate_version_parser, impl_payable_transaction, udc_uniqueness,
};
use sncast::{handle_wait_for_tx, WaitForTx};
use starknet::accounts::AccountError::Provider;
use starknet::accounts::{Account, ConnectedAccount, SingleOwnerAccount};
Expand Down Expand Up @@ -43,7 +45,7 @@ pub struct Deploy {
pub nonce: Option<Felt>,

/// Version of the deployment (can be inferred from fee token)
#[clap(short, long)]
#[clap(short, long, value_parser = parse_version)]
pub version: Option<DeployVersion>,

#[clap(flatten)]
Expand All @@ -68,6 +70,8 @@ pub enum DeployVersion {
V3,
}

generate_version_parser!(DeployVersion, V1, V3);

impl_payable_transaction!(Deploy, token_not_supported_for_deployment,
DeployVersion::V1 => FeeToken::Eth,
DeployVersion::V3 => FeeToken::Strk
Expand Down
9 changes: 7 additions & 2 deletions crates/sncast/src/starknet_commands/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use sncast::helpers::fee::{FeeArgs, FeeSettings, FeeToken, PayableTransaction};
use sncast::helpers::rpc::RpcArgs;
use sncast::response::errors::StarknetCommandError;
use sncast::response::structs::InvokeResponse;
use sncast::{apply_optional, handle_wait_for_tx, impl_payable_transaction, WaitForTx};
use sncast::{
apply_optional, generate_version_parser, handle_wait_for_tx, impl_payable_transaction,
WaitForTx,
};
use starknet::accounts::AccountError::Provider;
use starknet::accounts::{Account, ConnectedAccount, ExecutionV1, ExecutionV3, SingleOwnerAccount};
use starknet::core::types::{Call, InvokeTransactionResult};
Expand Down Expand Up @@ -38,7 +41,7 @@ pub struct Invoke {
pub nonce: Option<Felt>,

/// Version of invoke (can be inferred from fee token)
#[clap(short, long)]
#[clap(short, long, value_parser = parse_version)]
pub version: Option<InvokeVersion>,

#[clap(flatten)]
Expand All @@ -51,6 +54,8 @@ pub enum InvokeVersion {
V3,
}

generate_version_parser!(InvokeVersion, V1, V3);

impl_payable_transaction!(Invoke, token_not_supported_for_invoke,
InvokeVersion::V1 => FeeToken::Eth,
InvokeVersion::V3 => FeeToken::Strk
Expand Down
4 changes: 2 additions & 2 deletions crates/sncast/src/starknet_commands/multicall/run.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::starknet_commands::invoke::{execute_calls, InvokeVersion};
use crate::starknet_commands::invoke::{execute_calls, parse_version, InvokeVersion};
use anyhow::anyhow;
use anyhow::{Context, Result};
use camino::Utf8PathBuf;
Expand Down Expand Up @@ -31,7 +31,7 @@ pub struct Run {
pub fee_args: FeeArgs,

/// Version of invoke (can be inferred from fee token)
#[clap(short, long)]
#[clap(short, long, value_parser = parse_version)]
pub version: Option<InvokeVersion>,

#[clap(flatten)]
Expand Down
60 changes: 60 additions & 0 deletions crates/sncast/tests/e2e/account/deploy.rs
kkawula marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,66 @@ async fn test_fee_token_deprecation_warning_strk() {
"});
}

#[tokio::test]
async fn test_version_deprecation_warning() {
let tempdir = create_account(false, &OZ_CLASS_HASH.into_hex_string(), "oz").await;
let accounts_file = "accounts.json";

let args = vec![
"--accounts-file",
accounts_file,
"--wait",
"account",
"deploy",
"--url",
URL,
"--name",
"my_account",
"--version",
"v3",
];

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

snapbox.assert().success().stdout_matches(indoc! {r"
[WARNING] The '--version' flag is deprecated and will be removed in the future. Version 3 transactions will become the default and only available version.
Transaction hash: [..]
command: account deploy
transaction_hash: [..]

To see invocation details, visit:
transaction: [..]
"});
}

#[tokio::test]
async fn test_version_deprecation_warning_error() {
let tempdir = create_account(false, &OZ_CLASS_HASH.into_hex_string(), "oz").await;
let accounts_file = "accounts.json";

let args = vec![
"--accounts-file",
accounts_file,
"--wait",
"account",
"deploy",
"--url",
URL,
"--name",
"my_account",
"--version",
"v2137",
];

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

snapbox.assert().failure().stderr_matches(indoc! {r"
error: invalid value 'v2137' for '--version <VERSION>': Invalid value 'v2137'. Possible values: v1, v3

For more information, try '--help'.
"});
}

#[tokio::test]
pub async fn test_valid_class_hash() {
let tempdir = create_account(true, &OZ_CLASS_HASH.into_hex_string(), "oz").await;
Expand Down
80 changes: 80 additions & 0 deletions crates/sncast/tests/e2e/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,3 +729,83 @@ async fn test_no_scarb_profile() {
"},
);
}

#[tokio::test]
async fn test_version_deprecation_warning() {
let contract_path = duplicate_contract_directory_with_salt(
CONTRACTS_DIR.to_string() + "/map",
"put",
"human_readable",
);
let tempdir = create_and_deploy_oz_account().await;
join_tempdirs(&contract_path, &tempdir);

let args = vec![
"--accounts-file",
"accounts.json",
"--account",
"my_account",
"declare",
"--url",
URL,
"--contract-name",
"Map",
"--max-fee",
"99999999999999999",
"--version",
"v2",
];

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

let output = snapbox.assert().success();

assert_stdout_contains(
output,
indoc! {r"
[WARNING] The '--version' flag is deprecated and will be removed in the future. Version 3 transactions will become the default and only available version.
command: declare
class_hash: 0x0[..]
transaction_hash: 0x0[..]

To see declaration details, visit:
class: https://[..]
transaction: https://[..]
" },
);
}

#[tokio::test]
async fn test_version_deprecation_warning_error() {
let contract_path = duplicate_contract_directory_with_salt(
CONTRACTS_DIR.to_string() + "/map",
"put",
"human_readable",
);
let tempdir = create_and_deploy_oz_account().await;
join_tempdirs(&contract_path, &tempdir);

let args = vec![
"--accounts-file",
"accounts.json",
"--account",
"my_account",
"declare",
"--url",
URL,
"--contract-name",
"Map",
"--max-fee",
"99999999999999999",
"--version",
"v2137",
];

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

snapbox.assert().failure().stderr_matches(indoc! {r"
error: invalid value 'v2137' for '--version <VERSION>': Invalid value 'v2137'. Possible values: v2, v3

For more information, try '--help'.
"});
}
Loading