BaconState cleanup, warnings fixed, and invalid proof of possession induction test added

This commit is contained in:
Grant Wuerker 2018-12-29 17:53:48 -06:00
parent 598562da73
commit c180c6c94f
5 changed files with 30 additions and 26 deletions

View File

@ -103,21 +103,4 @@ mod tests {
spec.initial_validators.len()
);
}
/*
#[test]
fn test_genesis_bad_validator() {
let mut spec = ChainSpec::foundation();
let random_kp = Keypair::random();
spec.initial_validators[4].proof_of_possession = create_proof_of_possession(&random_kp);
let state = genesis_beacon_state(&spec).unwrap();
assert_eq!(
state.validator_registry.len(),
spec.initial_validators.len() - 1
);
}
*/
}

View File

@ -1,8 +1,11 @@
use super::ChainSpec;
use bls::{create_proof_of_possession, Keypair, PublicKey, SecretKey};
use bls::{Keypair, PublicKey, SecretKey};
use types::{Address, Hash256, ValidatorRecord};
/// The size of a validators deposit in GWei.
pub const DEPOSIT_GWEI: u64 = 32_000_000_000;
impl ChainSpec {
/// Returns a `ChainSpec` compatible with the specification from Ethereum Foundation.
///
@ -64,7 +67,7 @@ impl ChainSpec {
* Intialization parameters
*/
initial_validators: initial_validators_for_testing(),
initial_balances: vec![0,0,0,0],
initial_balances: initial_balances_for_testing(),
genesis_time: 1544672897,
processed_pow_receipt_root: Hash256::from("pow_root".as_bytes()),
}
@ -113,6 +116,10 @@ fn initial_validators_for_testing() -> Vec<ValidatorRecord> {
initial_validators
}
fn initial_balances_for_testing() -> Vec<u64> {
vec![DEPOSIT_GWEI; 4]
}
#[cfg(test)]
mod tests {
use super::*;

View File

@ -10,7 +10,6 @@ pub struct ChainConfig {
pub max_validator_churn_quotient: u64,
pub genesis_time: u64,
pub slot_duration_millis: u64,
// TODO: Come back to this
pub initial_validators: Vec<ValidatorRecord>,
// New constants

View File

@ -2,9 +2,6 @@ use bls::{verify_proof_of_possession};
use types::{BeaconState, Deposit, ValidatorRecord, ValidatorStatus};
use spec::ChainSpec;
/// The size of a validators deposit in GWei.
pub const DEPOSIT_GWEI: u64 = 32_000_000_000;
#[derive(Debug, PartialEq, Clone)]
pub enum ValidatorInductionError {
InvalidShard,
@ -84,7 +81,10 @@ fn min_empty_validator_index(
mod tests {
use super::*;
use types::{Hash256, DepositData, DepositInput};
use bls::{create_proof_of_possession, Keypair};
/// The size of a validators deposit in GWei.
pub const DEPOSIT_GWEI: u64 = 32_000_000_000;
fn deposit_equals_record(dep: &Deposit, val: &ValidatorRecord) -> bool {
(dep.deposit_data.deposit_input.pubkey == val.pubkey)
@ -169,4 +169,19 @@ mod tests {
assert_eq!(state.validator_registry.len(), 1);
assert_eq!(state.validator_balances.len(), 1);
}
#[test]
fn test_process_deposit_invalid_proof_of_possession() {
let mut state = BeaconState::default();
let mut deposit = Deposit::zero_with_rand_keypair();
let spec = ChainSpec::foundation();
deposit.deposit_data.value = DEPOSIT_GWEI;
deposit.deposit_data.deposit_input.proof_of_possession = create_proof_of_possession(&Keypair::random());
let result = process_deposit(&mut state, &deposit, &spec);
assert_eq!(result, Err(ValidatorInductionError::InvaidProofOfPossession));
assert_eq!(state.validator_registry.len(), 0);
assert_eq!(state.validator_balances.len(), 0);
}
}

View File

@ -5,4 +5,4 @@ extern crate spec;
mod inductor;
pub use crate::inductor::{ValidatorInductionError};
pub use crate::inductor::{ValidatorInductionError, process_deposit};