diff --git a/src/bank.rs b/src/bank.rs index 8fee843eb6602a..3a7c7540e8f5c3 100644 --- a/src/bank.rs +++ b/src/bank.rs @@ -24,9 +24,9 @@ pub const MAX_ENTRY_IDS: usize = 1024 * 4; #[derive(Debug, PartialEq, Eq)] pub enum BankError { - AccountNotFound, - InsufficientFunds, - InvalidTransferSignature, + AccountNotFound(PublicKey), + InsufficientFunds(PublicKey), + InvalidTransferSignature(Signature), } pub type Result = result::Result; @@ -167,11 +167,11 @@ impl Bank { let option = bals.get(&tr.from); if option.is_none() { - return Err(BankError::AccountNotFound); + return Err(BankError::AccountNotFound(tr.from)); } if !self.reserve_signature_with_last_id(&tr.sig, &tr.last_id) { - return Err(BankError::InvalidTransferSignature); + return Err(BankError::InvalidTransferSignature(tr.sig)); } loop { @@ -180,7 +180,7 @@ impl Bank { if current < tr.contract.tokens { self.forget_signature_with_last_id(&tr.sig, &tr.last_id); - return Err(BankError::InsufficientFunds); + return Err(BankError::InsufficientFunds(tr.from)); } let result = bal.compare_exchange( @@ -427,9 +427,10 @@ mod tests { fn test_account_not_found() { let mint = Mint::new(1); let bank = Bank::new(&mint); + let keypair = KeyPair::new(); assert_eq!( - bank.transfer(1, &KeyPair::new(), mint.pubkey(), mint.last_id()), - Err(BankError::AccountNotFound) + bank.transfer(1, &keypair, mint.pubkey(), mint.last_id()), + Err(BankError::AccountNotFound(keypair.pubkey())) ); assert_eq!(bank.transaction_count(), 0); } @@ -444,7 +445,7 @@ mod tests { assert_eq!(bank.transaction_count(), 1); assert_eq!( bank.transfer(10_001, &mint.keypair(), pubkey, mint.last_id()), - Err(BankError::InsufficientFunds) + Err(BankError::InsufficientFunds(mint.pubkey())) ); assert_eq!(bank.transaction_count(), 1); diff --git a/src/crdt.rs b/src/crdt.rs index eef6981f4720dd..1393fb5a53828e 100644 --- a/src/crdt.rs +++ b/src/crdt.rs @@ -502,7 +502,7 @@ impl Crdt { } #[cfg(test)] -mod test { +mod tests { use crdt::{Crdt, ReplicatedData}; use logger; use packet::Blob; diff --git a/src/signature.rs b/src/signature.rs index 0bb704f8000b17..1521f815f4af6b 100644 --- a/src/signature.rs +++ b/src/signature.rs @@ -72,27 +72,23 @@ impl GenKeys { pub fn gen_n_seeds(&self, n_seeds: i64) -> Vec<[u8; 16]> { let mut rng = self.generator.borrow_mut(); - let seeds = (0..n_seeds) + (0..n_seeds) .into_iter() - .map(|_| { - let seed: [u8; 16] = rng.gen(); - seed - }) - .collect(); - seeds + .map(|_| rng.gen::<[u8; 16]>()) + .collect() } pub fn gen_n_keys(&self, n_keys: i64, tokens_per_user: i64) -> Vec<(Vec, i64)> { - let keys = self.gen_n_seeds(n_keys); + let seeds = self.gen_n_seeds(n_keys); - let users: Vec<_> = keys.into_par_iter() + seeds + .into_par_iter() .map(|seed| { let new: GenKeys = GenKeys::new(&seed[..]); let pkcs8 = KeyPair::generate_pkcs8(&new).unwrap().to_vec(); (pkcs8, tokens_per_user) }) - .collect(); - users + .collect() } } @@ -104,22 +100,12 @@ impl SecureRandom for GenKeys { } } -#[cfg(all(feature = "unstable", test))] +#[cfg(test)] mod tests { - extern crate test; - - use self::test::Bencher; use super::*; use std::collections::HashSet; use std::iter::FromIterator; - #[bench] - fn bench_gen_keys(b: &mut Bencher) { - let seed: &[_] = &[1, 2, 3, 4]; - let rnd = GenKeys::new(seed); - b.iter(|| rnd.gen_n_keys(1000, 1)); - } - #[test] fn test_new_key_is_redundant() { let seed: &[_] = &[1, 2, 3, 4]; @@ -145,3 +131,20 @@ mod tests { assert_eq!(users1_set, users2_set); } } + +#[cfg(all(feature = "unstable", test))] +mod bench { + extern crate test; + + use self::test::Bencher; + use super::*; + use std::collections::HashSet; + use std::iter::FromIterator; + + #[bench] + fn bench_gen_keys(b: &mut Bencher) { + let seed: &[_] = &[1, 2, 3, 4]; + let rnd = GenKeys::new(seed); + b.iter(|| rnd.gen_n_keys(1000, 1)); + } +}