aboutsummaryrefslogtreecommitdiff
path: root/tests/unit_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit_tests')
-rw-r--r--tests/unit_tests/CMakeLists.txt2
-rw-r--r--tests/unit_tests/chacha.cpp (renamed from tests/unit_tests/chacha8.cpp)2
-rw-r--r--tests/unit_tests/crypto.cpp24
-rw-r--r--tests/unit_tests/hardfork.cpp2
-rw-r--r--tests/unit_tests/http.cpp22
-rw-r--r--tests/unit_tests/memwipe.cpp4
-rw-r--r--tests/unit_tests/serialization.cpp9
-rw-r--r--tests/unit_tests/slow_memmem.cpp4
-rw-r--r--tests/unit_tests/subaddress.cpp17
-rw-r--r--tests/unit_tests/varint.cpp1
-rw-r--r--tests/unit_tests/vercmp.cpp2
11 files changed, 27 insertions, 62 deletions
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
index cfacd5688..ba3acef0c 100644
--- a/tests/unit_tests/CMakeLists.txt
+++ b/tests/unit_tests/CMakeLists.txt
@@ -36,7 +36,7 @@ set(unit_tests_sources
block_reward.cpp
bulletproofs.cpp
canonical_amounts.cpp
- chacha8.cpp
+ chacha.cpp
checkpoints.cpp
command_line.cpp
crypto.cpp
diff --git a/tests/unit_tests/chacha8.cpp b/tests/unit_tests/chacha.cpp
index bf0699eba..eadebf9d8 100644
--- a/tests/unit_tests/chacha8.cpp
+++ b/tests/unit_tests/chacha.cpp
@@ -32,7 +32,7 @@
#include "gtest/gtest.h"
-#include "crypto/chacha8.h"
+#include "crypto/chacha.h"
namespace
{
diff --git a/tests/unit_tests/crypto.cpp b/tests/unit_tests/crypto.cpp
index d9a7b8ad5..3a8e787ec 100644
--- a/tests/unit_tests/crypto.cpp
+++ b/tests/unit_tests/crypto.cpp
@@ -47,14 +47,6 @@ 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()
{
@@ -69,22 +61,6 @@ 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);
- keccak(source, inlen, md, mdlen);
-
- if (md[0] != 0x00)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
}
TEST(Crypto, Ostream)
diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp
index c235f49fd..0a472a421 100644
--- a/tests/unit_tests/hardfork.cpp
+++ b/tests/unit_tests/hardfork.cpp
@@ -118,7 +118,7 @@ public:
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_meta(const crypto::hash& txid, txpool_tx_meta_t &meta) const { return false; }
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, bool include_unrelayed_txes = false) const { return false; }
diff --git a/tests/unit_tests/http.cpp b/tests/unit_tests/http.cpp
index 5e427f064..0e8f9f747 100644
--- a/tests/unit_tests/http.cpp
+++ b/tests/unit_tests/http.cpp
@@ -60,12 +60,18 @@
#include "md5_l.h"
#include "string_tools.h"
+#include "crypto/crypto.h"
namespace {
namespace http = epee::net_utils::http;
using fields = std::unordered_map<std::string, std::string>;
using auth_responses = std::vector<fields>;
+void rng(size_t len, uint8_t *ptr)
+{
+ crypto::rand(len, ptr);
+}
+
std::string quoted(std::string str)
{
str.insert(str.begin(), '"');
@@ -250,13 +256,13 @@ std::string get_nc(std::uint32_t count)
TEST(HTTP_Server_Auth, NotRequired)
{
- http::http_server_auth auth{};
+ http::http_server_auth auth{}; // no rng here
EXPECT_FALSE(auth.get_response(http::http_request_info{}));
}
TEST(HTTP_Server_Auth, MissingAuth)
{
- http::http_server_auth auth{{"foo", "bar"}};
+ http::http_server_auth auth{{"foo", "bar"}, rng};
EXPECT_TRUE(bool(auth.get_response(http::http_request_info{})));
{
http::http_request_info request{};
@@ -267,7 +273,7 @@ TEST(HTTP_Server_Auth, MissingAuth)
TEST(HTTP_Server_Auth, BadSyntax)
{
- http::http_server_auth auth{{"foo", "bar"}};
+ http::http_server_auth auth{{"foo", "bar"}, rng};
EXPECT_TRUE(bool(auth.get_response(make_request({{u8"algorithm", "fo\xFF"}}))));
EXPECT_TRUE(bool(auth.get_response(make_request({{u8"cnonce", "\"000\xFF\""}}))));
EXPECT_TRUE(bool(auth.get_response(make_request({{u8"cnonce \xFF =", "\"000\xFF\""}}))));
@@ -277,7 +283,7 @@ TEST(HTTP_Server_Auth, BadSyntax)
TEST(HTTP_Server_Auth, MD5)
{
http::login user{"foo", "bar"};
- http::http_server_auth auth{user};
+ http::http_server_auth auth{user, rng};
const auto response = auth.get_response(make_request(fields{}));
ASSERT_TRUE(bool(response));
@@ -326,7 +332,7 @@ TEST(HTTP_Server_Auth, MD5_sess)
constexpr const char cnonce[] = "not a good cnonce";
http::login user{"foo", "bar"};
- http::http_server_auth auth{user};
+ http::http_server_auth auth{user, rng};
const auto response = auth.get_response(make_request(fields{}));
ASSERT_TRUE(bool(response));
@@ -378,7 +384,7 @@ TEST(HTTP_Server_Auth, MD5_auth)
constexpr const char qop[] = "auth";
http::login user{"foo", "bar"};
- http::http_server_auth auth{user};
+ http::http_server_auth auth{user, rng};
const auto response = auth.get_response(make_request(fields{}));
ASSERT_TRUE(bool(response));
@@ -446,7 +452,7 @@ TEST(HTTP_Server_Auth, MD5_sess_auth)
constexpr const char qop[] = "auth";
http::login user{"foo", "bar"};
- http::http_server_auth auth{user};
+ http::http_server_auth auth{user, rng};
const auto response = auth.get_response(make_request(fields{}));
ASSERT_TRUE(bool(response));
@@ -523,7 +529,7 @@ TEST(HTTP_Auth, DogFood)
const http::login user{"some_user", "ultimate password"};
- http::http_server_auth server{user};
+ http::http_server_auth server{user, rng};
http::http_client_auth client{user};
http::http_request_info request{};
diff --git a/tests/unit_tests/memwipe.cpp b/tests/unit_tests/memwipe.cpp
index b2b19fbf5..59f50cef8 100644
--- a/tests/unit_tests/memwipe.cpp
+++ b/tests/unit_tests/memwipe.cpp
@@ -30,7 +30,7 @@
#include <stdint.h>
#include "misc_log_ex.h"
-#include "common/memwipe.h"
+#include "memwipe.h"
// Probably won't catch the optimized out case, but at least we test
// it works in the normal case
@@ -47,7 +47,7 @@ static void test(bool wipe)
if ((intptr_t)quux == foop)
{
MDEBUG(std::hex << std::setw(8) << std::setfill('0') << *(uint32_t*)quux);
- if (wipe) ASSERT_TRUE(!memcmp(quux, "\0\0\0", 3));
+ if (wipe) ASSERT_TRUE(memcmp(quux, "bar", 3));
}
else MWARNING("We did not get the same location, cannot check");
free(quux);
diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp
index 9e76efadf..8a75ac435 100644
--- a/tests/unit_tests/serialization.cpp
+++ b/tests/unit_tests/serialization.cpp
@@ -38,7 +38,6 @@
#include "cryptonote_basic/cryptonote_basic.h"
#include "cryptonote_basic/cryptonote_basic_impl.h"
#include "ringct/rctSigs.h"
-#include "serialization/serialization.h"
#include "serialization/binary_archive.h"
#include "serialization/json_archive.h"
#include "serialization/debug_archive.h"
@@ -802,12 +801,12 @@ TEST(Serialization, portability_outputs)
// decrypt (copied from wallet2::decrypt)
auto decrypt = [] (const std::string &ciphertext, const crypto::secret_key &skey, bool authenticated) -> string
{
- const size_t prefix_size = sizeof(chacha8_iv) + (authenticated ? sizeof(crypto::signature) : 0);
+ const size_t prefix_size = sizeof(chacha_iv) + (authenticated ? sizeof(crypto::signature) : 0);
if(ciphertext.size() < prefix_size)
return {};
- crypto::chacha8_key key;
- crypto::generate_chacha8_key(&skey, sizeof(skey), key);
- const crypto::chacha8_iv &iv = *(const crypto::chacha8_iv*)&ciphertext[0];
+ crypto::chacha_key key;
+ crypto::generate_chacha_key(&skey, sizeof(skey), key);
+ const crypto::chacha_iv &iv = *(const crypto::chacha_iv*)&ciphertext[0];
std::string plaintext;
plaintext.resize(ciphertext.size() - prefix_size);
if (authenticated)
diff --git a/tests/unit_tests/slow_memmem.cpp b/tests/unit_tests/slow_memmem.cpp
index 0312019be..6e1dcb85f 100644
--- a/tests/unit_tests/slow_memmem.cpp
+++ b/tests/unit_tests/slow_memmem.cpp
@@ -81,7 +81,6 @@ static const struct {
{1,"x",1,"x",0},
{2,"x",1,"",1},
{1,"x",1,"",0},
- {1,"x",2,"",0},
{1,"x",2,"x",0},
{2,"ax",2,"x",0},
{1,"xx",2,"xx",0},
@@ -103,7 +102,7 @@ static const struct {
{8,"xxxxxxab",3,"xyz",0},
{8,"xxxxxxab",6,"abcdef",0},
{9,"\0xxxxxab",3,"ab",6},
- {4,"\0\0a",3,"\0a",1},
+ {4,"\0\0a",3,"\0a",1}, //
};
TEST(slowmem,Success)
@@ -122,7 +121,6 @@ TEST(slowmem,Success)
free(pat);
free(buf);
ASSERT_EQ(res,T[n].res);
-ASSERT_EQ(1,1);
#ifdef VERBOSE
if (res!=T[n].res) printf("failed (got %zu, expected %zu)",res,T[n].res); else printf("ok");
printf("\n");
diff --git a/tests/unit_tests/subaddress.cpp b/tests/unit_tests/subaddress.cpp
index c304b7347..ca950b25d 100644
--- a/tests/unit_tests/subaddress.cpp
+++ b/tests/unit_tests/subaddress.cpp
@@ -44,7 +44,7 @@ class WalletSubaddress : public ::testing::Test
{
try
{
- w1.generate(wallet_name, password, recovery_key, true, false);
+ w1.generate("", password, recovery_key, true, false);
}
catch (const std::exception& e)
{
@@ -58,24 +58,9 @@ class WalletSubaddress : public ::testing::Test
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";
diff --git a/tests/unit_tests/varint.cpp b/tests/unit_tests/varint.cpp
index 2b31cdfdf..577ad4d26 100644
--- a/tests/unit_tests/varint.cpp
+++ b/tests/unit_tests/varint.cpp
@@ -36,7 +36,6 @@
#include <boost/foreach.hpp>
#include "cryptonote_basic/cryptonote_basic.h"
#include "cryptonote_basic/cryptonote_basic_impl.h"
-#include "serialization/serialization.h"
#include "serialization/binary_archive.h"
#include "serialization/json_archive.h"
#include "serialization/debug_archive.h"
diff --git a/tests/unit_tests/vercmp.cpp b/tests/unit_tests/vercmp.cpp
index d48dfdf7c..8f359585d 100644
--- a/tests/unit_tests/vercmp.cpp
+++ b/tests/unit_tests/vercmp.cpp
@@ -40,4 +40,6 @@ TEST(vercmp, two_one) { ASSERT_TRUE(tools::vercmp("2", "1") > 0); }
TEST(vercmp, ten_nine) { ASSERT_TRUE(tools::vercmp("10", "9") > 0); }
TEST(vercmp, one_dot_ten_one_dot_nine) { ASSERT_TRUE(tools::vercmp("1.10", "1.9") > 0); }
TEST(vercmp, one_one_dot_nine) { ASSERT_TRUE(tools::vercmp("1", "1.9") < 0); }
+TEST(vercmp, to_master) { ASSERT_TRUE(tools::vercmp("1.0", "1.0-master") < 0); }
+TEST(vercmp, from_master) { ASSERT_TRUE(tools::vercmp("1.0-master", "1.1") < 0); }