Skip to content

Commit

Permalink
test: Re-enable VoteKeeper tests
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Nov 15, 2023
1 parent 7e67ea9 commit 577c1ee
Showing 1 changed file with 117 additions and 111 deletions.
228 changes: 117 additions & 111 deletions Code/test/tests/vote_keeper.rs
Original file line number Diff line number Diff line change
@@ -1,111 +1,117 @@
// use malachite_common::Round;
// use malachite_vote::keeper::{Message, VoteKeeper};
//
// use malachite_test::{Address, TestContext, ValueId, Vote};
//
// const ADDRESS1: Address = Address::new([41; 20]);
// const ADDRESS2: Address = Address::new([42; 20]);
// const ADDRESS3: Address = Address::new([43; 20]);
// const ADDRESS4: Address = Address::new([44; 20]);
//
// #[test]
// fn prevote_apply_nil() {
// let mut keeper: VoteKeeper<TestContext> = VoteKeeper::new(Round::new(0), 3);
//
// let vote = Vote::new_prevote(Round::new(0), None, ADDRESS1);
// let msg = keeper.apply_vote(vote.clone(), 1);
// assert_eq!(msg, None);
//
// let vote = Vote::new_prevote(Round::new(0), None, ADDRESS2);
// let msg = keeper.apply_vote(vote.clone(), 1);
// assert_eq!(msg, None);
//
// let vote = Vote::new_prevote(Round::new(0), None, ADDRESS3);
// let msg = keeper.apply_vote(vote, 1);
// assert_eq!(msg, Some(Message::PolkaNil));
// }
//
// #[test]
// fn precommit_apply_nil() {
// let mut keeper: VoteKeeper<TestContext> = VoteKeeper::new(Round::new(0), 3);
//
// let vote = Vote::new_precommit(Round::new(0), None, ADDRESS1);
// let msg = keeper.apply_vote(vote.clone(), 1);
// assert_eq!(msg, None);
//
// let vote = Vote::new_precommit(Round::new(0), None, ADDRESS2);
// let msg = keeper.apply_vote(vote.clone(), 1);
// assert_eq!(msg, None);
//
// let vote = Vote::new_precommit(Round::new(0), None, ADDRESS3);
// let msg = keeper.apply_vote(vote, 1);
// assert_eq!(msg, Some(Message::PrecommitAny));
// }
//
// #[test]
// fn prevote_apply_single_value() {
// let mut keeper: VoteKeeper<TestContext> = VoteKeeper::new(Round::new(0), 4);
//
// let v = ValueId::new(1);
// let val = Some(v);
//
// let vote = Vote::new_prevote(Round::new(0), val, ADDRESS1);
// let msg = keeper.apply_vote(vote.clone(), 1);
// assert_eq!(msg, None);
//
// let vote = Vote::new_prevote(Round::new(0), val, ADDRESS2);
// let msg = keeper.apply_vote(vote.clone(), 1);
// assert_eq!(msg, None);
//
// let vote_nil = Vote::new_prevote(Round::new(0), None, ADDRESS3);
// let msg = keeper.apply_vote(vote_nil, 1);
// assert_eq!(msg, Some(Message::PolkaAny));
//
// let vote = Vote::new_prevote(Round::new(0), val, ADDRESS4);
// let msg = keeper.apply_vote(vote, 1);
// assert_eq!(msg, Some(Message::PolkaValue(v)));
// }
//
// #[test]
// fn precommit_apply_single_value() {
// let mut keeper: VoteKeeper<TestContext> = VoteKeeper::new(Round::new(0), 4);
//
// let v = ValueId::new(1);
// let val = Some(v);
//
// let vote = Vote::new_precommit(Round::new(0), val, ADDRESS1);
// let msg = keeper.apply_vote(vote.clone(), 1);
// assert_eq!(msg, None);
//
// let vote = Vote::new_precommit(Round::new(0), val, ADDRESS2);
// let msg = keeper.apply_vote(vote.clone(), 1);
// assert_eq!(msg, None);
//
// let vote_nil = Vote::new_precommit(Round::new(0), None, ADDRESS3);
// let msg = keeper.apply_vote(vote_nil, 1);
// assert_eq!(msg, Some(Message::PrecommitAny));
//
// let vote = Vote::new_precommit(Round::new(0), val, ADDRESS4);
// let msg = keeper.apply_vote(vote, 1);
// assert_eq!(msg, Some(Message::PrecommitValue(v)));
// }
//
// #[test]
// fn skip_round() {
// let mut keeper: VoteKeeper<TestContext> = VoteKeeper::new(Round::new(0), 4);
//
// let v = ValueId::new(1);
// let val = Some(v);
//
// let vote = Vote::new_prevote(Round::new(0), val, ADDRESS1);
// let msg = keeper.apply_vote(vote.clone(), 1);
// assert_eq!(msg, None);
//
// let vote = Vote::new_prevote(Round::new(1), val, ADDRESS2);
// let msg = keeper.apply_vote(vote.clone(), 1);
// assert_eq!(msg, None);
//
// let vote = Vote::new_prevote(Round::new(1), val, ADDRESS3);
// let msg = keeper.apply_vote(vote, 1);
// assert_eq!(msg, Some(Message::SkipRound(Round::new(1))));
// }
use malachite_common::Round;
use malachite_vote::keeper::{Message, VoteKeeper};

use malachite_test::{Address, TestContext, ValueId, Vote};

const ADDRESS1: Address = Address::new([41; 20]);
const ADDRESS2: Address = Address::new([42; 20]);
const ADDRESS3: Address = Address::new([43; 20]);
const ADDRESS4: Address = Address::new([44; 20]);

#[test]
fn prevote_apply_nil() {
let mut keeper: VoteKeeper<TestContext> = VoteKeeper::new(3, Default::default());
let round = Round::new(0);

let vote = Vote::new_prevote(round, None, ADDRESS1);
let msg = keeper.apply_vote(vote.clone(), 1, round);
assert_eq!(msg, None);

let vote = Vote::new_prevote(round, None, ADDRESS2);
let msg = keeper.apply_vote(vote.clone(), 1, round);
assert_eq!(msg, None);

let vote = Vote::new_prevote(round, None, ADDRESS3);
let msg = keeper.apply_vote(vote, 1, round);
assert_eq!(msg, Some(Message::PolkaNil));
}

#[test]
fn precommit_apply_nil() {
let mut keeper: VoteKeeper<TestContext> = VoteKeeper::new(3, Default::default());
let round = Round::new(0);

let vote = Vote::new_precommit(round, None, ADDRESS1);
let msg = keeper.apply_vote(vote.clone(), 1, round);
assert_eq!(msg, None);

let vote = Vote::new_precommit(round, None, ADDRESS2);
let msg = keeper.apply_vote(vote.clone(), 1, round);
assert_eq!(msg, None);

let vote = Vote::new_precommit(round, None, ADDRESS3);
let msg = keeper.apply_vote(vote, 1, round);
assert_eq!(msg, Some(Message::PrecommitAny));
}

#[test]
fn prevote_apply_single_value() {
let mut keeper: VoteKeeper<TestContext> = VoteKeeper::new(4, Default::default());

let v = ValueId::new(1);
let val = Some(v);
let round = Round::new(0);

let vote = Vote::new_prevote(round, val, ADDRESS1);
let msg = keeper.apply_vote(vote.clone(), 1, round);
assert_eq!(msg, None);

let vote = Vote::new_prevote(round, val, ADDRESS2);
let msg = keeper.apply_vote(vote.clone(), 1, round);
assert_eq!(msg, None);

let vote_nil = Vote::new_prevote(round, None, ADDRESS3);
let msg = keeper.apply_vote(vote_nil, 1, round);
assert_eq!(msg, Some(Message::PolkaAny));

let vote = Vote::new_prevote(round, val, ADDRESS4);
let msg = keeper.apply_vote(vote, 1, round);
assert_eq!(msg, Some(Message::PolkaValue(v)));
}

#[test]
fn precommit_apply_single_value() {
let mut keeper: VoteKeeper<TestContext> = VoteKeeper::new(4, Default::default());

let v = ValueId::new(1);
let val = Some(v);
let round = Round::new(0);

let vote = Vote::new_precommit(round, val, ADDRESS1);
let msg = keeper.apply_vote(vote.clone(), 1, round);
assert_eq!(msg, None);

let vote = Vote::new_precommit(round, val, ADDRESS2);
let msg = keeper.apply_vote(vote.clone(), 1, round);
assert_eq!(msg, None);

let vote_nil = Vote::new_precommit(round, None, ADDRESS3);
let msg = keeper.apply_vote(vote_nil, 1, round);
assert_eq!(msg, Some(Message::PrecommitAny));

let vote = Vote::new_precommit(round, val, ADDRESS4);
let msg = keeper.apply_vote(vote, 1, round);
assert_eq!(msg, Some(Message::PrecommitValue(v)));
}

#[test]
fn skip_round() {
let mut keeper: VoteKeeper<TestContext> = VoteKeeper::new(4, Default::default());

let v = ValueId::new(1);
let val = Some(v);
let cur_round = Round::new(0);
let fut_round = Round::new(1);

let vote = Vote::new_prevote(cur_round, val, ADDRESS1);
let msg = keeper.apply_vote(vote.clone(), 1, cur_round);
assert_eq!(msg, None);

let vote = Vote::new_prevote(fut_round, val, ADDRESS2);
let msg = keeper.apply_vote(vote.clone(), 1, cur_round);
assert_eq!(msg, None);

let vote = Vote::new_prevote(fut_round, val, ADDRESS3);
let msg = keeper.apply_vote(vote, 1, cur_round);
assert_eq!(msg, Some(Message::SkipRound(Round::new(1))));
}

0 comments on commit 577c1ee

Please sign in to comment.