Skip to content

Commit

Permalink
Merge branch 'master' into franciszekjob/sncast-guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
franciszekjob authored Jan 17, 2025
2 parents a27799a + 8ce451e commit 443dba0
Show file tree
Hide file tree
Showing 24 changed files with 279 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*.* text eol=lf
*.png -text
*.jpg -text
*.gif -text
4 changes: 4 additions & 0 deletions .github/workflows/scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:

jobs:
get-scarb-versions:
if: "! github.event.repository.fork"
name: Get Scarb versions
outputs:
versions: ${{ steps.get_versions.outputs.versions }}
Expand All @@ -30,6 +31,7 @@ jobs:
echo "versions=[${scarb_versions[@]}]" >> "$GITHUB_OUTPUT"
test-forge-unit-and-integration:
if: "! github.event.repository.fork"
runs-on: ubuntu-latest
needs: get-scarb-versions
strategy:
Expand All @@ -50,6 +52,7 @@ jobs:
- run: cargo test --release -p forge integration

test-forge-e2e:
if: "! github.event.repository.fork"
runs-on: ubuntu-latest
needs: get-scarb-versions
strategy:
Expand Down Expand Up @@ -89,6 +92,7 @@ jobs:
- run: cargo test --release -p forge e2e

test-cast:
if: "! github.event.repository.fork"
runs-on: ubuntu-latest
needs: get-scarb-versions
strategy:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.36.0] - 2025-01-15

### Forge

#### Changed
Expand All @@ -24,6 +26,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Values passed to the `--max-fee`, `--max-gas`, and `--max-gas-unit-price` flags must be greater than 0

#### Deprecated

- `--version` flag

## [0.35.1] - 2024-12-16

### Forge
Expand Down
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ members = [
]

[workspace.package]
version = "0.35.1"
version = "0.36.0"
edition = "2021"
repository = "https://github.com/foundry-rs/starknet-foundry"
license = "MIT"
Expand Down
20 changes: 19 additions & 1 deletion crates/sncast/src/helpers/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ impl FeeArgs {
}
}

#[allow(clippy::too_many_lines)]
pub async fn try_into_fee_settings<P: Provider>(
&self,
provider: P,
Expand Down Expand Up @@ -106,6 +107,7 @@ impl FeeArgs {

let max_gas = NonZeroFelt::try_from(Felt::from(max_fee).floor_div(&max_gas_unit_price))
.unwrap_or_else(|_| unreachable!("Calculated max gas must be >= 1 because max_fee >= max_gas_unit_price ensures a positive result"));
print_max_fee_conversion_info(max_fee, max_gas, max_gas_unit_price);
FeeSettings::Strk {
max_gas: Some(
NonZeroU64::try_from_(max_gas).map_err(anyhow::Error::msg)?,
Expand All @@ -123,6 +125,7 @@ impl FeeArgs {

let max_gas_unit_price = NonZeroFelt::try_from(Felt::from(max_fee).floor_div(&max_gas))
.unwrap_or_else(|_| unreachable!("Calculated max gas unit price must be >= 1 because max_fee >= max_gas ensures a positive result"));
print_max_fee_conversion_info(max_fee, max_gas, max_gas_unit_price);
FeeSettings::Strk {
max_gas: Some(
NonZeroU64::try_from_(max_gas).map_err(anyhow::Error::msg)?,
Expand All @@ -144,6 +147,7 @@ impl FeeArgs {
// TODO(#2852)
let max_gas = NonZeroFelt::try_from(Felt::from(max_fee)
.floor_div(&max_gas_unit_price)).context("Calculated max-gas from provided --max-fee and the current network gas price is 0. Please increase --max-fee to obtain a positive gas amount")?;
print_max_fee_conversion_info(max_fee, max_gas, max_gas_unit_price);
FeeSettings::Strk {
max_gas: Some(
NonZeroU64::try_from_(max_gas).map_err(anyhow::Error::msg)?,
Expand Down Expand Up @@ -270,7 +274,8 @@ impl FromStr for FeeToken {
}

fn parse_fee_token(s: &str) -> Result<FeeToken, String> {
let deprecation_message = "Specifying '--fee-token' flag is deprecated and will be removed in the future. Use '--version' instead";
let deprecation_message =
"Specifying '--fee-token' flag is deprecated and will be removed in the future.";
print_as_warning(&Error::msg(deprecation_message));

let parsed_token: FeeToken = s.parse()?;
Expand All @@ -284,6 +289,19 @@ fn parse_fee_token(s: &str) -> Result<FeeToken, String> {
Ok(parsed_token)
}

fn print_max_fee_conversion_info(
max_fee: impl Into<Felt>,
max_gas: impl Into<Felt>,
max_gas_unit_price: impl Into<Felt>,
) {
let max_fee: Felt = max_fee.into();
let max_gas: Felt = max_gas.into();
let max_gas_unit_price: Felt = max_gas_unit_price.into();
println!(
"Specifying '--max-fee' flag while using v3 transactions results in conversion to '--max-gas' and '--max-gas-unit-price' flags\nConverted {max_fee} max fee to {max_gas} max gas and {max_gas_unit_price} max gas unit price\n",
);
}

fn parse_non_zero_felt(s: &str) -> Result<NonZeroFelt, String> {
let felt: Felt = s.parse().map_err(|_| "Failed to parse value")?;
felt.try_into()
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;
10 changes: 10 additions & 0 deletions crates/sncast/src/helpers/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use anyhow::Error;
use clap::ValueEnum;
use shared::print::print_as_warning;

const DEPRECATION_MESSAGE: &str = "The '--version' flag is deprecated and will be removed in the future. Version 3 will become the only type of transaction available.";

pub fn parse_version<T: ValueEnum>(s: &str) -> Result<T, String> {
print_as_warning(&Error::msg(DEPRECATION_MESSAGE));
T::from_str(s, true)
}
3 changes: 2 additions & 1 deletion crates/sncast/src/starknet_commands/account/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use sncast::helpers::constants::{BRAAVOS_BASE_ACCOUNT_CLASS_HASH, KEYSTORE_PASSW
use sncast::helpers::error::token_not_supported_for_deployment;
use sncast::helpers::fee::{FeeArgs, FeeSettings, FeeToken, PayableTransaction};
use sncast::helpers::rpc::RpcArgs;
use sncast::helpers::version::parse_version;
use sncast::response::structs::InvokeResponse;
use sncast::{
apply_optional, chain_id_to_network_name, check_account_file_exists,
Expand Down Expand Up @@ -38,7 +39,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::<AccountDeployVersion>)]
pub version: Option<AccountDeployVersion>,

#[clap(flatten)]
Expand Down
3 changes: 2 additions & 1 deletion crates/sncast/src/starknet_commands/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use scarb_api::StarknetContractArtifacts;
use sncast::helpers::error::token_not_supported_for_declaration;
use sncast::helpers::fee::{FeeArgs, FeeSettings, FeeToken, PayableTransaction};
use sncast::helpers::rpc::RpcArgs;
use sncast::helpers::version::parse_version;
use sncast::response::errors::StarknetCommandError;
use sncast::response::structs::{
AlreadyDeclaredResponse, DeclareResponse, DeclareTransactionResponse,
Expand Down Expand Up @@ -44,7 +45,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::<DeclareVersion>)]
pub version: Option<DeclareVersion>,

#[clap(flatten)]
Expand Down
3 changes: 2 additions & 1 deletion crates/sncast/src/starknet_commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use conversions::IntoConv;
use sncast::helpers::error::token_not_supported_for_deployment;
use sncast::helpers::fee::{FeeArgs, FeeSettings, FeeToken, PayableTransaction};
use sncast::helpers::rpc::RpcArgs;
use sncast::helpers::version::parse_version;
use sncast::response::errors::StarknetCommandError;
use sncast::response::structs::DeployResponse;
use sncast::{extract_or_generate_salt, impl_payable_transaction, udc_uniqueness};
Expand Down Expand Up @@ -43,7 +44,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::<DeployVersion>)]
pub version: Option<DeployVersion>,

#[clap(flatten)]
Expand Down
3 changes: 2 additions & 1 deletion crates/sncast/src/starknet_commands/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use conversions::IntoConv;
use sncast::helpers::error::token_not_supported_for_invoke;
use sncast::helpers::fee::{FeeArgs, FeeSettings, FeeToken, PayableTransaction};
use sncast::helpers::rpc::RpcArgs;
use sncast::helpers::version::parse_version;
use sncast::response::errors::StarknetCommandError;
use sncast::response::structs::InvokeResponse;
use sncast::{apply_optional, handle_wait_for_tx, impl_payable_transaction, WaitForTx};
Expand Down Expand Up @@ -38,7 +39,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::<InvokeVersion>)]
pub version: Option<InvokeVersion>,

#[clap(flatten)]
Expand Down
3 changes: 2 additions & 1 deletion crates/sncast/src/starknet_commands/multicall/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use sncast::helpers::constants::UDC_ADDRESS;
use sncast::helpers::error::token_not_supported_for_invoke;
use sncast::helpers::fee::{FeeArgs, FeeToken, PayableTransaction};
use sncast::helpers::rpc::RpcArgs;
use sncast::helpers::version::parse_version;
use sncast::response::errors::handle_starknet_command_error;
use sncast::response::structs::InvokeResponse;
use sncast::{extract_or_generate_salt, impl_payable_transaction, udc_uniqueness, WaitForTx};
Expand All @@ -31,7 +32,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::<InvokeVersion>)]
pub version: Option<InvokeVersion>,

#[clap(flatten)]
Expand Down
45 changes: 43 additions & 2 deletions crates/sncast/tests/e2e/account/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ async fn test_fee_token_deprecation_warning_eth() {
let snapbox = runner(&args).current_dir(tempdir.path());

snapbox.assert().success().stdout_matches(indoc! {r"
[WARNING] Specifying '--fee-token' flag is deprecated and will be removed in the future. Use '--version' instead
[WARNING] Specifying '--fee-token' flag is deprecated and will be removed in the future.
[WARNING] Eth transactions will stop being supported in the future due to 'SNIP-16'
Transaction hash: [..]
command: account deploy
Expand Down Expand Up @@ -432,7 +432,39 @@ async fn test_fee_token_deprecation_warning_strk() {
let snapbox = runner(&args).current_dir(tempdir.path());

snapbox.assert().success().stdout_matches(indoc! {r"
[WARNING] Specifying '--fee-token' flag is deprecated and will be removed in the future. Use '--version' instead
[WARNING] Specifying '--fee-token' flag is deprecated and will be removed in the future.
Transaction hash: [..]
command: account deploy
transaction_hash: [..]
To see invocation details, visit:
transaction: [..]
"});
}

#[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 will become the only type of transaction available.
Transaction hash: [..]
command: account deploy
transaction_hash: [..]
Expand Down Expand Up @@ -463,6 +495,9 @@ pub async fn test_valid_class_hash() {
let snapbox = runner(&args).current_dir(tempdir.path());

snapbox.assert().success().stdout_matches(indoc! {r"
Specifying '--max-fee' flag while using v3 transactions results in conversion to '--max-gas' and '--max-gas-unit-price' flags
Converted [..] max fee to [..] max gas and [..] max gas unit price
command: account deploy
transaction_hash: [..]
Expand Down Expand Up @@ -584,6 +619,9 @@ pub async fn test_happy_case_keystore(account_type: &str) {
let snapbox = runner(&args).current_dir(tempdir.path());

snapbox.assert().stdout_matches(indoc! {r"
Specifying '--max-fee' flag while using v3 transactions results in conversion to '--max-gas' and '--max-gas-unit-price' flags
Converted [..] max fee to [..] max gas and [..] max gas unit price
command: account deploy
transaction_hash: 0x0[..]
Expand Down Expand Up @@ -857,6 +895,9 @@ pub async fn test_deploy_keystore_other_args() {

let snapbox = runner(&args).current_dir(tempdir.path());
snapbox.assert().stdout_matches(indoc! {r"
Specifying '--max-fee' flag while using v3 transactions results in conversion to '--max-gas' and '--max-gas-unit-price' flags
Converted [..] max fee to [..] max gas and [..] max gas unit price
command: account deploy
transaction_hash: 0x0[..]
Expand Down
37 changes: 37 additions & 0 deletions crates/sncast/tests/e2e/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,3 +729,40 @@ 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",
"v3",
];

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 will become the only type of transaction available.
" },
);
}
Loading

0 comments on commit 443dba0

Please sign in to comment.