mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-21 05:44:44 +00:00
BaconState cleanup, warnings fixed, and invalid proof of possession induction test added
This commit is contained in:
@@ -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,
|
||||
@@ -83,8 +80,11 @@ fn min_empty_validator_index(
|
||||
#[cfg(test)]
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,4 +5,4 @@ extern crate spec;
|
||||
|
||||
mod inductor;
|
||||
|
||||
pub use crate::inductor::{ValidatorInductionError};
|
||||
pub use crate::inductor::{ValidatorInductionError, process_deposit};
|
||||
|
||||
Reference in New Issue
Block a user