Skip to content

Commit

Permalink
test(blockifier): test enforce_fee flag with new resource bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
dorimedini-starkware committed Oct 13, 2024
1 parent c941c05 commit 24b7c7a
Showing 1 changed file with 44 additions and 6 deletions.
50 changes: 44 additions & 6 deletions crates/blockifier/src/transaction/account_transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ use crate::test_utils::{
get_tx_resources,
CairoVersion,
BALANCE,
DEFAULT_STRK_L1_DATA_GAS_PRICE,
DEFAULT_STRK_L1_GAS_PRICE,
DEFAULT_STRK_L2_GAS_PRICE,
MAX_FEE,
};
use crate::transaction::account_transaction::AccountTransaction;
Expand Down Expand Up @@ -163,21 +165,36 @@ fn test_rc96_holes(block_context: BlockContext, default_l1_resource_bounds: Vali
}

#[rstest]
#[case::deprecated_tx(TransactionVersion::ONE, GasVectorComputationMode::NoL2Gas)]
#[case::l1_bounds(TransactionVersion::THREE, GasVectorComputationMode::NoL2Gas)]
#[case::all_bounds(TransactionVersion::THREE, GasVectorComputationMode::All)]
fn test_fee_enforcement(
block_context: BlockContext,
#[values(TransactionVersion::ONE, TransactionVersion::THREE)] version: TransactionVersion,
#[case] version: TransactionVersion,
#[case] gas_bounds_mode: GasVectorComputationMode,
#[values(true, false)] zero_bounds: bool,
) {
let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo0);
let state = &mut test_state(&block_context.chain_info, BALANCE, &[(account, 1)]);
let uint_bound = u8::from(!zero_bounds);
let deploy_account_tx = deploy_account_tx(
deploy_account_tx_args! {
class_hash: account.get_class_hash(),
max_fee: Fee(u128::from(!zero_bounds)),
resource_bounds: l1_resource_bounds(
u8::from(!zero_bounds).into(),
DEFAULT_STRK_L1_GAS_PRICE.into()
),
max_fee: Fee(u128::from(uint_bound)),
resource_bounds: match gas_bounds_mode {
GasVectorComputationMode::NoL2Gas => l1_resource_bounds(
uint_bound.into(),
DEFAULT_STRK_L1_GAS_PRICE.into()
),
GasVectorComputationMode::All => create_all_resource_bounds(
uint_bound.into(),
DEFAULT_STRK_L1_GAS_PRICE.into(),
uint_bound.into(),
DEFAULT_STRK_L2_GAS_PRICE.into(),
uint_bound.into(),
DEFAULT_STRK_L1_DATA_GAS_PRICE.into(),
),
},
version,
},
&mut NonceManager::default(),
Expand All @@ -189,6 +206,27 @@ fn test_fee_enforcement(
assert_eq!(result.is_err(), enforce_fee);
}

#[rstest]
fn test_all_bounds_combinations_enforce_fee(
#[values(0, 1)] l1_gas_bound: u64,
#[values(0, 1)] l1_data_gas_bound: u64,
#[values(0, 1)] l2_gas_bound: u64,
) {
let expected_enforce_fee = l1_gas_bound + l1_data_gas_bound + l2_gas_bound > 0;
let account_tx = account_invoke_tx(invoke_tx_args! {
version: TransactionVersion::THREE,
resource_bounds: create_all_resource_bounds(
l1_gas_bound.into(),
DEFAULT_STRK_L1_GAS_PRICE.into(),
l2_gas_bound.into(),
DEFAULT_STRK_L2_GAS_PRICE.into(),
l1_data_gas_bound.into(),
DEFAULT_STRK_L1_DATA_GAS_PRICE.into(),
),
});
assert_eq!(account_tx.create_tx_info().enforce_fee(), expected_enforce_fee);
}

#[rstest]
#[case::positive_case_deprecated_tx(true, true)]
#[case::positive_case_new_tx(true, false)]
Expand Down

0 comments on commit 24b7c7a

Please sign in to comment.