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 10, 2024
1 parent baf905b commit 63f505b
Showing 1 changed file with 50 additions and 7 deletions.
57 changes: 50 additions & 7 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 All @@ -78,10 +80,10 @@ use crate::transaction::test_utils::{
create_all_resource_bounds,
create_test_init_data,
default_all_resource_bounds,
default_l1_resource_bounds,
deploy_and_fund_account,
l1_resource_bounds,
max_fee,
default_l1_resource_bounds,
run_invoke_tx,
FaultyAccountTxCreatorArgs,
TestInitData,
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,32 @@ fn test_fee_enforcement(
assert_eq!(result.is_err(), enforce_fee);
}

#[rstest]
#[case::l1_gas_only(1, 1, 0, 0, 0, 0)]
#[case::l1_data_gas_only(0, 0, 1, 1, 0, 0)]
#[case::l2_gas_only(0, 0, 0, 0, 1, 1)]
fn test_all_bounds_combinations_enforce_fee(
#[case] l1_gas_bound: u64,
#[case] l1_gas_price_bound: u128,
#[case] l1_data_gas_bound: u64,
#[case] l1_data_gas_price_bound: u128,
#[case] l2_gas_bound: u64,
#[case] l2_gas_price_bound: u128,
) {
let account_tx = account_invoke_tx(invoke_tx_args! {
version: TransactionVersion::THREE,
resource_bounds: create_all_resource_bounds(
l1_gas_bound.into(),
l1_gas_price_bound.into(),
l2_gas_bound.into(),
l2_gas_price_bound.into(),
l1_data_gas_bound.into(),
l1_data_gas_price_bound.into(),
),
});
assert!(account_tx.create_tx_info().enforce_fee());
}

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

0 comments on commit 63f505b

Please sign in to comment.