Skip to content

Commit

Permalink
chore(consensus): use non zero validator id in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Dec 9, 2024
1 parent 9267f36 commit 2101554
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 22 deletions.
14 changes: 10 additions & 4 deletions crates/sequencing/papyrus_consensus/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ use papyrus_protobuf::converters::ProtobufConversionError;
use starknet_api::block::{BlockHash, BlockNumber};
use starknet_types_core::felt::Felt;

use crate::types::{ConsensusContext, ConsensusError, ProposalContentId, Round, ValidatorId};
use crate::types::{
ConsensusContext,
ConsensusError,
ProposalContentId,
Round,
ValidatorId,
DEFAULT_VALIDATOR_ID,
};

/// Define a consensus block which can be used to enable auto mocking Context.
#[derive(Debug, PartialEq, Clone)]
Expand All @@ -31,9 +38,8 @@ impl TryFrom<MockProposalPart> for ProposalInit {
fn try_from(part: MockProposalPart) -> Result<Self, Self::Error> {
Ok(ProposalInit {
height: BlockNumber(part.0),
round: 0,
proposer: ValidatorId::default(),
valid_round: None,
proposer: DEFAULT_VALIDATOR_ID.into(),
..Default::default()
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use papyrus_consensus::types::{
ProposalContentId,
Round,
ValidatorId,
DEFAULT_VALIDATOR_ID,
};
use papyrus_network::network_manager::{BroadcastTopicClient, BroadcastTopicClientTrait};
use papyrus_protobuf::consensus::{
Expand Down Expand Up @@ -70,7 +71,9 @@ impl PapyrusConsensusContext {
network_broadcast_client,
network_proposal_sender,
// TODO(Matan): Set the actual validator IDs (contract addresses).
validators: (100..100 + num_validators).map(ValidatorId::from).collect(),
validators: (0..num_validators)
.map(|i| ValidatorId::from(DEFAULT_VALIDATOR_ID + i))
.collect(),
sync_broadcast_sender,
valid_proposals: Arc::new(Mutex::new(BTreeMap::new())),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async fn validate_proposal_success() {
.validate_proposal(
block_number,
0,
ValidatorId::default(),
ValidatorId::from(DEFAULT_VALIDATOR_ID),
Duration::MAX,
validate_receiver,
)
Expand Down Expand Up @@ -101,7 +101,7 @@ async fn validate_proposal_fail() {
.validate_proposal(
block_number,
0,
ValidatorId::default(),
ValidatorId::from(DEFAULT_VALIDATOR_ID),
Duration::MAX,
validate_receiver,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use papyrus_consensus::types::{
ProposalContentId,
Round,
ValidatorId,
DEFAULT_VALIDATOR_ID,
};
use papyrus_network::network_manager::{BroadcastTopicClient, BroadcastTopicClientTrait};
use papyrus_protobuf::consensus::{
Expand Down Expand Up @@ -118,7 +119,9 @@ impl SequencerConsensusContext {
outbound_proposal_sender,
vote_broadcast_client,
// TODO(Matan): Set the actual validator IDs (contract addresses).
validators: (100..100 + num_validators).map(ValidatorId::from).collect(),
validators: (0..num_validators)
.map(|i| ValidatorId::from(DEFAULT_VALIDATOR_ID + i))
.collect(),
valid_proposals: Arc::new(Mutex::new(HeightToIdToContent::new())),
proposal_id: 0,
current_height: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use futures::channel::mpsc;
use futures::{FutureExt, SinkExt};
use lazy_static::lazy_static;
use papyrus_consensus::stream_handler::StreamHandler;
use papyrus_consensus::types::{ConsensusContext, ValidatorId};
use papyrus_consensus::types::{ConsensusContext, ValidatorId, DEFAULT_VALIDATOR_ID};
use papyrus_network::network_manager::test_utils::{
mock_register_broadcast_topic,
BroadcastNetworkMock,
Expand Down Expand Up @@ -130,12 +130,8 @@ async fn build_proposal() {
});
let (mut context, _network) = setup(batcher);

let init = ProposalInit {
height: BlockNumber(0),
round: 0,
proposer: ValidatorId::default(),
valid_round: None,
};
let init =
ProposalInit { proposer: ValidatorId::from(DEFAULT_VALIDATOR_ID), ..Default::default() };
// TODO(Asmaa): Test proposal content.
let fin_receiver = context.build_proposal(init, TIMEOUT).await;
assert_eq!(fin_receiver.await.unwrap().0, STATE_DIFF_COMMITMENT.0.0);
Expand Down Expand Up @@ -200,7 +196,13 @@ async fn validate_proposal_success() {
.await
.unwrap();
let fin_receiver = context
.validate_proposal(BlockNumber(0), 0, ValidatorId::default(), TIMEOUT, content_receiver)
.validate_proposal(
BlockNumber(0),
0,
ValidatorId::from(DEFAULT_VALIDATOR_ID),
TIMEOUT,
content_receiver,
)
.await;
content_sender.close_channel();
assert_eq!(fin_receiver.await.unwrap().0.0, STATE_DIFF_COMMITMENT.0.0);
Expand Down Expand Up @@ -252,7 +254,13 @@ async fn repropose() {
.await
.unwrap();
let fin_receiver = context
.validate_proposal(BlockNumber(0), 0, ValidatorId::default(), TIMEOUT, content_receiver)
.validate_proposal(
BlockNumber(0),
0,
ValidatorId::from(DEFAULT_VALIDATOR_ID),
TIMEOUT,
content_receiver,
)
.await;
content_sender.close_channel();
assert_eq!(fin_receiver.await.unwrap().0.0, STATE_DIFF_COMMITMENT.0.0);
Expand Down Expand Up @@ -321,7 +329,13 @@ async fn proposals_from_different_rounds() {
content_sender.send(prop_part_txs.clone()).await.unwrap();

let fin_receiver_past_round = context
.validate_proposal(BlockNumber(0), 0, ValidatorId::default(), TIMEOUT, content_receiver)
.validate_proposal(
BlockNumber(0),
0,
ValidatorId::from(DEFAULT_VALIDATOR_ID),
TIMEOUT,
content_receiver,
)
.await;
// No fin was sent, channel remains open.
assert!(fin_receiver_past_round.await.is_err());
Expand All @@ -331,7 +345,13 @@ async fn proposals_from_different_rounds() {
content_sender.send(prop_part_txs.clone()).await.unwrap();
content_sender.send(prop_part_fin.clone()).await.unwrap();
let fin_receiver_curr_round = context
.validate_proposal(BlockNumber(0), 1, ValidatorId::default(), TIMEOUT, content_receiver)
.validate_proposal(
BlockNumber(0),
1,
ValidatorId::from(DEFAULT_VALIDATOR_ID),
TIMEOUT,
content_receiver,
)
.await;
assert_eq!(fin_receiver_curr_round.await.unwrap().0.0, STATE_DIFF_COMMITMENT.0.0);

Expand All @@ -340,7 +360,13 @@ async fn proposals_from_different_rounds() {
content_sender.send(prop_part_txs.clone()).await.unwrap();
content_sender.send(prop_part_fin.clone()).await.unwrap();
let fin_receiver_future_round = context
.validate_proposal(BlockNumber(0), 2, ValidatorId::default(), TIMEOUT, content_receiver)
.validate_proposal(
BlockNumber(0),
2,
ValidatorId::from(DEFAULT_VALIDATOR_ID),
TIMEOUT,
content_receiver,
)
.await;
content_sender.close_channel();
// Even with sending fin and closing the channel.
Expand Down Expand Up @@ -396,7 +422,13 @@ async fn interrupt_active_proposal() {
// without needing interrupt.
let (mut _content_sender_0, content_receiver) = mpsc::channel(CHANNEL_SIZE);
let fin_receiver_0 = context
.validate_proposal(BlockNumber(0), 0, ValidatorId::default(), TIMEOUT, content_receiver)
.validate_proposal(
BlockNumber(0),
0,
ValidatorId::from(DEFAULT_VALIDATOR_ID),
TIMEOUT,
content_receiver,
)
.await;

let (mut content_sender_1, content_receiver) = mpsc::channel(CHANNEL_SIZE);
Expand All @@ -414,7 +446,13 @@ async fn interrupt_active_proposal() {
.await
.unwrap();
let fin_receiver_1 = context
.validate_proposal(BlockNumber(0), 1, ValidatorId::default(), TIMEOUT, content_receiver)
.validate_proposal(
BlockNumber(0),
1,
ValidatorId::from(DEFAULT_VALIDATOR_ID),
TIMEOUT,
content_receiver,
)
.await;
// Move the context to the next round.
context.set_height_and_round(BlockNumber(0), 1).await;
Expand Down

0 comments on commit 2101554

Please sign in to comment.