Browse Source

Merge pull request #2462 from arkpar/key-delete

Save keys after deletion
cl-refactor
Gav Wood 10 years ago
parent
commit
00e08549c9
  1. 1
      libethcore/KeyManager.cpp
  2. 30
      test/libethcore/keymanager.cpp

1
libethcore/KeyManager.cpp

@ -213,6 +213,7 @@ void KeyManager::kill(Address const& _a)
m_addrLookup.erase(_a);
m_keyInfo.erase(id);
m_store.kill(id);
write(m_keysFile);
}
Addresses KeyManager::accounts() const

30
test/libethcore/keymanager.cpp

@ -107,11 +107,10 @@ BOOST_AUTO_TEST_CASE(KeyManagerHints)
BOOST_AUTO_TEST_CASE(KeyManagerAccounts)
{
KeyManager km;
string password = "hardPassword";
TransientDirectory tmpDir;
km.setKeysFile(tmpDir.path()+ "keysFile.json");
KeyManager km(tmpDir.path()+ "keysFile.json", tmpDir.path());
BOOST_CHECK_NO_THROW(km.create(password));
BOOST_CHECK(km.accounts().empty());
@ -121,4 +120,31 @@ BOOST_AUTO_TEST_CASE(KeyManagerAccounts)
km.kill(a);
}
BOOST_AUTO_TEST_CASE(KeyManagerKill)
{
string password = "hardPassword";
TransientDirectory tmpDir;
KeyPair kp = KeyPair::create();
{
KeyManager km(tmpDir.path() + "keysFile.json", tmpDir.path());
BOOST_CHECK_NO_THROW(km.create(password));
BOOST_CHECK(km.accounts().empty());
BOOST_CHECK(km.load(password));
BOOST_CHECK(km.import(kp.secret(), "test"));
}
{
KeyManager km(tmpDir.path() + "keysFile.json", tmpDir.path());
BOOST_CHECK(km.load(password));
Addresses addresses = km.accounts();
BOOST_CHECK(addresses.size() == 1 && addresses[0] == kp.address());
km.kill(addresses[0]);
}
{
KeyManager km(tmpDir.path() + "keysFile.json", tmpDir.path());
BOOST_CHECK(km.load(password));
BOOST_CHECK(km.accounts().empty());
}
}
BOOST_AUTO_TEST_SUITE_END()

Loading…
Cancel
Save