diff --git a/node/actors/bft/src/leader/tests.rs b/node/actors/bft/src/leader/tests.rs index 005477ec..e2fd34c2 100644 --- a/node/actors/bft/src/leader/tests.rs +++ b/node/actors/bft/src/leader/tests.rs @@ -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] @@ -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::() - .unwrap(); + .unwrap() + .msg; + + let replica_prepare = replica_prepare.cast::().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] @@ -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::() - .unwrap(); + .unwrap() + .msg; + + let replica_commit = replica_commit.cast::().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] diff --git a/node/actors/bft/src/replica/tests.rs b/node/actors/bft/src/replica/tests.rs index cf61a0ad..fedea79c 100644 --- a/node/actors/bft/src/replica/tests.rs +++ b/node/actors/bft/src/replica/tests.rs @@ -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, }; @@ -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::() - .unwrap(); + .unwrap() + .msg; + + let leader_prepare = leader_prepare.cast::().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] @@ -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::() - .unwrap(); + .unwrap() + .msg; + + let leader_commit = leader_commit.cast::().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]