Skip to content

Commit

Permalink
test(batcher): block builder transaction failed test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yael-Starkware committed Nov 21, 2024
1 parent 02a4d32 commit 488568d
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions crates/starknet_batcher/src/block_builder_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use assert_matches::assert_matches;
use blockifier::blockifier::transaction_executor::TransactionExecutorError;
use blockifier::bouncer::BouncerWeights;
use blockifier::fee::fee_checks::FeeCheckError;
use blockifier::state::errors::StateError;
use blockifier::transaction::objects::{RevertError, TransactionExecutionInfo};
use blockifier::transaction::transaction_execution::Transaction as BlockifierTransaction;
use indexmap::IndexMap;
use indexmap::{indexmap, IndexMap};
use mockall::predicate::eq;
use mockall::Sequence;
use rstest::rstest;
Expand Down Expand Up @@ -232,6 +233,43 @@ fn stream_done_test_expectations() -> TestExpectations {
}
}

fn transaction_failed_test_expectations() -> TestExpectations {
let input_txs = test_txs(0..3);

let mut expected_txs_output = input_txs.clone();
expected_txs_output.remove(1);

let mut mock_transaction_executor = MockTransactionExecutorTrait::new();
let execution_error =
TransactionExecutorError::StateError(StateError::OutOfRangeContractAddress);
mock_transaction_executor.expect_add_txs_to_block().times(1).return_once(move |_| {
vec![Ok(execution_info()), Err(execution_error), Ok(execution_info())]
});

let execution_infos_mapping = indexmap![
TransactionHash(felt!(u8::try_from(0).unwrap()))=> execution_info(),
TransactionHash(felt!(u8::try_from(2).unwrap()))=> execution_info(),
];
let expected_block_artifacts = block_execution_artifacts(execution_infos_mapping);
let expected_block_artifacts_copy = expected_block_artifacts.clone();
mock_transaction_executor.expect_close_block().times(1).return_once(move || {
Ok((
expected_block_artifacts_copy.commitment_state_diff,
expected_block_artifacts_copy.visited_segments_mapping,
expected_block_artifacts_copy.bouncer_weights,
))
});

let mock_tx_provider = mock_tx_provider_limitless_calls(1, vec![input_txs]);

TestExpectations {
mock_transaction_executor,
mock_tx_provider,
expected_block_artifacts,
expected_txs_output,
}
}

// Fill the executor outputs with some non-default values to make sure the block_builder uses
// them.
fn block_builder_expected_output(execution_info_len: usize) -> BlockExecutionArtifacts {
Expand Down Expand Up @@ -356,14 +394,14 @@ async fn run_build_block(
block_builder.build_block().await
}

// TODO: Add test case for failed transaction.
#[rstest]
#[case::one_chunk_block(one_chunk_test_expectations())]
#[case::two_chunks_block(two_chunks_test_expectations())]
#[case::empty_block(empty_block_test_expectations())]
#[case::block_full(block_full_test_expectations())]
#[case::deadline_reached_after_first_chunk(test_expectations_with_delay())]
#[case::stream_done(stream_done_test_expectations())]
#[case::transaction_failed(transaction_failed_test_expectations())]
#[tokio::test]
async fn test_build_block(#[case] test_expectations: TestExpectations) {
let (output_tx_sender, output_tx_receiver) = output_channel();
Expand Down

0 comments on commit 488568d

Please sign in to comment.