From 90e20cbcad54787eaf239bef016756a884b03f62 Mon Sep 17 00:00:00 2001 From: debris Date: Fri, 11 Mar 2016 20:08:01 +0100 Subject: [PATCH 1/2] additional (failing) sstore test --- util/src/keys/store.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/util/src/keys/store.rs b/util/src/keys/store.rs index ea97cc80e..cbef7b5f9 100644 --- a/util/src/keys/store.rs +++ b/util/src/keys/store.rs @@ -381,6 +381,7 @@ mod tests { use super::*; use devtools::*; use common::*; + use crypto::KeyPair; #[test] fn can_insert() { @@ -555,4 +556,15 @@ mod tests { let accounts = sstore.accounts().unwrap(); assert_eq!(30, accounts.len()); } + + #[test] + fn validate_generated_addresses() { + let temp = RandomTempPath::create_dir(); + let mut sstore = SecretStore::new_test(&temp); + let addr = sstore.new_account("test").unwrap(); + let _ok = sstore.unlock_account(&addr, "test").unwrap(); + let secret = sstore.account_secret(&addr).unwrap(); + let kp = KeyPair::from_secret(secret).unwrap(); + assert_eq!(Address::from(kp.public().sha3()), addr); + } } From b1327a045fa39e5e9552797a5f137de383206517 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Fri, 11 Mar 2016 22:47:12 +0400 Subject: [PATCH 2/2] fixed new account generation --- util/src/keys/store.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/src/keys/store.rs b/util/src/keys/store.rs index cbef7b5f9..cd5fa8427 100644 --- a/util/src/keys/store.rs +++ b/util/src/keys/store.rs @@ -214,12 +214,12 @@ impl SecretStore { /// Creates new account pub fn new_account(&mut self, pass: &str) -> Result { - let secret = H256::random(); + let key_pair = crypto::KeyPair::create().expect("Error creating key-pair. Something wrong with crypto libraries?"); + let address = Address::from(key_pair.public().sha3()); let key_id = H128::random(); - self.insert(key_id.clone(), secret, pass); + self.insert(key_id.clone(), key_pair.secret().clone(), pass); let mut key_file = self.directory.get(&key_id).expect("the key was just inserted"); - let address = Address::random(); key_file.account = Some(address); try!(self.directory.save(key_file)); Ok(address)