diff --git a/eth2/block_producer/src/lib.rs b/eth2/block_producer/src/lib.rs index ed65622d4..8ed10ce1a 100644 --- a/eth2/block_producer/src/lib.rs +++ b/eth2/block_producer/src/lib.rs @@ -213,7 +213,7 @@ impl From for Error { #[cfg(test)] mod tests { - use super::test_utils::{TestBeaconNode, TestEpochMap, TestSigner}; + use super::test_utils::{EpochMap, LocalSigner, SimulatedBeaconNode}; use super::*; use slot_clock::TestingSlotClock; use types::{ @@ -232,10 +232,10 @@ mod tests { let spec = Arc::new(ChainSpec::foundation()); let slot_clock = Arc::new(TestingSlotClock::new(0)); - let beacon_node = Arc::new(TestBeaconNode::default()); - let signer = Arc::new(TestSigner::new(Keypair::random())); + let beacon_node = Arc::new(SimulatedBeaconNode::default()); + let signer = Arc::new(LocalSigner::new(Keypair::random())); - let mut epoch_map = TestEpochMap::new(spec.epoch_length); + let mut epoch_map = EpochMap::new(spec.epoch_length); let produce_slot = 100; let produce_epoch = produce_slot / spec.epoch_length; epoch_map.map.insert(produce_epoch, produce_slot); diff --git a/eth2/block_producer/src/test_utils/epoch_map.rs b/eth2/block_producer/src/test_utils/epoch_map.rs index 848ae252e..c7d1e6b4c 100644 --- a/eth2/block_producer/src/test_utils/epoch_map.rs +++ b/eth2/block_producer/src/test_utils/epoch_map.rs @@ -1,12 +1,12 @@ use crate::{DutiesReader, DutiesReaderError}; use std::collections::HashMap; -pub struct TestEpochMap { +pub struct EpochMap { epoch_length: u64, pub map: HashMap, } -impl TestEpochMap { +impl EpochMap { pub fn new(epoch_length: u64) -> Self { Self { epoch_length, @@ -15,7 +15,7 @@ impl TestEpochMap { } } -impl DutiesReader for TestEpochMap { +impl DutiesReader for EpochMap { fn is_block_production_slot(&self, slot: u64) -> Result { let epoch = slot / self.epoch_length; match self.map.get(&epoch) { diff --git a/eth2/block_producer/src/test_utils/signer.rs b/eth2/block_producer/src/test_utils/local_signer.rs similarity index 85% rename from eth2/block_producer/src/test_utils/signer.rs rename to eth2/block_producer/src/test_utils/local_signer.rs index 62163f5b2..0ebefa29d 100644 --- a/eth2/block_producer/src/test_utils/signer.rs +++ b/eth2/block_producer/src/test_utils/local_signer.rs @@ -3,13 +3,13 @@ use std::sync::RwLock; use types::{Keypair, Signature}; /// A test-only struct used to simulate a Beacon Node. -pub struct TestSigner { +pub struct LocalSigner { keypair: Keypair, should_sign: RwLock, } -impl TestSigner { - /// Produce a new TestSigner with signing enabled by default. +impl LocalSigner { + /// Produce a new LocalSigner with signing enabled by default. pub fn new(keypair: Keypair) -> Self { Self { keypair, @@ -24,7 +24,7 @@ impl TestSigner { } } -impl Signer for TestSigner { +impl Signer for LocalSigner { fn sign_block_proposal(&self, message: &[u8]) -> Option { Some(Signature::new(message, &self.keypair.sk)) } diff --git a/eth2/block_producer/src/test_utils/mod.rs b/eth2/block_producer/src/test_utils/mod.rs index 0dd384b12..481247dd0 100644 --- a/eth2/block_producer/src/test_utils/mod.rs +++ b/eth2/block_producer/src/test_utils/mod.rs @@ -1,7 +1,7 @@ -mod beacon_node; mod epoch_map; -mod signer; +mod local_signer; +mod simulated_beacon_node; -pub use self::beacon_node::TestBeaconNode; -pub use self::epoch_map::TestEpochMap; -pub use self::signer::TestSigner; +pub use self::epoch_map::EpochMap; +pub use self::local_signer::LocalSigner; +pub use self::simulated_beacon_node::SimulatedBeaconNode; diff --git a/eth2/block_producer/src/test_utils/beacon_node.rs b/eth2/block_producer/src/test_utils/simulated_beacon_node.rs similarity index 87% rename from eth2/block_producer/src/test_utils/beacon_node.rs rename to eth2/block_producer/src/test_utils/simulated_beacon_node.rs index f132ce6ec..772670a12 100644 --- a/eth2/block_producer/src/test_utils/beacon_node.rs +++ b/eth2/block_producer/src/test_utils/simulated_beacon_node.rs @@ -8,7 +8,7 @@ type PublishResult = Result; /// A test-only struct used to simulate a Beacon Node. #[derive(Default)] -pub struct TestBeaconNode { +pub struct SimulatedBeaconNode { pub nonce_input: RwLock>, pub nonce_result: RwLock>, @@ -19,7 +19,7 @@ pub struct TestBeaconNode { pub publish_result: RwLock>, } -impl TestBeaconNode { +impl SimulatedBeaconNode { /// Set the result to be returned when `produce_beacon_block` is called. pub fn set_next_nonce_result(&self, result: NonceResult) { *self.nonce_result.write().unwrap() = Some(result); @@ -36,12 +36,12 @@ impl TestBeaconNode { } } -impl BeaconNode for TestBeaconNode { +impl BeaconNode for SimulatedBeaconNode { fn proposer_nonce(&self, pubkey: &PublicKey) -> NonceResult { *self.nonce_input.write().unwrap() = Some(pubkey.clone()); match *self.nonce_result.read().unwrap() { Some(ref r) => r.clone(), - None => panic!("TestBeaconNode: nonce_result == None"), + None => panic!("SimulatedBeaconNode: nonce_result == None"), } } @@ -50,7 +50,7 @@ impl BeaconNode for TestBeaconNode { *self.produce_input.write().unwrap() = Some((slot, randao_reveal.clone())); match *self.produce_result.read().unwrap() { Some(ref r) => r.clone(), - None => panic!("TestBeaconNode: produce_result == None"), + None => panic!("SimulatedBeaconNode: produce_result == None"), } } @@ -59,7 +59,7 @@ impl BeaconNode for TestBeaconNode { *self.publish_input.write().unwrap() = Some(block); match *self.publish_result.read().unwrap() { Some(ref r) => r.clone(), - None => panic!("TestBeaconNode: publish_result == None"), + None => panic!("SimulatedBeaconNode: publish_result == None"), } } } diff --git a/validator_client/src/main.rs b/validator_client/src/main.rs index 3b516870a..0e1fd4a6b 100644 --- a/validator_client/src/main.rs +++ b/validator_client/src/main.rs @@ -1,7 +1,7 @@ use self::block_producer_service::{BeaconBlockGrpcClient, BlockProducerService}; use self::duties::{DutiesManager, DutiesManagerService, EpochDutiesMap}; use crate::config::ClientConfig; -use block_producer::{test_utils::TestSigner, BlockProducer}; +use block_producer::{test_utils::LocalSigner, BlockProducer}; use bls::Keypair; use clap::{App, Arg}; use grpcio::{ChannelBuilder, EnvBuilder}; @@ -140,7 +140,7 @@ fn main() { let producer_thread = { let spec = spec.clone(); let pubkey = keypair.pk.clone(); - let signer = Arc::new(TestSigner::new(keypair.clone())); + let signer = Arc::new(LocalSigner::new(keypair.clone())); let duties_map = duties_map.clone(); let slot_clock = slot_clock.clone(); let log = log.clone();