aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/core_tests/chaingen.h2
-rw-r--r--tests/crypto/CMakeLists.txt3
-rw-r--r--tests/libwallet_api_tests/CMakeLists.txt59
-rw-r--r--tests/libwallet_api_tests/main.cpp212
-rw-r--r--tests/unit_tests/CMakeLists.txt4
-rw-r--r--tests/unit_tests/hardfork.cpp1
-rw-r--r--tests/unit_tests/unbound.cpp49
8 files changed, 328 insertions, 3 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 990be9143..d1be97afc 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -63,6 +63,7 @@ add_subdirectory(unit_tests)
add_subdirectory(difficulty)
add_subdirectory(hash)
add_subdirectory(net_load_tests)
+add_subdirectory(libwallet_api_tests)
# add_subdirectory(daemon_tests)
diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h
index d0d912cbb..44170d116 100644
--- a/tests/core_tests/chaingen.h
+++ b/tests/core_tests/chaingen.h
@@ -472,7 +472,7 @@ inline bool replay_events_through_core(cryptonote::core& cr, const std::vector<t
//--------------------------------------------------------------------------
template<class t_test_class>
struct get_test_options {
- const std::pair<uint8_t, uint64_t> hard_forks[1] = {std::make_pair(1, 0)};
+ const std::pair<uint8_t, uint64_t> hard_forks[1] = {std::make_pair((uint8_t)1, (uint64_t)0)};
const cryptonote::test_options test_options = {
hard_forks
};
diff --git a/tests/crypto/CMakeLists.txt b/tests/crypto/CMakeLists.txt
index f42428a65..86946aa5c 100644
--- a/tests/crypto/CMakeLists.txt
+++ b/tests/crypto/CMakeLists.txt
@@ -40,7 +40,8 @@ set(crypto_headers
add_executable(crypto-tests
${crypto_sources}
${crypto_headers})
-target_link_libraries(crypto-tests)
+target_link_libraries(crypto-tests
+ ${Boost_SYSTEM_LIBRARY})
set_property(TARGET crypto-tests
PROPERTY
FOLDER "tests")
diff --git a/tests/libwallet_api_tests/CMakeLists.txt b/tests/libwallet_api_tests/CMakeLists.txt
new file mode 100644
index 000000000..e60947084
--- /dev/null
+++ b/tests/libwallet_api_tests/CMakeLists.txt
@@ -0,0 +1,59 @@
+# Copyright (c) 2014-2016, The Monero Project
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification, are
+# permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this list of
+# conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice, this list
+# of conditions and the following disclaimer in the documentation and/or other
+# materials provided with the distribution.
+#
+# 3. Neither the name of the copyright holder nor the names of its contributors may be
+# used to endorse or promote products derived from this software without specific
+# prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+set(libwallet_api_tests_sources
+ main.cpp
+)
+
+set(libwallet_api_tests_headers
+ )
+
+add_executable(libwallet_api_tests
+ ${libwallet_api_tests_sources}
+ ${libwallet_api_tests_headers})
+
+target_link_libraries(libwallet_api_tests
+ LINK_PRIVATE
+ wallet
+ ${GTEST_MAIN_LIBRARIES}
+ ${EXTRA_LIBRARIES})
+
+set_property(TARGET libwallet_api_tests
+ PROPERTY
+ FOLDER "tests")
+
+if (NOT MSVC)
+ set_property(TARGET libwallet_api_tests
+ APPEND_STRING
+ PROPERTY
+ COMPILE_FLAGS " -Wno-undef -Wno-sign-compare")
+endif ()
+
+add_test(
+ NAME libwallet_api_tests
+ COMMAND libwallet_api_tests)
diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp
new file mode 100644
index 000000000..9701c300c
--- /dev/null
+++ b/tests/libwallet_api_tests/main.cpp
@@ -0,0 +1,212 @@
+// Copyright (c) 2014-2016, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+
+#include "gtest/gtest.h"
+#include "wallet/wallet2_api.h"
+#include <boost/filesystem.hpp>
+#include <boost/algorithm/string.hpp>
+
+#include <iostream>
+#include <vector>
+
+
+using namespace std;
+//unsigned int epee::g_test_dbg_lock_sleep = 0;
+
+
+
+struct WalletManagerTest : public testing::Test
+{
+ Bitmonero::WalletManager * wmgr;
+
+ const char * WALLET_NAME = "testwallet";
+ const char * WALLET_NAME_COPY = "testwallet_copy";
+ const char * WALLET_NAME_WITH_DIR = "walletdir/testwallet_test";
+ const char * WALLET_NAME_WITH_DIR_NON_WRITABLE = "/var/walletdir/testwallet_test";
+ const char * WALLET_PASS = "password";
+ const char * WALLET_PASS2 = "password22";
+ const char * WALLET_LANG = "English";
+
+ WalletManagerTest()
+ {
+ std::cout << __FUNCTION__ << std::endl;
+ wmgr = Bitmonero::WalletManagerFactory::getWalletManager();
+ deleteWallet(WALLET_NAME);
+ deleteDir(boost::filesystem::path(WALLET_NAME_WITH_DIR).parent_path().string());
+ }
+
+
+ ~WalletManagerTest()
+ {
+ std::cout << __FUNCTION__ << std::endl;
+ //deleteWallet(WALLET_NAME);
+ }
+
+
+ void deleteWallet(const std::string & walletname)
+ {
+ std::cout << "** deleting wallet: " << walletname << std::endl;
+ boost::filesystem::remove(walletname);
+ boost::filesystem::remove(walletname + ".address.txt");
+ boost::filesystem::remove(walletname + ".keys");
+ }
+
+ void deleteDir(const std::string &path)
+ {
+ std::cout << "** removing dir recursively: " << path << std::endl;
+ boost::filesystem::remove_all(path);
+ }
+
+};
+
+
+TEST_F(WalletManagerTest, WalletManagerCreatesWallet)
+{
+
+ Bitmonero::Wallet * wallet = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
+ ASSERT_TRUE(wallet->status() == Bitmonero::Wallet::Status_Ok);
+ ASSERT_TRUE(!wallet->seed().empty());
+ std::vector<std::string> words;
+ std::string seed = wallet->seed();
+ boost::split(words, seed, boost::is_any_of(" "), boost::token_compress_on);
+ ASSERT_TRUE(words.size() == 25);
+ std::cout << "** seed: " << wallet->seed() << std::endl;
+ ASSERT_FALSE(wallet->address().empty());
+ std::cout << "** address: " << wallet->address() << std::endl;
+ ASSERT_TRUE(wmgr->closeWallet(wallet));
+
+}
+
+TEST_F(WalletManagerTest, WalletManagerOpensWallet)
+{
+
+ Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
+ std::string seed1 = wallet1->seed();
+ ASSERT_TRUE(wmgr->closeWallet(wallet1));
+ Bitmonero::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
+ ASSERT_TRUE(wallet2->status() == Bitmonero::Wallet::Status_Ok);
+ ASSERT_TRUE(wallet2->seed() == seed1);
+ std::cout << "** seed: " << wallet2->seed() << std::endl;
+}
+
+
+TEST_F(WalletManagerTest, WalletManagerChangesPassword)
+{
+ Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
+ std::string seed1 = wallet1->seed();
+ ASSERT_TRUE(wallet1->setPassword(WALLET_PASS2));
+ ASSERT_TRUE(wmgr->closeWallet(wallet1));
+ Bitmonero::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME, WALLET_PASS2);
+ ASSERT_TRUE(wallet2->status() == Bitmonero::Wallet::Status_Ok);
+ ASSERT_TRUE(wallet2->seed() == seed1);
+ ASSERT_TRUE(wmgr->closeWallet(wallet2));
+ Bitmonero::Wallet * wallet3 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
+ ASSERT_FALSE(wallet3->status() == Bitmonero::Wallet::Status_Ok);
+}
+
+
+
+TEST_F(WalletManagerTest, WalletManagerRecoversWallet)
+{
+ Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
+ std::string seed1 = wallet1->seed();
+ std::string address1 = wallet1->address();
+ ASSERT_FALSE(address1.empty());
+ ASSERT_TRUE(wmgr->closeWallet(wallet1));
+ deleteWallet(WALLET_NAME);
+ Bitmonero::Wallet * wallet2 = wmgr->recoveryWallet(WALLET_NAME, seed1);
+ ASSERT_TRUE(wallet2->status() == Bitmonero::Wallet::Status_Ok);
+ ASSERT_TRUE(wallet2->seed() == seed1);
+ ASSERT_TRUE(wallet2->address() == address1);
+ ASSERT_TRUE(wmgr->closeWallet(wallet2));
+}
+
+
+TEST_F(WalletManagerTest, WalletManagerStoresWallet1)
+{
+ Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
+ std::string seed1 = wallet1->seed();
+ std::string address1 = wallet1->address();
+
+ ASSERT_TRUE(wallet1->store(""));
+ ASSERT_TRUE(wallet1->store(WALLET_NAME_COPY));
+ ASSERT_TRUE(wmgr->closeWallet(wallet1));
+ Bitmonero::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME_COPY, WALLET_PASS);
+ ASSERT_TRUE(wallet2->status() == Bitmonero::Wallet::Status_Ok);
+ ASSERT_TRUE(wallet2->seed() == seed1);
+ ASSERT_TRUE(wallet2->address() == address1);
+ ASSERT_TRUE(wmgr->closeWallet(wallet2));
+}
+
+TEST_F(WalletManagerTest, WalletManagerStoresWallet2)
+{
+ Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
+ std::string seed1 = wallet1->seed();
+ std::string address1 = wallet1->address();
+
+ ASSERT_TRUE(wallet1->store(WALLET_NAME_WITH_DIR));
+ ASSERT_TRUE(wmgr->closeWallet(wallet1));
+
+ wallet1 = wmgr->openWallet(WALLET_NAME_WITH_DIR, WALLET_PASS);
+ ASSERT_TRUE(wallet1->status() == Bitmonero::Wallet::Status_Ok);
+ ASSERT_TRUE(wallet1->seed() == seed1);
+ ASSERT_TRUE(wallet1->address() == address1);
+ ASSERT_TRUE(wmgr->closeWallet(wallet1));
+}
+
+TEST_F(WalletManagerTest, WalletManagerStoresWallet3)
+{
+ Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
+ std::string seed1 = wallet1->seed();
+ std::string address1 = wallet1->address();
+
+ ASSERT_FALSE(wallet1->store(WALLET_NAME_WITH_DIR_NON_WRITABLE));
+ ASSERT_TRUE(wmgr->closeWallet(wallet1));
+
+ wallet1 = wmgr->openWallet(WALLET_NAME_WITH_DIR_NON_WRITABLE, WALLET_PASS);
+ ASSERT_FALSE(wallet1->status() == Bitmonero::Wallet::Status_Ok);
+
+ ASSERT_FALSE(wmgr->closeWallet(wallet1));
+
+ wallet1 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
+ ASSERT_TRUE(wallet1->status() == Bitmonero::Wallet::Status_Ok);
+ ASSERT_TRUE(wallet1->seed() == seed1);
+ ASSERT_TRUE(wallet1->address() == address1);
+ ASSERT_TRUE(wmgr->closeWallet(wallet1));
+
+}
+
+
+int main(int argc, char** argv)
+{
+ //epee::debug::get_set_enable_assert(true, false);
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
index db20bbc2d..2e5100229 100644
--- a/tests/unit_tests/CMakeLists.txt
+++ b/tests/unit_tests/CMakeLists.txt
@@ -49,7 +49,8 @@ set(unit_tests_sources
test_format_utils.cpp
test_peerlist.cpp
test_protocol_pack.cpp
- hardfork.cpp)
+ hardfork.cpp
+ unbound.cpp)
set(unit_tests_headers
unit_tests_utils.h)
@@ -69,6 +70,7 @@ target_link_libraries(unit_tests
${Boost_REGEX_LIBRARY}
${Boost_SYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY}
+ ${UNBOUND_LIBRARIES}
${EXTRA_LIBRARIES})
set_property(TARGET unit_tests
PROPERTY
diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp
index 1faef2082..6d4a100df 100644
--- a/tests/unit_tests/hardfork.cpp
+++ b/tests/unit_tests/hardfork.cpp
@@ -109,6 +109,7 @@ public:
virtual bool for_all_transactions(std::function<bool(const crypto::hash&, const cryptonote::transaction&)>) const { return true; }
virtual bool for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)> f) const { return true; }
virtual bool is_read_only() const { return false; }
+ virtual std::map<uint64_t, uint64_t> get_output_histogram(const std::vector<uint64_t> &amounts) const { return std::map<uint64_t, uint64_t>(); }
virtual void add_block( const block& blk
, const size_t& block_size
diff --git a/tests/unit_tests/unbound.cpp b/tests/unit_tests/unbound.cpp
new file mode 100644
index 000000000..25026ec58
--- /dev/null
+++ b/tests/unit_tests/unbound.cpp
@@ -0,0 +1,49 @@
+// Copyright (c) 2016, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+
+#include "gtest/gtest.h"
+
+extern "C" int dnskey_algo_id_is_supported(int);
+
+TEST(unbound, supported_algorithms)
+{
+ // Monero causes these to be tried, but we don't have access
+ // to this internal unbound header here, so we use raw numbers
+ // LDNS_RSASHA1 = 5,
+ // LDNS_RSASHA1_NSEC3 = 7,
+ // LDNS_RSASHA256 = 8, /* RFC 5702 */
+ // LDNS_ECDSAP256SHA256 = 13, /* RFC 6605 */
+
+ ASSERT_TRUE(dnskey_algo_id_is_supported(5));
+ ASSERT_TRUE(dnskey_algo_id_is_supported(7));
+ ASSERT_TRUE(dnskey_algo_id_is_supported(8));
+ ASSERT_TRUE(dnskey_algo_id_is_supported(13));
+}
+