Skip to content

Commit

Permalink
chore(sequencing): remove ConsensusMessage from converter test
Browse files Browse the repository at this point in the history
  • Loading branch information
guy-starkware committed Dec 10, 2024
1 parent bb55d27 commit de4cddf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions crates/papyrus_protobuf/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub struct Vote {
pub voter: ContractAddress,
}

// TODO: remove this once we are sure everything works using just Vote.
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
pub enum ConsensusMessage {
Proposal(Proposal), // To be deprecated
Expand Down
1 change: 1 addition & 0 deletions crates/papyrus_protobuf/src/converters/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::consensus::{
use crate::converters::ProtobufConversionError;
use crate::{auto_impl_into_and_try_from_vec_u8, protobuf};

// TODO(guyn): remove this once we integrate ProposalPart everywhere.
impl TryFrom<protobuf::Proposal> for Proposal {
type Error = ProtobufConversionError;

Expand Down
10 changes: 5 additions & 5 deletions crates/papyrus_protobuf/src/converters/consensus_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use starknet_api::transaction::{
};

use crate::consensus::{
ConsensusMessage,
Proposal,
ConsensusMessage, // TODO: remove this
Proposal, // TODO: remove this
ProposalFin,
ProposalInit,
ProposalPart,
Expand Down Expand Up @@ -51,11 +51,11 @@ fn add_gas_values_to_transaction(transactions: &mut [Transaction]) {
fn convert_stream_message_to_vec_u8_and_back() {
let mut rng = get_rng();

// Test that we can convert a StreamMessage with a ConsensusMessage message to bytes and back.
let mut stream_message: StreamMessage<ConsensusMessage> =
// Test that we can convert a StreamMessage with a ProposalPart message to bytes and back.
let mut stream_message: StreamMessage<ProposalPart> =
StreamMessage::get_test_instance(&mut rng);

if let StreamMessageBody::Content(ConsensusMessage::Proposal(proposal)) =
if let StreamMessageBody::Content(ProposalPart::Transactions(proposal)) =
&mut stream_message.message
{
add_gas_values_to_transaction(&mut proposal.transactions);
Expand Down
7 changes: 5 additions & 2 deletions crates/papyrus_protobuf/src/converters/test_instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ auto_impl_get_test_instance! {

// The auto_impl_get_test_instance macro does not work for StreamMessage because it has
// a generic type. TODO(guyn): try to make the macro work with generic types.
impl GetTestInstance for StreamMessage<ConsensusMessage> {
impl GetTestInstance for StreamMessage<ProposalPart> {
fn get_test_instance(rng: &mut rand_chacha::ChaCha8Rng) -> Self {
let message = if rng.gen_bool(0.5) {
StreamMessageBody::Content(ConsensusMessage::Proposal(Proposal::get_test_instance(rng)))
StreamMessageBody::Content(ProposalPart::Transactions(TransactionBatch {
transactions: vec![Transaction::get_test_instance(rng)],
tx_hashes: vec![TransactionHash::get_test_instance(rng)],
}))
} else {
StreamMessageBody::Fin
};
Expand Down

0 comments on commit de4cddf

Please sign in to comment.