slight corrections to attestation validation
This commit is contained in:
parent
7e1819f693
commit
048f8b6f01
@ -16,3 +16,4 @@ pub mod shard_and_committee;
|
||||
pub mod transition;
|
||||
pub mod validator_record;
|
||||
pub mod validation;
|
||||
pub mod helpers;
|
||||
|
@ -1,20 +1,20 @@
|
||||
use super::super::crystallized_state::CrystallizedState;
|
||||
use super::super::active_state::ActiveState;
|
||||
use super::super::attestation_record::AttestationRecord;
|
||||
use super::super::block::Block;
|
||||
use super::super::chain_config::ChainConfig;
|
||||
use super::CrystallizedState;
|
||||
use super::ActiveState;
|
||||
use super::AttestationRecord;
|
||||
use super::Block;
|
||||
use super::ChainConfig;
|
||||
|
||||
use ::utils::errors::AttestationValidationError;
|
||||
|
||||
// implementation of validate_attestation in the v2.1 python reference implementation
|
||||
// see: https://github.com/ethereum/beacon_chain/blob/a79ab2c6f03cbdabf2b6d9d435c26e2b216e09a5/beacon_chain/state/state_transition.py#L61
|
||||
pub fn validate_attestation(
|
||||
crystallized_state: &CrystallizedState,
|
||||
crystallized_state: &CrystallizedState,
|
||||
active_state: &ActiveState,
|
||||
attestation: &AttestationRecord,
|
||||
block: &Block,
|
||||
chain_config: &ChainConfig)
|
||||
-> Result<bool, AttestationValidationError> {
|
||||
chain_config: &ChainConfig)
|
||||
-> Result<bool, AttestationValidationError> {
|
||||
|
||||
if !(attestation.slot < block.slot_number) {
|
||||
return Err(AttestationValidationError::SlotTooHigh);
|
||||
@ -24,24 +24,24 @@ pub fn validate_attestation(
|
||||
return Err(AttestationValidationError::SlotTooLow(format!("Attestation slot number too low\n\tFound: {:?}, Needed greater than: {:?}", attestation.slot, block.slot_number - chain_config.cycle_length as u64)));
|
||||
}
|
||||
|
||||
return Ok(true);
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
mod tests {
|
||||
|
||||
use super::*;
|
||||
// test helper functions
|
||||
|
||||
fn generate_standard_state() -> (
|
||||
CrystallizedState,
|
||||
ActiveState,
|
||||
AttestationRecord,
|
||||
Block,
|
||||
ChainConfig) {
|
||||
|
||||
let crystallized_state = CrystallizedState::zero();
|
||||
fn generate_standard_state() -> (
|
||||
CrystallizedState,
|
||||
ActiveState,
|
||||
AttestationRecord,
|
||||
Block,
|
||||
ChainConfig) {
|
||||
|
||||
let crystallized_state = CrystallizedState::zero();
|
||||
let active_state = ActiveState::zero();
|
||||
let attestation_record = AttestationRecord::zero();
|
||||
let block = Block::zero();
|
||||
@ -49,10 +49,9 @@ mod tests {
|
||||
|
||||
return (crystallized_state, active_state, attestation_record, block, chain_config);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_attestation_validation_slot_high() {
|
||||
fn test_attestation_validation_slot_high() {
|
||||
// generate standard state
|
||||
let (crystallized_state, active_state, mut attestation_record, mut block, chain_config) = generate_standard_state();
|
||||
// set slot too high
|
||||
@ -64,14 +63,19 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_attestation_validation_slot_low() {
|
||||
fn test_attestation_validation_slot_low() {
|
||||
// generate standard state
|
||||
let (crystallized_state, active_state, mut attestation_record, mut block, chain_config) = generate_standard_state();
|
||||
// set slot too high
|
||||
attestation_record.slot = 2;
|
||||
block.slot_number = 10;
|
||||
|
||||
let result = validate_attestation(&crystallized_state, &active_state, &attestation_record, &block, &chain_config);
|
||||
let result = validate_attestation(
|
||||
&crystallized_state,
|
||||
&active_state,
|
||||
&attestation_record,
|
||||
&block,
|
||||
&chain_config);
|
||||
//assert_eq!(result, Err(AttestationValidationError::SlotTooLow));
|
||||
}
|
||||
}
|
||||
|
@ -1 +1,7 @@
|
||||
use super::crystallized_state::CrystallizedState;
|
||||
use super::active_state::ActiveState;
|
||||
use super::attestation_record::AttestationRecord;
|
||||
use super::block::Block;
|
||||
use super::chain_config::ChainConfig;
|
||||
|
||||
mod attestation_validation;
|
||||
|
Loading…
Reference in New Issue
Block a user