Merge pull request #682 from ethcore/additional_sstore_test

additional (failing) SecretStore test
This commit is contained in:
Arkadiy Paronyan 2016-03-11 22:45:43 +01:00
commit 1031ce641d

View File

@ -220,12 +220,12 @@ impl SecretStore {
/// Creates new account /// Creates new account
pub fn new_account(&mut self, pass: &str) -> Result<Address, ::std::io::Error> { pub fn new_account(&mut self, pass: &str) -> Result<Address, ::std::io::Error> {
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(); 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 mut key_file = self.directory.get(&key_id).expect("the key was just inserted");
let address = Address::random();
key_file.account = Some(address); key_file.account = Some(address);
try!(self.directory.save(key_file)); try!(self.directory.save(key_file));
Ok(address) Ok(address)
@ -387,6 +387,7 @@ mod tests {
use super::*; use super::*;
use devtools::*; use devtools::*;
use common::*; use common::*;
use crypto::KeyPair;
#[test] #[test]
fn can_insert() { fn can_insert() {
@ -561,4 +562,15 @@ mod tests {
let accounts = sstore.accounts().unwrap(); let accounts = sstore.accounts().unwrap();
assert_eq!(30, accounts.len()); 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);
}
} }