Add tests for genesis and modify genesis to match new specs
This commit is contained in:
parent
3fd624923b
commit
0b47b81a6c
@ -39,9 +39,6 @@ fn genesis_signature() -> Signature {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
// TODO: enhance these tests.
|
||||
// https://github.com/sigp/lighthouse/issues/117
|
||||
|
||||
#[test]
|
||||
fn test_genesis() {
|
||||
let spec = ChainSpec::foundation();
|
||||
@ -51,7 +48,7 @@ mod tests {
|
||||
genesis_beacon_block(state_root, &spec);
|
||||
}
|
||||
|
||||
// Tests parent_root, randao_reveal, deposit_root are the zero hash after creation and slot == 0
|
||||
// Tests items that are 0 or zero_hash
|
||||
#[test]
|
||||
fn test_zero_items() {
|
||||
let spec = ChainSpec::foundation();
|
||||
@ -61,13 +58,13 @@ mod tests {
|
||||
|
||||
let genesis_block = genesis_beacon_block(state_root, &spec);
|
||||
|
||||
assert!(genesis_block.slot == 0);
|
||||
assert!(genesis_block.parent_root.is_zero());
|
||||
assert!(genesis_block.randao_reveal.is_zero());
|
||||
assert!(genesis_block.slot == 0);
|
||||
// assert!(genesis_block.depsoit_root.is_zero());
|
||||
|
||||
assert!(genesis_block.candidate_pow_receipt_root.is_zero()); // aka deposit_root
|
||||
}
|
||||
|
||||
// Tests the BeaconBlockBody inside BeaconBlock
|
||||
#[test]
|
||||
fn test_beacon_body() {
|
||||
let spec = ChainSpec::foundation();
|
||||
@ -77,12 +74,13 @@ mod tests {
|
||||
|
||||
let genesis_block = genesis_beacon_block(state_root, &spec);
|
||||
|
||||
// Custody items are not being implemented until phase 1 so tests to be added later
|
||||
|
||||
assert!(genesis_block.body.proposer_slashings.is_empty());
|
||||
assert!(genesis_block.body.casper_slashings.is_empty());
|
||||
assert!(genesis_block.body.attestations.is_empty());
|
||||
assert!(genesis_block.body.deposits.is_empty());
|
||||
assert!(genesis_block.body.exits.is_empty());
|
||||
// Specs have changed to include 3 more variables in BeaconBody to be added later
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -102,6 +100,6 @@ mod tests {
|
||||
assert!(raw_sig_bytes.len() == 97);
|
||||
for item in raw_sig_bytes.iter() {
|
||||
assert!(*item == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,8 +68,8 @@ pub fn genesis_beacon_state(spec: &ChainSpec) -> Result<BeaconState, Error> {
|
||||
* Recent state
|
||||
*/
|
||||
latest_crosslinks: vec![initial_crosslink; spec.shard_count as usize],
|
||||
latest_block_roots: vec![spec.zero_hash; spec.epoch_length as usize],
|
||||
latest_penalized_exit_balances: vec![],
|
||||
latest_block_roots: vec![spec.zero_hash; spec.latest_block_roots_length as usize],
|
||||
latest_penalized_exit_balances: vec![0; spec.latest_penalized_exit_length as usize],
|
||||
latest_attestations: vec![],
|
||||
batched_block_roots: vec![],
|
||||
/*
|
||||
@ -94,9 +94,6 @@ mod tests {
|
||||
use super::*;
|
||||
use types::Hash256;
|
||||
|
||||
// TODO: enhance these tests.
|
||||
// https://github.com/sigp/lighthouse/issues/117
|
||||
|
||||
#[test]
|
||||
fn test_gen_state() {
|
||||
let spec = ChainSpec::foundation();
|
||||
@ -109,6 +106,7 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
// Test Misc
|
||||
#[test]
|
||||
fn test_gen_state_misc() {
|
||||
let spec = ChainSpec::foundation();
|
||||
@ -116,12 +114,13 @@ mod tests {
|
||||
let state = genesis_beacon_state(&spec).unwrap();
|
||||
|
||||
assert_eq!(state.slot, 0);
|
||||
assert_eq!(state.genesis_time, spec.genesis_time);
|
||||
assert_eq!(state.genesis_time, spec.genesis_time);
|
||||
assert_eq!(state.fork_data.pre_fork_version, 0);
|
||||
assert_eq!(state.fork_data.post_fork_version, 0);
|
||||
assert_eq!(state.fork_data.fork_slot, 0);
|
||||
}
|
||||
|
||||
// Test validators
|
||||
#[test]
|
||||
fn test_gen_state_validators() {
|
||||
let spec = ChainSpec::foundation();
|
||||
@ -135,17 +134,24 @@ mod tests {
|
||||
assert_eq!(state.validator_registry_delta_chain_tip, Hash256::zero());
|
||||
}
|
||||
|
||||
// Test randomness and committees
|
||||
#[test]
|
||||
fn test_gen_state_randomness_committees() {
|
||||
let spec = ChainSpec::foundation();
|
||||
|
||||
let state = genesis_beacon_state(&spec).unwrap();
|
||||
|
||||
// Note: specs now have randao_mixes containing 8,192 zero hashes
|
||||
assert_eq!(state.randao_mix, Hash256::zero());
|
||||
// Array of size 8,192 each being zero_hash
|
||||
assert_eq!(state.latest_randao_mixes.len(), 8_192);
|
||||
for item in state.latest_randao_mixes.iter() {
|
||||
assert_eq!(*item, Hash256::zero());
|
||||
}
|
||||
|
||||
// Note: next_seed has changed to latest_vdf_outputs[8,192]8,192]
|
||||
assert_eq!(state.next_seed, Hash256::zero());
|
||||
// Array of size 8,192 each being a zero hash
|
||||
assert_eq!(state.latest_vdf_outputs.len(), (8_192 / 64));
|
||||
for item in state.latest_vdf_outputs.iter() {
|
||||
assert_eq!(*item, Hash256::zero());
|
||||
}
|
||||
|
||||
// TODO: Check shard and committee shuffling requires solving issue:
|
||||
// https://github.com/sigp/lighthouse/issues/151
|
||||
@ -154,60 +160,68 @@ mod tests {
|
||||
// initial_shuffling = initial_shuffling.append(initial_shuffling.clone());
|
||||
}
|
||||
|
||||
// Custody not implemented until Phase 1
|
||||
// This test will always pass until Phase 1
|
||||
#[test]
|
||||
fn test_gen_state_custody_finanilty() {
|
||||
fn test_gen_state_custody() {}
|
||||
|
||||
// Test finality
|
||||
#[test]
|
||||
fn test_gen_state_finanilty() {
|
||||
let spec = ChainSpec::foundation();
|
||||
|
||||
let state = genesis_beacon_state(&spec).unwrap();
|
||||
|
||||
// Note: custody_challenges are not included yet but are in Eth2.0 specs
|
||||
|
||||
assert_eq!(state.previous_justified_slot, 0);
|
||||
assert_eq!(state.justified_slot, 0);
|
||||
assert_eq!(state.justification_bitfield, 0);
|
||||
assert_eq!(state.finalized_slot, 0);
|
||||
}
|
||||
|
||||
// Test recent state
|
||||
#[test]
|
||||
fn test_gen_state_recent_state() {
|
||||
let spec = ChainSpec::foundation();
|
||||
|
||||
let state = genesis_beacon_state(&spec).unwrap();
|
||||
|
||||
|
||||
// Test latest_crosslinks
|
||||
assert_eq!(state.latest_crosslinks.len(), 1024);
|
||||
assert_eq!(state.latest_crosslinks.len(), 1_024);
|
||||
for link in state.latest_crosslinks.iter() {
|
||||
assert_eq!(link.slot, 0);
|
||||
assert_eq!(link.shard_block_root, Hash256::zero());
|
||||
}
|
||||
|
||||
// Test latest_block_roots
|
||||
assert_eq!(state.latest_block_roots.len(), 64);
|
||||
assert_eq!(state.latest_block_roots.len(), 8_192);
|
||||
for block in state.latest_block_roots.iter() {
|
||||
assert_eq!(*block, Hash256::zero());
|
||||
}
|
||||
|
||||
// Test latest_penalized_exit_balances
|
||||
// Note: Eth2.0 specs says this should be an array of length LATEST_PENALIZE_EXIT_LENGTH
|
||||
// = (8,192)
|
||||
assert!(state.latest_penalized_exit_balances.is_empty());
|
||||
assert_eq!(state.latest_penalized_exit_balances.len(), 8_192);
|
||||
for item in state.latest_penalized_exit_balances.iter() {
|
||||
assert!(*item == 0);
|
||||
}
|
||||
|
||||
// Test latest_attestations
|
||||
assert!(state.latest_attestations.is_empty());
|
||||
|
||||
// Note: missing batched_block_roots in new spec
|
||||
|
||||
// batched_block_roots
|
||||
assert!(state.batched_block_roots.is_empty());
|
||||
}
|
||||
|
||||
// Note: here we refer to it as pow_reciept in the Eth2.0 specs it is called deposit
|
||||
// Test PoW Receipts a.k.a. deposits
|
||||
#[test]
|
||||
fn test_gen_state_deposit_root() {
|
||||
let spec = ChainSpec::foundation();
|
||||
|
||||
let state = genesis_beacon_state(&spec).unwrap();
|
||||
|
||||
assert_eq!(state.processed_pow_receipt_root, spec.processed_pow_receipt_root);
|
||||
assert_eq!(
|
||||
state.processed_pow_receipt_root,
|
||||
spec.processed_pow_receipt_root
|
||||
);
|
||||
assert!(state.candidate_pow_receipt_roots.is_empty());
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,10 @@ impl ChainSpec {
|
||||
beacon_chain_shard_number: u64::max_value(),
|
||||
bls_withdrawal_prefix_byte: 0x00,
|
||||
max_casper_votes: 1_024,
|
||||
latest_block_roots_length: 8_192,
|
||||
latest_randao_mixes_length: 8_192,
|
||||
latest_penalized_exit_length: 8_192,
|
||||
max_withdrawals_per_epoch: 4,
|
||||
/*
|
||||
* Deposit contract
|
||||
*/
|
||||
|
@ -18,7 +18,10 @@ pub struct ChainSpec {
|
||||
pub beacon_chain_shard_number: u64,
|
||||
pub bls_withdrawal_prefix_byte: u8,
|
||||
pub max_casper_votes: u64,
|
||||
pub latest_block_roots_length: u64,
|
||||
pub latest_randao_mixes_length: u64,
|
||||
pub latest_penalized_exit_length: u64,
|
||||
pub max_withdrawals_per_epoch: u64,
|
||||
/*
|
||||
* Deposit contract
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user