Skip to content

Commit

Permalink
Rename TestConsensus to TestContext
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Nov 1, 2023
1 parent e46a95b commit d39d681
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions Code/test/src/consensus.rs → Code/test/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use crate::value::*;
use crate::vote::*;

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct TestConsensus;
pub struct TestContext;

impl Context for TestConsensus {
impl Context for TestContext {
type Address = Address;
type Height = Height;
type Proposal = Proposal;
Expand Down
4 changes: 2 additions & 2 deletions Code/test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#![forbid(unsafe_code)]
#![deny(trivial_casts, trivial_numeric_casts)]

mod consensus;
mod context;
mod height;
mod proposal;
mod signing;
mod validator_set;
mod value;
mod vote;

pub use crate::consensus::*;
pub use crate::context::*;
pub use crate::height::*;
pub use crate::proposal::*;
pub use crate::signing::*;
Expand Down
4 changes: 2 additions & 2 deletions Code/test/src/proposal.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use malachite_common::Round;

use crate::{Height, TestConsensus, Value};
use crate::{Height, TestContext, Value};

/// A proposal for a value in a round
#[derive(Clone, Debug, PartialEq, Eq)]
Expand All @@ -22,7 +22,7 @@ impl Proposal {
}
}

impl malachite_common::Proposal<TestConsensus> for Proposal {
impl malachite_common::Proposal<TestContext> for Proposal {
fn height(&self) -> Height {
self.height
}
Expand Down
6 changes: 3 additions & 3 deletions Code/test/src/validator_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};

use malachite_common::VotingPower;

use crate::{signing::PublicKey, TestConsensus};
use crate::{signing::PublicKey, TestContext};

#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Address([u8; Self::LENGTH]);
Expand Down Expand Up @@ -42,7 +42,7 @@ impl Validator {
}
}

impl malachite_common::Validator<TestConsensus> for Validator {
impl malachite_common::Validator<TestContext> for Validator {
fn address(&self) -> &Address {
&self.address
}
Expand Down Expand Up @@ -142,7 +142,7 @@ impl ValidatorSet {
}
}

impl malachite_common::ValidatorSet<TestConsensus> for ValidatorSet {
impl malachite_common::ValidatorSet<TestContext> for ValidatorSet {
fn total_voting_power(&self) -> VotingPower {
self.total_voting_power()
}
Expand Down
6 changes: 3 additions & 3 deletions Code/test/src/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use signature::Signer;

use malachite_common::{Round, SignedVote, VoteType};

use crate::{Address, PrivateKey, TestConsensus, ValueId};
use crate::{Address, PrivateKey, TestContext, ValueId};

/// A vote for a value in a round
#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -50,7 +50,7 @@ impl Vote {
bytes
}

pub fn signed(self, private_key: &PrivateKey) -> SignedVote<TestConsensus> {
pub fn signed(self, private_key: &PrivateKey) -> SignedVote<TestContext> {
let signature = private_key.sign(&self.to_bytes());

SignedVote {
Expand All @@ -60,7 +60,7 @@ impl Vote {
}
}

impl malachite_common::Vote<TestConsensus> for Vote {
impl malachite_common::Vote<TestContext> for Vote {
fn round(&self) -> Round {
self.round
}
Expand Down
16 changes: 8 additions & 8 deletions Code/test/tests/consensus_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ use malachite_consensus::executor::{Event, Executor, Message};
use malachite_round::state::{RoundValue, State, Step};

use malachite_test::{
Address, Height, PrivateKey, Proposal, TestConsensus, Validator, ValidatorSet, Vote,
Address, Height, PrivateKey, Proposal, TestContext, Validator, ValidatorSet, Vote,
};
use rand::rngs::StdRng;
use rand::SeedableRng;

struct TestStep {
desc: &'static str,
input_event: Option<Event<TestConsensus>>,
expected_output: Option<Message<TestConsensus>>,
new_state: State<TestConsensus>,
input_event: Option<Event<TestContext>>,
expected_output: Option<Message<TestContext>>,
new_state: State<TestContext>,
}

fn to_input_msg(output: Message<TestConsensus>) -> Option<Event<TestConsensus>> {
fn to_input_msg(output: Message<TestContext>) -> Option<Event<TestContext>> {
match output {
Message::Propose(p) => Some(Event::Proposal(p)),
Message::Vote(v) => Some(Event::Vote(v)),
Expand All @@ -26,7 +26,7 @@ fn to_input_msg(output: Message<TestConsensus>) -> Option<Event<TestConsensus>>

#[test]
fn executor_steps_proposer() {
let value = TestConsensus::DUMMY_VALUE; // TODO: get value from external source
let value = TestContext::DUMMY_VALUE; // TODO: get value from external source
let value_id = value.id();

let mut rng = StdRng::seed_from_u64(0x42);
Expand Down Expand Up @@ -207,7 +207,7 @@ fn executor_steps_proposer() {

#[test]
fn executor_steps_not_proposer() {
let value = TestConsensus::DUMMY_VALUE; // TODO: get value from external source
let value = TestContext::DUMMY_VALUE; // TODO: get value from external source
let value_id = value.id();

let mut rng = StdRng::seed_from_u64(0x42);
Expand Down Expand Up @@ -388,7 +388,7 @@ fn executor_steps_not_proposer() {

#[test]
fn executor_steps_not_proposer_timeout() {
let value = TestConsensus::DUMMY_VALUE; // TODO: get value from external source
let value = TestContext::DUMMY_VALUE; // TODO: get value from external source
let value_id = value.id();

let mut rng = StdRng::seed_from_u64(0x42);
Expand Down
6 changes: 3 additions & 3 deletions Code/test/tests/round.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use malachite_test::{Address, Height, Proposal, TestConsensus, Value};
use malachite_test::{Address, Height, Proposal, TestContext, Value};

use malachite_common::{Round, Timeout, TimeoutStep};
use malachite_round::events::Event;
Expand All @@ -13,7 +13,7 @@ fn test_propose() {
let value = Value::new(42);
let height = Height::new(10);

let mut state: State<TestConsensus> = State::default();
let mut state: State<TestContext> = State::default();
let data = RoundData::new(Round::new(0), &height, &ADDRESS);

let transition = apply_event(state.clone(), &data, Event::NewRoundProposer(value));
Expand All @@ -32,7 +32,7 @@ fn test_prevote() {
let value = Value::new(42);
let height = Height::new(1);

let state: State<TestConsensus> = State::default().new_round(Round::new(1));
let state: State<TestContext> = State::default().new_round(Round::new(1));
let data = RoundData::new(Round::new(1), &height, &ADDRESS);

let transition = apply_event(state, &data, Event::NewRound);
Expand Down
8 changes: 4 additions & 4 deletions Code/test/tests/round_votes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ use malachite_common::Round;
use malachite_vote::count::Threshold;
use malachite_vote::RoundVotes;

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

const ADDRESS: Address = Address::new([42; 20]);

#[test]
fn add_votes_nil() {
let total = 3;

let mut round_votes: RoundVotes<TestConsensus> =
let mut round_votes: RoundVotes<TestContext> =
RoundVotes::new(Height::new(1), Round::new(0), total);

// add a vote for nil. nothing changes.
Expand All @@ -34,7 +34,7 @@ fn add_votes_single_value() {
let total = 4;
let weight = 1;

let mut round_votes: RoundVotes<TestConsensus> =
let mut round_votes: RoundVotes<TestContext> =
RoundVotes::new(Height::new(1), Round::new(0), total);

// add a vote. nothing changes.
Expand Down Expand Up @@ -64,7 +64,7 @@ fn add_votes_multi_values() {
let val2 = Some(v2);
let total = 15;

let mut round_votes: RoundVotes<TestConsensus> =
let mut round_votes: RoundVotes<TestContext> =
RoundVotes::new(Height::new(1), Round::new(0), total);

// add a vote for v1. nothing changes.
Expand Down
10 changes: 5 additions & 5 deletions Code/test/tests/vote_keeper.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use malachite_common::Round;
use malachite_vote::keeper::{Message, VoteKeeper};

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

const ADDRESS: Address = Address::new([42; 20]);

#[test]
fn prevote_apply_nil() {
let mut keeper: VoteKeeper<TestConsensus> = VoteKeeper::new(Height::new(1), Round::INITIAL, 3);
let mut keeper: VoteKeeper<TestContext> = VoteKeeper::new(Height::new(1), Round::INITIAL, 3);

let vote = Vote::new_prevote(Round::new(0), None, ADDRESS);

Expand All @@ -23,7 +23,7 @@ fn prevote_apply_nil() {

#[test]
fn precommit_apply_nil() {
let mut keeper: VoteKeeper<TestConsensus> = VoteKeeper::new(Height::new(1), Round::INITIAL, 3);
let mut keeper: VoteKeeper<TestContext> = VoteKeeper::new(Height::new(1), Round::INITIAL, 3);

let vote = Vote::new_precommit(Round::new(0), None, ADDRESS);

Expand All @@ -39,7 +39,7 @@ fn precommit_apply_nil() {

#[test]
fn prevote_apply_single_value() {
let mut keeper: VoteKeeper<TestConsensus> = VoteKeeper::new(Height::new(1), Round::INITIAL, 4);
let mut keeper: VoteKeeper<TestContext> = VoteKeeper::new(Height::new(1), Round::INITIAL, 4);

let v = ValueId::new(1);
let val = Some(v);
Expand All @@ -61,7 +61,7 @@ fn prevote_apply_single_value() {

#[test]
fn precommit_apply_single_value() {
let mut keeper: VoteKeeper<TestConsensus> = VoteKeeper::new(Height::new(1), Round::INITIAL, 4);
let mut keeper: VoteKeeper<TestContext> = VoteKeeper::new(Height::new(1), Round::INITIAL, 4);

let v = ValueId::new(1);
let val = Some(v);
Expand Down

0 comments on commit d39d681

Please sign in to comment.