Skip to content

Commit

Permalink
fix(sequencing): imporve e2e flow test assertion messages (#2580)
Browse files Browse the repository at this point in the history
This makes the errors on one of the e2e flow test more comprehensible.
  • Loading branch information
guy-starkware authored Dec 9, 2024
1 parent 65eda61 commit e72832e
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions crates/starknet_integration_tests/tests/end_to_end_flow_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,28 @@ async fn listen_to_broadcasted_messages(
message_id: incoming_message_id,
} = broadcasted_messages_receiver.next().await.unwrap().0.unwrap();

assert_eq!(incoming_message_id, 0);
assert_eq!(
incoming_message_id, 0,
"Expected the first message in the stream to have id 0, got {}",
incoming_message_id
);
let StreamMessageBody::Content(ProposalPart::Init(incoming_proposal_init)) = init_message
else {
panic!("Expected an init message. Got: {:?}", init_message)
};
assert_eq!(incoming_proposal_init, expected_proposal_init);
assert_eq!(
incoming_proposal_init, expected_proposal_init,
"Unexpected init message: {:?}, expected: {:?}",
incoming_proposal_init, expected_proposal_init
);

let mut received_tx_hashes = HashSet::new();
let mut got_proposal_fin = false;
let mut got_channel_fin = false;
loop {
let StreamMessage { message, stream_id, message_id: _ } =
broadcasted_messages_receiver.next().await.unwrap().0.unwrap();
assert_eq!(stream_id, first_stream_id);
assert_eq!(stream_id, first_stream_id, "Expected the same stream id for all messages");
match message {
StreamMessageBody::Content(ProposalPart::Init(init)) => {
panic!("Unexpected init: {:?}", init)
Expand All @@ -126,24 +134,32 @@ async fn listen_to_broadcasted_messages(
);
}
StreamMessageBody::Content(ProposalPart::Fin(proposal_fin)) => {
assert_eq!(proposal_fin, expected_proposal_fin);
assert_eq!(
proposal_fin, expected_proposal_fin,
"Unexpected fin message: {:?}, expected: {:?}",
proposal_fin, expected_proposal_fin
);
got_proposal_fin = true;
}
StreamMessageBody::Fin => {
got_channel_fin = true;
}
}
if got_proposal_fin
&& got_channel_fin
&& received_tx_hashes.len() == expected_batched_tx_hashes.len()
{
if got_proposal_fin && got_channel_fin {
assert!(
received_tx_hashes.len() == expected_batched_tx_hashes.len(),
"Expected {} transactions, got {}",
expected_batched_tx_hashes.len(),
received_tx_hashes.len()
);
break;
}
}

// Using HashSet to ignore the order of the transactions (broadcast can lead to reordering).
assert_eq!(
received_tx_hashes,
expected_batched_tx_hashes.iter().cloned().collect::<HashSet<_>>()
expected_batched_tx_hashes.iter().cloned().collect::<HashSet<_>>(),
"Unexpected transactions"
);
}

0 comments on commit e72832e

Please sign in to comment.