Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Fixing phrases generated on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Drwięga committed Nov 25, 2016
1 parent 86522c8 commit a56df30
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions ethstore/src/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,27 @@ impl Random for [u8; 32] {
pub fn random_phrase(words: usize) -> String {
lazy_static! {
static ref WORDS: Vec<String> = String::from_utf8_lossy(include_bytes!("../res/wordlist.txt"))
.split("\n")
.lines()
.map(|s| s.to_owned())
.collect();
}
let mut rng = OsRng::new().unwrap();
(0..words).map(|_| rng.choose(&WORDS).unwrap()).join(" ")
}

#[test]
fn should_produce_right_number_of_words() {
let p = random_phrase(10);
assert_eq!(p.split(" ").count(), 10);
}
#[cfg(test)]
mod tests {
use super::random_phrase;

#[test]
fn should_produce_right_number_of_words() {
let p = random_phrase(10);
assert_eq!(p.split(" ").count(), 10);
}

#[test]
fn should_not_include_carriage_return() {
let p = random_phrase(10);
assert!(!p.contains('\r'), "Carriage return should be trimmed.");
}
}

0 comments on commit a56df30

Please sign in to comment.