aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/core_proxy/core_proxy.h1
-rw-r--r--tests/core_tests/chaingen.h2
-rw-r--r--tests/core_tests/transaction_tests.cpp3
-rw-r--r--tests/net_load_tests/net_load_tests.h2
-rw-r--r--tests/unit_tests/CMakeLists.txt1
-rw-r--r--tests/unit_tests/ban.cpp1
-rw-r--r--tests/unit_tests/crypto.cpp5
-rw-r--r--tests/unit_tests/epee_levin_protocol_handler_async.cpp2
-rw-r--r--tests/unit_tests/epee_utils.cpp29
-rw-r--r--tests/unit_tests/logging.cpp177
-rw-r--r--tests/unit_tests/mnemonics.cpp1
-rw-r--r--tests/unit_tests/mul_div.cpp2
-rw-r--r--tests/unit_tests/multisig.cpp2
-rw-r--r--tests/unit_tests/notify.cpp2
-rw-r--r--tests/unit_tests/ringct.cpp2
-rw-r--r--tests/unit_tests/slow_memmem.cpp8
-rw-r--r--tests/unit_tests/subaddress.cpp2
-rw-r--r--tests/unit_tests/testdb.h2
18 files changed, 224 insertions, 20 deletions
diff --git a/tests/core_proxy/core_proxy.h b/tests/core_proxy/core_proxy.h
index 7d36a0f68..023c220ae 100644
--- a/tests/core_proxy/core_proxy.h
+++ b/tests/core_proxy/core_proxy.h
@@ -104,5 +104,6 @@ namespace tests
cryptonote::difficulty_type get_block_cumulative_difficulty(uint64_t height) const { return 0; }
bool fluffy_blocks_enabled() const { return false; }
uint64_t prevalidate_block_hashes(uint64_t height, const std::vector<crypto::hash> &hashes) { return 0; }
+ bool pad_transactions() const { return false; }
};
}
diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h
index 6b9277a30..b380aca01 100644
--- a/tests/core_tests/chaingen.h
+++ b/tests/core_tests/chaingen.h
@@ -511,7 +511,7 @@ inline bool do_replay_events(std::vector<test_event_entry>& events)
// FIXME: make sure that vm has arg_testnet_on set to true or false if
// this test needs for it to be so.
get_test_options<t_test_class> gto;
- if (!c.init(vm, NULL, &gto.test_options))
+ if (!c.init(vm, &gto.test_options))
{
MERROR("Failed to init core");
return false;
diff --git a/tests/core_tests/transaction_tests.cpp b/tests/core_tests/transaction_tests.cpp
index 3c6954bc6..810dec6fc 100644
--- a/tests/core_tests/transaction_tests.cpp
+++ b/tests/core_tests/transaction_tests.cpp
@@ -54,9 +54,6 @@ bool test_transaction_generation_and_ring_signature()
account_base miner_acc6;
miner_acc6.generate();
- std::string add_str = miner_acc3.get_public_address_str(MAINNET);
-
-
account_base rv_acc;
rv_acc.generate();
account_base rv_acc2;
diff --git a/tests/net_load_tests/net_load_tests.h b/tests/net_load_tests/net_load_tests.h
index 7f3c6dfe9..7e92c21b9 100644
--- a/tests/net_load_tests/net_load_tests.h
+++ b/tests/net_load_tests/net_load_tests.h
@@ -137,7 +137,6 @@ namespace net_load_tests
public:
open_close_test_helper(test_tcp_server& tcp_server, size_t open_request_target, size_t max_opened_connection_count)
: m_tcp_server(tcp_server)
- , m_open_request_target(open_request_target)
, m_max_opened_connection_count(max_opened_connection_count)
, m_opened_connection_count(0)
, m_next_opened_conn_idx(0)
@@ -203,7 +202,6 @@ namespace net_load_tests
private:
test_tcp_server& m_tcp_server;
- size_t m_open_request_target;
size_t m_max_opened_connection_count;
std::atomic<size_t> m_opened_connection_count;
std::atomic<size_t> m_next_opened_conn_idx;
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
index a46f11b5f..f7012746d 100644
--- a/tests/unit_tests/CMakeLists.txt
+++ b/tests/unit_tests/CMakeLists.txt
@@ -54,6 +54,7 @@ set(unit_tests_sources
hashchain.cpp
http.cpp
keccak.cpp
+ logging.cpp
main.cpp
memwipe.cpp
mlocker.cpp
diff --git a/tests/unit_tests/ban.cpp b/tests/unit_tests/ban.cpp
index e3dbdaef1..12625a949 100644
--- a/tests/unit_tests/ban.cpp
+++ b/tests/unit_tests/ban.cpp
@@ -83,6 +83,7 @@ public:
cryptonote::difficulty_type get_block_cumulative_difficulty(uint64_t height) const { return 0; }
bool fluffy_blocks_enabled() const { return false; }
uint64_t prevalidate_block_hashes(uint64_t height, const std::vector<crypto::hash> &hashes) { return 0; }
+ bool pad_transactions() { return false; }
void stop() {}
};
diff --git a/tests/unit_tests/crypto.cpp b/tests/unit_tests/crypto.cpp
index 29fa88f9d..e09ec7f7a 100644
--- a/tests/unit_tests/crypto.cpp
+++ b/tests/unit_tests/crypto.cpp
@@ -47,6 +47,9 @@ namespace
"8b655970153799af2aeadc9ff1add0ea6c7251d54154cfa92c173a0dd39c1f94"
"6c7251d54154cfa92c173a0dd39c1f948b655970153799af2aeadc9ff1add0ea";
+ template<typename T> void *addressof(T &t) { return &t; }
+ template<> void *addressof(crypto::secret_key &k) { return addressof(unwrap(unwrap(k))); }
+
template<typename T>
bool is_formatted()
{
@@ -55,7 +58,7 @@ namespace
static_assert(alignof(T) == 1, "T must have 1 byte alignment");
static_assert(sizeof(T) <= sizeof(source), "T is too large for source");
static_assert(sizeof(T) * 2 <= sizeof(expected), "T is too large for destination");
- std::memcpy(std::addressof(value), source, sizeof(T));
+ std::memcpy(addressof(value), source, sizeof(T));
std::stringstream out;
out << "BEGIN" << value << "END";
diff --git a/tests/unit_tests/epee_levin_protocol_handler_async.cpp b/tests/unit_tests/epee_levin_protocol_handler_async.cpp
index 72d8f3205..10e62c167 100644
--- a/tests/unit_tests/epee_levin_protocol_handler_async.cpp
+++ b/tests/unit_tests/epee_levin_protocol_handler_async.cpp
@@ -294,7 +294,7 @@ TEST_F(positive_test_connection_to_levin_protocol_handler_calls, handler_initial
TEST_F(positive_test_connection_to_levin_protocol_handler_calls, concurent_handler_initialization_and_destruction_is_correct)
{
const size_t connection_count = 10000;
- auto create_and_destroy_connections = [this, connection_count]()
+ auto create_and_destroy_connections = [this]()
{
std::vector<test_connection_ptr> connections(connection_count);
for (size_t i = 0; i < connection_count; ++i)
diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp
index c2b0b7647..c384ce9a5 100644
--- a/tests/unit_tests/epee_utils.cpp
+++ b/tests/unit_tests/epee_utils.cpp
@@ -456,6 +456,35 @@ TEST(StringTools, PodToHex)
);
}
+TEST(StringTools, ParseHex)
+{
+ static const char data[] = "a10b68c2";
+ for (size_t i = 0; i < sizeof(data); i += 2)
+ {
+ std::string res;
+ ASSERT_TRUE(epee::string_tools::parse_hexstr_to_binbuff(std::string(data, i), res));
+ std::string hex = epee::string_tools::buff_to_hex_nodelimer(res);
+ ASSERT_EQ(hex.size(), i);
+ ASSERT_EQ(memcmp(data, hex.data(), i), 0);
+ }
+}
+
+TEST(StringTools, ParseNotHex)
+{
+ std::string res;
+ for (size_t i = 0; i < 256; ++i)
+ {
+ std::string inputHexString = std::string(2, static_cast<char>(i));
+ if ((i >= '0' && i <= '9') || (i >= 'A' && i <= 'F') || (i >= 'a' && i <= 'f')) {
+ ASSERT_TRUE(epee::string_tools::parse_hexstr_to_binbuff(inputHexString, res));
+ } else {
+ ASSERT_FALSE(epee::string_tools::parse_hexstr_to_binbuff(inputHexString, res));
+ }
+ }
+
+ ASSERT_FALSE(epee::string_tools::parse_hexstr_to_binbuff(std::string("a"), res));
+}
+
TEST(StringTools, GetIpString)
{
EXPECT_EQ(
diff --git a/tests/unit_tests/logging.cpp b/tests/unit_tests/logging.cpp
new file mode 100644
index 000000000..476e92bef
--- /dev/null
+++ b/tests/unit_tests/logging.cpp
@@ -0,0 +1,177 @@
+// Copyright (c) 2016-2018, 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 "file_io_utils.h"
+#include "misc_log_ex.h"
+
+static std::string log_filename;
+
+static void init()
+{
+ boost::filesystem::path p = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
+ log_filename = p.string();
+ mlog_configure(log_filename, false, 0);
+}
+
+static void cleanup()
+{
+ boost::filesystem::remove(log_filename);
+}
+
+static size_t nlines(const std::string &str)
+{
+ size_t n = 0;
+ for (const char *ptr = str.c_str(); *ptr; ++ptr)
+ if (*ptr == '\n')
+ ++n;
+ return n;
+}
+
+static bool load_log_to_string(const std::string &filename, std::string &str)
+{
+ if (!epee::file_io_utils::load_file_to_string(filename, str))
+ return false;
+ for (const char *ptr = str.c_str(); *ptr; ++ptr)
+ {
+ if (*ptr == '\n')
+ {
+ std::string prefix = std::string(str.c_str(), ptr - str.c_str());
+ if (prefix.find("New log categories:") != std::string::npos)
+ {
+ str = std::string(ptr + 1, strlen(ptr + 1));
+ break;
+ }
+ }
+ }
+ return true;
+}
+
+static void log()
+{
+ MFATAL("fatal");
+ MERROR("error");
+ MWARNING("warning");
+ MINFO("info");
+ MDEBUG("debug");
+ MTRACE("trace");
+
+ MCINFO("a.b.c.d", "a.b.c.d");
+ MCINFO("a.b.c.e", "a.b.c.e");
+ MCINFO("global", "global");
+ MCINFO("x.y.z", "x.y.z");
+ MCINFO("y.y.z", "y.y.z");
+ MCINFO("x.y.x", "x.y.x");
+}
+
+TEST(logging, no_logs)
+{
+ init();
+ mlog_set_categories("");
+ log();
+ std::string str;
+ ASSERT_TRUE(load_log_to_string(log_filename, str));
+ ASSERT_TRUE(str == "");
+ cleanup();
+}
+
+TEST(logging, default)
+{
+ init();
+ log();
+ std::string str;
+ ASSERT_TRUE(load_log_to_string(log_filename, str));
+ ASSERT_TRUE(str.find("global") != std::string::npos);
+ ASSERT_TRUE(str.find("fatal") != std::string::npos);
+ ASSERT_TRUE(str.find("error") != std::string::npos);
+ ASSERT_TRUE(str.find("debug") == std::string::npos);
+ ASSERT_TRUE(str.find("trace") == std::string::npos);
+ cleanup();
+}
+
+TEST(logging, all)
+{
+ init();
+ mlog_set_categories("*:TRACE");
+ log();
+ std::string str;
+ ASSERT_TRUE(load_log_to_string(log_filename, str));
+ ASSERT_TRUE(str.find("global") != std::string::npos);
+ ASSERT_TRUE(str.find("fatal") != std::string::npos);
+ ASSERT_TRUE(str.find("error") != std::string::npos);
+ ASSERT_TRUE(str.find("debug") != std::string::npos);
+ ASSERT_TRUE(str.find("trace") != std::string::npos);
+ cleanup();
+}
+
+TEST(logging, glob_suffix)
+{
+ init();
+ mlog_set_categories("x.y*:TRACE");
+ log();
+ std::string str;
+ ASSERT_TRUE(load_log_to_string(log_filename, str));
+ ASSERT_TRUE(str.find("global") == std::string::npos);
+ ASSERT_TRUE(str.find("x.y.z") != std::string::npos);
+ ASSERT_TRUE(str.find("x.y.x") != std::string::npos);
+ ASSERT_TRUE(str.find("y.y.z") == std::string::npos);
+ cleanup();
+}
+
+TEST(logging, glob_prefix)
+{
+ init();
+ mlog_set_categories("*y.z:TRACE");
+ log();
+ std::string str;
+ ASSERT_TRUE(load_log_to_string(log_filename, str));
+ ASSERT_TRUE(str.find("global") == std::string::npos);
+ ASSERT_TRUE(str.find("x.y.z") != std::string::npos);
+ ASSERT_TRUE(str.find("x.y.x") == std::string::npos);
+ ASSERT_TRUE(str.find("y.y.z") != std::string::npos);
+ cleanup();
+}
+
+TEST(logging, last_precedence)
+{
+ init();
+ mlog_set_categories("gobal:FATAL,glo*:DEBUG");
+ log();
+ std::string str;
+ ASSERT_TRUE(load_log_to_string(log_filename, str));
+ ASSERT_TRUE(nlines(str) == 1);
+ ASSERT_TRUE(str.find("global") != std::string::npos);
+ ASSERT_TRUE(str.find("x.y.z") == std::string::npos);
+ ASSERT_TRUE(str.find("x.y.x") == std::string::npos);
+ ASSERT_TRUE(str.find("y.y.z") == std::string::npos);
+ cleanup();
+}
+
diff --git a/tests/unit_tests/mnemonics.cpp b/tests/unit_tests/mnemonics.cpp
index 0b74a6b94..4dc2d931e 100644
--- a/tests/unit_tests/mnemonics.cpp
+++ b/tests/unit_tests/mnemonics.cpp
@@ -75,7 +75,6 @@ namespace
*/
void test_language(const Language::Base &language)
{
- const std::vector<std::string> &word_list = language.get_word_list();
epee::wipeable_string w_seed = "", w_return_seed = "";
std::string seed, return_seed;
// Generate a random seed without checksum
diff --git a/tests/unit_tests/mul_div.cpp b/tests/unit_tests/mul_div.cpp
index 8408d0da1..768b95d4b 100644
--- a/tests/unit_tests/mul_div.cpp
+++ b/tests/unit_tests/mul_div.cpp
@@ -30,7 +30,7 @@
#include "gtest/gtest.h"
-#include "common/int-util.h"
+#include "int-util.h"
namespace
{
diff --git a/tests/unit_tests/multisig.cpp b/tests/unit_tests/multisig.cpp
index 7268f2690..eb3196863 100644
--- a/tests/unit_tests/multisig.cpp
+++ b/tests/unit_tests/multisig.cpp
@@ -112,7 +112,7 @@ static void make_wallets(std::vector<tools::wallet2>& wallets, unsigned int M)
}
for (auto& wallet: wallets) {
- ASSERT_FALSE(wallet.multisig() || wallet.multisig() || wallet.multisig());
+ ASSERT_FALSE(wallet.multisig());
}
std::vector<std::string> mxis;
diff --git a/tests/unit_tests/notify.cpp b/tests/unit_tests/notify.cpp
index edc4eabdf..105d21ca8 100644
--- a/tests/unit_tests/notify.cpp
+++ b/tests/unit_tests/notify.cpp
@@ -49,7 +49,7 @@ TEST(notify, works)
tmp = "/tmp";
static const char *filename = "monero-notify-unit-test-XXXXXX";
const size_t len = strlen(tmp) + 1 + strlen(filename);
- std::unique_ptr<char[]> name_template_((char*)malloc(len + 1));
+ std::unique_ptr<char[]> name_template_(new char[len + 1]);
char *name_template = name_template_.get();
ASSERT_TRUE(name_template != NULL);
snprintf(name_template, len + 1, "%s/%s", tmp, filename);
diff --git a/tests/unit_tests/ringct.cpp b/tests/unit_tests/ringct.cpp
index 52bdb00cf..ccef5f3e7 100644
--- a/tests/unit_tests/ringct.cpp
+++ b/tests/unit_tests/ringct.cpp
@@ -968,8 +968,6 @@ static rctSig make_sig()
#define TEST_rctSig_elements(name, op) \
TEST(ringct, rctSig_##name) \
{ \
- const uint64_t inputs[] = {1000, 1000}; \
- const uint64_t outputs[] = {1000, 1000}; \
rct::rctSig sig = make_sig(); \
ASSERT_TRUE(rct::verRct(sig)); \
op; \
diff --git a/tests/unit_tests/slow_memmem.cpp b/tests/unit_tests/slow_memmem.cpp
index 1c67f5b58..436259bee 100644
--- a/tests/unit_tests/slow_memmem.cpp
+++ b/tests/unit_tests/slow_memmem.cpp
@@ -45,7 +45,7 @@
//#define VERBOSE
#ifdef TEST_ORIGINAL
-uint64_t slow_memmem_original(void* start_buff, size_t buflen,void* pat,size_t patlen)
+size_t slow_memmem_original(void* start_buff, size_t buflen,void* pat,size_t patlen)
{
void* buf = start_buff;
void* end=(char*)buf+buflen-patlen;
@@ -63,7 +63,7 @@ uint64_t slow_memmem_original(void* start_buff, size_t buflen,void* pat,size_t p
#define slow_memmem slow_memmem_original
#else
namespace cryptonote {
- uint64_t slow_memmem(const void* start_buff, size_t buflen,const void* pat,size_t patlen);
+ size_t slow_memmem(const void* start_buff, size_t buflen,const void* pat,size_t patlen);
}
using namespace cryptonote;
#endif
@@ -73,7 +73,7 @@ static const struct {
const char *buf;
size_t patlen;
const char *pat;
- uint64_t res;
+ size_t res;
} T[]={
{0,"",0,"",0},
{1,"",0,"",0},
@@ -117,7 +117,7 @@ TEST(slowmem,Success)
memcpy(buf,T[n].buf,T[n].buflen);
void *pat=malloc(T[n].patlen);
memcpy(pat,T[n].pat,T[n].patlen);
- uint64_t res=slow_memmem(buf,T[n].buflen,pat,T[n].patlen);
+ size_t res=slow_memmem(buf,T[n].buflen,pat,T[n].patlen);
free(pat);
free(buf);
ASSERT_EQ(res,T[n].res);
diff --git a/tests/unit_tests/subaddress.cpp b/tests/unit_tests/subaddress.cpp
index 8ff4c5f0d..67802d736 100644
--- a/tests/unit_tests/subaddress.cpp
+++ b/tests/unit_tests/subaddress.cpp
@@ -49,7 +49,7 @@ class WalletSubaddress : public ::testing::Test
catch (const std::exception& e)
{
LOG_ERROR("failed to generate wallet: " << e.what());
- throw e;
+ throw;
}
w1.add_subaddress_account(test_label);
diff --git a/tests/unit_tests/testdb.h b/tests/unit_tests/testdb.h
index b6962cc41..a9c772920 100644
--- a/tests/unit_tests/testdb.h
+++ b/tests/unit_tests/testdb.h
@@ -93,7 +93,7 @@ public:
virtual cryptonote::tx_out_index get_output_tx_and_index_from_global(const uint64_t& index) const { return cryptonote::tx_out_index(); }
virtual cryptonote::tx_out_index get_output_tx_and_index(const uint64_t& amount, const uint64_t& index) const { return cryptonote::tx_out_index(); }
virtual void get_output_tx_and_index(const uint64_t& amount, const std::vector<uint64_t> &offsets, std::vector<cryptonote::tx_out_index> &indices) const {}
- virtual void get_output_key(const uint64_t &amount, const std::vector<uint64_t> &offsets, std::vector<cryptonote::output_data_t> &outputs, bool allow_partial = false) {}
+ virtual void get_output_key(const epee::span<const uint64_t> &amounts, const std::vector<uint64_t> &offsets, std::vector<cryptonote::output_data_t> &outputs, bool allow_partial = false) {}
virtual bool can_thread_bulk_indices() const { return false; }
virtual std::vector<uint64_t> get_tx_output_indices(const crypto::hash& h) const { return std::vector<uint64_t>(); }
virtual std::vector<uint64_t> get_tx_amount_output_indices(const uint64_t tx_index) const { return std::vector<uint64_t>(); }