Skip to content

Commit

Permalink
Add fields assertions to yielded messages
Browse files Browse the repository at this point in the history
  • Loading branch information
moshababo committed Nov 29, 2023
1 parent 05436e3 commit 1c06852
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 15 deletions.
51 changes: 43 additions & 8 deletions node/actors/bft/src/leader/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use assert_matches::assert_matches;
use rand::Rng;
use zksync_consensus_roles::validator::{
self, CommitQC, ConsensusMsg, LeaderCommit, LeaderPrepare, Phase, ProtocolVersion,
ReplicaCommit, ViewNumber,
ReplicaCommit, ReplicaPrepare, ViewNumber,
};

#[tokio::test]
Expand All @@ -22,12 +22,32 @@ async fn replica_prepare_sanity_yield_leader_prepare() {
let mut util = UTHarness::new().await;

let replica_prepare = util.new_current_replica_prepare(|_| {});
util.dispatch_replica_prepare(replica_prepare).unwrap();
util.recv_signed()
util.dispatch_replica_prepare(replica_prepare.clone())
.unwrap();
let leader_prepare = util
.recv_signed()
.await
.unwrap()
.cast::<LeaderPrepare>()
.unwrap();
.unwrap()
.msg;

let replica_prepare = replica_prepare.cast::<ReplicaPrepare>().unwrap().msg;
assert_matches!(
leader_prepare,
LeaderPrepare {
protocol_version,
view,
proposal,
proposal_payload: _,
justification,
} => {
assert_eq!(protocol_version, replica_prepare.protocol_version);
assert_eq!(view, replica_prepare.view);
assert_eq!(proposal.parent, replica_prepare.high_vote.proposal.hash());
assert_eq!(justification, util.new_prepare_qc(|msg| *msg = replica_prepare));
}
);
}

#[tokio::test]
Expand Down Expand Up @@ -211,16 +231,31 @@ async fn replica_commit_sanity() {
}

#[tokio::test]
async fn replica_commit_sanity_yield_leader_commit() {
async fn replica_commit_yield_leader_commit() {
let mut util = UTHarness::new().await;

let replica_commit = util.new_procedural_replica_commit().await;
util.dispatch_replica_commit(replica_commit).unwrap();
util.recv_signed()
util.dispatch_replica_commit(replica_commit.clone())
.unwrap();
let leader_commit = util
.recv_signed()
.await
.unwrap()
.cast::<LeaderCommit>()
.unwrap();
.unwrap()
.msg;

let replica_commit = replica_commit.cast::<ReplicaCommit>().unwrap().msg;
assert_matches!(
leader_commit,
LeaderCommit {
protocol_version,
justification,
} => {
assert_eq!(protocol_version, replica_commit.protocol_version);
assert_eq!(justification, util.new_commit_qc(|msg| *msg = replica_commit));
}
);
}

#[tokio::test]
Expand Down
52 changes: 45 additions & 7 deletions node/actors/bft/src/replica/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use assert_matches::assert_matches;
use rand::Rng;
use std::cell::RefCell;
use zksync_consensus_roles::validator::{
BlockHeaderHash, ConsensusMsg, LeaderPrepare, Payload, PrepareQC, ReplicaCommit,
BlockHeaderHash, ConsensusMsg, LeaderCommit, LeaderPrepare, Payload, PrepareQC, ReplicaCommit,
ReplicaPrepare, ViewNumber,
};

Expand All @@ -28,12 +28,30 @@ async fn leader_prepare_sanity_yield_replica_commit() {
let mut util = UTHarness::new().await;

let leader_prepare = util.new_procedural_leader_prepare().await;
util.dispatch_leader_prepare(leader_prepare).await.unwrap();
util.recv_signed()
util.dispatch_leader_prepare(leader_prepare.clone())
.await
.unwrap();
let replica_commit = util
.recv_signed()
.await
.unwrap()
.cast::<ReplicaCommit>()
.unwrap();
.unwrap()
.msg;

let leader_prepare = leader_prepare.cast::<LeaderPrepare>().unwrap().msg;
assert_matches!(
replica_commit,
ReplicaCommit {
protocol_version,
view,
proposal,
} => {
assert_eq!(protocol_version, leader_prepare.protocol_version);
assert_eq!(view, leader_prepare.view);
assert_eq!(proposal, leader_prepare.proposal);
}
);
}

#[tokio::test]
Expand Down Expand Up @@ -416,12 +434,32 @@ async fn leader_commit_sanity_yield_replica_prepare() {
let mut util = UTHarness::new().await;

let leader_commit = util.new_procedural_leader_commit().await;
util.dispatch_leader_commit(leader_commit).await.unwrap();
util.recv_signed()
util.dispatch_leader_commit(leader_commit.clone())
.await
.unwrap();
let replica_prepare = util
.recv_signed()
.await
.unwrap()
.cast::<ReplicaPrepare>()
.unwrap();
.unwrap()
.msg;

let leader_commit = leader_commit.cast::<LeaderCommit>().unwrap().msg;
assert_matches!(
replica_prepare,
ReplicaPrepare {
protocol_version,
view,
high_vote,
high_qc,
} => {
assert_eq!(protocol_version, leader_commit.protocol_version);
assert_eq!(view, leader_commit.justification.message.view.next());
assert_eq!(high_vote, leader_commit.justification.message);
assert_eq!(high_qc, leader_commit.justification)
}
);
}

#[tokio::test]
Expand Down

0 comments on commit 1c06852

Please sign in to comment.