diff --git a/beacon_node/beacon_chain/Cargo.toml b/beacon_node/beacon_chain/Cargo.toml index d6dac9a4b..7e157dffb 100644 --- a/beacon_node/beacon_chain/Cargo.toml +++ b/beacon_node/beacon_chain/Cargo.toml @@ -5,6 +5,7 @@ authors = ["Paul Hauner "] edition = "2018" [dependencies] +block_producer = { path = "../../eth2/block_producer" } bls = { path = "../../eth2/utils/bls" } boolean-bitfield = { path = "../../eth2/utils/boolean-bitfield" } db = { path = "../db" } diff --git a/beacon_node/beacon_chain/tests/chain.rs b/beacon_node/beacon_chain/tests/chain.rs index 9c76bf59d..390d48ea4 100644 --- a/beacon_node/beacon_chain/tests/chain.rs +++ b/beacon_node/beacon_chain/tests/chain.rs @@ -1,12 +1,77 @@ use beacon_chain::{BeaconChain, BlockProcessingOutcome}; -use bls::Signature; +#[cfg(test)] +use block_producer::{ + test_utils::{TestEpochMap, TestSigner}, + BeaconNode as BeaconBlockNode, BeaconNodeError as BeaconBlockNodeError, BlockProducer, +}; use db::{ stores::{BeaconBlockStore, BeaconStateStore}, MemoryDB, }; use slot_clock::TestingSlotClock; use spec::ChainSpec; -use std::sync::Arc; +use std::sync::{Arc, RwLock}; +use types::{BeaconBlock, Keypair}; + +struct DirectBeaconNode(); + +impl BeaconBlockNode for DirectBeaconNode { + fn produce_beacon_block(&self, slot: u64) -> Result, BeaconBlockNodeError> { + Err(BeaconBlockNodeError::DecodeFailure) + } + + /// Returns the value specified by the `set_next_publish_result`. + fn publish_beacon_block(&self, block: BeaconBlock) -> Result { + Err(BeaconBlockNodeError::DecodeFailure) + } +} + +struct Validator { + block_producer: BlockProducer, + spec: Arc, + epoch_map: Arc, + keypair: Keypair, + beacon_node: Arc, + slot_clock: Arc>, + signer: Arc, +} + +impl Validator { + pub fn new() -> Self { + let spec = Arc::new(ChainSpec::foundation()); + let keypair = Keypair::random(); + let slot_clock = Arc::new(RwLock::new(TestingSlotClock::new(0))); + let signer = Arc::new(TestSigner::new(keypair.clone())); + let beacon_node = Arc::new(DirectBeaconNode()); + let epoch_map = Arc::new(TestEpochMap::new()); + + let block_producer = BlockProducer::new( + spec.clone(), + epoch_map.clone(), + slot_clock.clone(), + beacon_node.clone(), + signer.clone(), + ); + + Self { + block_producer, + spec, + epoch_map, + keypair, + beacon_node, + slot_clock, + signer, + } + } +} + +fn generate_validators(n: usize) -> Vec { + let mut validators = Vec::with_capacity(n); + for _ in 0..n { + validators.push(Validator::new()); + } + validators +} fn in_memory_test_stores() -> ( Arc, @@ -34,6 +99,7 @@ fn it_constructs() { let (_db, _chain) = in_memory_test_chain(ChainSpec::foundation()); } +/* #[test] fn it_produces() { let (_db, mut chain) = in_memory_test_chain(ChainSpec::foundation()); @@ -48,3 +114,4 @@ fn it_processes_a_block_it_produces() { assert_eq!(outcome, BlockProcessingOutcome::Processed); assert_eq!(chain.canonical_leaf_block, new_block_hash); } +*/