mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
Add first changes to syncing logic
- Adds testing framework - Breaks out new `NetworkContext` object
This commit is contained in:
3
beacon_node/beacon_chain/src/test_utils/mod.rs
Normal file
3
beacon_node/beacon_chain/src/test_utils/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
mod testing_beacon_chain_builder;
|
||||
|
||||
pub use testing_beacon_chain_builder::TestingBeaconChainBuilder;
|
||||
@@ -0,0 +1,50 @@
|
||||
pub use crate::{BeaconChain, BeaconChainError, CheckPoint};
|
||||
use db::{
|
||||
stores::{BeaconBlockStore, BeaconStateStore},
|
||||
MemoryDB,
|
||||
};
|
||||
use fork_choice::BitwiseLMDGhost;
|
||||
use slot_clock::TestingSlotClock;
|
||||
use ssz::TreeHash;
|
||||
use std::sync::Arc;
|
||||
use types::test_utils::TestingBeaconStateBuilder;
|
||||
use types::*;
|
||||
|
||||
type TestingBeaconChain = BeaconChain<MemoryDB, TestingSlotClock, BitwiseLMDGhost<MemoryDB>>;
|
||||
|
||||
pub struct TestingBeaconChainBuilder {
|
||||
state_builder: TestingBeaconStateBuilder,
|
||||
}
|
||||
|
||||
impl TestingBeaconChainBuilder {
|
||||
pub fn build(self, spec: &ChainSpec) -> TestingBeaconChain {
|
||||
let db = Arc::new(MemoryDB::open());
|
||||
let block_store = Arc::new(BeaconBlockStore::new(db.clone()));
|
||||
let state_store = Arc::new(BeaconStateStore::new(db.clone()));
|
||||
let slot_clock = TestingSlotClock::new(spec.genesis_slot.as_u64());
|
||||
let fork_choice = BitwiseLMDGhost::new(block_store.clone(), state_store.clone());
|
||||
|
||||
let (genesis_state, _keypairs) = self.state_builder.build();
|
||||
|
||||
let mut genesis_block = BeaconBlock::empty(&spec);
|
||||
genesis_block.state_root = Hash256::from_slice(&genesis_state.hash_tree_root());
|
||||
|
||||
// Create the Beacon Chain
|
||||
BeaconChain::from_genesis(
|
||||
state_store.clone(),
|
||||
block_store.clone(),
|
||||
slot_clock,
|
||||
genesis_state,
|
||||
genesis_block,
|
||||
spec.clone(),
|
||||
fork_choice,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TestingBeaconStateBuilder> for TestingBeaconChainBuilder {
|
||||
fn from(state_builder: TestingBeaconStateBuilder) -> TestingBeaconChainBuilder {
|
||||
TestingBeaconChainBuilder { state_builder }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user