Skip to content

Commit

Permalink
mv make new
Browse files Browse the repository at this point in the history
  • Loading branch information
moshababo committed Nov 21, 2023
1 parent ef8cc5f commit 14be873
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions node/actors/bft/src/tests/unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,32 +70,32 @@ use zksync_consensus_roles::validator::{
///
#[tokio::test]
async fn replica_prepare_sanity() {
let mut util = Util::make().await;
let mut util = Util::new().await;

let replica_prepare = util.make_replica_prepare(None::<fn(&mut ReplicaPrepare)>);
let replica_prepare = util.new_replica_prepare(None::<fn(&mut ReplicaPrepare)>);
let res = util.dispatch_replica_prepare(replica_prepare);
assert_matches!(res, Ok(()));
}

#[tokio::test]
async fn replica_prepare_sanity_yield_leader_prepare() {
let mut util = Util::make().await;
let mut util = Util::new().await;

let replica_prepare = util.make_replica_prepare(None::<fn(&mut ReplicaPrepare)>);
let replica_prepare = util.new_replica_prepare(None::<fn(&mut ReplicaPrepare)>);
let res = util.dispatch_replica_prepare(replica_prepare);
assert_matches!(res, Ok(()));
let _ = util.recv_leader_prepare().await.unwrap();
}

#[tokio::test]
async fn replica_prepare_old_view() {
let mut util = Util::make().await;
let mut util = Util::new().await;

util.set_replica_view(ViewNumber(1));
util.set_leader_view(ViewNumber(2));
util.set_leader_phase(Phase::Prepare);

let replica_prepare = util.make_replica_prepare(None::<fn(&mut ReplicaPrepare)>);
let replica_prepare = util.new_replica_prepare(None::<fn(&mut ReplicaPrepare)>);
let res = util.dispatch_replica_prepare(replica_prepare);

assert_matches!(
Expand All @@ -109,11 +109,11 @@ async fn replica_prepare_old_view() {

#[tokio::test]
async fn replica_prepare_during_commit() {
let mut util = Util::make().await;
let mut util = Util::new().await;

util.set_leader_phase(Phase::Commit);

let replica_prepare = util.make_replica_prepare(None::<fn(&mut ReplicaPrepare)>);
let replica_prepare = util.new_replica_prepare(None::<fn(&mut ReplicaPrepare)>);
let res = util.dispatch_replica_prepare(replica_prepare);

assert_matches!(
Expand All @@ -127,14 +127,14 @@ async fn replica_prepare_during_commit() {

#[tokio::test]
async fn replica_prepare_already_exists() {
let mut util = Util::make_with(2).await;
let mut util = Util::new_with(2).await;

let view = ViewNumber(2);
util.set_replica_view(view);
util.set_leader_view(view);

assert_eq!(util.view_leader(view), util.own_key().public());
let replica_prepare = util.make_replica_prepare(None::<fn(&mut ReplicaPrepare)>);
let replica_prepare = util.new_replica_prepare(None::<fn(&mut ReplicaPrepare)>);

let res = util.dispatch_replica_prepare(replica_prepare.clone());
assert_matches!(
Expand All @@ -156,14 +156,14 @@ async fn replica_prepare_already_exists() {

#[tokio::test]
async fn replica_prepare_num_received_below_threshold() {
let mut util = Util::make_with(2).await;
let mut util = Util::new_with(2).await;

let view = ViewNumber(2);
util.set_replica_view(view);
util.set_leader_view(view);
assert_eq!(util.view_leader(view), util.own_key().public());

let replica_prepare = util.make_replica_prepare(None::<fn(&mut ReplicaPrepare)>);
let replica_prepare = util.new_replica_prepare(None::<fn(&mut ReplicaPrepare)>);
let res = util.dispatch_replica_prepare(replica_prepare);
assert_matches!(
res,
Expand All @@ -176,9 +176,9 @@ async fn replica_prepare_num_received_below_threshold() {

#[tokio::test]
async fn leader_prepare_sanity() {
let mut util = Util::make().await;
let mut util = Util::new().await;

let replica_prepare = util.make_replica_prepare(None::<fn(&mut ReplicaPrepare)>);
let replica_prepare = util.new_replica_prepare(None::<fn(&mut ReplicaPrepare)>);
let res = util.dispatch_replica_prepare(replica_prepare);
assert_matches!(res, Ok(()));
let leader_prepare = util.recv_signed().await.unwrap();
Expand All @@ -189,15 +189,15 @@ async fn leader_prepare_sanity() {

#[tokio::test]
async fn leader_prepare_invalid_leader() {
let mut util = Util::make_with(2).await;
let mut util = Util::new_with(2).await;

let view = ViewNumber(2);
util.set_replica_view(view);
util.set_leader_view(view);

assert_eq!(util.view_leader(view), util.key_at(0).public());

let replica_prepare_one = util.make_replica_prepare(None::<fn(&mut ReplicaPrepare)>);
let replica_prepare_one = util.new_replica_prepare(None::<fn(&mut ReplicaPrepare)>);
let res = util.dispatch_replica_prepare(replica_prepare_one.clone());
assert_matches!(
res,
Expand Down Expand Up @@ -233,9 +233,9 @@ async fn leader_prepare_invalid_leader() {

#[tokio::test]
async fn leader_prepare_invalid_sig() {
let mut util = Util::make().await;
let mut util = Util::new().await;

let mut leader_prepare = util.make_leader_prepare(None::<fn(&mut LeaderPrepare)>);
let mut leader_prepare = util.new_leader_prepare(None::<fn(&mut LeaderPrepare)>);
leader_prepare.sig = util.rng().gen();
let res = util.dispatch_leader_prepare(leader_prepare).await;

Expand All @@ -249,9 +249,9 @@ async fn leader_prepare_invalid_sig() {

#[tokio::test]
async fn leader_prepare_invalid_prepare_qc_different_views() {
let mut util = Util::make().await;
let mut util = Util::new().await;

let replica_prepare = util.make_replica_prepare(None::<fn(&mut ReplicaPrepare)>);
let replica_prepare = util.new_replica_prepare(None::<fn(&mut ReplicaPrepare)>);
let res = util.dispatch_replica_prepare(replica_prepare.clone());
assert_matches!(res, Ok(()));

Expand Down Expand Up @@ -328,11 +328,11 @@ mod util {
}

impl Util {
pub async fn make() -> Util {
Util::make_with(1).await
pub async fn new() -> Util {
Util::new_with(1).await
}

pub async fn make_with(num_validators: i32) -> Util {
pub async fn new_with(num_validators: i32) -> Util {
let ctx = ctx::test_root(&ctx::RealClock);
let mut rng = StdRng::seed_from_u64(6516565651);
let keys: Vec<_> = (0..num_validators).map(|_| rng.gen()).collect();
Expand All @@ -353,11 +353,11 @@ mod util {
}
}

pub fn own_key(&mut self) -> &SecretKey {
pub fn own_key(&self) -> &SecretKey {
&self.consensus.inner.secret_key
}

pub fn key_at(&mut self, index: usize) -> &SecretKey {
pub fn key_at(&self, index: usize) -> &SecretKey {
&self.keys[index]
}

Expand All @@ -381,7 +381,7 @@ mod util {
self.consensus.replica.phase = phase
}

pub fn make_replica_prepare(
pub fn new_replica_prepare(
&mut self,
mutate_callback: Option<impl FnOnce(&mut ReplicaPrepare)>,
) -> Signed<ConsensusMsg> {
Expand All @@ -401,7 +401,7 @@ mod util {
.sign_msg(ConsensusMsg::ReplicaPrepare(msg))
}

pub(crate) fn make_leader_prepare(
pub(crate) fn new_leader_prepare(
&mut self,
mutate_callback: Option<impl FnOnce(&mut LeaderPrepare)>,
) -> Signed<ConsensusMsg> {
Expand Down

0 comments on commit 14be873

Please sign in to comment.