mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-22 22:34:45 +00:00
Add progress on test rig
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
use beacon_chain::{BeaconChain, BlockProcessingOutcome};
|
||||
use self::utils::TestRig;
|
||||
use beacon_chain::BeaconChain;
|
||||
#[cfg(test)]
|
||||
use block_producer::{
|
||||
test_utils::{TestEpochMap, TestSigner},
|
||||
BeaconNode as BeaconBlockNode, BeaconNodeError as BeaconBlockNodeError, BlockProducer,
|
||||
};
|
||||
use block_producer::{test_utils::TestSigner, BlockProducer};
|
||||
use db::{
|
||||
stores::{BeaconBlockStore, BeaconStateStore},
|
||||
MemoryDB,
|
||||
@@ -11,92 +9,19 @@ use db::{
|
||||
use slot_clock::TestingSlotClock;
|
||||
use spec::ChainSpec;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use types::{BeaconBlock, Keypair};
|
||||
use types::{Keypair, Validator};
|
||||
|
||||
struct DirectBeaconNode();
|
||||
|
||||
impl BeaconBlockNode for DirectBeaconNode {
|
||||
fn produce_beacon_block(&self, slot: u64) -> Result<Option<BeaconBlock>, BeaconBlockNodeError> {
|
||||
Err(BeaconBlockNodeError::DecodeFailure)
|
||||
}
|
||||
|
||||
/// Returns the value specified by the `set_next_publish_result`.
|
||||
fn publish_beacon_block(&self, block: BeaconBlock) -> Result<bool, BeaconBlockNodeError> {
|
||||
Err(BeaconBlockNodeError::DecodeFailure)
|
||||
}
|
||||
}
|
||||
|
||||
struct Validator {
|
||||
block_producer: BlockProducer<TestingSlotClock, DirectBeaconNode, TestEpochMap, TestSigner>,
|
||||
spec: Arc<ChainSpec>,
|
||||
epoch_map: Arc<TestEpochMap>,
|
||||
keypair: Keypair,
|
||||
beacon_node: Arc<DirectBeaconNode>,
|
||||
slot_clock: Arc<RwLock<TestingSlotClock>>,
|
||||
signer: Arc<TestSigner>,
|
||||
}
|
||||
|
||||
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<Validator> {
|
||||
let mut validators = Vec::with_capacity(n);
|
||||
for _ in 0..n {
|
||||
validators.push(Validator::new());
|
||||
}
|
||||
validators
|
||||
}
|
||||
|
||||
fn in_memory_test_stores() -> (
|
||||
Arc<MemoryDB>,
|
||||
Arc<BeaconBlockStore<MemoryDB>>,
|
||||
Arc<BeaconStateStore<MemoryDB>>,
|
||||
) {
|
||||
let db = Arc::new(MemoryDB::open());
|
||||
let block_store = Arc::new(BeaconBlockStore::new(db.clone()));
|
||||
let state_store = Arc::new(BeaconStateStore::new(db.clone()));
|
||||
(db, block_store, state_store)
|
||||
}
|
||||
|
||||
fn in_memory_test_chain(
|
||||
spec: ChainSpec,
|
||||
) -> (Arc<MemoryDB>, BeaconChain<MemoryDB, TestingSlotClock>) {
|
||||
let (db, block_store, state_store) = in_memory_test_stores();
|
||||
let slot_clock = TestingSlotClock::new(0);
|
||||
|
||||
let chain = BeaconChain::genesis(state_store, block_store, slot_clock, spec);
|
||||
(db, chain.unwrap())
|
||||
}
|
||||
mod utils;
|
||||
|
||||
#[test]
|
||||
fn it_constructs() {
|
||||
let (_db, _chain) = in_memory_test_chain(ChainSpec::foundation());
|
||||
fn rig_can_generate_validators() {
|
||||
/*
|
||||
let (_db, mut chain) = in_memory_test_chain(ChainSpec::foundation());
|
||||
let validators = generate_validators(2, &chain);
|
||||
chain.spec = inject_validators_into_spec(chain.spec.clone(), &validators[..]);
|
||||
*/
|
||||
let mut rig = TestRig::new(ChainSpec::foundation());
|
||||
rig.generate_validators(2);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user