From d39e93314c1300fdc46112eec5c8d518dcfe252e Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Tue, 14 Nov 2023 20:48:51 +0100 Subject: [PATCH] chore(common): Remove `Context::DUMMY_VALUE` --- Code/common/src/context.rs | 3 --- Code/test/src/context.rs | 2 -- Code/test/tests/driver.rs | 32 ++++++++++++++++---------------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Code/common/src/context.rs b/Code/common/src/context.rs index 8396ab72a..3f848e3c0 100644 --- a/Code/common/src/context.rs +++ b/Code/common/src/context.rs @@ -18,9 +18,6 @@ where type Vote: Vote; 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; diff --git a/Code/test/src/context.rs b/Code/test/src/context.rs index 8f579dca7..f61eba295 100644 --- a/Code/test/src/context.rs +++ b/Code/test/src/context.rs @@ -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 { use signature::Signer; let signature = self.private_key.sign(&vote.to_bytes()); diff --git a/Code/test/tests/driver.rs b/Code/test/tests/driver.rs index a057b1325..bec1bbb13 100644 --- a/Code/test/tests/driver.rs +++ b/Code/test/tests/driver.rs @@ -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 { @@ -60,8 +61,7 @@ impl ProposerSelector 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)); @@ -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 { @@ -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), @@ -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 { @@ -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), @@ -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), @@ -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(); @@ -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(); @@ -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(); @@ -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)); @@ -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)); @@ -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));