From 18cd8e5ae01e032474afce2ed4cca4255edcd529 Mon Sep 17 00:00:00 2001 From: Yael Doweck Date: Mon, 28 Oct 2024 15:31:03 +0200 Subject: [PATCH] refactor(batcher): block builder test, add empty block case --- crates/batcher/src/block_builder_test.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/batcher/src/block_builder_test.rs b/crates/batcher/src/block_builder_test.rs index 05820a91fe..43d6a68bee 100644 --- a/crates/batcher/src/block_builder_test.rs +++ b/crates/batcher/src/block_builder_test.rs @@ -88,6 +88,18 @@ fn two_chunks_test_expectations( (mock_transaction_executor, mock_tx_provider, expected_block_artifacts) } +fn empty_block_test_expectations() +-> (MockTransactionExecutorTrait, MockTransactionProvider, BlockExecutionArtifacts) { + let mut mock_transaction_executor = MockTransactionExecutorTrait::new(); + mock_transaction_executor.expect_add_txs_to_block().times(0); + + let expected_block_artifacts = set_close_block_expectations(&mut mock_transaction_executor, 0); + + let mock_tx_provider = mock_tx_provider(1, vec![vec![]]); + + (mock_transaction_executor, mock_tx_provider, expected_block_artifacts) +} + // 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 { @@ -169,11 +181,12 @@ async fn run_build_block( block_builder.build_block(deadline, Box::new(tx_provider), output_sender).await.unwrap() } -// TODO: Add test cases for block full, empty block, failed transaction, +// TODO: Add test cases for block full, failed transaction, // timeout reached. #[rstest] #[case::one_chunk_block(3, test_txs(0..3), one_chunk_test_expectations(&input_txs))] #[case::two_chunks_block(6, test_txs(0..6), two_chunks_test_expectations(&input_txs))] +#[case::empty_block(0, vec![], empty_block_test_expectations())] #[tokio::test] async fn test_build_block( #[case] expected_block_size: usize,