Add TreeHash derives for cache objects.

This allows us to avoid a verbose manual impl for BeaconState
This commit is contained in:
Paul Hauner 2019-03-15 18:36:16 +11:00
parent 7660cbd419
commit b37cf3a269
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
2 changed files with 22 additions and 0 deletions

View File

@ -1,5 +1,7 @@
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)]
@ -67,3 +69,14 @@ 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,4 +1,6 @@
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;
@ -36,3 +38,10 @@ 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()
}
}