Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(blockifier): global validate and execute sierra gas; deprecated tx #2684

Open
wants to merge 1 commit into
base: aner/global_max_sierra_gas_3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 72 additions & 36 deletions crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use starknet_api::executable_transaction::AccountTransaction as ApiExecutableTra
use starknet_api::execution_resources::{GasAmount, GasVector};
use starknet_api::state::StorageKey;
use starknet_api::test_utils::declare::executable_declare_tx;
use starknet_api::test_utils::deploy_account::executable_deploy_account_tx;
use starknet_api::test_utils::deploy_account::{executable_deploy_account_tx, DeployAccountTxArgs};
use starknet_api::test_utils::invoke::{executable_invoke_tx, InvokeTxArgs};
use starknet_api::test_utils::NonceManager;
use starknet_api::transaction::fields::Resource::{L1DataGas, L1Gas, L2Gas};
Expand Down Expand Up @@ -2610,23 +2610,38 @@ fn test_balance_print() {
}

#[rstest]
#[case::small_user_bounds(create_gas_amount_bounds_with_default_price(
GasVector{ l1_gas: GasAmount(1652), l2_gas: GasAmount(654321), l1_data_gas: GasAmount(0) }
))]
#[case::user_bounds_between_validate_and_execute(create_gas_amount_bounds_with_default_price(
GasVector{
l1_gas: GasAmount(1652),
l2_gas: versioned_constants.validate_max_sierra_gas + GasAmount(1234567),
l1_data_gas: GasAmount(0),
}
))]
#[case::large_user_bounds(default_all_resource_bounds())]
#[case::l1_user_bounds(default_l1_resource_bounds())]
// TODO(Aner): Add case for deprecated tx version.
#[case::small_user_bounds(invoke_tx_args! {
version: TransactionVersion::THREE,
resource_bounds: create_gas_amount_bounds_with_default_price(
GasVector{ l1_gas: GasAmount(1652), l2_gas: GasAmount(654321), l1_data_gas: GasAmount(0) }
),
})]
#[case::user_bounds_between_validate_and_execute(invoke_tx_args! {
version: TransactionVersion::THREE,
resource_bounds: create_gas_amount_bounds_with_default_price(
GasVector{
l1_gas: GasAmount(1652),
l2_gas: versioned_constants.validate_max_sierra_gas + GasAmount(1234567),
l1_data_gas: GasAmount(0),
}
),
})]
#[case::large_user_bounds(invoke_tx_args! {
version: TransactionVersion::THREE,
resource_bounds: default_all_resource_bounds(),
})]
#[case::l1_user_bounds(invoke_tx_args! {
version: TransactionVersion::THREE,
resource_bounds: default_l1_resource_bounds(),
})]
#[case::deprecated_tx_version(invoke_tx_args! {
version: TransactionVersion::ONE,
max_fee: Fee(1000000000000000),
})]
fn test_invoke_max_sierra_gas_validate_execute(
block_context: BlockContext,
versioned_constants: VersionedConstants,
#[case] user_resource_bounds: ValidResourceBounds,
#[case] tx_args: InvokeTxArgs,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1(RunnableCairo1::Casm))]
account_cairo_version: CairoVersion,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1(RunnableCairo1::Casm))]
Expand All @@ -2640,11 +2655,13 @@ fn test_invoke_max_sierra_gas_validate_execute(
let account_contract_address = account_contract.get_instance_address(0);
let calldata = create_calldata(test_contract_address, "recurse", &[felt!(10_u8)]);
let invoke_tx = invoke_tx_with_default_flags(invoke_tx_args! {
sender_address: account_contract_address,
calldata: Calldata(Arc::clone(&calldata.0)),
resource_bounds: user_resource_bounds,
sender_address: account_contract_address, calldata: Calldata(Arc::clone(&calldata.0)), .. tx_args
});
let user_initial_gas = user_initial_gas_from_bounds(user_resource_bounds, Some(&block_context));
let user_initial_gas = if tx_args.version == TransactionVersion::THREE {
user_initial_gas_from_bounds(tx_args.resource_bounds, Some(&block_context))
} else {
initial_gas_amount_from_block_context(Some(&block_context))
};

let actual_execution_info = invoke_tx.execute(state, &block_context).unwrap();

Expand Down Expand Up @@ -2711,25 +2728,40 @@ fn test_invoke_max_sierra_gas_validate_execute(
}

#[rstest]
#[case::small_user_bounds(create_gas_amount_bounds_with_default_price(
GasVector{ l1_gas: GasAmount(2203), l1_data_gas: GasAmount(0), l2_gas: GasAmount(654321) }
))]
#[case::user_bounds_between_validate_and_execute(create_gas_amount_bounds_with_default_price(
GasVector{
l1_gas: GasAmount(2203),
l2_gas:versioned_constants.validate_max_sierra_gas + GasAmount(1234567),
l1_data_gas: GasAmount(0),
}
))]
#[case::large_user_bounds(default_all_resource_bounds())]
#[case::l1_user_bounds(default_l1_resource_bounds())]
// TODO(Aner): Add case for deprecated tx version.
#[case::small_user_bounds(deploy_account_tx_args! {
version: TransactionVersion::THREE,
resource_bounds: create_gas_amount_bounds_with_default_price(
GasVector{ l1_gas: GasAmount(2203), l2_gas: GasAmount(654321), l1_data_gas: GasAmount(0) }
),
})]
#[case::user_bounds_between_validate_and_execute(deploy_account_tx_args! {
version: TransactionVersion::THREE,
resource_bounds: create_gas_amount_bounds_with_default_price(
GasVector{
l1_gas: GasAmount(2203),
l2_gas: versioned_constants.validate_max_sierra_gas + GasAmount(1234567),
l1_data_gas: GasAmount(0),
}
),
})]
#[case::large_user_bounds(deploy_account_tx_args! {
version: TransactionVersion::THREE,
resource_bounds: default_all_resource_bounds(),
})]
#[case::l1_user_bounds(deploy_account_tx_args! {
version: TransactionVersion::THREE,
resource_bounds: default_l1_resource_bounds(),
})]
#[case::deprecated_tx_version(deploy_account_tx_args! {
version: TransactionVersion::ONE,
max_fee: Fee(1000000000000000),
})]
fn test_deploy_max_sierra_gas_validate_execute(
block_context: BlockContext,
versioned_constants: VersionedConstants,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1(RunnableCairo1::Casm))]
cairo_version: CairoVersion,
#[case] user_resource_bounds: ValidResourceBounds,
#[case] tx_args: DeployAccountTxArgs,
) {
let chain_info = &block_context.chain_info;
let mut nonce_manager = NonceManager::default();
Expand All @@ -2738,15 +2770,19 @@ fn test_deploy_max_sierra_gas_validate_execute(
let state = &mut test_state(chain_info, BALANCE, &[(account, 1)]);
let deploy_account = AccountTransaction::new_with_default_flags(executable_deploy_account_tx(
deploy_account_tx_args! {
resource_bounds: user_resource_bounds,
class_hash: account_class_hash
class_hash: account_class_hash,
.. tx_args
},
&mut nonce_manager,
));

// Extract deploy account transaction fields for testing, as it is consumed when creating an
// account transaction.
let user_initial_gas = user_initial_gas_from_bounds(user_resource_bounds, Some(&block_context));
let user_initial_gas = if tx_args.version == TransactionVersion::THREE {
user_initial_gas_from_bounds(tx_args.resource_bounds, Some(&block_context))
} else {
initial_gas_amount_from_block_context(Some(&block_context))
};

// Update the balance of the about to be deployed account contract in the erc20 contract, so it
// can pay for the transaction execution.
Expand Down
Loading