Merge branch 'genesis_tests' into spec-updates
This commit is contained in:
commit
9c6c6071c0
@ -6,7 +6,6 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bls = { path = "../utils/bls" }
|
bls = { path = "../utils/bls" }
|
||||||
bls-aggregates = { git = "https://github.com/sigp/signature-schemes" }
|
|
||||||
spec = { path = "../spec" }
|
spec = { path = "../spec" }
|
||||||
ssz = { path = "../utils/ssz" }
|
ssz = { path = "../utils/ssz" }
|
||||||
types = { path = "../types" }
|
types = { path = "../types" }
|
||||||
|
@ -37,12 +37,10 @@ mod tests {
|
|||||||
genesis_beacon_block(state_root, &spec);
|
genesis_beacon_block(state_root, &spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests items that are 0 or zero_hash
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_zero_items() {
|
fn test_zero_items() {
|
||||||
let spec = ChainSpec::foundation();
|
let spec = ChainSpec::foundation();
|
||||||
|
|
||||||
// Note: state_root will not be available without a state (test in beacon_state)
|
|
||||||
let state_root = Hash256::zero();
|
let state_root = Hash256::zero();
|
||||||
|
|
||||||
let genesis_block = genesis_beacon_block(state_root, &spec);
|
let genesis_block = genesis_beacon_block(state_root, &spec);
|
||||||
@ -53,12 +51,10 @@ mod tests {
|
|||||||
assert!(genesis_block.candidate_pow_receipt_root.is_zero()); // aka deposit_root
|
assert!(genesis_block.candidate_pow_receipt_root.is_zero()); // aka deposit_root
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests the BeaconBlockBody inside BeaconBlock
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_beacon_body() {
|
fn test_beacon_body() {
|
||||||
let spec = ChainSpec::foundation();
|
let spec = ChainSpec::foundation();
|
||||||
|
|
||||||
// Note: state_root will not be available without a state (test in beacon_state)
|
|
||||||
let state_root = Hash256::zero();
|
let state_root = Hash256::zero();
|
||||||
|
|
||||||
let genesis_block = genesis_beacon_block(state_root, &spec);
|
let genesis_block = genesis_beacon_block(state_root, &spec);
|
||||||
@ -76,7 +72,6 @@ mod tests {
|
|||||||
fn test_signature() {
|
fn test_signature() {
|
||||||
let spec = ChainSpec::foundation();
|
let spec = ChainSpec::foundation();
|
||||||
|
|
||||||
// Note: state_root will not be available without a state (test in beacon_state)
|
|
||||||
let state_root = Hash256::zero();
|
let state_root = Hash256::zero();
|
||||||
|
|
||||||
let genesis_block = genesis_beacon_block(state_root, &spec);
|
let genesis_block = genesis_beacon_block(state_root, &spec);
|
||||||
@ -86,7 +81,6 @@ mod tests {
|
|||||||
let raw_sig = genesis_block.signature.as_raw();
|
let raw_sig = genesis_block.signature.as_raw();
|
||||||
let raw_sig_bytes = raw_sig.as_bytes();
|
let raw_sig_bytes = raw_sig.as_bytes();
|
||||||
|
|
||||||
assert!(raw_sig_bytes.len() == 97);
|
|
||||||
for item in raw_sig_bytes.iter() {
|
for item in raw_sig_bytes.iter() {
|
||||||
assert!(*item == 0);
|
assert!(*item == 0);
|
||||||
}
|
}
|
||||||
|
@ -93,14 +93,11 @@ impl From<ValidatorAssignmentError> for Error {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
extern crate bls;
|
|
||||||
extern crate validator_induction;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use types::Hash256;
|
use types::Hash256;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gen_state() {
|
fn test_genesis_state() {
|
||||||
let spec = ChainSpec::foundation();
|
let spec = ChainSpec::foundation();
|
||||||
|
|
||||||
let state = genesis_beacon_state(&spec).unwrap();
|
let state = genesis_beacon_state(&spec).unwrap();
|
||||||
@ -111,9 +108,8 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test Misc
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gen_state_misc() {
|
fn test_genesis_state_misc() {
|
||||||
let spec = ChainSpec::foundation();
|
let spec = ChainSpec::foundation();
|
||||||
|
|
||||||
let state = genesis_beacon_state(&spec).unwrap();
|
let state = genesis_beacon_state(&spec).unwrap();
|
||||||
@ -125,9 +121,8 @@ mod tests {
|
|||||||
assert_eq!(state.fork_data.fork_slot, 0);
|
assert_eq!(state.fork_data.fork_slot, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test validators
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gen_state_validators() {
|
fn test_genesis_state_validators() {
|
||||||
let spec = ChainSpec::foundation();
|
let spec = ChainSpec::foundation();
|
||||||
|
|
||||||
let state = genesis_beacon_state(&spec).unwrap();
|
let state = genesis_beacon_state(&spec).unwrap();
|
||||||
@ -139,9 +134,8 @@ mod tests {
|
|||||||
assert_eq!(state.validator_registry_delta_chain_tip, Hash256::zero());
|
assert_eq!(state.validator_registry_delta_chain_tip, Hash256::zero());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test randomness and committees
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gen_state_randomness_committees() {
|
fn test_genesis_state_randomness_committees() {
|
||||||
let spec = ChainSpec::foundation();
|
let spec = ChainSpec::foundation();
|
||||||
|
|
||||||
let state = genesis_beacon_state(&spec).unwrap();
|
let state = genesis_beacon_state(&spec).unwrap();
|
||||||
@ -166,13 +160,11 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Custody not implemented until Phase 1
|
// Custody not implemented until Phase 1
|
||||||
// This test will always pass until Phase 1
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gen_state_custody() {}
|
fn test_genesis_state_custody() {}
|
||||||
|
|
||||||
// Test finality
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gen_state_finanilty() {
|
fn test_genesis_state_finanilty() {
|
||||||
let spec = ChainSpec::foundation();
|
let spec = ChainSpec::foundation();
|
||||||
|
|
||||||
let state = genesis_beacon_state(&spec).unwrap();
|
let state = genesis_beacon_state(&spec).unwrap();
|
||||||
@ -183,9 +175,8 @@ mod tests {
|
|||||||
assert_eq!(state.finalized_slot, 0);
|
assert_eq!(state.finalized_slot, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test recent state
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gen_state_recent_state() {
|
fn test_genesis_state_recent_state() {
|
||||||
let spec = ChainSpec::foundation();
|
let spec = ChainSpec::foundation();
|
||||||
|
|
||||||
let state = genesis_beacon_state(&spec).unwrap();
|
let state = genesis_beacon_state(&spec).unwrap();
|
||||||
@ -216,9 +207,8 @@ mod tests {
|
|||||||
assert!(state.batched_block_roots.is_empty());
|
assert!(state.batched_block_roots.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test PoW Receipts a.k.a. deposits
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gen_state_deposit_root() {
|
fn test_genesis_state_deposit_root() {
|
||||||
let spec = ChainSpec::foundation();
|
let spec = ChainSpec::foundation();
|
||||||
|
|
||||||
let state = genesis_beacon_state(&spec).unwrap();
|
let state = genesis_beacon_state(&spec).unwrap();
|
||||||
|
@ -9,7 +9,7 @@ use hashing::canonical_hash;
|
|||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
use ssz::{ssz_encode, Decodable, DecodeError, Encodable, SszStream};
|
use ssz::{ssz_encode, Decodable, DecodeError, Encodable, SszStream};
|
||||||
|
|
||||||
// Custody will not be added to the specs until Phase 1 (Sharding Phase) so dummay class used.
|
// Custody will not be added to the specs until Phase 1 (Sharding Phase) so dummy class used.
|
||||||
type CustodyChallenge = usize;
|
type CustodyChallenge = usize;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Default)]
|
#[derive(Debug, PartialEq, Clone, Default)]
|
||||||
|
Loading…
Reference in New Issue
Block a user