mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-23 23:04:53 +00:00
Finish genesis for BeaconChain
This commit is contained in:
@@ -2,7 +2,6 @@ extern crate types;
|
||||
extern crate validator_induction;
|
||||
extern crate validator_shuffling;
|
||||
|
||||
mod blocks;
|
||||
mod genesis;
|
||||
|
||||
use std::collections::HashMap;
|
||||
@@ -13,6 +12,7 @@ use types::{
|
||||
Hash256,
|
||||
};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum BeaconChainError {
|
||||
InvalidGenesis,
|
||||
DBError(String),
|
||||
@@ -24,15 +24,14 @@ pub struct BeaconChain {
|
||||
pub fork_latest_block_hashes: Vec<Hash256>,
|
||||
pub active_states: HashMap<Hash256, ActiveState>,
|
||||
pub crystallized_states: HashMap<Hash256, CrystallizedState>,
|
||||
pub config: ChainConfig,
|
||||
}
|
||||
|
||||
impl BeaconChain {
|
||||
pub fn new(config: ChainConfig)
|
||||
-> Result<Self, BeaconChainError>
|
||||
{
|
||||
let initial_validators = vec![];
|
||||
let (active_state, crystallized_state) = BeaconChain::genesis_states(
|
||||
&initial_validators, &config)?;
|
||||
let (active_state, crystallized_state) = BeaconChain::genesis_states(&config)?;
|
||||
|
||||
let canonical_latest_block_hash = Hash256::zero();
|
||||
let fork_latest_block_hashes = vec![];
|
||||
@@ -48,6 +47,7 @@ impl BeaconChain {
|
||||
fork_latest_block_hashes,
|
||||
active_states,
|
||||
crystallized_states,
|
||||
config,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -56,9 +56,26 @@ impl BeaconChain {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use types::ValidatorRegistration;
|
||||
|
||||
#[test]
|
||||
fn test_new_chain() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
let mut config = ChainConfig::standard();
|
||||
|
||||
for _ in 0..4 {
|
||||
config.initial_validators.push(ValidatorRegistration::random())
|
||||
}
|
||||
|
||||
let chain = BeaconChain::new(config.clone()).unwrap();
|
||||
let (act, cry) = BeaconChain::genesis_states(&config).unwrap();
|
||||
|
||||
assert_eq!(chain.last_finalized_slot, None);
|
||||
assert_eq!(chain.canonical_latest_block_hash, Hash256::zero());
|
||||
|
||||
let stored_act = chain.active_states.get(&Hash256::zero()).unwrap();
|
||||
assert_eq!(act, *stored_act);
|
||||
|
||||
let stored_cry = chain.crystallized_states.get(&Hash256::zero()).unwrap();
|
||||
assert_eq!(cry, *stored_cry);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user