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): refactor default testing resource bounds #1306

Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions crates/blockifier/src/blockifier/stateful_validator_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::test_utils::{
block_context,
create_account_tx_for_validate_test_nonce_0,
max_l1_resource_bounds,
default_l1_resource_bounds,
FaultyAccountTxCreatorArgs,
INVALID,
VALID,
Expand All @@ -33,7 +33,7 @@ fn test_tx_validator(
#[case] validate_constructor: bool,
#[case] tx_version: TransactionVersion,
block_context: BlockContext,
max_l1_resource_bounds: ValidResourceBounds,
default_l1_resource_bounds: ValidResourceBounds,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion,
) {
let chain_info = &block_context.chain_info;
Expand All @@ -54,7 +54,7 @@ fn test_tx_validator(
validate_constructor,
// TODO(Arni, 1/5/2024): Add test for insufficient maximal resources.
max_fee: BALANCE,
resource_bounds: max_l1_resource_bounds,
resource_bounds: default_l1_resource_bounds,
..Default::default()
};

Expand All @@ -75,7 +75,7 @@ fn test_tx_validator(
}

#[rstest]
fn test_tx_validator_skip_validate(max_l1_resource_bounds: ValidResourceBounds) {
fn test_tx_validator_skip_validate(default_l1_resource_bounds: ValidResourceBounds) {
let block_context = BlockContext::create_for_testing();
let faulty_account = FeatureContract::FaultyAccount(CairoVersion::Cairo1);
let state = test_state(&block_context.chain_info, BALANCE, &[(faulty_account, 1)]);
Expand All @@ -87,7 +87,7 @@ fn test_tx_validator_skip_validate(max_l1_resource_bounds: ValidResourceBounds)
tx_version: TransactionVersion::THREE,
sender_address: faulty_account.get_instance_address(0),
class_hash: faulty_account.get_class_hash(),
resource_bounds: max_l1_resource_bounds,
resource_bounds: default_l1_resource_bounds,
..Default::default()
});

Expand Down
10 changes: 7 additions & 3 deletions crates/blockifier/src/concurrency/fee_utils_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@ use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::{fund_account, test_state, test_state_inner};
use crate::test_utils::{create_trivial_calldata, CairoVersion, BALANCE};
use crate::transaction::objects::FeeType;
use crate::transaction::test_utils::{account_invoke_tx, block_context, max_l1_resource_bounds};
use crate::transaction::test_utils::{
account_invoke_tx,
block_context,
default_l1_resource_bounds,
};

#[rstest]
pub fn test_fill_sequencer_balance_reads(
block_context: BlockContext,
max_l1_resource_bounds: ValidResourceBounds,
default_l1_resource_bounds: ValidResourceBounds,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] erc20_version: CairoVersion,
) {
let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1);
let account_tx = account_invoke_tx(invoke_tx_args! {
sender_address: account.get_instance_address(0),
calldata: create_trivial_calldata(account.get_instance_address(0)),
resource_bounds: max_l1_resource_bounds,
resource_bounds: default_l1_resource_bounds,
});
let chain_info = &block_context.chain_info;
let state = &mut test_state_inner(chain_info, BALANCE, &[(account, 1)], erc20_version);
Expand Down
6 changes: 3 additions & 3 deletions crates/blockifier/src/concurrency/versioned_state_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::{CairoVersion, BALANCE, DEFAULT_STRK_L1_GAS_PRICE};
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::objects::HasRelatedFeeType;
use crate::transaction::test_utils::{l1_resource_bounds, max_l1_resource_bounds};
use crate::transaction::test_utils::{default_l1_resource_bounds, l1_resource_bounds};
use crate::transaction::transactions::ExecutableTransaction;

#[fixture]
Expand Down Expand Up @@ -211,7 +211,7 @@ fn test_versioned_state_proxy() {

#[rstest]
// Test parallel execution of two transactions that use the same versioned state.
fn test_run_parallel_txs(max_l1_resource_bounds: ValidResourceBounds) {
fn test_run_parallel_txs(default_l1_resource_bounds: ValidResourceBounds) {
let block_context = BlockContext::create_for_account_testing();
let chain_info = &block_context.chain_info;
let zero_bounds = true;
Expand Down Expand Up @@ -254,7 +254,7 @@ fn test_run_parallel_txs(max_l1_resource_bounds: ValidResourceBounds) {
let constructor_calldata = calldata![ctor_grind_arg, ctor_storage_arg];
let deploy_tx_args = deploy_account_tx_args! {
class_hash,
resource_bounds: max_l1_resource_bounds,
resource_bounds: default_l1_resource_bounds,
constructor_calldata: constructor_calldata.clone(),
};
let nonce_manager = &mut NonceManager::default();
Expand Down
28 changes: 14 additions & 14 deletions crates/blockifier/src/concurrency/worker_logic_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ use crate::transaction::objects::HasRelatedFeeType;
use crate::transaction::test_utils::{
account_invoke_tx,
calculate_class_info_for_testing,
default_l1_resource_bounds,
emit_n_events_tx,
max_fee,
max_l1_resource_bounds,
};
use crate::transaction::transaction_execution::Transaction;

Expand All @@ -64,7 +64,7 @@ fn trivial_calldata_invoke_tx(
account_invoke_tx(invoke_tx_args! {
sender_address: account_address,
calldata: create_trivial_calldata(test_contract_address),
resource_bounds: max_l1_resource_bounds(),
resource_bounds: default_l1_resource_bounds(),
nonce,
})
}
Expand Down Expand Up @@ -263,7 +263,7 @@ fn test_commit_tx_when_sender_is_sequencer() {
}

#[rstest]
fn test_worker_execute(max_l1_resource_bounds: ValidResourceBounds) {
fn test_worker_execute(default_l1_resource_bounds: ValidResourceBounds) {
// Settings.
let block_context = BlockContext::create_for_account_testing();
let account_contract = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1);
Expand All @@ -288,7 +288,7 @@ fn test_worker_execute(max_l1_resource_bounds: ValidResourceBounds) {
"test_storage_read_write",
&[*storage_key.0.key(),storage_value ], // Calldata: address, value.
),
resource_bounds: max_l1_resource_bounds,
resource_bounds: default_l1_resource_bounds,
nonce: nonce_manager.next(account_address)
});

Expand All @@ -301,7 +301,7 @@ fn test_worker_execute(max_l1_resource_bounds: ValidResourceBounds) {
"test_storage_read_write",
&[*storage_key.0.key(),storage_value ], // Calldata: address, value.
),
resource_bounds: max_l1_resource_bounds,
resource_bounds: default_l1_resource_bounds,
nonce: nonce_manager.next(account_address)

});
Expand All @@ -313,7 +313,7 @@ fn test_worker_execute(max_l1_resource_bounds: ValidResourceBounds) {
"write_and_revert",
&[felt!(1991_u16),storage_value ], // Calldata: address, value.
),
resource_bounds: max_l1_resource_bounds,
resource_bounds: default_l1_resource_bounds,
nonce: nonce_manager.next(account_address)

});
Expand Down Expand Up @@ -437,7 +437,7 @@ fn test_worker_execute(max_l1_resource_bounds: ValidResourceBounds) {
}

#[rstest]
fn test_worker_validate(max_l1_resource_bounds: ValidResourceBounds) {
fn test_worker_validate(default_l1_resource_bounds: ValidResourceBounds) {
// Settings.
let block_context = BlockContext::create_for_account_testing();
let account_contract = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1);
Expand All @@ -464,7 +464,7 @@ fn test_worker_validate(max_l1_resource_bounds: ValidResourceBounds) {
"test_storage_read_write",
&[*storage_key.0.key(),storage_value0 ], // Calldata: address, value.
),
resource_bounds: max_l1_resource_bounds,
resource_bounds: default_l1_resource_bounds,
nonce: nonce_manager.next(account_address)
});

Expand All @@ -475,7 +475,7 @@ fn test_worker_validate(max_l1_resource_bounds: ValidResourceBounds) {
"test_storage_read_write",
&[*storage_key.0.key(),storage_value1 ], // Calldata: address, value.
),
resource_bounds: max_l1_resource_bounds,
resource_bounds: default_l1_resource_bounds,
nonce: nonce_manager.next(account_address)

});
Expand Down Expand Up @@ -544,7 +544,7 @@ fn test_worker_validate(max_l1_resource_bounds: ValidResourceBounds) {
#[case::declare_cairo1(CairoVersion::Cairo1, TransactionVersion::THREE)]
fn test_deploy_before_declare(
max_fee: Fee,
max_l1_resource_bounds: ValidResourceBounds,
default_l1_resource_bounds: ValidResourceBounds,
#[case] cairo_version: CairoVersion,
#[case] version: TransactionVersion,
) {
Expand All @@ -565,7 +565,7 @@ fn test_deploy_before_declare(
let declare_tx = declare_tx(
declare_tx_args! {
sender_address: account_address_0,
resource_bounds: max_l1_resource_bounds,
resource_bounds: default_l1_resource_bounds,
class_hash: test_class_hash,
compiled_class_hash: test_compiled_class_hash,
version,
Expand All @@ -589,7 +589,7 @@ fn test_deploy_before_declare(
felt!(1_u8), // Constructor calldata arg2.
]
),
resource_bounds: max_l1_resource_bounds,
resource_bounds: default_l1_resource_bounds,
nonce: nonce!(0_u8)
});

Expand Down Expand Up @@ -634,7 +634,7 @@ fn test_deploy_before_declare(
}

#[rstest]
fn test_worker_commit_phase(max_l1_resource_bounds: ValidResourceBounds) {
fn test_worker_commit_phase(default_l1_resource_bounds: ValidResourceBounds) {
// Settings.
let block_context = BlockContext::create_for_account_testing();
let account_contract = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1);
Expand Down Expand Up @@ -662,7 +662,7 @@ fn test_worker_commit_phase(max_l1_resource_bounds: ValidResourceBounds) {
Transaction::Account(account_invoke_tx(invoke_tx_args! {
sender_address,
calldata: calldata.clone(),
resource_bounds: max_l1_resource_bounds,
resource_bounds: default_l1_resource_bounds,
nonce: nonce_manager.next(sender_address)
}))
})
Expand Down
8 changes: 4 additions & 4 deletions crates/blockifier/src/execution/stack_trace_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::transaction::test_utils::{
account_invoke_tx,
block_context,
create_account_tx_for_validate_test_nonce_0,
max_l1_resource_bounds,
default_l1_resource_bounds,
run_invoke_tx,
FaultyAccountTxCreatorArgs,
INVALID,
Expand Down Expand Up @@ -618,7 +618,7 @@ fn test_account_ctor_frame_stack_trace(
scenario: INVALID,
class_hash,
max_fee: BALANCE,
resource_bounds: max_l1_resource_bounds(),
resource_bounds: default_l1_resource_bounds(),
validate_constructor: true,
..Default::default()
});
Expand Down Expand Up @@ -666,7 +666,7 @@ An ASSERT_EQ instruction failed: 1 != 0.
/// point selector).
fn test_contract_ctor_frame_stack_trace(
block_context: BlockContext,
max_l1_resource_bounds: ValidResourceBounds,
default_l1_resource_bounds: ValidResourceBounds,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion,
) {
let chain_info = &block_context.chain_info;
Expand Down Expand Up @@ -703,7 +703,7 @@ fn test_contract_ctor_frame_stack_trace(
validate_constructor,
]
),
resource_bounds: max_l1_resource_bounds,
resource_bounds: default_l1_resource_bounds,
nonce: Nonce(felt!(0_u8)),
});

Expand Down
10 changes: 5 additions & 5 deletions crates/blockifier/src/fee/fee_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ use crate::test_utils::{
DEFAULT_ETH_L1_DATA_GAS_PRICE,
DEFAULT_ETH_L1_GAS_PRICE,
DEFAULT_L1_DATA_GAS_MAX_AMOUNT,
DEFAULT_L1_GAS_AMOUNT,
DEFAULT_L2_GAS_MAX_AMOUNT,
DEFAULT_STRK_L1_GAS_PRICE,
MAX_L1_GAS_AMOUNT,
};
use crate::transaction::objects::FeeType;
use crate::transaction::test_utils::{
Expand Down Expand Up @@ -237,25 +237,25 @@ fn test_discounted_gas_overdraft(
/// resource. If the gas used exceeds the limit, the post-execution validation should fail.
#[rstest]
#[case::l1_bound_overdraft(
(2 * MAX_L1_GAS_AMOUNT.0).into(),
(2 * DEFAULT_L1_GAS_AMOUNT.0).into(),
DEFAULT_L2_GAS_MAX_AMOUNT,
DEFAULT_L1_DATA_GAS_MAX_AMOUNT,
Some(Resource::L1Gas)
)]
#[case::l2_bound_overdraft(
MAX_L1_GAS_AMOUNT,
DEFAULT_L1_GAS_AMOUNT,
(2 * DEFAULT_L2_GAS_MAX_AMOUNT.0).into(),
DEFAULT_L1_DATA_GAS_MAX_AMOUNT,
Some(Resource::L2Gas)
)]
#[case::l1_data_bound_overdraft(
MAX_L1_GAS_AMOUNT,
DEFAULT_L1_GAS_AMOUNT,
DEFAULT_L2_GAS_MAX_AMOUNT,
(2 * DEFAULT_L1_DATA_GAS_MAX_AMOUNT.0).into(),
Some(Resource::L1DataGas)
)]
#[case::no_overdraft(
(MAX_L1_GAS_AMOUNT.0 / 2).into(),
(DEFAULT_L1_GAS_AMOUNT.0 / 2).into(),
(DEFAULT_L2_GAS_MAX_AMOUNT.0 / 2).into(),
(DEFAULT_L1_DATA_GAS_MAX_AMOUNT.0 / 2).into(),
None
Expand Down
33 changes: 23 additions & 10 deletions crates/blockifier/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,10 @@ pub fn test_erc20_sequencer_balance_key() -> StorageKey {
}

// The max_fee / resource bounds used for txs in this test.
pub const MAX_L1_GAS_AMOUNT: GasAmount = GasAmount(1000000);
pub const MAX_L1_GAS_PRICE: NonzeroGasPrice = DEFAULT_STRK_L1_GAS_PRICE;
pub const MAX_RESOURCE_COMMITMENT: Fee = MAX_L1_GAS_AMOUNT.nonzero_saturating_mul(MAX_L1_GAS_PRICE);
pub const MAX_FEE: Fee = MAX_L1_GAS_AMOUNT.nonzero_saturating_mul(DEFAULT_ETH_L1_GAS_PRICE);

// The amount of test-token allocated to the account in this test, set to a multiple of the max
// amount deprecated / non-deprecated transactions commit to paying.
pub const BALANCE: Fee = Fee(10 * const_max(MAX_FEE.0, MAX_RESOURCE_COMMITMENT.0));
// V3 transactions:
pub const DEFAULT_L1_GAS_AMOUNT: GasAmount = GasAmount(u64::pow(10, 6));
pub const DEFAULT_L1_DATA_GAS_MAX_AMOUNT: GasAmount = GasAmount(u64::pow(10, 6));
pub const DEFAULT_L2_GAS_MAX_AMOUNT: GasAmount = GasAmount(u64::pow(10, 9));

pub const DEFAULT_ETH_L1_GAS_PRICE: NonzeroGasPrice =
NonzeroGasPrice::new_unchecked(GasPrice(100 * u128::pow(10, 9))); // Given in units of Wei.
Expand All @@ -113,10 +109,27 @@ pub const DEFAULT_ETH_L1_DATA_GAS_PRICE: NonzeroGasPrice =
NonzeroGasPrice::new_unchecked(GasPrice(u128::pow(10, 6))); // Given in units of Wei.
pub const DEFAULT_STRK_L1_DATA_GAS_PRICE: NonzeroGasPrice =
NonzeroGasPrice::new_unchecked(GasPrice(u128::pow(10, 9))); // Given in units of STRK.
pub const DEFAULT_L1_DATA_GAS_MAX_AMOUNT: GasAmount = GasAmount(u64::pow(10, 6));
pub const DEFAULT_STRK_L2_GAS_PRICE: NonzeroGasPrice =
NonzeroGasPrice::new_unchecked(GasPrice(u128::pow(10, 9)));
pub const DEFAULT_L2_GAS_MAX_AMOUNT: GasAmount = GasAmount(u64::pow(10, 6));

// Deprecated transactions:
pub const MAX_FEE: Fee = DEFAULT_L1_GAS_AMOUNT.nonzero_saturating_mul(DEFAULT_ETH_L1_GAS_PRICE);

// Commitment fee bounds.
const DEFAULT_L1_BOUNDS_COMMITTED_FEE: Fee =
DEFAULT_L1_GAS_AMOUNT.nonzero_saturating_mul(DEFAULT_STRK_L1_GAS_PRICE);
const DEFAULT_ALL_BOUNDS_COMMITTED_FEE: Fee = DEFAULT_L1_BOUNDS_COMMITTED_FEE
.saturating_add(DEFAULT_L2_GAS_MAX_AMOUNT.nonzero_saturating_mul(DEFAULT_STRK_L2_GAS_PRICE))
.saturating_add(
DEFAULT_L1_DATA_GAS_MAX_AMOUNT.nonzero_saturating_mul(DEFAULT_STRK_L1_DATA_GAS_PRICE),
);
// The amount of test-token allocated to the account in this test, set to a multiple of the max
// amount deprecated / non-deprecated transactions commit to paying.
pub const BALANCE: Fee = Fee(10
* const_max(
const_max(DEFAULT_ALL_BOUNDS_COMMITTED_FEE.0, DEFAULT_L1_BOUNDS_COMMITTED_FEE.0),
MAX_FEE.0,
));

// The block number of the BlockContext being used for testing.
pub const CURRENT_BLOCK_NUMBER: u64 = 2001;
Expand Down
Loading
Loading