diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 618833781d1cb4001d8dfc3a69c8a62d3db44297..4c77715b669049108d37e68414323477648200ea 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,7 +8,7 @@ endif() file(GLOB UNIT_TESTS "tests/*.cpp") 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) file(GLOB SLOW_TESTS "slow_tests/*.cpp") diff --git a/tests/tests/misc_tests.cpp b/tests/tests/misc_tests.cpp index 0220ab36a51463e5751c6db2e6b849bde4fd6e4d..5d9ec70a0c9d205197fa2c2aa42da1c5942a57f4 100644 --- a/tests/tests/misc_tests.cpp +++ b/tests/tests/misc_tests.cpp @@ -1,7 +1,9 @@ #include #include +#include #include +#include #include @@ -130,6 +132,58 @@ BOOST_AUTO_TEST_CASE(authority_checker) BOOST_CHECK(!MakeAuthorityChecker(GetCAuthority, {b}).satisfied(A)); } 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() } // namespace eos