Update beacon_chain as per test bugs

This commit is contained in:
Paul Hauner
2019-01-25 11:30:06 +11:00
parent 643fc20063
commit f4f5b3a13c
9 changed files with 188 additions and 86 deletions

View File

@@ -1,36 +1,46 @@
use super::{DirectBeaconNode, DirectDuties};
use beacon_chain::BeaconChain;
#[cfg(test)]
use block_producer::{test_utils::TestSigner, BlockProducer};
use block_producer::{test_utils::TestSigner, BlockProducer, Error as PollError};
use db::MemoryDB;
use slot_clock::TestingSlotClock;
use spec::ChainSpec;
use std::sync::{Arc, RwLock};
use types::{Keypair, Validator};
pub struct TestValidator<'a> {
pub use block_producer::PollOutcome;
#[derive(Debug, PartialEq)]
pub enum ProduceError {
DidNotProduce(PollOutcome),
PollError(PollError),
}
pub struct TestValidator {
block_producer: BlockProducer<
TestingSlotClock,
DirectBeaconNode<'a, MemoryDB, TestingSlotClock>,
DirectDuties<'a, MemoryDB, TestingSlotClock>,
DirectBeaconNode<MemoryDB, TestingSlotClock>,
DirectDuties<MemoryDB, TestingSlotClock>,
TestSigner,
>,
spec: Arc<ChainSpec>,
epoch_map: Arc<DirectDuties<'a, MemoryDB, TestingSlotClock>>,
epoch_map: Arc<DirectDuties<MemoryDB, TestingSlotClock>>,
keypair: Keypair,
beacon_node: Arc<DirectBeaconNode<'a, MemoryDB, TestingSlotClock>>,
slot_clock: Arc<RwLock<TestingSlotClock>>,
beacon_node: Arc<DirectBeaconNode<MemoryDB, TestingSlotClock>>,
slot_clock: Arc<TestingSlotClock>,
signer: Arc<TestSigner>,
}
impl<'a> TestValidator<'a> {
pub fn new(beacon_chain: &'a BeaconChain<MemoryDB, TestingSlotClock>) -> Self {
impl TestValidator {
pub fn new(
keypair: Keypair,
beacon_chain: Arc<BeaconChain<MemoryDB, TestingSlotClock>>,
) -> Self {
let spec = Arc::new(ChainSpec::foundation());
let keypair = Keypair::random();
let slot_clock = Arc::new(RwLock::new(TestingSlotClock::new(0)));
let slot_clock = Arc::new(TestingSlotClock::new(0));
let signer = Arc::new(TestSigner::new(keypair.clone()));
let beacon_node = Arc::new(DirectBeaconNode::new(beacon_chain));
let epoch_map = Arc::new(DirectDuties::new(keypair.pk.clone(), beacon_chain));
let beacon_node = Arc::new(DirectBeaconNode::new(beacon_chain.clone()));
let epoch_map = Arc::new(DirectDuties::new(keypair.pk.clone(), beacon_chain.clone()));
let block_producer = BlockProducer::new(
spec.clone(),
@@ -52,10 +62,15 @@ impl<'a> TestValidator<'a> {
}
}
pub fn validator_record(&self) -> Validator {
Validator {
pubkey: self.keypair.pk.clone(),
..std::default::Default::default()
pub fn produce_block(&mut self) -> Result<PollOutcome, ProduceError> {
match self.block_producer.poll() {
Ok(PollOutcome::BlockProduced(slot)) => Ok(PollOutcome::BlockProduced(slot)),
Ok(outcome) => Err(ProduceError::DidNotProduce(outcome)),
Err(error) => Err(ProduceError::PollError(error)),
}
}
pub fn set_slot(&mut self, slot: u64) {
self.slot_clock.set_slot(slot)
}
}