Skip to content

Commit 44563cf

Browse files
Print max fee conversion info when using v3 txs (#2797)
<!-- Reference any GitHub issues resolved by this PR --> Closes #2707 ## Introduced changes <!-- A brief description of the changes --> Display info about about conversion when using `--max-fee` flag with v3 transactions ## Checklist <!-- Make sure all of these are complete --> - [x] Linked relevant issue - [x] Updated relevant documentation - [x] Added relevant tests - [x] Performed self-review of the code - [x] Added changes to `CHANGELOG.md` --------- Co-authored-by: Piotr Figiela <[email protected]>
1 parent 9dca1ce commit 44563cf

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

crates/sncast/src/helpers/fee.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ impl FeeArgs {
6161
}
6262
}
6363

64+
#[allow(clippy::too_many_lines)]
6465
pub async fn try_into_fee_settings<P: Provider>(
6566
&self,
6667
provider: P,
@@ -106,6 +107,7 @@ impl FeeArgs {
106107

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

124126
let max_gas_unit_price = NonZeroFelt::try_from(Felt::from(max_fee).floor_div(&max_gas))
125127
.unwrap_or_else(|_| unreachable!("Calculated max gas unit price must be >= 1 because max_fee >= max_gas ensures a positive result"));
128+
print_max_fee_conversion_info(max_fee, max_gas, max_gas_unit_price);
126129
FeeSettings::Strk {
127130
max_gas: Some(
128131
NonZeroU64::try_from_(max_gas).map_err(anyhow::Error::msg)?,
@@ -144,6 +147,7 @@ impl FeeArgs {
144147
// TODO(#2852)
145148
let max_gas = NonZeroFelt::try_from(Felt::from(max_fee)
146149
.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")?;
150+
print_max_fee_conversion_info(max_fee, max_gas, max_gas_unit_price);
147151
FeeSettings::Strk {
148152
max_gas: Some(
149153
NonZeroU64::try_from_(max_gas).map_err(anyhow::Error::msg)?,
@@ -285,6 +289,19 @@ fn parse_fee_token(s: &str) -> Result<FeeToken, String> {
285289
Ok(parsed_token)
286290
}
287291

292+
fn print_max_fee_conversion_info(
293+
max_fee: impl Into<Felt>,
294+
max_gas: impl Into<Felt>,
295+
max_gas_unit_price: impl Into<Felt>,
296+
) {
297+
let max_fee: Felt = max_fee.into();
298+
let max_gas: Felt = max_gas.into();
299+
let max_gas_unit_price: Felt = max_gas_unit_price.into();
300+
println!(
301+
"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",
302+
);
303+
}
304+
288305
fn parse_non_zero_felt(s: &str) -> Result<NonZeroFelt, String> {
289306
let felt: Felt = s.parse().map_err(|_| "Failed to parse value")?;
290307
felt.try_into()

crates/sncast/tests/e2e/account/deploy.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,9 @@ pub async fn test_valid_class_hash() {
495495
let snapbox = runner(&args).current_dir(tempdir.path());
496496

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

618621
snapbox.assert().stdout_matches(indoc! {r"
622+
Specifying '--max-fee' flag while using v3 transactions results in conversion to '--max-gas' and '--max-gas-unit-price' flags
623+
Converted [..] max fee to [..] max gas and [..] max gas unit price
624+
619625
command: account deploy
620626
transaction_hash: 0x0[..]
621627
@@ -889,6 +895,9 @@ pub async fn test_deploy_keystore_other_args() {
889895

890896
let snapbox = runner(&args).current_dir(tempdir.path());
891897
snapbox.assert().stdout_matches(indoc! {r"
898+
Specifying '--max-fee' flag while using v3 transactions results in conversion to '--max-gas' and '--max-gas-unit-price' flags
899+
Converted [..] max fee to [..] max gas and [..] max gas unit price
900+
892901
command: account deploy
893902
transaction_hash: 0x0[..]
894903

crates/sncast/tests/e2e/invoke.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,19 @@ async fn test_happy_case_strk(class_hash: Felt, account_type: AccountType) {
128128
];
129129

130130
let snapbox = runner(&args).current_dir(tempdir.path());
131-
let output = snapbox.assert().success().get_output().stdout.clone();
131+
let output = snapbox.assert().success();
132+
let stdout = output.get_output().stdout.clone();
132133

133-
let hash = get_transaction_hash(&output);
134+
let hash = get_transaction_hash(&stdout);
134135
let receipt = get_transaction_receipt(hash).await;
135136

137+
assert_stdout_contains(
138+
output,
139+
indoc! {
140+
"Specifying '--max-fee' flag while using v3 transactions results in conversion to '--max-gas' and '--max-gas-unit-price' flags
141+
Converted [..] max fee to [..] max gas and [..] max gas unit price"
142+
},
143+
);
136144
assert!(matches!(receipt, Invoke(_)));
137145
}
138146

0 commit comments

Comments
 (0)