aboutsummaryrefslogtreecommitdiff
path: root/tests/unit_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit_tests')
-rw-r--r--tests/unit_tests/CMakeLists.txt1
-rw-r--r--tests/unit_tests/crypto.cpp28
-rw-r--r--tests/unit_tests/epee_levin_protocol_handler_async.cpp8
-rw-r--r--tests/unit_tests/hardfork.cpp4
-rw-r--r--tests/unit_tests/main.cpp2
-rw-r--r--tests/unit_tests/sha256.cpp2
-rw-r--r--tests/unit_tests/subaddress.cpp118
7 files changed, 157 insertions, 6 deletions
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
index c7efcf074..e10648d20 100644
--- a/tests/unit_tests/CMakeLists.txt
+++ b/tests/unit_tests/CMakeLists.txt
@@ -55,6 +55,7 @@ set(unit_tests_sources
serialization.cpp
sha256.cpp
slow_memmem.cpp
+ subaddress.cpp
test_tx_utils.cpp
test_peerlist.cpp
test_protocol_pack.cpp
diff --git a/tests/unit_tests/crypto.cpp b/tests/unit_tests/crypto.cpp
index 3a8e787ec..51e26c2bb 100644
--- a/tests/unit_tests/crypto.cpp
+++ b/tests/unit_tests/crypto.cpp
@@ -47,6 +47,14 @@ namespace
"8b655970153799af2aeadc9ff1add0ea6c7251d54154cfa92c173a0dd39c1f94"
"6c7251d54154cfa92c173a0dd39c1f948b655970153799af2aeadc9ff1add0ea";
+ static std::uint8_t md[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00
+ };
+
template<typename T>
bool is_formatted()
{
@@ -61,6 +69,26 @@ namespace
out << "BEGIN" << value << "END";
return out.str() == "BEGIN<" + std::string{expected, sizeof(T) * 2} + ">END";
}
+
+ bool keccak_harness()
+ {
+ size_t inlen = sizeof(source);
+ int mdlen = (int)sizeof(md);
+ int ret = keccak(source, inlen, md, mdlen);
+
+ if (md[0] != 0x00)
+ {
+ return true;
+ }
+ else if (!ret)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
}
TEST(Crypto, Ostream)
diff --git a/tests/unit_tests/epee_levin_protocol_handler_async.cpp b/tests/unit_tests/epee_levin_protocol_handler_async.cpp
index d2aa31555..c749c2531 100644
--- a/tests/unit_tests/epee_levin_protocol_handler_async.cpp
+++ b/tests/unit_tests/epee_levin_protocol_handler_async.cpp
@@ -187,9 +187,11 @@ namespace
typedef std::unique_ptr<test_connection> test_connection_ptr;
- async_protocol_handler_test()
+ async_protocol_handler_test():
+ m_pcommands_handler(new test_levin_commands_handler()),
+ m_commands_handler(*m_pcommands_handler)
{
- m_handler_config.m_pcommands_handler = &m_commands_handler;
+ m_handler_config.set_handler(m_pcommands_handler, [](epee::levin::levin_commands_handler<test_levin_connection_context> *handler) { delete handler; });
m_handler_config.m_invoke_timeout = invoke_timeout;
m_handler_config.m_max_packet_size = max_packet_size;
}
@@ -212,7 +214,7 @@ namespace
protected:
boost::asio::io_service m_io_service;
test_levin_protocol_handler_config m_handler_config;
- test_levin_commands_handler m_commands_handler;
+ test_levin_commands_handler *m_pcommands_handler, &m_commands_handler;
};
class positive_test_connection_to_levin_protocol_handler_calls : public async_protocol_handler_test
diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp
index 2b0904224..c235f49fd 100644
--- a/tests/unit_tests/hardfork.cpp
+++ b/tests/unit_tests/hardfork.cpp
@@ -115,13 +115,13 @@ public:
virtual void add_txpool_tx(const transaction &tx, const txpool_tx_meta_t& details) {}
virtual void update_txpool_tx(const crypto::hash &txid, const txpool_tx_meta_t& details) {}
- virtual uint64_t get_txpool_tx_count() const { return 0; }
+ virtual uint64_t get_txpool_tx_count(bool include_unrelayed_txes = true) const { return 0; }
virtual bool txpool_has_tx(const crypto::hash &txid) const { return false; }
virtual void remove_txpool_tx(const crypto::hash& txid) {}
virtual txpool_tx_meta_t get_txpool_tx_meta(const crypto::hash& txid) const { return txpool_tx_meta_t(); }
virtual bool get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const { return false; }
virtual cryptonote::blobdata get_txpool_tx_blob(const crypto::hash& txid) const { return ""; }
- virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false) const { return false; }
+ virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false, bool include_unrelayed_txes = false) const { return false; }
virtual void add_block( const block& blk
, const size_t& block_size
diff --git a/tests/unit_tests/main.cpp b/tests/unit_tests/main.cpp
index 797d45a30..76f2b2749 100644
--- a/tests/unit_tests/main.cpp
+++ b/tests/unit_tests/main.cpp
@@ -35,6 +35,7 @@
#include "include_base_utils.h"
#include "common/command_line.h"
+#include "common/util.h"
#include "unit_tests_utils.h"
namespace po = boost::program_options;
@@ -43,6 +44,7 @@ boost::filesystem::path unit_test::data_dir;
int main(int argc, char** argv)
{
+ tools::on_startup();
epee::string_tools::set_module_name_and_folder(argv[0]);
mlog_configure(mlog_get_default_log_path("unit_tests.log"), true);
epee::debug::get_set_enable_assert(true, false);
diff --git a/tests/unit_tests/sha256.cpp b/tests/unit_tests/sha256.cpp
index f4ad39466..0d657a1a9 100644
--- a/tests/unit_tests/sha256.cpp
+++ b/tests/unit_tests/sha256.cpp
@@ -28,8 +28,8 @@
#include "gtest/gtest.h"
-#include "string_tools.h"
#include "common/util.h"
+#include "string_tools.h"
static bool check(const std::string &data, const char *expected_hash_hex)
{
diff --git a/tests/unit_tests/subaddress.cpp b/tests/unit_tests/subaddress.cpp
new file mode 100644
index 000000000..c304b7347
--- /dev/null
+++ b/tests/unit_tests/subaddress.cpp
@@ -0,0 +1,118 @@
+// Copyright (c) 2014-2017, 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 <boost/filesystem.hpp>
+#include "gtest/gtest.h"
+
+#include "include_base_utils.h"
+#include "wallet/wallet2.h"
+#include "crypto/crypto.h"
+#include "cryptonote_basic/account.h"
+#include "cryptonote_basic/cryptonote_basic_impl.h"
+#include "wallet/api/subaddress.h"
+
+class WalletSubaddress : public ::testing::Test
+{
+ protected:
+ virtual void SetUp()
+ {
+ try
+ {
+ w1.generate(wallet_name, password, recovery_key, true, false);
+ }
+ catch (const std::exception& e)
+ {
+ LOG_ERROR("failed to generate wallet: " << e.what());
+ throw e;
+ }
+
+ w1.add_subaddress_account(test_label);
+ w1.set_subaddress_label(subaddress_index, test_label);
+ }
+
+ virtual void TearDown()
+ {
+ boost::filesystem::wpath wallet_file(wallet_name);
+ boost::filesystem::wpath wallet_address_file(wallet_name + ".address.txt");
+ boost::filesystem::wpath wallet_keys_file(wallet_name + ".keys");
+
+ if ( boost::filesystem::exists(wallet_file) )
+ boost::filesystem::remove(wallet_file);
+
+ if ( boost::filesystem::exists(wallet_address_file) )
+ boost::filesystem::remove(wallet_address_file);
+
+ if ( boost::filesystem::exists(wallet_keys_file) )
+ boost::filesystem::remove(wallet_keys_file);
+ }
+
+ tools::wallet2 w1;
+ std::string path_working_dir = ".";
+ std::string path_test_wallet = "test_wallet";
+ const std::string wallet_name = path_working_dir + "/" + path_test_wallet;
+ const std::string password = "testpass";
+ crypto::secret_key recovery_key = crypto::secret_key();
+ const std::string test_label = "subaddress test label";
+
+ uint32_t major_index = 0;
+ uint32_t minor_index = 0;
+ const cryptonote::subaddress_index subaddress_index = {major_index, minor_index};
+};
+
+TEST_F(WalletSubaddress, GetSubaddressLabel)
+{
+ EXPECT_EQ(test_label, w1.get_subaddress_label(subaddress_index));
+}
+
+TEST_F(WalletSubaddress, AddSubaddress)
+{
+ std::string label = "test adding subaddress";
+ w1.add_subaddress(0, label);
+ EXPECT_EQ(label, w1.get_subaddress_label({0, 1}));
+}
+
+TEST_F(WalletSubaddress, OutOfBoundsIndexes)
+{
+ try
+ {
+ w1.get_subaddress_label({1,0});
+ }
+ catch(const std::exception& e)
+ {
+ EXPECT_STREQ("index_major is out of bound", e.what());
+ }
+ try
+ {
+ w1.get_subaddress_label({0,2});
+ }
+ catch(const std::exception& e)
+ {
+ EXPECT_STREQ("index.minor is out of bound", e.what());
+ }
+}