Skip to content

Commit

Permalink
refactor(batcher): add a batcher creation function to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Yael-Starkware committed Nov 17, 2024
1 parent a07960d commit 9373e8c
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions crates/starknet_batcher/src/batcher_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,19 @@ fn mempool_client() -> MockMempoolClient {
MockMempoolClient::new()
}

fn batcher(proposal_manager: MockProposalManagerTraitWrapper) -> Batcher {
Batcher::new(
batcher_config(),
Arc::new(storage_reader()),
Box::new(storage_writer()),
Arc::new(mempool_client()),
Box::new(proposal_manager),
)
}

#[rstest]
#[tokio::test]
async fn get_stream_content(
batcher_config: BatcherConfig,
storage_reader: MockBatcherStorageReaderTrait,
storage_writer: MockBatcherStorageWriterTrait,
mempool_client: MockMempoolClient,
) {
async fn get_stream_content() {
const PROPOSAL_ID: ProposalId = ProposalId(0);
// Expecting 3 chunks of streamed txs.
let expected_streamed_txs = test_txs(0..STREAMING_CHUNK_SIZE * 2 + 1);
Expand All @@ -96,13 +101,7 @@ async fn get_stream_content(
.times(1)
.return_once(move |_| async move { Ok(expected_proposal_commitment) }.boxed());

let mut batcher = Batcher::new(
batcher_config,
Arc::new(storage_reader),
Box::new(storage_writer),
Arc::new(mempool_client),
Box::new(proposal_manager),
);
let mut batcher = batcher(proposal_manager);

batcher.start_height(StartHeightInput { height: INITIAL_HEIGHT }).await.unwrap();
batcher
Expand Down Expand Up @@ -197,12 +196,7 @@ async fn decision_reached(

#[rstest]
#[tokio::test]
async fn decision_reached_no_executed_proposal(
batcher_config: BatcherConfig,
storage_reader: MockBatcherStorageReaderTrait,
storage_writer: MockBatcherStorageWriterTrait,
mempool_client: MockMempoolClient,
) {
async fn decision_reached_no_executed_proposal() {
const PROPOSAL_ID: ProposalId = ProposalId(0);
let expected_error = BatcherError::ExecutedProposalNotFound { proposal_id: PROPOSAL_ID };

Expand All @@ -213,13 +207,7 @@ async fn decision_reached_no_executed_proposal(
},
);

let mut batcher = Batcher::new(
batcher_config,
Arc::new(storage_reader),
Box::new(storage_writer),
Arc::new(mempool_client),
Box::new(proposal_manager),
);
let mut batcher = batcher(proposal_manager);
let decision_reached_result =
batcher.decision_reached(DecisionReachedInput { proposal_id: PROPOSAL_ID }).await;
assert_eq!(decision_reached_result, Err(expected_error));
Expand Down

0 comments on commit 9373e8c

Please sign in to comment.