Skip to content

Commit

Permalink
test(blockifier): global validate and execute sierra_gas; deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
aner-starkware committed Dec 14, 2024
1 parent 772a04a commit ee5e587
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 100 deletions.
30 changes: 14 additions & 16 deletions crates/blockifier/src/transaction/account_transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use starknet_api::executable_transaction::{
AccountTransaction as ApiExecutableTransaction,
DeclareTransaction as ApiExecutableDeclareTransaction,
};
use starknet_api::execution_resources::GasAmount;
use starknet_api::execution_resources::{GasAmount, GasVector};
use starknet_api::hash::StarkHash;
use starknet_api::state::StorageKey;
use starknet_api::test_utils::declare::executable_declare_tx;
Expand Down Expand Up @@ -79,7 +79,6 @@ use crate::test_utils::{
DEFAULT_L1_DATA_GAS_MAX_AMOUNT,
DEFAULT_L1_GAS_AMOUNT,
DEFAULT_L2_GAS_MAX_AMOUNT,
DEFAULT_STRK_L1_DATA_GAS_PRICE,
DEFAULT_STRK_L1_GAS_PRICE,
DEFAULT_STRK_L2_GAS_PRICE,
MAX_FEE,
Expand All @@ -95,6 +94,7 @@ use crate::transaction::test_utils::{
calculate_class_info_for_testing,
create_account_tx_for_validate_test_nonce_0,
create_all_resource_bounds,
create_gas_amount_bounds_with_default_price,
create_test_init_data,
default_all_resource_bounds,
default_l1_resource_bounds,
Expand Down Expand Up @@ -205,13 +205,12 @@ fn test_fee_enforcement(
(if zero_bounds { 0 } else { DEFAULT_L1_GAS_AMOUNT.0 }).into(),
DEFAULT_STRK_L1_GAS_PRICE.into()
),
GasVectorComputationMode::All => create_all_resource_bounds(
(if zero_bounds { 0 } else { DEFAULT_L1_GAS_AMOUNT.0 }).into(),
DEFAULT_STRK_L1_GAS_PRICE.into(),
(if zero_bounds { 0 } else { DEFAULT_L2_GAS_MAX_AMOUNT.0 }).into(),
DEFAULT_STRK_L2_GAS_PRICE.into(),
(if zero_bounds { 0 } else { DEFAULT_L1_DATA_GAS_MAX_AMOUNT.0 }).into(),
DEFAULT_STRK_L1_DATA_GAS_PRICE.into(),
GasVectorComputationMode::All => create_gas_amount_bounds_with_default_price(
GasVector{
l1_gas: (if zero_bounds { 0 } else { DEFAULT_L1_GAS_AMOUNT.0 }).into(),
l2_gas: (if zero_bounds { 0 } else { DEFAULT_L2_GAS_MAX_AMOUNT.0 }).into(),
l1_data_gas: (if zero_bounds { 0 } else { DEFAULT_L1_DATA_GAS_MAX_AMOUNT.0 }).into(),
},
),
},
version,
Expand All @@ -237,13 +236,12 @@ fn test_all_bounds_combinations_enforce_fee(
let expected_enforce_fee = l1_gas_bound + l1_data_gas_bound + l2_gas_bound > 0;
let account_tx = invoke_tx_with_default_flags(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(),
resource_bounds: create_gas_amount_bounds_with_default_price(
GasVector {
l1_gas: l1_gas_bound.into(),
l2_gas: l2_gas_bound.into(),
l1_data_gas: l1_data_gas_bound.into(),
},
),
});
assert_eq!(account_tx.enforce_fee(), expected_enforce_fee);
Expand Down
20 changes: 5 additions & 15 deletions crates/blockifier/src/transaction/post_execution_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use assert_matches::assert_matches;
use rstest::rstest;
use starknet_api::block::FeeType;
use starknet_api::core::ContractAddress;
use starknet_api::execution_resources::GasAmount;
use starknet_api::execution_resources::{GasAmount, GasVector};
use starknet_api::state::StorageKey;
use starknet_api::transaction::fields::{
AllResourceBounds,
Expand All @@ -22,20 +22,13 @@ use crate::fee::fee_checks::FeeCheckError;
use crate::state::state_api::StateReader;
use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::{
create_calldata,
CairoVersion,
BALANCE,
DEFAULT_STRK_L1_DATA_GAS_PRICE,
DEFAULT_STRK_L1_GAS_PRICE,
DEFAULT_STRK_L2_GAS_PRICE,
};
use crate::test_utils::{create_calldata, CairoVersion, BALANCE, DEFAULT_STRK_L1_GAS_PRICE};
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::errors::TransactionExecutionError;
use crate::transaction::objects::{HasRelatedFeeType, TransactionInfoCreator};
use crate::transaction::test_utils::{
block_context,
create_all_resource_bounds,
create_gas_amount_bounds_with_default_price,
default_all_resource_bounds,
default_l1_resource_bounds,
invoke_tx_with_default_flags,
Expand Down Expand Up @@ -374,14 +367,11 @@ fn test_revert_on_resource_overuse(
Resource::L2Gas => l2_gas.0 -= 1,
Resource::L1DataGas => l1_data_gas.0 -= 1,
}
create_all_resource_bounds(
create_gas_amount_bounds_with_default_price(GasVector {
l1_gas,
DEFAULT_STRK_L1_GAS_PRICE.into(),
l2_gas,
DEFAULT_STRK_L2_GAS_PRICE.into(),
l1_data_gas,
DEFAULT_STRK_L1_DATA_GAS_PRICE.into(),
)
})
}
}
};
Expand Down
45 changes: 20 additions & 25 deletions crates/blockifier/src/transaction/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use starknet_api::abi::abi_utils::get_fee_token_var_address;
use starknet_api::block::{FeeType, GasPrice};
use starknet_api::contract_class::{ClassInfo, ContractClass, SierraVersion};
use starknet_api::core::{ClassHash, ContractAddress, Nonce};
use starknet_api::execution_resources::GasAmount;
use starknet_api::execution_resources::{GasAmount, GasVector};
use starknet_api::test_utils::declare::executable_declare_tx;
use starknet_api::test_utils::deploy_account::{executable_deploy_account_tx, DeployAccountTxArgs};
use starknet_api::test_utils::invoke::{executable_invoke_tx, InvokeTxArgs};
Expand Down Expand Up @@ -59,6 +59,16 @@ pub const STORAGE_WRITE: u64 = 8;

/// Test fixtures.
#[fixture]
pub fn block_context() -> BlockContext {
BlockContext::create_for_account_testing()
}

#[fixture]
pub fn versioned_constants(block_context: BlockContext) -> VersionedConstants {
block_context.versioned_constants().clone()
}

#[fixture]
pub fn max_fee() -> Fee {
MAX_FEE
Expand All @@ -80,42 +90,27 @@ pub fn create_resource_bounds(computation_mode: &GasVectorComputationMode) -> Va
GasVectorComputationMode::NoL2Gas => {
l1_resource_bounds(DEFAULT_L1_GAS_AMOUNT, DEFAULT_STRK_L1_GAS_PRICE.into())
}
GasVectorComputationMode::All => create_all_resource_bounds(
DEFAULT_L1_GAS_AMOUNT,
DEFAULT_STRK_L1_GAS_PRICE.into(),
DEFAULT_L2_GAS_MAX_AMOUNT,
DEFAULT_STRK_L2_GAS_PRICE.into(),
DEFAULT_L1_DATA_GAS_MAX_AMOUNT,
DEFAULT_STRK_L1_DATA_GAS_PRICE.into(),
),
GasVectorComputationMode::All => create_gas_amount_bounds_with_default_price(GasVector {
l1_gas: DEFAULT_L1_GAS_AMOUNT,
l1_data_gas: DEFAULT_L1_DATA_GAS_MAX_AMOUNT,
l2_gas: DEFAULT_L2_GAS_MAX_AMOUNT,
}),
}
}

pub fn create_gas_amount_bounds_with_default_price(
l1_gas_amount: GasAmount,
l2_gas_amount: GasAmount,
l1_data_gas_amount: GasAmount,
GasVector { l1_gas, l1_data_gas, l2_gas }: GasVector,
) -> ValidResourceBounds {
create_all_resource_bounds(
l1_gas_amount,
l1_gas,
DEFAULT_STRK_L1_GAS_PRICE.into(),
l2_gas_amount,
l2_gas,
DEFAULT_STRK_L2_GAS_PRICE.into(),
l1_data_gas_amount,
l1_data_gas,
DEFAULT_STRK_L1_DATA_GAS_PRICE.into(),
)
}

#[fixture]
pub fn block_context() -> BlockContext {
BlockContext::create_for_account_testing()
}

#[fixture]
pub fn versioned_constants(block_context: BlockContext) -> VersionedConstants {
block_context.versioned_constants().clone()
}

/// Struct containing the data usually needed to initialize a test.
pub struct TestInitData {
pub state: CachedState<DictStateReader>,
Expand Down
Loading

0 comments on commit ee5e587

Please sign in to comment.