Skip to content

Commit

Permalink
[WIP] Add unit tests for zksync_consensus_bft
Browse files Browse the repository at this point in the history
  • Loading branch information
moshababo committed Nov 20, 2023
1 parent 95c1853 commit 5d7b2e0
Show file tree
Hide file tree
Showing 9 changed files with 637 additions and 2 deletions.
2 changes: 2 additions & 0 deletions node/actors/bft/src/leader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ mod state_machine;
#[cfg(test)]
mod tests;

pub(crate) use replica_commit::Error as ReplicaCommitError;
pub(crate) use replica_prepare::Error as ReplicaPrepareError;
pub(crate) use state_machine::StateMachine;
2 changes: 1 addition & 1 deletion node/actors/bft/src/leader/replica_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use zksync_consensus_network::io::{ConsensusInputMessage, Target};
use zksync_consensus_roles::validator;

/// Errors that can occur when processing a "replica commit" message.
#[derive(Debug, thiserror::Error)]
#[derive(Debug, PartialEq, thiserror::Error)]
pub(crate) enum Error {
/// Unexpected proposal.
#[error("unexpected proposal")]
Expand Down
6 changes: 6 additions & 0 deletions node/actors/bft/src/leader/replica_prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ pub(crate) enum Error {
InvalidHighQC(#[source] anyhow::Error),
}

impl PartialEq for Error {
fn eq(&self, other: &Self) -> bool {
self.to_string() == other.to_string()
}
}

impl StateMachine {
#[instrument(level = "trace", ret)]
pub(crate) fn process_replica_prepare(
Expand Down
6 changes: 6 additions & 0 deletions node/actors/bft/src/replica/leader_prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ pub(crate) enum Error {
Internal(#[from] anyhow::Error),
}

impl PartialEq for Error {
fn eq(&self, other: &Self) -> bool {
self.to_string() == other.to_string()
}
}

impl StateMachine {
/// Processes a leader prepare message.
#[instrument(level = "trace", ret)]
Expand Down
2 changes: 2 additions & 0 deletions node/actors/bft/src/replica/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ mod state_machine;
mod tests;
mod timer;

pub(crate) use leader_commit::Error as LeaderCommitError;
pub(crate) use leader_prepare::Error as LeaderPrepareError;
pub(crate) use state_machine::StateMachine;
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,37 @@ async fn run_test(behavior: Behavior, network: Network) {
async fn honest_mock_network() {
run_test(Behavior::Honest, Network::Mock).await
}

#[tokio::test(flavor = "multi_thread")]
async fn honest_real_network() {
run_test(Behavior::Honest, Network::Real).await
}

#[tokio::test(flavor = "multi_thread")]
async fn offline_mock_network() {
run_test(Behavior::Offline, Network::Mock).await
}

#[tokio::test(flavor = "multi_thread")]
async fn offline_real_network() {
run_test(Behavior::Offline, Network::Real).await
}

#[tokio::test(flavor = "multi_thread")]
async fn random_mock_network() {
run_test(Behavior::Random, Network::Mock).await
}

#[tokio::test(flavor = "multi_thread")]
async fn random_real_network() {
run_test(Behavior::Random, Network::Real).await
}

#[tokio::test(flavor = "multi_thread")]
async fn byzantine_mock_network() {
run_test(Behavior::Byzantine, Network::Mock).await
}

#[tokio::test(flavor = "multi_thread")]
async fn byzantine_real_network() {
run_test(Behavior::Byzantine, Network::Real).await
Expand Down
2 changes: 2 additions & 0 deletions node/actors/bft/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod integration_tests;
mod unit_tests;
Loading

0 comments on commit 5d7b2e0

Please sign in to comment.