Skip to content

Commit

Permalink
test(blockifier): uncover an error in test_l1_handler in the case of …
Browse files Browse the repository at this point in the history
…transaction version three
  • Loading branch information
ArniStarkware committed Nov 18, 2024
1 parent 3f82a9f commit bcaf5fe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
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
8 changes: 1 addition & 7 deletions crates/starknet_api/src/test_utils/l1_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,9 @@ macro_rules! l1_handler_tx_args {
pub fn executable_l1_handler_tx(
l1_handler_tx_args: L1HandlerTxArgs,
) -> ExecutableL1HandlerTransaction {
let tx_version = l1_handler_tx_args.version;
// TODO(Arni): Re-enable this validation.
// if tx_version != TransactionVersion::THREE {
// panic!("Unsupported transaction version: {:?}.", l1_handler_tx_args.version);
// }

ExecutableL1HandlerTransaction {
tx: L1HandlerTransaction {
version: tx_version,
version: l1_handler_tx_args.version,
nonce: l1_handler_tx_args.nonce,
contract_address: l1_handler_tx_args.contract_address,
entry_point_selector: l1_handler_tx_args.entry_point_selector,
Expand Down

0 comments on commit bcaf5fe

Please sign in to comment.