CJentzsch
9 years ago
1 changed files with 77 additions and 0 deletions
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
/** @file keymanager.cpp
|
||||
|
* @author Christoph Jentzsch <cj@ethdev.com> |
||||
|
* @date 2015 |
||||
|
* Keymanager test functions. |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
#include <boost/test/unit_test.hpp> |
||||
|
#include <test/TestHelper.h> |
||||
|
#include <libdevcore/TransientDirectory.h> |
||||
|
#include <libethcore/KeyManager.h> |
||||
|
|
||||
|
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() |
Loading…
Reference in new issue