Skip to content

Commit

Permalink
chore(common): Remove Context::DUMMY_VALUE
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Nov 14, 2023
1 parent bde9355 commit d39e933
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
3 changes: 0 additions & 3 deletions Code/common/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ where
type Vote: Vote<Self>;
type SigningScheme: SigningScheme; // TODO: Do we need to support multiple signing schemes?

// FIXME: Remove altogether
const DUMMY_VALUE: Self::Value;

/// Sign the given vote our private key.
fn sign_vote(&self, vote: Self::Vote) -> SignedVote<Self>;

Expand Down
2 changes: 0 additions & 2 deletions Code/test/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ impl Context for TestContext {
type Vote = Vote;
type SigningScheme = Ed25519;

const DUMMY_VALUE: Self::Value = Value::new(9999);

fn sign_vote(&self, vote: Self::Vote) -> SignedVote<Self> {
use signature::Signer;
let signature = self.private_key.sign(&vote.to_bytes());
Expand Down
32 changes: 16 additions & 16 deletions Code/test/tests/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ use futures::executor::block_on;
use rand::rngs::StdRng;
use rand::SeedableRng;

use malachite_common::{Context, Round, Timeout};
use malachite_common::{Round, Timeout};
use malachite_driver::{Driver, Error, Event, Message, ProposerSelector, Validity};
use malachite_round::state::{RoundValue, State, Step};
use malachite_test::{
Address, Height, PrivateKey, Proposal, TestContext, TestEnv, Validator, ValidatorSet, Vote,
Address, Height, PrivateKey, Proposal, TestContext, TestEnv, Validator, ValidatorSet, Value,
Vote,
};

struct TestStep {
Expand Down Expand Up @@ -60,8 +61,7 @@ impl ProposerSelector<TestContext> for FixedProposer {

#[test]
fn driver_steps_proposer() {
let value = TestContext::DUMMY_VALUE;
let value_id = value.id();
let value = Value::new(9999);

let sel = RotateProposer::default();
let env = TestEnv::new(move |_, _| Some(value));
Expand Down Expand Up @@ -107,7 +107,7 @@ fn driver_steps_proposer() {
desc: "Receive our own proposal, prevote for it (v1)",
input_event: None,
expected_output: Some(Message::Vote(
Vote::new_prevote(Round::new(0), Some(value_id), my_addr).signed(&my_sk),
Vote::new_prevote(Round::new(0), Some(value.id()), my_addr).signed(&my_sk),
)),
expected_round: Round::new(0),
new_state: State {
Expand All @@ -134,7 +134,7 @@ fn driver_steps_proposer() {
TestStep {
desc: "v2 prevotes for our proposal",
input_event: Some(Event::Vote(
Vote::new_prevote(Round::new(0), Some(value_id), addr2).signed(&sk2),
Vote::new_prevote(Round::new(0), Some(value.id()), addr2).signed(&sk2),
)),
expected_output: None,
expected_round: Round::new(0),
Expand All @@ -149,10 +149,10 @@ fn driver_steps_proposer() {
TestStep {
desc: "v3 prevotes for our proposal, we get +2/3 prevotes, precommit for it (v1)",
input_event: Some(Event::Vote(
Vote::new_prevote(Round::new(0), Some(value_id), addr3).signed(&sk3),
Vote::new_prevote(Round::new(0), Some(value.id()), addr3).signed(&sk3),
)),
expected_output: Some(Message::Vote(
Vote::new_precommit(Round::new(0), Some(value_id), my_addr).signed(&my_sk),
Vote::new_precommit(Round::new(0), Some(value.id()), my_addr).signed(&my_sk),
)),
expected_round: Round::new(0),
new_state: State {
Expand Down Expand Up @@ -191,7 +191,7 @@ fn driver_steps_proposer() {
TestStep {
desc: "v2 precommits for our proposal",
input_event: Some(Event::Vote(
Vote::new_precommit(Round::new(0), Some(value_id), addr2).signed(&sk2),
Vote::new_precommit(Round::new(0), Some(value.id()), addr2).signed(&sk2),
)),
expected_output: None,
expected_round: Round::new(0),
Expand All @@ -212,7 +212,7 @@ fn driver_steps_proposer() {
TestStep {
desc: "v3 precommits for our proposal, we get +2/3 precommits, decide it (v1)",
input_event: Some(Event::Vote(
Vote::new_precommit(Round::new(0), Some(value_id), addr3).signed(&sk3),
Vote::new_precommit(Round::new(0), Some(value.id()), addr3).signed(&sk3),
)),
expected_output: Some(Message::Decide(Round::new(0), value)),
expected_round: Round::new(0),
Expand Down Expand Up @@ -255,7 +255,7 @@ fn driver_steps_proposer() {

#[test]
fn driver_steps_not_proposer_valid() {
let value = TestContext::DUMMY_VALUE;
let value = Value::new(9999);
let value_id = value.id();

let sel = RotateProposer::default();
Expand Down Expand Up @@ -451,7 +451,7 @@ fn driver_steps_not_proposer_valid() {

#[test]
fn driver_steps_not_proposer_invalid() {
let value = TestContext::DUMMY_VALUE;
let value = Value::new(9999);
let value_id = value.id();

let sel = RotateProposer::default();
Expand Down Expand Up @@ -593,7 +593,7 @@ fn driver_steps_not_proposer_invalid() {

#[test]
fn driver_steps_not_proposer_timeout_multiple_rounds() {
let value = TestContext::DUMMY_VALUE;
let value = Value::new(9999);
let value_id = value.id();

let sel = RotateProposer::default();
Expand Down Expand Up @@ -826,7 +826,7 @@ fn driver_steps_no_value_to_propose() {

#[test]
fn driver_steps_proposer_not_found() {
let value = TestContext::DUMMY_VALUE;
let value = Value::new(9999);

let env = TestEnv::new(move |_, _| Some(value));

Expand Down Expand Up @@ -857,7 +857,7 @@ fn driver_steps_proposer_not_found() {

#[test]
fn driver_steps_validator_not_found() {
let value = TestContext::DUMMY_VALUE;
let value = Value::new(9999);

let env = TestEnv::new(move |_, _| Some(value));

Expand Down Expand Up @@ -894,7 +894,7 @@ fn driver_steps_validator_not_found() {

#[test]
fn driver_steps_invalid_signature() {
let value = TestContext::DUMMY_VALUE;
let value = Value::new(9999);

let env = TestEnv::new(move |_, _| Some(value));

Expand Down

0 comments on commit d39e933

Please sign in to comment.