diff --git a/beacon_chain/genesis/Cargo.toml b/beacon_chain/genesis/Cargo.toml index f8708af1f0..f1958eaa7d 100644 --- a/beacon_chain/genesis/Cargo.toml +++ b/beacon_chain/genesis/Cargo.toml @@ -2,6 +2,7 @@ name = "genesis" version = "0.1.0" authors = ["Paul Hauner "] +edition = "2018" [dependencies] bls = { path = "../utils/bls" } diff --git a/beacon_chain/genesis/src/beacon_block.rs b/beacon_chain/genesis/src/beacon_block.rs new file mode 100644 index 0000000000..9e2c75d24e --- /dev/null +++ b/beacon_chain/genesis/src/beacon_block.rs @@ -0,0 +1,38 @@ +use bls::Signature; +use spec::ChainSpec; +use types::{BeaconBlock, BeaconBlockBody}; + +/// Generate a genesis BeaconBlock. +pub fn genesis_beacon_block(spec: &ChainSpec) -> BeaconBlock { + BeaconBlock { + slot: spec.initial_slot_number, + parent_root: spec.zero_hash, + state_root: spec.zero_hash, + randao_reveal: spec.zero_hash, + candidate_pow_receipt_root: spec.zero_hash, + signature: Signature::default(), + body: BeaconBlockBody { + proposer_slashings: vec![], + casper_slashings: vec![], + attestations: vec![], + deposits: vec![], + exits: vec![], + }, + } +} + +#[cfg(test)] +mod tests { + use super::*; + + // TODO: enhance these tests. + // https://github.com/sigp/lighthouse/issues/117 + + #[test] + fn test_genesis() { + let spec = ChainSpec::foundation(); + + // This only checks that the function runs without panic. + genesis_beacon_block(&spec); + } +} diff --git a/beacon_chain/genesis/src/block.rs b/beacon_chain/genesis/src/block.rs deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/beacon_chain/genesis/src/lib.rs b/beacon_chain/genesis/src/lib.rs index 1f901e7a71..e590fa8be8 100644 --- a/beacon_chain/genesis/src/lib.rs +++ b/beacon_chain/genesis/src/lib.rs @@ -4,6 +4,7 @@ extern crate validator_induction; extern crate validator_shuffling; mod beacon_state; +mod beacon_block; -pub use beacon_state::{genesis_beacon_state, Error as GenesisError}; - +pub use crate::beacon_block::genesis_beacon_block; +pub use crate::beacon_state::{genesis_beacon_state, Error as GenesisError}; diff --git a/beacon_chain/types/src/beacon_block.rs b/beacon_chain/types/src/beacon_block.rs index b6ac9e9e02..36b625eb57 100644 --- a/beacon_chain/types/src/beacon_block.rs +++ b/beacon_chain/types/src/beacon_block.rs @@ -1,7 +1,7 @@ use super::ssz::{Decodable, DecodeError, Encodable, SszStream}; use super::{BeaconBlockBody, Hash256}; use crate::test_utils::TestRandom; -use bls::AggregateSignature; +use bls::Signature; use rand::RngCore; #[derive(Debug, PartialEq, Clone, Default)] @@ -11,7 +11,7 @@ pub struct BeaconBlock { pub state_root: Hash256, pub randao_reveal: Hash256, pub candidate_pow_receipt_root: Hash256, - pub signature: AggregateSignature, + pub signature: Signature, pub body: BeaconBlockBody, }