diff --git a/libethcore/KeyManager.cpp b/libethcore/KeyManager.cpp index 602c60b4a..26cf451d0 100644 --- a/libethcore/KeyManager.cpp +++ b/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 diff --git a/test/libethcore/keymanager.cpp b/test/libethcore/keymanager.cpp index 44ee9ae51..808f060fc 100644 --- a/test/libethcore/keymanager.cpp +++ b/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()