Skip to content

Commit c0bac21

Browse files
committed
apollo_consensus_orchestrator: add helper func to test sending proposal to validate
1 parent ee608ff commit c0bac21

File tree

3 files changed

+50
-71
lines changed

3 files changed

+50
-71
lines changed

crates/apollo_consensus_orchestrator/src/sequencer_consensus_context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,10 @@ impl SequencerConsensusContext {
440440
error!("Failed to prepare blob for next height at height {height}: {e:?}");
441441
}
442442
}
443+
444+
pub fn get_config(&self) -> &ContextConfig {
445+
&self.config
446+
}
443447
}
444448

445449
#[async_trait]

crates/apollo_consensus_orchestrator/src/sequencer_consensus_context_test.rs

Lines changed: 8 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use crate::orchestrator_versioned_constants::VersionedConstants;
4646
use crate::test_utils::{
4747
block_info,
4848
create_test_and_network_deps,
49+
send_proposal_to_validator_context,
4950
SetupDepsArgs,
5051
ETH_TO_FRI_RATE,
5152
INTERNAL_TX_BATCH,
@@ -81,26 +82,10 @@ async fn validate_proposal_success() {
8182
// Initialize the context for a specific height, starting with round 0.
8283
context.set_height_and_round(BlockNumber(0), 0).await.unwrap();
8384

84-
let (mut content_sender, content_receiver) =
85-
mpsc::channel(context.config.static_config.proposal_buffer_size);
86-
content_sender.send(ProposalPart::BlockInfo(block_info(BlockNumber(0)))).await.unwrap();
87-
content_sender
88-
.send(ProposalPart::Transactions(TransactionBatch { transactions: TX_BATCH.to_vec() }))
89-
.await
90-
.unwrap();
91-
content_sender
92-
.send(ProposalPart::ExecutedTransactionCount(INTERNAL_TX_BATCH.len().try_into().unwrap()))
93-
.await
94-
.unwrap();
95-
content_sender
96-
.send(ProposalPart::Fin(ProposalFin {
97-
proposal_commitment: ProposalCommitment(STATE_DIFF_COMMITMENT.0.0),
98-
}))
99-
.await
100-
.unwrap();
85+
let content_receiver =
86+
send_proposal_to_validator_context(&mut context, block_info(BlockNumber(0))).await;
10187
let fin_receiver =
10288
context.validate_proposal(ProposalInit::default(), TIMEOUT, content_receiver).await;
103-
content_sender.close_channel();
10489
assert_eq!(fin_receiver.await.unwrap().0, STATE_DIFF_COMMITMENT.0.0);
10590
}
10691

@@ -258,23 +243,8 @@ async fn interrupt_active_proposal() {
258243
let fin_receiver_0 =
259244
context.validate_proposal(ProposalInit::default(), TIMEOUT, content_receiver).await;
260245

261-
let (mut content_sender_1, content_receiver) =
262-
mpsc::channel(context.config.static_config.proposal_buffer_size);
263-
content_sender_1.send(ProposalPart::BlockInfo(block_info(BlockNumber(0)))).await.unwrap();
264-
content_sender_1
265-
.send(ProposalPart::Transactions(TransactionBatch { transactions: TX_BATCH.to_vec() }))
266-
.await
267-
.unwrap();
268-
content_sender_1
269-
.send(ProposalPart::ExecutedTransactionCount(INTERNAL_TX_BATCH.len().try_into().unwrap()))
270-
.await
271-
.unwrap();
272-
content_sender_1
273-
.send(ProposalPart::Fin(ProposalFin {
274-
proposal_commitment: ProposalCommitment(STATE_DIFF_COMMITMENT.0.0),
275-
}))
276-
.await
277-
.unwrap();
246+
let content_receiver =
247+
send_proposal_to_validator_context(&mut context, block_info(BlockNumber(0))).await;
278248
let fin_receiver_1 = context
279249
.validate_proposal(
280250
ProposalInit { round: 1, ..Default::default() },
@@ -605,8 +575,6 @@ async fn gas_price_limits(#[case] maximum: bool) {
605575
let mut context = deps.build_context();
606576

607577
context.set_height_and_round(BlockNumber(0), 0).await.unwrap();
608-
let (mut content_sender, content_receiver) =
609-
mpsc::channel(context.config.static_config.proposal_buffer_size);
610578

611579
let mut block_info = block_info(BlockNumber(0));
612580

@@ -621,21 +589,7 @@ async fn gas_price_limits(#[case] maximum: bool) {
621589
}
622590

623591
// Send the block info, some transactions and then fin.
624-
content_sender.send(ProposalPart::BlockInfo(block_info).clone()).await.unwrap();
625-
content_sender
626-
.send(ProposalPart::Transactions(TransactionBatch { transactions: TX_BATCH.to_vec() }))
627-
.await
628-
.unwrap();
629-
content_sender
630-
.send(ProposalPart::ExecutedTransactionCount(INTERNAL_TX_BATCH.len().try_into().unwrap()))
631-
.await
632-
.unwrap();
633-
content_sender
634-
.send(ProposalPart::Fin(ProposalFin {
635-
proposal_commitment: ProposalCommitment(STATE_DIFF_COMMITMENT.0.0),
636-
}))
637-
.await
638-
.unwrap();
592+
let content_receiver = send_proposal_to_validator_context(&mut context, block_info).await;
639593

640594
// Even though we used the minimum/maximum gas price, not the values we gave the provider,
641595
// the proposal should be still be valid due to the clamping of limit prices.
@@ -845,26 +799,10 @@ async fn oracle_fails_on_second_block(#[case] l1_oracle_failure: bool) {
845799
// Initialize the context for a specific height, starting with round 0.
846800
context.set_height_and_round(BlockNumber(0), 0).await.unwrap();
847801

848-
let (mut content_sender, content_receiver) =
849-
mpsc::channel(context.config.static_config.proposal_buffer_size);
850-
content_sender.send(ProposalPart::BlockInfo(block_info(BlockNumber(0)))).await.unwrap();
851-
content_sender
852-
.send(ProposalPart::Transactions(TransactionBatch { transactions: TX_BATCH.to_vec() }))
853-
.await
854-
.unwrap();
855-
content_sender
856-
.send(ProposalPart::ExecutedTransactionCount(INTERNAL_TX_BATCH.len().try_into().unwrap()))
857-
.await
858-
.unwrap();
859-
content_sender
860-
.send(ProposalPart::Fin(ProposalFin {
861-
proposal_commitment: ProposalCommitment(STATE_DIFF_COMMITMENT.0.0),
862-
}))
863-
.await
864-
.unwrap();
802+
let content_receiver =
803+
send_proposal_to_validator_context(&mut context, block_info(BlockNumber(0))).await;
865804
let fin_receiver =
866805
context.validate_proposal(ProposalInit::default(), TIMEOUT, content_receiver).await;
867-
content_sender.close_channel();
868806
let proposal_commitment = fin_receiver.await.unwrap();
869807
assert_eq!(proposal_commitment.0, STATE_DIFF_COMMITMENT.0.0);
870808

crates/apollo_consensus_orchestrator/src/test_utils.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,20 @@ use apollo_network::network_manager::test_utils::{
2828
TestSubscriberChannels,
2929
};
3030
use apollo_network::network_manager::{BroadcastTopicChannels, BroadcastTopicClient};
31-
use apollo_protobuf::consensus::{ConsensusBlockInfo, HeightAndRound, ProposalPart, Vote};
31+
use apollo_protobuf::consensus::{
32+
ConsensusBlockInfo,
33+
HeightAndRound,
34+
ProposalCommitment as ProtoProposalCommitment,
35+
ProposalFin,
36+
ProposalPart,
37+
TransactionBatch,
38+
Vote,
39+
};
3240
use apollo_state_sync_types::communication::MockStateSyncClient;
3341
use apollo_time::time::{Clock, DefaultClock};
3442
use futures::channel::mpsc;
3543
use futures::executor::block_on;
44+
use futures::SinkExt;
3645
use mockall::Sequence;
3746
use starknet_api::block::{
3847
BlockNumber,
@@ -350,6 +359,34 @@ pub(crate) fn block_info(height: BlockNumber) -> ConsensusBlockInfo {
350359
eth_to_fri_rate: ETH_TO_FRI_RATE,
351360
}
352361
}
362+
363+
// Send the given block info, some txs, the number of txs, and the fin, returning the
364+
// content_receiver.
365+
pub(crate) async fn send_proposal_to_validator_context(
366+
context: &mut SequencerConsensusContext,
367+
block_info: ConsensusBlockInfo,
368+
) -> mpsc::Receiver<ProposalPart> {
369+
let (mut content_sender, content_receiver) =
370+
mpsc::channel(context.get_config().static_config.proposal_buffer_size);
371+
content_sender.send(ProposalPart::BlockInfo(block_info)).await.unwrap();
372+
content_sender
373+
.send(ProposalPart::Transactions(TransactionBatch { transactions: TX_BATCH.to_vec() }))
374+
.await
375+
.unwrap();
376+
content_sender
377+
.send(ProposalPart::ExecutedTransactionCount(INTERNAL_TX_BATCH.len().try_into().unwrap()))
378+
.await
379+
.unwrap();
380+
content_sender
381+
.send(ProposalPart::Fin(ProposalFin {
382+
proposal_commitment: ProtoProposalCommitment(STATE_DIFF_COMMITMENT.0.0),
383+
}))
384+
.await
385+
.unwrap();
386+
content_sender.close_channel();
387+
content_receiver
388+
}
389+
353390
// Structs which aren't utilized but should not be dropped.
354391
pub(crate) struct NetworkDependencies {
355392
_vote_network: BroadcastNetworkMock<Vote>,

0 commit comments

Comments
 (0)