提交 8531b006 编写于 作者: B Brian Johnson

Adding some tests for wallet

上级 56ffe903
...@@ -8,7 +8,7 @@ endif() ...@@ -8,7 +8,7 @@ endif()
file(GLOB UNIT_TESTS "tests/*.cpp") file(GLOB UNIT_TESTS "tests/*.cpp")
add_executable( chain_test ${UNIT_TESTS} ${COMMON_SOURCES} ) add_executable( chain_test ${UNIT_TESTS} ${COMMON_SOURCES} )
target_link_libraries( chain_test eos_native_contract eos_chain chainbase eos_utilities eos_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) target_link_libraries( chain_test eos_native_contract eos_chain chainbase eos_utilities eos_egenesis_none eos_wallet fc ${PLATFORM_SPECIFIC_LIBS} )
if(WASM_TOOLCHAIN) if(WASM_TOOLCHAIN)
file(GLOB SLOW_TESTS "slow_tests/*.cpp") file(GLOB SLOW_TESTS "slow_tests/*.cpp")
......
#include <eos/chain/BlockchainConfiguration.hpp> #include <eos/chain/BlockchainConfiguration.hpp>
#include <eos/chain/authority.hpp> #include <eos/chain/authority.hpp>
#include <eos/utilities/key_conversion.hpp>
#include <eos/utilities/rand.hpp> #include <eos/utilities/rand.hpp>
#include <eos/wallet/wallet.hpp>
#include <fc/io/json.hpp> #include <fc/io/json.hpp>
...@@ -130,6 +132,58 @@ BOOST_AUTO_TEST_CASE(authority_checker) ...@@ -130,6 +132,58 @@ BOOST_AUTO_TEST_CASE(authority_checker)
BOOST_CHECK(!MakeAuthorityChecker(GetCAuthority, {b}).satisfied(A)); BOOST_CHECK(!MakeAuthorityChecker(GetCAuthority, {b}).satisfied(A));
} FC_LOG_AND_RETHROW() } } FC_LOG_AND_RETHROW() }
/// Test creating the wallet
BOOST_AUTO_TEST_CASE(wallet_test)
{ try {
using namespace eos::wallet;
using namespace eos::utilities;
wallet_data d;
d.ws_server = "test_server";
d.ws_port = 99;
d.ws_user = "bob";
d.ws_password = "user_pwd";
wallet_api wallet(d);
BOOST_CHECK(wallet.is_locked());
wallet.set_password("pass");
BOOST_CHECK(wallet.is_locked());
wallet.unlock("pass");
BOOST_CHECK(!wallet.is_locked());
BOOST_CHECK_EQUAL(0, wallet.list_keys().size());
auto priv = fc::ecc::private_key::generate();
auto pub = public_key_type( priv.get_public_key() );
auto wif = key_to_wif(priv.get_secret());
wallet.import_key(wif);
BOOST_CHECK_EQUAL(1, wallet.list_keys().size());
auto privCopy = wallet.get_private_key(pub);
BOOST_CHECK_EQUAL(wif, privCopy);
wallet.lock();
BOOST_CHECK(wallet.is_locked());
wallet.unlock("pass");
BOOST_CHECK_EQUAL(1, wallet.list_keys().size());
wallet.save_wallet_file("wallet_test.json");
wallet_data d2;
wallet_api wallet2(d2);
BOOST_CHECK(wallet2.is_locked());
wallet2.load_wallet_file("wallet_test.json");
BOOST_CHECK(wallet2.is_locked());
wallet2.unlock("pass");
BOOST_CHECK_EQUAL(1, wallet2.list_keys().size());
auto privCopy2 = wallet2.get_private_key(pub);
BOOST_CHECK_EQUAL(wif, privCopy2);
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
} // namespace eos } // namespace eos
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册