Tidy up SSZ testing on types crate
This commit is contained in:
parent
8aa9f83c48
commit
ad91648f30
@ -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() {
|
||||||
|
@ -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() {
|
||||||
|
@ -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() {
|
||||||
|
@ -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() {
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -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() {
|
||||||
|
@ -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() {
|
||||||
|
@ -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() {
|
||||||
|
@ -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() {
|
||||||
|
@ -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() {
|
||||||
|
@ -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() {
|
||||||
|
@ -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() {
|
||||||
|
@ -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() {
|
||||||
|
@ -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() {
|
||||||
|
@ -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() {
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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() {
|
||||||
|
@ -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() {
|
||||||
|
@ -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() {
|
||||||
|
@ -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() {
|
||||||
|
Loading…
Reference in New Issue
Block a user