Add TestRandom default field attr to BeaconState

This commit is contained in:
Paul Hauner 2019-03-16 14:32:23 +11:00
parent 33783d4baa
commit c648491c45
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
3 changed files with 4 additions and 23 deletions

View File

@ -8,7 +8,7 @@ use log::{debug, error, trace};
use pubkey_cache::PubkeyCache; use pubkey_cache::PubkeyCache;
use rand::RngCore; use rand::RngCore;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use ssz::{hash, Decodable, SignedRoot, TreeHash}; use ssz::{hash, SignedRoot};
use ssz_derive::{Decode, Encode, TreeHash}; use ssz_derive::{Decode, Encode, TreeHash};
use std::collections::HashMap; use std::collections::HashMap;
use swap_or_not_shuffle::shuffle_list; use swap_or_not_shuffle::shuffle_list;
@ -128,16 +128,19 @@ pub struct BeaconState {
#[ssz(skip_serializing)] #[ssz(skip_serializing)]
#[ssz(skip_deserializing)] #[ssz(skip_deserializing)]
#[tree_hash(skip_hashing)] #[tree_hash(skip_hashing)]
#[test_random(default)]
pub cache_index_offset: usize, pub cache_index_offset: usize,
#[serde(default)] #[serde(default)]
#[ssz(skip_serializing)] #[ssz(skip_serializing)]
#[ssz(skip_deserializing)] #[ssz(skip_deserializing)]
#[tree_hash(skip_hashing)] #[tree_hash(skip_hashing)]
#[test_random(default)]
pub caches: [EpochCache; CACHED_EPOCHS], pub caches: [EpochCache; CACHED_EPOCHS],
#[serde(default)] #[serde(default)]
#[ssz(skip_serializing)] #[ssz(skip_serializing)]
#[ssz(skip_deserializing)] #[ssz(skip_deserializing)]
#[tree_hash(skip_hashing)] #[tree_hash(skip_hashing)]
#[test_random(default)]
pub pubkey_cache: PubkeyCache, pub pubkey_cache: PubkeyCache,
} }

View File

@ -1,7 +1,5 @@
use super::{AttestationDuty, BeaconState, CrosslinkCommittees, Error}; use super::{AttestationDuty, BeaconState, CrosslinkCommittees, Error};
use crate::test_utils::TestRandom;
use crate::{ChainSpec, Epoch}; use crate::{ChainSpec, Epoch};
use rand::RngCore;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize)] #[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize)]
@ -69,14 +67,3 @@ impl EpochCache {
}) })
} }
} }
impl<T: RngCore> TestRandom<T> for [EpochCache; 3] {
/// Test random should generate an empty cache.
fn random_for_test(rng: &mut T) -> Self {
[
EpochCache::default(),
EpochCache::default(),
EpochCache::default(),
]
}
}

View File

@ -1,6 +1,4 @@
use crate::test_utils::TestRandom;
use crate::*; use crate::*;
use rand::RngCore;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use std::collections::HashMap; use std::collections::HashMap;
@ -38,10 +36,3 @@ impl PubkeyCache {
self.map.get(pubkey).cloned() self.map.get(pubkey).cloned()
} }
} }
impl<T: RngCore> TestRandom<T> for PubkeyCache {
/// Test random should generate an empty cache.
fn random_for_test(rng: &mut T) -> Self {
Self::default()
}
}