Re-apply removal of duplicated ssz_tests
Also, re-apply: "use cfg(test) for test macros"
This commit is contained in:
parent
243ef2db80
commit
6101036c8e
@ -20,29 +20,6 @@ pub struct Attestation {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(Attestation);
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = Attestation::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = Attestation::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -38,29 +38,6 @@ impl Eq for AttestationData {}
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(AttestationData);
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = AttestationData::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = AttestationData::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -25,31 +25,6 @@ impl<T: RngCore> TestRandom<T> for AttestationDataAndCustodyBit {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(AttestationDataAndCustodyBit);
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
|
|
||||||
let original = AttestationDataAndCustodyBit::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = AttestationDataAndCustodyBit::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,29 +16,6 @@ pub struct AttesterSlashing {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(AttesterSlashing);
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = AttesterSlashing::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = AttesterSlashing::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -70,29 +70,6 @@ impl BeaconBlock {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(BeaconBlock);
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = BeaconBlock::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = BeaconBlock::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -21,29 +21,6 @@ pub struct BeaconBlockBody {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(BeaconBlockBody);
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = BeaconBlockBody::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = BeaconBlockBody::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ use super::*;
|
|||||||
use crate::test_utils::TestingBeaconStateBuilder;
|
use crate::test_utils::TestingBeaconStateBuilder;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
||||||
use crate::{BeaconState, ChainSpec};
|
use crate::{BeaconState, ChainSpec};
|
||||||
use ssz::{ssz_encode, Decodable};
|
|
||||||
|
|
||||||
/// Tests that `get_attestation_participants` is consistent with the result of
|
/// Tests that `get_attestation_participants` is consistent with the result of
|
||||||
/// get_crosslink_committees_at_slot` with a full bitfield.
|
/// get_crosslink_committees_at_slot` with a full bitfield.
|
||||||
@ -51,25 +50,4 @@ pub fn get_attestation_participants_consistency() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(BeaconState);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = BeaconState::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
|
@ -19,29 +19,6 @@ pub struct Crosslink {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(Crosslink);
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = Crosslink::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = Crosslink::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -18,29 +18,6 @@ pub struct Deposit {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(Deposit);
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = Deposit::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = Deposit::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -18,29 +18,6 @@ pub struct DepositData {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(DepositData);
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = DepositData::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = DepositData::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -66,29 +66,6 @@ impl DepositInput {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(DepositInput);
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = DepositInput::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = DepositInput::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,29 +17,6 @@ pub struct Eth1Data {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(Eth1Data);
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = Eth1Data::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = Eth1Data::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,29 +17,6 @@ pub struct Eth1DataVote {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(Eth1DataVote);
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = Eth1DataVote::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = Eth1DataVote::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -29,29 +29,6 @@ impl Fork {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(Fork);
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = Fork::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = Fork::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#[macro_use]
|
||||||
pub mod test_utils;
|
pub mod test_utils;
|
||||||
|
|
||||||
pub mod attestation;
|
pub mod attestation;
|
||||||
|
@ -19,29 +19,6 @@ pub struct PendingAttestation {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(PendingAttestation);
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = PendingAttestation::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = PendingAttestation::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -23,30 +23,7 @@ pub struct Proposal {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
||||||
use ssz::{ssz_encode, Decodable, SignedRoot, TreeHash};
|
use ssz::{SignedRoot, TreeHash};
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = Proposal::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = Proposal::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(TreeHash)]
|
#[derive(TreeHash)]
|
||||||
struct SignedProposal {
|
struct SignedProposal {
|
||||||
@ -75,4 +52,5 @@ mod tests {
|
|||||||
assert_eq!(original.signed_root(), other.hash_tree_root());
|
assert_eq!(original.signed_root(), other.hash_tree_root());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssz_tests!(Proposal);
|
||||||
}
|
}
|
||||||
|
@ -18,29 +18,6 @@ pub struct ProposerSlashing {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(ProposerSlashing);
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = ProposerSlashing::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = ProposerSlashing::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -14,29 +14,6 @@ pub struct ShardReassignmentRecord {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(ShardReassignmentRecord);
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = ShardReassignmentRecord::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = ShardReassignmentRecord::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,6 @@ mod tests {
|
|||||||
use crate::chain_spec::ChainSpec;
|
use crate::chain_spec::ChainSpec;
|
||||||
use crate::slot_epoch::{Epoch, Slot};
|
use crate::slot_epoch::{Epoch, Slot};
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_is_double_vote_true() {
|
pub fn test_is_double_vote_true() {
|
||||||
@ -120,28 +119,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(SlashableAttestation);
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = SlashableAttestation::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = SlashableAttestation::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
|
|
||||||
fn create_slashable_attestation(
|
fn create_slashable_attestation(
|
||||||
slot_factor: u64,
|
slot_factor: u64,
|
||||||
|
@ -103,8 +103,6 @@ impl<'a> Iterator for SlotIter<'a> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod slot_tests {
|
mod slot_tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::ssz_encode;
|
|
||||||
|
|
||||||
all_tests!(Slot);
|
all_tests!(Slot);
|
||||||
}
|
}
|
||||||
@ -112,8 +110,6 @@ mod slot_tests {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod epoch_tests {
|
mod epoch_tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::ssz_encode;
|
|
||||||
|
|
||||||
all_tests!(Epoch);
|
all_tests!(Epoch);
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ macro_rules! impl_common {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// test macros
|
// test macros
|
||||||
#[allow(unused_macros)]
|
#[cfg(test)]
|
||||||
macro_rules! new_tests {
|
macro_rules! new_tests {
|
||||||
($type: ident) => {
|
($type: ident) => {
|
||||||
#[test]
|
#[test]
|
||||||
@ -260,7 +260,7 @@ macro_rules! new_tests {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_macros)]
|
#[cfg(test)]
|
||||||
macro_rules! from_into_tests {
|
macro_rules! from_into_tests {
|
||||||
($type: ident, $other: ident) => {
|
($type: ident, $other: ident) => {
|
||||||
#[test]
|
#[test]
|
||||||
@ -286,7 +286,7 @@ macro_rules! from_into_tests {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_macros)]
|
#[cfg(test)]
|
||||||
macro_rules! math_between_tests {
|
macro_rules! math_between_tests {
|
||||||
($type: ident, $other: ident) => {
|
($type: ident, $other: ident) => {
|
||||||
#[test]
|
#[test]
|
||||||
@ -434,7 +434,7 @@ macro_rules! math_between_tests {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_macros)]
|
#[cfg(test)]
|
||||||
macro_rules! math_tests {
|
macro_rules! math_tests {
|
||||||
($type: ident) => {
|
($type: ident) => {
|
||||||
#[test]
|
#[test]
|
||||||
@ -528,35 +528,7 @@ macro_rules! math_tests {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_macros)]
|
#[cfg(test)]
|
||||||
macro_rules! ssz_tests {
|
|
||||||
($type: ident) => {
|
|
||||||
#[test]
|
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = $type::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = $type::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = $type::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unused_macros)]
|
|
||||||
macro_rules! all_tests {
|
macro_rules! all_tests {
|
||||||
($type: ident) => {
|
($type: ident) => {
|
||||||
new_tests!($type);
|
new_tests!($type);
|
||||||
|
@ -33,11 +33,8 @@ impl SlotHeight {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
||||||
mod slot_height_tests {
|
mod slot_height_tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::ssz_encode;
|
|
||||||
|
|
||||||
all_tests!(SlotHeight);
|
all_tests!(SlotHeight);
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,57 @@ mod testing_voluntary_exit_builder;
|
|||||||
pub use generate_deterministic_keypairs::generate_deterministic_keypairs;
|
pub use generate_deterministic_keypairs::generate_deterministic_keypairs;
|
||||||
pub use keypairs_file::KeypairsFile;
|
pub use keypairs_file::KeypairsFile;
|
||||||
pub use rand::{prng::XorShiftRng, SeedableRng};
|
pub use rand::{prng::XorShiftRng, SeedableRng};
|
||||||
pub use test_random::TestRandom;
|
|
||||||
pub use testing_attestation_builder::TestingAttestationBuilder;
|
pub mod address;
|
||||||
pub use testing_attester_slashing_builder::TestingAttesterSlashingBuilder;
|
pub mod aggregate_signature;
|
||||||
pub use testing_beacon_block_builder::TestingBeaconBlockBuilder;
|
pub mod bitfield;
|
||||||
pub use testing_beacon_state_builder::{keypairs_path, TestingBeaconStateBuilder};
|
pub mod hash256;
|
||||||
pub use testing_deposit_builder::TestingDepositBuilder;
|
#[macro_use]
|
||||||
pub use testing_proposer_slashing_builder::TestingProposerSlashingBuilder;
|
mod macros;
|
||||||
pub use testing_transfer_builder::TestingTransferBuilder;
|
pub mod public_key;
|
||||||
pub use testing_voluntary_exit_builder::TestingVoluntaryExitBuilder;
|
pub mod secret_key;
|
||||||
|
pub mod signature;
|
||||||
|
|
||||||
|
pub trait TestRandom<T>
|
||||||
|
where
|
||||||
|
T: RngCore,
|
||||||
|
{
|
||||||
|
fn random_for_test(rng: &mut T) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: RngCore> TestRandom<T> for bool {
|
||||||
|
fn random_for_test(rng: &mut T) -> Self {
|
||||||
|
(rng.next_u32() % 2) == 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: RngCore> TestRandom<T> for u64 {
|
||||||
|
fn random_for_test(rng: &mut T) -> Self {
|
||||||
|
rng.next_u64()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: RngCore> TestRandom<T> for u32 {
|
||||||
|
fn random_for_test(rng: &mut T) -> Self {
|
||||||
|
rng.next_u32()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: RngCore> TestRandom<T> for usize {
|
||||||
|
fn random_for_test(rng: &mut T) -> Self {
|
||||||
|
rng.next_u32() as usize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: RngCore, U> TestRandom<T> for Vec<U>
|
||||||
|
where
|
||||||
|
U: TestRandom<T>,
|
||||||
|
{
|
||||||
|
fn random_for_test(rng: &mut T) -> Self {
|
||||||
|
vec![
|
||||||
|
<U>::random_for_test(rng),
|
||||||
|
<U>::random_for_test(rng),
|
||||||
|
<U>::random_for_test(rng),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -24,29 +24,6 @@ pub struct Transfer {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(Transfer);
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = Transfer::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = Transfer::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -54,18 +54,6 @@ impl Default for Validator {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = Validator::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_validator_can_be_active() {
|
fn test_validator_can_be_active() {
|
||||||
@ -90,15 +78,5 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(Validator);
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = Validator::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,29 +19,6 @@ pub struct VoluntaryExit {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
|
||||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
|
||||||
|
|
||||||
#[test]
|
ssz_tests!(VoluntaryExit);
|
||||||
pub fn test_ssz_round_trip() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = VoluntaryExit::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(original, decoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_hash_tree_root() {
|
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
|
||||||
let original = VoluntaryExit::random_for_test(&mut rng);
|
|
||||||
|
|
||||||
let result = original.hash_tree_root();
|
|
||||||
|
|
||||||
assert_eq!(result.len(), 32);
|
|
||||||
// TODO: Add further tests
|
|
||||||
// https://github.com/sigp/lighthouse/issues/170
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user