From 41844841c6e2ff68bab7a95e5664bd361ca37d34 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 11 Mar 2019 11:52:16 +1100 Subject: [PATCH] Update project tests to use new genesis structure --- .../beacon_chain/test_harness/src/lib.rs | 2 +- .../beacon_chain/test_harness/tests/chain.rs | 4 ++-- beacon_node/src/main.rs | 22 ++++++++++++++----- eth2/types/src/beacon_state/builder.rs | 3 ++- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/beacon_node/beacon_chain/test_harness/src/lib.rs b/beacon_node/beacon_chain/test_harness/src/lib.rs index 0703fd4a5..f58c1b598 100644 --- a/beacon_node/beacon_chain/test_harness/src/lib.rs +++ b/beacon_node/beacon_chain/test_harness/src/lib.rs @@ -15,7 +15,7 @@ //! let validator_count = 8; //! let spec = ChainSpec::few_validators(); //! -//! let mut harness = BeaconChainHarness::new(spec, validator_count); +//! let mut harness = BeaconChainHarness::new(spec, validator_count, None, true); //! //! harness.advance_chain_with_block(); //! diff --git a/beacon_node/beacon_chain/test_harness/tests/chain.rs b/beacon_node/beacon_chain/test_harness/tests/chain.rs index e72c3a5aa..e5a52a314 100644 --- a/beacon_node/beacon_chain/test_harness/tests/chain.rs +++ b/beacon_node/beacon_chain/test_harness/tests/chain.rs @@ -10,7 +10,7 @@ fn it_can_build_on_genesis_block() { let spec = ChainSpec::few_validators(); let validator_count = 8; - let mut harness = BeaconChainHarness::new(spec, validator_count as usize); + let mut harness = BeaconChainHarness::new(spec, validator_count as usize, None, true); harness.advance_chain_with_block(); } @@ -25,7 +25,7 @@ fn it_can_produce_past_first_epoch_boundary() { debug!("Starting harness build..."); - let mut harness = BeaconChainHarness::new(spec, validator_count); + let mut harness = BeaconChainHarness::new(spec, validator_count, None, true); debug!("Harness built, tests starting.."); diff --git a/beacon_node/src/main.rs b/beacon_node/src/main.rs index 072315b6b..c05438cfb 100644 --- a/beacon_node/src/main.rs +++ b/beacon_node/src/main.rs @@ -17,8 +17,12 @@ use db::{ use fork_choice::BitwiseLMDGhost; use slog::{error, info, o, Drain}; use slot_clock::SystemTimeSlotClock; +use ssz::TreeHash; use std::sync::Arc; -use types::{ChainSpec, Deposit, DepositData, DepositInput, Eth1Data, Hash256, Keypair}; +use types::{ + beacon_state::BeaconStateBuilder, BeaconBlock, ChainSpec, Deposit, DepositData, DepositInput, + Eth1Data, Hash256, Keypair, +}; fn main() { let decorator = slog_term::TermDecorator::new().build(); @@ -97,7 +101,8 @@ fn main() { .iter() .map(|_| Keypair::random()) .collect(); - let initial_validator_deposits = keypairs + + let initial_validator_deposits: Vec = keypairs .iter() .map(|keypair| Deposit { branch: vec![], // branch verification is not specified. @@ -114,14 +119,19 @@ fn main() { }) .collect(); + let mut state_builder = BeaconStateBuilder::new(genesis_time, latest_eth1_data, &spec); + state_builder.process_initial_deposits(&initial_validator_deposits, &spec); + let genesis_state = state_builder.build(&spec).unwrap(); + let state_root = Hash256::from_slice(&genesis_state.hash_tree_root()); + let genesis_block = BeaconBlock::genesis(state_root, &spec); + // Genesis chain - let _chain_result = BeaconChain::genesis( + let _chain_result = BeaconChain::from_genesis( state_store.clone(), block_store.clone(), slot_clock, - genesis_time, - latest_eth1_data, - initial_validator_deposits, + genesis_state, + genesis_block, spec, fork_choice, ); diff --git a/eth2/types/src/beacon_state/builder.rs b/eth2/types/src/beacon_state/builder.rs index c36cd11f4..22ca3e622 100644 --- a/eth2/types/src/beacon_state/builder.rs +++ b/eth2/types/src/beacon_state/builder.rs @@ -53,7 +53,8 @@ impl BeaconStateBuilder { /// Instantiate the validator registry from a YAML file. /// - /// This skips a lot of signing and verification, useful for fast test setups. + /// This skips a lot of signing and verification, useful if signing and verification has been + /// completed previously. /// /// Spec v0.4.0 pub fn import_existing_validators(