BaconState cleanup, warnings fixed, and invalid proof of possession induction test added
This commit is contained in:
parent
598562da73
commit
c180c6c94f
@ -103,21 +103,4 @@ mod tests {
|
|||||||
spec.initial_validators.len()
|
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
|
|
||||||
);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
use super::ChainSpec;
|
use super::ChainSpec;
|
||||||
use bls::{create_proof_of_possession, Keypair, PublicKey, SecretKey};
|
use bls::{Keypair, PublicKey, SecretKey};
|
||||||
|
|
||||||
use types::{Address, Hash256, ValidatorRecord};
|
use types::{Address, Hash256, ValidatorRecord};
|
||||||
|
|
||||||
|
/// The size of a validators deposit in GWei.
|
||||||
|
pub const DEPOSIT_GWEI: u64 = 32_000_000_000;
|
||||||
|
|
||||||
impl ChainSpec {
|
impl ChainSpec {
|
||||||
/// Returns a `ChainSpec` compatible with the specification from Ethereum Foundation.
|
/// Returns a `ChainSpec` compatible with the specification from Ethereum Foundation.
|
||||||
///
|
///
|
||||||
@ -64,7 +67,7 @@ impl ChainSpec {
|
|||||||
* Intialization parameters
|
* Intialization parameters
|
||||||
*/
|
*/
|
||||||
initial_validators: initial_validators_for_testing(),
|
initial_validators: initial_validators_for_testing(),
|
||||||
initial_balances: vec![0,0,0,0],
|
initial_balances: initial_balances_for_testing(),
|
||||||
genesis_time: 1544672897,
|
genesis_time: 1544672897,
|
||||||
processed_pow_receipt_root: Hash256::from("pow_root".as_bytes()),
|
processed_pow_receipt_root: Hash256::from("pow_root".as_bytes()),
|
||||||
}
|
}
|
||||||
@ -113,6 +116,10 @@ fn initial_validators_for_testing() -> Vec<ValidatorRecord> {
|
|||||||
initial_validators
|
initial_validators
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn initial_balances_for_testing() -> Vec<u64> {
|
||||||
|
vec![DEPOSIT_GWEI; 4]
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -10,7 +10,6 @@ pub struct ChainConfig {
|
|||||||
pub max_validator_churn_quotient: u64,
|
pub max_validator_churn_quotient: u64,
|
||||||
pub genesis_time: u64,
|
pub genesis_time: u64,
|
||||||
pub slot_duration_millis: u64,
|
pub slot_duration_millis: u64,
|
||||||
// TODO: Come back to this
|
|
||||||
pub initial_validators: Vec<ValidatorRecord>,
|
pub initial_validators: Vec<ValidatorRecord>,
|
||||||
|
|
||||||
// New constants
|
// New constants
|
||||||
|
@ -2,9 +2,6 @@ use bls::{verify_proof_of_possession};
|
|||||||
use types::{BeaconState, Deposit, ValidatorRecord, ValidatorStatus};
|
use types::{BeaconState, Deposit, ValidatorRecord, ValidatorStatus};
|
||||||
use spec::ChainSpec;
|
use spec::ChainSpec;
|
||||||
|
|
||||||
/// The size of a validators deposit in GWei.
|
|
||||||
pub const DEPOSIT_GWEI: u64 = 32_000_000_000;
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum ValidatorInductionError {
|
pub enum ValidatorInductionError {
|
||||||
InvalidShard,
|
InvalidShard,
|
||||||
@ -83,8 +80,11 @@ fn min_empty_validator_index(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
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 {
|
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)
|
||||||
@ -169,4 +169,19 @@ mod tests {
|
|||||||
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]
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,4 +5,4 @@ extern crate spec;
|
|||||||
|
|
||||||
mod inductor;
|
mod inductor;
|
||||||
|
|
||||||
pub use crate::inductor::{ValidatorInductionError};
|
pub use crate::inductor::{ValidatorInductionError, process_deposit};
|
||||||
|
Loading…
Reference in New Issue
Block a user