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

refactor(blockifier): remove constant from pre validate test #996

Open
wants to merge 1 commit into
base: yoav/blockifier/remove_constants/pre_validate/03
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
67 changes: 34 additions & 33 deletions crates/blockifier/src/transaction/execution_flavors_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ fn gas_and_fee(base_gas: u64, validate_mode: bool, fee_type: &FeeType) -> (u64,
)
}

fn calculate_actual_gas(
tx_execution_info: &TransactionExecutionInfo,
block_context: &BlockContext,
) -> u128 {
tx_execution_info
.receipt
.resources
.to_gas_vector(
&block_context.versioned_constants,
block_context.block_info.use_kzg_da,
&GasVectorComputationMode::NoL2Gas,
)
.unwrap()
.l1_gas
}

/// Asserts gas used and reported fee are as expected.
// TODO(Aner, 21/01/24) modify for 4844 (taking blob_gas into account).
fn check_gas_and_fee(
Expand All @@ -132,19 +148,7 @@ fn check_gas_and_fee(
expected_actual_fee: Fee,
expected_cost_of_resources: Fee,
) {
assert_eq!(
tx_execution_info
.receipt
.resources
.to_gas_vector(
&block_context.versioned_constants,
block_context.block_info.use_kzg_da,
&GasVectorComputationMode::NoL2Gas,
)
.unwrap()
.l1_gas,
expected_actual_gas.into()
);
assert_eq!(calculate_actual_gas(tx_execution_info, block_context), expected_actual_gas.into());

assert_eq!(tx_execution_info.receipt.fee, expected_actual_fee);
// Future compatibility: resources other than the L1 gas usage may affect the fee (currently,
Expand Down Expand Up @@ -352,16 +356,23 @@ fn test_simulate_validate_pre_validate_not_charge_fee(
get_pre_validate_test_args(cairo_version, version, only_query);
let account_address = pre_validation_base_args.sender_address;

let (actual_gas_used, actual_fee) = gas_and_fee(
u64_from_usize(
get_syscall_resources(SyscallSelector::CallContract).n_steps
+ get_tx_resources(TransactionType::InvokeFunction).n_steps
+ 1738,
),
validate,
&fee_type,
let tx_execution_info = account_invoke_tx(invoke_tx_args! {
nonce: nonce_manager.next(account_address),
..pre_validation_base_args.clone()
})
.execute(&mut state, &block_context, charge_fee, false)
.unwrap();
let base_gas = calculate_actual_gas(&tx_execution_info, &block_context).try_into().unwrap();
assert!(
base_gas
> u64_from_usize(
get_syscall_resources(SyscallSelector::CallContract).n_steps
+ get_tx_resources(TransactionType::InvokeFunction).n_steps
)
);

let (actual_gas_used, actual_fee) = gas_and_fee(base_gas, validate, &fee_type);

let mut execute_and_check_gas_and_fee = |(max_fee, resource_bounds)| {
let tx_execution_info = account_invoke_tx(invoke_tx_args! {
max_fee,
Expand Down Expand Up @@ -494,18 +505,8 @@ fn test_simulate_charge_fee_no_validation_fail_validate(

// Validation scenario: fallible validation.
let block_context = BlockContext::create_for_account_testing();
let base_gas = transaction_execution_info
.receipt
.resources
.to_gas_vector(
&block_context.versioned_constants,
block_context.block_info.use_kzg_da,
&GasVectorComputationMode::NoL2Gas,
)
.unwrap()
.l1_gas
.try_into()
.unwrap();
let base_gas =
calculate_actual_gas(&transaction_execution_info, &block_context).try_into().unwrap();
assert!(base_gas > u64_from_usize(get_tx_resources(TransactionType::InvokeFunction).n_steps));
let (actual_gas_used, actual_fee) = gas_and_fee(base_gas, validate, &fee_type);

Expand Down
Loading