Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

test(concurrency): test commit tx where the sequencer address is als… #1935

Merged
Merged
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
69 changes: 69 additions & 0 deletions crates/blockifier/src/concurrency/worker_logic_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,75 @@ pub fn test_commit_tx() {
}
}

#[test]
// When the sequencer is the sender, we use the sequential (full) fee transfer.
// Thus, we skip the last step of commit tx, meaning the execution result before and after
// commit tx should be the same (except for re-execution changes).
fn test_commit_tx_when_sender_is_sequencer() {
let mut block_context = BlockContext::create_for_account_testing_with_concurrency_mode(true);
let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1);
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo0);
let account_address = account.get_instance_address(0_u16);
let test_contract_address = test_contract.get_instance_address(0_u16);
block_context.block_info.sequencer_address = account_address;
let (sequencer_balance_key_low, sequencer_balance_key_high) =
get_sequencer_balance_keys(&block_context);

let sequencer_tx = [Transaction::AccountTransaction(trivial_calldata_invoke_tx(
account_address,
test_contract_address,
nonce!(0_u8),
))];

let mut bouncer = Bouncer::new(block_context.bouncer_config.clone());

let state = test_state(&block_context.chain_info, BALANCE, &[(account, 1), (test_contract, 1)]);
let versioned_state = safe_versioned_state_for_testing(state);
let executor = WorkerExecutor::new(
versioned_state,
&sequencer_tx,
&block_context,
Mutex::new(&mut bouncer),
);
let tx_index = 0;
let tx_versioned_state = executor.state.pin_version(tx_index);

// Execute and save the execution result.
executor.execute_tx(tx_index);
let execution_task_outputs = lock_mutex_in_array(&executor.execution_outputs, tx_index);
let execution_result = &execution_task_outputs.as_ref().unwrap().result;
let fee_transfer_call_info =
execution_result.as_ref().unwrap().fee_transfer_call_info.as_ref().unwrap();
let read_values_before_commit = fee_transfer_call_info.storage_read_values.clone();
drop(execution_task_outputs);

let tx_context = &executor.block_context.to_tx_context(&sequencer_tx[0]);
let fee_token_address =
executor.block_context.chain_info.fee_token_address(&tx_context.tx_info.fee_type());
let sequencer_balance_high_before =
tx_versioned_state.get_storage_at(fee_token_address, sequencer_balance_key_high).unwrap();
let sequencer_balance_low_before =
tx_versioned_state.get_storage_at(fee_token_address, sequencer_balance_key_low).unwrap();

// Commit tx and check that the commit made no changes in the execution result or the state.
executor.commit_tx(tx_index);
let execution_task_outputs = lock_mutex_in_array(&executor.execution_outputs, tx_index);
let commit_result = &execution_task_outputs.as_ref().unwrap().result;
let fee_transfer_call_info =
commit_result.as_ref().unwrap().fee_transfer_call_info.as_ref().unwrap();
// Check that the result call info is the same as before the commit.
assert_eq!(read_values_before_commit, fee_transfer_call_info.storage_read_values);

let sequencer_balance_low_after =
tx_versioned_state.get_storage_at(fee_token_address, sequencer_balance_key_low).unwrap();
let sequencer_balance_high_after =
tx_versioned_state.get_storage_at(fee_token_address, sequencer_balance_key_high).unwrap();

// Check that the sequencer balance is the same as before the commit.
assert_eq!(sequencer_balance_low_before, sequencer_balance_low_after);
assert_eq!(sequencer_balance_high_before, sequencer_balance_high_after);
}

#[test]
fn test_worker_execute() {
// Settings.
Expand Down
Loading