bad whitespace removed

This commit is contained in:
Grant Wuerker 2019-01-07 22:16:15 -06:00
parent 0a1c299206
commit cdb8e602e8
2 changed files with 35 additions and 35 deletions

View File

@ -99,7 +99,7 @@ fn initial_validators_for_testing() -> Vec<ValidatorRecord> {
} }
}; };
let validator_record = ValidatorRecord { let validator_record = ValidatorRecord {
pubkey: keypair.pk.clone(), pubkey: keypair.pk.clone(),
withdrawal_credentials: Hash256::zero(), withdrawal_credentials: Hash256::zero(),
randao_commitment: Hash256::zero(), randao_commitment: Hash256::zero(),
randao_layers: 0, randao_layers: 0,

View File

@ -12,29 +12,29 @@ pub enum ValidatorInductionError {
pub fn process_deposit( pub fn process_deposit(
state: &mut BeaconState, state: &mut BeaconState,
deposit: &Deposit, deposit: &Deposit,
spec: &ChainSpec) spec: &ChainSpec)
-> Result<usize, ValidatorInductionError> { -> Result<usize, ValidatorInductionError> {
let deposit_input = &deposit.deposit_data.deposit_input; let deposit_input = &deposit.deposit_data.deposit_input;
let deposit_data = &deposit.deposit_data; let deposit_data = &deposit.deposit_data;
// TODO: Update the signature validation as defined in the spec once issues #91 and #70 are completed // TODO: Update the signature validation as defined in the spec once issues #91 and #70 are completed
if !verify_proof_of_possession(&deposit_input.proof_of_possession, &deposit_input.pubkey) { if !verify_proof_of_possession(&deposit_input.proof_of_possession, &deposit_input.pubkey) {
return Err(ValidatorInductionError::InvaidProofOfPossession); return Err(ValidatorInductionError::InvaidProofOfPossession);
} }
let validator_index = state.validator_registry.iter() let validator_index = state.validator_registry.iter()
.position(|validator| validator.pubkey == deposit_input.pubkey); .position(|validator| validator.pubkey == deposit_input.pubkey);
match validator_index { match validator_index {
Some(i) => { Some(i) => {
if state.validator_registry[i].withdrawal_credentials == deposit_input.withdrawal_credentials { if state.validator_registry[i].withdrawal_credentials == deposit_input.withdrawal_credentials {
state.validator_balances[i] += deposit_data.value; state.validator_balances[i] += deposit_data.value;
return Ok(i); return Ok(i);
} }
Err(ValidatorInductionError::InvalidWithdrawalCredentials) Err(ValidatorInductionError::InvalidWithdrawalCredentials)
}, },
None => { None => {
let validator = ValidatorRecord { let validator = ValidatorRecord {
pubkey: deposit_input.pubkey.clone(), pubkey: deposit_input.pubkey.clone(),
withdrawal_credentials: deposit_input.withdrawal_credentials, withdrawal_credentials: deposit_input.withdrawal_credentials,
@ -47,7 +47,7 @@ pub fn process_deposit(
latest_custody_reseed_slot: 0, latest_custody_reseed_slot: 0,
penultimate_custody_reseed_slot: 0 penultimate_custody_reseed_slot: 0
}; };
match min_empty_validator_index(state, spec) { match min_empty_validator_index(state, spec) {
Some(i) => { Some(i) => {
state.validator_registry[i] = validator; state.validator_registry[i] = validator;
@ -67,10 +67,10 @@ pub fn process_deposit(
fn min_empty_validator_index( fn min_empty_validator_index(
state: &BeaconState, state: &BeaconState,
spec: &ChainSpec spec: &ChainSpec
) -> Option<usize> { ) -> Option<usize> {
for i in 0..state.validator_registry.len() { for i in 0..state.validator_registry.len() {
if state.validator_balances[i] == 0 if state.validator_balances[i] == 0
&& state.validator_registry[i].latest_status_change_slot && state.validator_registry[i].latest_status_change_slot
+ spec.zero_balance_validator_ttl <= state.slot { + spec.zero_balance_validator_ttl <= state.slot {
return Some(i); return Some(i);
} }
@ -82,27 +82,27 @@ fn min_empty_validator_index(
mod tests { mod tests {
use super::*; use super::*;
use types::test_utils::{SeedableRng, TestRandom, XorShiftRng}; use types::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use bls::{create_proof_of_possession, Keypair}; use bls::{create_proof_of_possession, Keypair};
/// The size of a validators deposit in GWei. /// The size of a validators deposit in GWei.
pub const DEPOSIT_GWEI: u64 = 32_000_000_000; pub const DEPOSIT_GWEI: u64 = 32_000_000_000;
fn get_deposit() -> Deposit { fn get_deposit() -> Deposit {
let mut rng = XorShiftRng::from_seed([42; 16]); let mut rng = XorShiftRng::from_seed([42; 16]);
let mut deposit = Deposit::random_for_test(&mut rng); let mut deposit = Deposit::random_for_test(&mut rng);
let kp = Keypair::random(); let kp = Keypair::random();
deposit.deposit_data.deposit_input.pubkey = kp.pk.clone(); deposit.deposit_data.deposit_input.pubkey = kp.pk.clone();
deposit.deposit_data.deposit_input.proof_of_possession = create_proof_of_possession(&kp); deposit.deposit_data.deposit_input.proof_of_possession = create_proof_of_possession(&kp);
deposit deposit
} }
fn get_validator() -> ValidatorRecord { fn get_validator() -> ValidatorRecord {
let mut rng = XorShiftRng::from_seed([42; 16]); let mut rng = XorShiftRng::from_seed([42; 16]);
ValidatorRecord::random_for_test(&mut rng) ValidatorRecord::random_for_test(&mut rng)
} }
fn deposit_equals_record(dep: &Deposit, val: &ValidatorRecord) -> bool { fn deposit_equals_record(dep: &Deposit, val: &ValidatorRecord) -> bool {
(dep.deposit_data.deposit_input.pubkey == val.pubkey) (dep.deposit_data.deposit_input.pubkey == val.pubkey)
& (dep.deposit_data.deposit_input.withdrawal_credentials == val.withdrawal_credentials) & (dep.deposit_data.deposit_input.withdrawal_credentials == val.withdrawal_credentials)
@ -116,7 +116,7 @@ mod tests {
let mut deposit = get_deposit(); let mut deposit = get_deposit();
let spec = ChainSpec::foundation(); let spec = ChainSpec::foundation();
deposit.deposit_data.value = DEPOSIT_GWEI; deposit.deposit_data.value = DEPOSIT_GWEI;
let result = process_deposit(&mut state, &deposit, &spec); let result = process_deposit(&mut state, &deposit, &spec);
assert_eq!(result.unwrap(), 0); assert_eq!(result.unwrap(), 0);
@ -140,63 +140,63 @@ mod tests {
assert_eq!(state.validator_balances.len(), i + 1); assert_eq!(state.validator_balances.len(), i + 1);
} }
} }
#[test] #[test]
fn test_process_deposit_top_out() { fn test_process_deposit_top_out() {
let mut state = BeaconState::default(); let mut state = BeaconState::default();
let spec = ChainSpec::foundation(); let spec = ChainSpec::foundation();
let mut deposit = get_deposit(); let mut deposit = get_deposit();
let mut validator = get_validator(); let mut validator = get_validator();
deposit.deposit_data.value = DEPOSIT_GWEI; deposit.deposit_data.value = DEPOSIT_GWEI;
validator.pubkey = deposit.deposit_data.deposit_input.pubkey.clone(); validator.pubkey = deposit.deposit_data.deposit_input.pubkey.clone();
validator.withdrawal_credentials = deposit.deposit_data.deposit_input.withdrawal_credentials; validator.withdrawal_credentials = deposit.deposit_data.deposit_input.withdrawal_credentials;
validator.randao_commitment = deposit.deposit_data.deposit_input.randao_commitment; validator.randao_commitment = deposit.deposit_data.deposit_input.randao_commitment;
state.validator_registry.push(validator); state.validator_registry.push(validator);
state.validator_balances.push(DEPOSIT_GWEI); state.validator_balances.push(DEPOSIT_GWEI);
let result = process_deposit(&mut state, &deposit, &spec); let result = process_deposit(&mut state, &deposit, &spec);
assert_eq!(result.unwrap(), 0); assert_eq!(result.unwrap(), 0);
assert!(deposit_equals_record(&deposit, &state.validator_registry[0])); assert!(deposit_equals_record(&deposit, &state.validator_registry[0]));
assert_eq!(state.validator_balances[0], DEPOSIT_GWEI * 2); assert_eq!(state.validator_balances[0], DEPOSIT_GWEI * 2);
assert_eq!(state.validator_registry.len(), 1); assert_eq!(state.validator_registry.len(), 1);
assert_eq!(state.validator_balances.len(), 1); assert_eq!(state.validator_balances.len(), 1);
} }
#[test] #[test]
fn test_process_deposit_replace_validator() { fn test_process_deposit_replace_validator() {
let mut state = BeaconState::default(); let mut state = BeaconState::default();
let spec = ChainSpec::foundation(); let spec = ChainSpec::foundation();
let mut validator = get_validator(); let mut validator = get_validator();
validator.latest_status_change_slot = 0; validator.latest_status_change_slot = 0;
state.validator_registry.push(validator); state.validator_registry.push(validator);
state.validator_balances.push(0); state.validator_balances.push(0);
let mut deposit = get_deposit(); let mut deposit = get_deposit();
deposit.deposit_data.value = DEPOSIT_GWEI; deposit.deposit_data.value = DEPOSIT_GWEI;
state.slot = spec.zero_balance_validator_ttl; state.slot = spec.zero_balance_validator_ttl;
let result = process_deposit(&mut state, &deposit, &spec); let result = process_deposit(&mut state, &deposit, &spec);
assert_eq!(result.unwrap(), 0); assert_eq!(result.unwrap(), 0);
assert!(deposit_equals_record(&deposit, &state.validator_registry[0])); assert!(deposit_equals_record(&deposit, &state.validator_registry[0]));
assert_eq!(state.validator_balances[0], DEPOSIT_GWEI); assert_eq!(state.validator_balances[0], DEPOSIT_GWEI);
assert_eq!(state.validator_registry.len(), 1); assert_eq!(state.validator_registry.len(), 1);
assert_eq!(state.validator_balances.len(), 1); assert_eq!(state.validator_balances.len(), 1);
} }
#[test] #[test]
fn test_process_deposit_invalid_proof_of_possession() { fn test_process_deposit_invalid_proof_of_possession() {
let mut state = BeaconState::default(); let mut state = BeaconState::default();
let mut deposit = get_deposit(); let mut deposit = get_deposit();
let spec = ChainSpec::foundation(); let spec = ChainSpec::foundation();
deposit.deposit_data.value = DEPOSIT_GWEI; deposit.deposit_data.value = DEPOSIT_GWEI;
deposit.deposit_data.deposit_input.proof_of_possession = create_proof_of_possession(&Keypair::random()); deposit.deposit_data.deposit_input.proof_of_possession = create_proof_of_possession(&Keypair::random());
let result = process_deposit(&mut state, &deposit, &spec); let result = process_deposit(&mut state, &deposit, &spec);
assert_eq!(result, Err(ValidatorInductionError::InvaidProofOfPossession)); assert_eq!(result, Err(ValidatorInductionError::InvaidProofOfPossession));