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): uncover an error in test_l1_handler in the case of transaction version three #2146

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,17 @@ fn test_invoke(
}

#[rstest]
fn test_l1_handler(block_context: BlockContext) {
fn test_l1_handler(
block_context: BlockContext,
#[values(TransactionVersion::ZERO, TransactionVersion::THREE)] version: TransactionVersion,
) {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1);
let state = test_state(&block_context.chain_info, BALANCE, &[(test_contract, 1)]);

let tx = Transaction::L1Handler(l1handler_tx(
Fee(1908000000000000),
test_contract.get_instance_address(0),
version,
));
let expected_bouncer_weights = BouncerWeights {
state_diff_size: 4,
Expand Down
8 changes: 6 additions & 2 deletions crates/blockifier/src/test_utils/l1_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ use starknet_api::transaction::fields::Fee;
use starknet_api::transaction::TransactionVersion;
use starknet_types_core::felt::Felt;

pub fn l1handler_tx(l1_fee: Fee, contract_address: ContractAddress) -> L1HandlerTransaction {
pub fn l1handler_tx(
l1_fee: Fee,
contract_address: ContractAddress,
version: TransactionVersion,
) -> L1HandlerTransaction {
let calldata = calldata![
Felt::from(0x123), // from_address.
Felt::from(0x876), // key.
Felt::from(0x44) // value.
];

executable_l1_handler_tx(L1HandlerTxArgs {
version: TransactionVersion::ZERO,
version,
contract_address,
entry_point_selector: selector_from_name("l1_handler_set_value"),
calldata,
Expand Down
11 changes: 7 additions & 4 deletions crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2242,15 +2242,18 @@ fn test_only_query_flag(
}

#[rstest]
fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) {
fn test_l1_handler(
#[values(false, true)] use_kzg_da: bool,
#[values(TransactionVersion::ZERO, TransactionVersion::THREE)] version: TransactionVersion,
) {
let gas_mode = GasVectorComputationMode::NoL2Gas;
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1);
let chain_info = &ChainInfo::create_for_testing();
let state = &mut test_state(chain_info, BALANCE, &[(test_contract, 1)]);
let block_context = &BlockContext::create_for_account_testing_with_kzg(use_kzg_da);
let contract_address = test_contract.get_instance_address(0);
let versioned_constants = &block_context.versioned_constants;
let tx = l1handler_tx(Fee(1), contract_address);
let tx = l1handler_tx(Fee(1), contract_address, version);
let calldata = tx.tx.calldata.clone();
let key = calldata.0[1];
let value = calldata.0[2];
Expand Down Expand Up @@ -2384,9 +2387,9 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) {

// set the storage back to 0, so the fee will also include the storage write.
// TODO(Meshi, 15/6/2024): change the l1_handler_set_value cairo function to
// always uptade the storage instad.
// always update the storage instead.
state.set_storage_at(contract_address, StorageKey::try_from(key).unwrap(), Felt::ZERO).unwrap();
let tx_no_fee = l1handler_tx(Fee(0), contract_address);
let tx_no_fee = l1handler_tx(Fee(0), contract_address, version);
let error = tx_no_fee.execute(state, block_context, false, true).unwrap_err(); // Do not charge fee as L1Handler's resource bounds (/max fee) is 0.
// Today, we check that the paid_fee is positive, no matter what was the actual fee.
let expected_actual_fee =
Expand Down
Loading