From 05c02db1c7257135c7a799ea0236ccc10796bfab Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 23 Jun 2015 10:37:03 +0200 Subject: [PATCH] add keymanager tests --- test/libethcore/keymanager.cpp | 77 ++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 test/libethcore/keymanager.cpp diff --git a/test/libethcore/keymanager.cpp b/test/libethcore/keymanager.cpp new file mode 100644 index 000000000..0588059f9 --- /dev/null +++ b/test/libethcore/keymanager.cpp @@ -0,0 +1,77 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file keymanager.cpp + * @author Christoph Jentzsch + * @date 2015 + * Keymanager test functions. + */ + + +#include +#include +#include +#include + +using namespace std; +using namespace dev; +using namespace dev::eth; + +BOOST_AUTO_TEST_SUITE(KeyManagerTests) + +BOOST_AUTO_TEST_CASE(KeyInfoDefaultConstructor) +{ + KeyInfo kiDefault; + BOOST_CHECK_EQUAL(kiDefault.accountName, ""); + BOOST_CHECK(kiDefault.passHash == h256()); +} + +BOOST_AUTO_TEST_CASE(KeyInfoConstructor) +{ + h256 passHash("0x2a"); + string accountName = "myAccount"; + KeyInfo ki(passHash, accountName); + BOOST_CHECK_EQUAL(ki.accountName, "myAccount"); + BOOST_CHECK(ki.passHash == h256("0x2a")); +} + +BOOST_AUTO_TEST_CASE(KeyManagerConstructor) +{ + KeyManager km; + BOOST_CHECK_EQUAL(km.keysFile(), km.defaultPath()); + BOOST_CHECK_EQUAL(km.defaultPath(), getDataDir("ethereum") + "/keys.info"); + BOOST_CHECK(km.store().keys() == SecretStore().keys()); +} + +BOOST_AUTO_TEST_CASE(KeyManagerKeysFile) +{ + KeyManager km; + string password = "hardPassword"; + + // set to valid path + TransientDirectory tmpDir; + km.setKeysFile(tmpDir.path()); + BOOST_CHECK(!km.exists()); + BOOST_CHECK_THROW(km.create(password), FileError); + km.setKeysFile(tmpDir.path() + "/notExistingDir/keysFile.json"); + BOOST_CHECK_THROW(km.create(password), FileError); + BOOST_CHECK(!km.exists()); + km.setKeysFile(tmpDir.path() + "keysFile.json"); + BOOST_CHECK_NO_THROW(km.create(password)); +} + + +BOOST_AUTO_TEST_SUITE_END()