From f88155625c709efd6dc42c7faae537e6bff486c6 Mon Sep 17 00:00:00 2001 From: thojest Date: Mon, 18 Feb 2019 12:12:01 +0100 Subject: [PATCH] added comment to indicate highest spec version of implemented functions; added realistic test scenario for is_surround_vote (lighthouse-150) --- eth2/types/src/slashable_vote_data.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/eth2/types/src/slashable_vote_data.rs b/eth2/types/src/slashable_vote_data.rs index 170cd635e..ff9e8b658 100644 --- a/eth2/types/src/slashable_vote_data.rs +++ b/eth2/types/src/slashable_vote_data.rs @@ -1,5 +1,5 @@ use super::AttestationData; -use crate::spec::ChainSpec; +use crate::chain_spec::ChainSpec; use crate::test_utils::TestRandom; use bls::AggregateSignature; use rand::RngCore; @@ -15,10 +15,16 @@ pub struct SlashableVoteData { } impl SlashableVoteData { + /// Check if ``attestation_data_1`` and ``attestation_data_2`` have the same target. + /// + /// Spec v0.3.0 pub fn is_double_vote(&self, other: &SlashableVoteData, spec: &ChainSpec) -> bool { self.data.slot.epoch(spec.epoch_length) == other.data.slot.epoch(spec.epoch_length) } + /// Check if ``attestation_data_1`` surrounds ``attestation_data_2``. + /// + /// Spec v0.3.0 pub fn is_surround_vote(&self, other: &SlashableVoteData, spec: &ChainSpec) -> bool { let source_epoch_1 = self.data.justified_epoch; let source_epoch_2 = other.data.justified_epoch; @@ -82,8 +88,8 @@ impl TestRandom for SlashableVoteData { #[cfg(test)] mod tests { use super::*; + use crate::chain_spec::ChainSpec; use crate::slot_epoch::{Epoch, Slot}; - use crate::spec::ChainSpec; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng}; use ssz::ssz_encode; @@ -123,6 +129,18 @@ mod tests { ); } + #[test] + pub fn test_is_surround_vote_true_realistic() { + let spec = ChainSpec::foundation(); + let slashable_vote_first = create_slashable_vote_data(4, 1, &spec); + let slashable_vote_second = create_slashable_vote_data(3, 2, &spec); + + assert_eq!( + slashable_vote_first.is_surround_vote(&slashable_vote_second, &spec), + true + ); + } + #[test] pub fn test_is_surround_vote_false_source_epoch_fails() { let spec = ChainSpec::foundation();