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

Fixing phrases generated on windows #3614

Merged
merged 1 commit into from
Nov 25, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.");
}
}