Tidy up SSZ testing on types crate

This commit is contained in:
Paul Hauner 2019-01-04 18:10:14 +11:00
parent 8aa9f83c48
commit ad91648f30
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
21 changed files with 42 additions and 42 deletions

View File

@ -64,8 +64,7 @@ impl<T: RngCore> TestRandom<T> for Attestation {
mod tests { mod tests {
use super::super::ssz::ssz_encode; use super::super::ssz::ssz_encode;
use super::*; use super::*;
use crate::test_utils::TestRandom; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use rand::{prng::XorShiftRng, SeedableRng};
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {

View File

@ -104,8 +104,7 @@ impl<T: RngCore> TestRandom<T> for AttestationData {
mod tests { mod tests {
use super::super::ssz::ssz_encode; use super::super::ssz::ssz_encode;
use super::*; use super::*;
use crate::test_utils::TestRandom; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use rand::{prng::XorShiftRng, SeedableRng};
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {

View File

@ -79,8 +79,7 @@ impl<T: RngCore> TestRandom<T> for BeaconBlock {
mod tests { mod tests {
use super::super::ssz::ssz_encode; use super::super::ssz::ssz_encode;
use super::*; use super::*;
use crate::test_utils::TestRandom; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use rand::{prng::XorShiftRng, SeedableRng};
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {

View File

@ -59,8 +59,7 @@ impl<T: RngCore> TestRandom<T> for BeaconBlockBody {
mod tests { mod tests {
use super::super::ssz::ssz_encode; use super::super::ssz::ssz_encode;
use super::*; use super::*;
use crate::test_utils::TestRandom; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use rand::{prng::XorShiftRng, SeedableRng};
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {

View File

@ -166,3 +166,21 @@ impl<T: RngCore> TestRandom<T> for BeaconState {
} }
} }
} }
#[cfg(test)]
mod tests {
use super::super::ssz::ssz_encode;
use super::*;
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
#[test]
pub fn test_ssz_round_trip() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = BeaconState::random_for_test(&mut rng);
let bytes = ssz_encode(&original);
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
assert_eq!(original, decoded);
}
}

View File

@ -44,8 +44,7 @@ impl<T: RngCore> TestRandom<T> for CandidatePoWReceiptRootRecord {
mod tests { mod tests {
use super::super::ssz::ssz_encode; use super::super::ssz::ssz_encode;
use super::*; use super::*;
use crate::test_utils::TestRandom; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use rand::{prng::XorShiftRng, SeedableRng};
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {

View File

@ -44,8 +44,7 @@ impl<T: RngCore> TestRandom<T> for CasperSlashing {
mod tests { mod tests {
use super::super::ssz::ssz_encode; use super::super::ssz::ssz_encode;
use super::*; use super::*;
use crate::test_utils::TestRandom; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use rand::{prng::XorShiftRng, SeedableRng};
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {

View File

@ -54,8 +54,7 @@ impl<T: RngCore> TestRandom<T> for CrosslinkRecord {
mod tests { mod tests {
use super::super::ssz::ssz_encode; use super::super::ssz::ssz_encode;
use super::*; use super::*;
use crate::test_utils::TestRandom; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use rand::{prng::XorShiftRng, SeedableRng};
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {

View File

@ -49,8 +49,7 @@ impl<T: RngCore> TestRandom<T> for DepositData {
mod tests { mod tests {
use super::super::ssz::ssz_encode; use super::super::ssz::ssz_encode;
use super::*; use super::*;
use crate::test_utils::TestRandom; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use rand::{prng::XorShiftRng, SeedableRng};
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {

View File

@ -55,8 +55,7 @@ impl<T: RngCore> TestRandom<T> for DepositInput {
mod tests { mod tests {
use super::super::ssz::ssz_encode; use super::super::ssz::ssz_encode;
use super::*; use super::*;
use crate::test_utils::TestRandom; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use rand::{prng::XorShiftRng, SeedableRng};
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {

View File

@ -49,8 +49,7 @@ impl<T: RngCore> TestRandom<T> for Exit {
mod tests { mod tests {
use super::super::ssz::ssz_encode; use super::super::ssz::ssz_encode;
use super::*; use super::*;
use crate::test_utils::TestRandom; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use rand::{prng::XorShiftRng, SeedableRng};
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {

View File

@ -48,8 +48,7 @@ impl<T: RngCore> TestRandom<T> for ForkData {
mod tests { mod tests {
use super::super::ssz::ssz_encode; use super::super::ssz::ssz_encode;
use super::*; use super::*;
use crate::test_utils::TestRandom; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use rand::{prng::XorShiftRng, SeedableRng};
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {

View File

@ -54,8 +54,7 @@ impl<T: RngCore> TestRandom<T> for PendingAttestationRecord {
mod tests { mod tests {
use super::super::ssz::ssz_encode; use super::super::ssz::ssz_encode;
use super::*; use super::*;
use crate::test_utils::TestRandom; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use rand::{prng::XorShiftRng, SeedableRng};
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {

View File

@ -49,8 +49,7 @@ impl<T: RngCore> TestRandom<T> for ProposalSignedData {
mod tests { mod tests {
use super::super::ssz::ssz_encode; use super::super::ssz::ssz_encode;
use super::*; use super::*;
use crate::test_utils::TestRandom; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use rand::{prng::XorShiftRng, SeedableRng};
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {

View File

@ -60,8 +60,7 @@ impl<T: RngCore> TestRandom<T> for ProposerSlashing {
mod tests { mod tests {
use super::super::ssz::ssz_encode; use super::super::ssz::ssz_encode;
use super::*; use super::*;
use crate::test_utils::TestRandom; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use rand::{prng::XorShiftRng, SeedableRng};
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {

View File

@ -5,7 +5,7 @@ pub trait BeaconBlockReader {
fn parent_root(&self) -> Hash256; fn parent_root(&self) -> Hash256;
fn state_root(&self) -> Hash256; fn state_root(&self) -> Hash256;
fn canonical_root(&self) -> Hash256; fn canonical_root(&self) -> Hash256;
fn to_beacon_block(self) -> BeaconBlock; fn into_beacon_block(self) -> Option<BeaconBlock>;
} }
impl BeaconBlockReader for BeaconBlock { impl BeaconBlockReader for BeaconBlock {
@ -25,7 +25,7 @@ impl BeaconBlockReader for BeaconBlock {
self.canonical_root() self.canonical_root()
} }
fn to_beacon_block(self) -> BeaconBlock { fn into_beacon_block(self) -> Option<BeaconBlock> {
self Some(self)
} }
} }

View File

@ -3,7 +3,7 @@ use crate::{BeaconState, Hash256};
pub trait BeaconStateReader { pub trait BeaconStateReader {
fn slot(&self) -> u64; fn slot(&self) -> u64;
fn canonical_root(&self) -> Hash256; fn canonical_root(&self) -> Hash256;
fn to_beacon_state(self) -> BeaconState; fn into_beacon_state(self) -> Option<BeaconState>;
} }
impl BeaconStateReader for BeaconState { impl BeaconStateReader for BeaconState {
@ -15,7 +15,7 @@ impl BeaconStateReader for BeaconState {
self.canonical_root() self.canonical_root()
} }
fn to_beacon_state(self) -> BeaconState { fn into_beacon_state(self) -> Option<BeaconState> {
self Some(self)
} }
} }

View File

@ -37,8 +37,7 @@ impl<T: RngCore> TestRandom<T> for ShardCommittee {
mod tests { mod tests {
use super::super::ssz::ssz_encode; use super::super::ssz::ssz_encode;
use super::*; use super::*;
use crate::test_utils::TestRandom; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use rand::{prng::XorShiftRng, SeedableRng};
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {

View File

@ -48,8 +48,7 @@ impl<T: RngCore> TestRandom<T> for ShardReassignmentRecord {
mod tests { mod tests {
use super::super::ssz::ssz_encode; use super::super::ssz::ssz_encode;
use super::*; use super::*;
use crate::test_utils::TestRandom; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use rand::{prng::XorShiftRng, SeedableRng};
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {

View File

@ -55,8 +55,7 @@ impl<T: RngCore> TestRandom<T> for SlashableVoteData {
mod tests { mod tests {
use super::super::ssz::ssz_encode; use super::super::ssz::ssz_encode;
use super::*; use super::*;
use crate::test_utils::TestRandom; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use rand::{prng::XorShiftRng, SeedableRng};
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {

View File

@ -150,8 +150,7 @@ impl<T: RngCore> TestRandom<T> for ValidatorRecord {
mod tests { mod tests {
use super::super::ssz::ssz_encode; use super::super::ssz::ssz_encode;
use super::*; use super::*;
use crate::test_utils::TestRandom; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use rand::{prng::XorShiftRng, SeedableRng};
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {