From 707f1163447b581bdcc2c73b2c4986e825c0eb6b Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Wed, 11 Jul 2018 18:17:04 +1000 Subject: [PATCH] Add keypair gen fn for testing --- src/state/validator_record.rs | 22 ++++++++-------------- src/utils/mod.rs | 1 + src/utils/test_helpers.rs | 13 +++++++++++++ 3 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 src/utils/test_helpers.rs diff --git a/src/state/validator_record.rs b/src/state/validator_record.rs index 17e883be4..ce9f9992f 100644 --- a/src/state/validator_record.rs +++ b/src/state/validator_record.rs @@ -17,8 +17,10 @@ impl ValidatorRecord { withdrawal_address: Address, randao_commitment: Sha256Digest, balance: u64, - switch_dynasty: u64) -> ValidatorRecord { - ValidatorRecord { + switch_dynasty: u64) + -> Self + { + Self { pubkey: pubkey, withdrawal_shard: withdrawal_shard, withdrawal_address: withdrawal_address, @@ -50,20 +52,12 @@ mod tests { extern crate rand; use super::*; - use super::super::utils::bls::Keypair; - use self::rand::{ SeedableRng, XorShiftRng }; - - fn get_keypair() -> Keypair { - let mut rng = XorShiftRng::from_seed([0xbc4f6d44, - 0xd62f276c, - 0xb963afd0, - 0x5455863d]); - Keypair::generate(&mut rng) - } + use super::super:: + utils::test_helpers::get_dangerous_test_keypair; #[test] fn test_new() { - let keypair = get_keypair();; + let keypair = get_dangerous_test_keypair();; let withdrawal_shard = 1; let withdrawal_address = Address::random(); let randao_commitment = Sha256Digest::random(); @@ -88,7 +82,7 @@ mod tests { #[test] fn test_serialization() { - let keypair = get_keypair(); + let keypair = get_dangerous_test_keypair(); let v = ValidatorRecord { pubkey: keypair.public, withdrawal_shard: 100, diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 59a7d823e..e2428fe36 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -7,3 +7,4 @@ use super::state::crystallized_state; pub mod types; pub mod bls; +pub mod test_helpers; diff --git a/src/utils/test_helpers.rs b/src/utils/test_helpers.rs new file mode 100644 index 000000000..8d4e6078f --- /dev/null +++ b/src/utils/test_helpers.rs @@ -0,0 +1,13 @@ +extern crate rand; + +use super::bls::Keypair; +use self::rand::{ SeedableRng, XorShiftRng }; + +// Returns a keypair for use in testing purposes. +pub fn get_dangerous_test_keypair() -> Keypair { + let mut rng = XorShiftRng::from_seed([0xbc4f6d44, + 0xd62f276c, + 0xb963afd0, + 0x5455863d]); + Keypair::generate(&mut rng) +}