Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
chore: remove some 'as' conversions and enforce no 'as' conversions (#…
Browse files Browse the repository at this point in the history
…1575)

* chore: remove final f64s

Signed-off-by: Dori Medini <dori@starkware.co>

* chore: remove some 'as' conversions and enforce no 'as' conversions

Signed-off-by: Dori Medini <dori@starkware.co>
  • Loading branch information
dorimedini-starkware committed Feb 22, 2024
1 parent c61d883 commit 147bfa0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ future-incompatible = "deny"
nonstandard-style = "deny"
rust-2018-idioms = "deny"
unused = "deny"

[workspace.lints.clippy]
as_conversions = "deny"
9 changes: 5 additions & 4 deletions crates/blockifier/src/fee/fee_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::test_utils::{CairoVersion, BALANCE};
use crate::transaction::errors::TransactionFeeError;
use crate::transaction::objects::{GasVector, ResourcesMapping};
use crate::transaction::test_utils::{account_invoke_tx, l1_resource_bounds};
use crate::utils::u128_from_usize;
use crate::versioned_constants::VersionedConstants;

fn get_vm_resource_usage() -> ResourcesMapping {
Expand All @@ -42,7 +43,7 @@ fn test_calculate_l1_gas_by_vm_usage() {
// Verify calculation - in our case, n_steps is the heaviest resource.
let l1_gas_by_vm_usage = vm_resource_usage.0.get(constants::N_STEPS_RESOURCE).unwrap();
assert_eq!(
GasVector { l1_gas: *l1_gas_by_vm_usage as u128, l1_data_gas: 0 },
GasVector { l1_gas: u128_from_usize(*l1_gas_by_vm_usage), l1_data_gas: 0 },
calculate_l1_gas_by_vm_usage(&versioned_constants, &vm_resource_usage).unwrap()
);

Expand Down Expand Up @@ -102,11 +103,11 @@ fn test_discounted_gas_overdraft(

if expect_failure {
let error = report.error().unwrap();
let expected_actual_amount =
l1_gas_used as u128 + (l1_data_gas_used as u128 * data_gas_price) / gas_price;
let expected_actual_amount = u128_from_usize(l1_gas_used)
+ (u128_from_usize(l1_data_gas_used) * data_gas_price) / gas_price;
assert_matches!(
error, FeeCheckError::MaxL1GasAmountExceeded { max_amount, actual_amount }
if max_amount == gas_bound as u128 && actual_amount == expected_actual_amount
if max_amount == u128::from(gas_bound) && actual_amount == expected_actual_amount
)
} else {
assert_matches!(report.error(), None);
Expand Down
1 change: 1 addition & 0 deletions crates/blockifier/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ pub fn test_erc20_faulty_account_balance_key() -> StorageKey {

// The max_fee / resource bounds used for txs in this test.
pub const MAX_L1_GAS_AMOUNT: u64 = 1000000;
#[allow(clippy::as_conversions)]
pub const MAX_L1_GAS_AMOUNT_U128: u128 = MAX_L1_GAS_AMOUNT as u128;
pub const MAX_L1_GAS_PRICE: u128 = DEFAULT_STRK_L1_GAS_PRICE;
pub const MAX_RESOURCE_COMMITMENT: u128 = MAX_L1_GAS_AMOUNT_U128 * MAX_L1_GAS_PRICE;
Expand Down
1 change: 1 addition & 0 deletions crates/blockifier/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ where

/// Returns the max value of two constants, at compile time.
pub const fn const_max(a: u128, b: u128) -> u128 {
#[allow(clippy::as_conversions)]
[a, b][(a < b) as usize]
}

Expand Down

0 comments on commit 147bfa0

Please sign in to comment.