From b37cf3a2698562e3c523e798e580b44ed42d2646 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Fri, 15 Mar 2019 18:36:16 +1100 Subject: [PATCH] Add TreeHash derives for cache objects. This allows us to avoid a verbose manual impl for BeaconState --- eth2/types/src/beacon_state/epoch_cache.rs | 13 +++++++++++++ eth2/types/src/beacon_state/pubkey_cache.rs | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/eth2/types/src/beacon_state/epoch_cache.rs b/eth2/types/src/beacon_state/epoch_cache.rs index ddcca0a9a..3e580eee1 100644 --- a/eth2/types/src/beacon_state/epoch_cache.rs +++ b/eth2/types/src/beacon_state/epoch_cache.rs @@ -1,5 +1,7 @@ use super::{AttestationDuty, BeaconState, CrosslinkCommittees, Error}; +use crate::test_utils::TestRandom; use crate::{ChainSpec, Epoch}; +use rand::RngCore; use serde_derive::{Deserialize, Serialize}; #[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize)] @@ -67,3 +69,14 @@ impl EpochCache { }) } } + +impl TestRandom for [EpochCache; 3] { + /// Test random should generate an empty cache. + fn random_for_test(rng: &mut T) -> Self { + [ + EpochCache::default(), + EpochCache::default(), + EpochCache::default(), + ] + } +} diff --git a/eth2/types/src/beacon_state/pubkey_cache.rs b/eth2/types/src/beacon_state/pubkey_cache.rs index 340bdb311..22fe32694 100644 --- a/eth2/types/src/beacon_state/pubkey_cache.rs +++ b/eth2/types/src/beacon_state/pubkey_cache.rs @@ -1,4 +1,6 @@ +use crate::test_utils::TestRandom; use crate::*; +use rand::RngCore; use serde_derive::{Deserialize, Serialize}; use std::collections::HashMap; @@ -36,3 +38,10 @@ impl PubkeyCache { self.map.get(pubkey).cloned() } } + +impl TestRandom for PubkeyCache { + /// Test random should generate an empty cache. + fn random_for_test(rng: &mut T) -> Self { + Self::default() + } +}