aboutsummaryrefslogtreecommitdiff
path: root/tests/unit_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit_tests')
-rw-r--r--tests/unit_tests/bulletproofs.cpp9
-rw-r--r--tests/unit_tests/epee_utils.cpp12
-rw-r--r--tests/unit_tests/json_serialization.cpp47
-rw-r--r--tests/unit_tests/levin.cpp96
-rw-r--r--tests/unit_tests/net.cpp7
-rw-r--r--tests/unit_tests/node_server.cpp1
-rw-r--r--tests/unit_tests/serialization.cpp1
7 files changed, 125 insertions, 48 deletions
diff --git a/tests/unit_tests/bulletproofs.cpp b/tests/unit_tests/bulletproofs.cpp
index 760769551..a73b80848 100644
--- a/tests/unit_tests/bulletproofs.cpp
+++ b/tests/unit_tests/bulletproofs.cpp
@@ -179,15 +179,6 @@ TEST(bulletproofs, invalid_31)
ASSERT_FALSE(rct::bulletproof_VERIFY(proof));
}
-TEST(bulletproofs, invalid_gamma_0)
-{
- rct::key invalid_amount = rct::zero();
- invalid_amount[8] = 1;
- rct::key gamma = rct::zero();
- rct::Bulletproof proof = bulletproof_PROVE(invalid_amount, gamma);
- ASSERT_FALSE(rct::bulletproof_VERIFY(proof));
-}
-
static const char * const torsion_elements[] =
{
"c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa",
diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp
index 6f887afda..513c2227c 100644
--- a/tests/unit_tests/epee_utils.cpp
+++ b/tests/unit_tests/epee_utils.cpp
@@ -45,6 +45,7 @@
#include "boost/archive/portable_binary_iarchive.hpp"
#include "boost/archive/portable_binary_oarchive.hpp"
#include "byte_slice.h"
+#include "crypto/crypto.h"
#include "hex.h"
#include "net/net_utils_base.h"
#include "net/local_ip.h"
@@ -850,6 +851,17 @@ TEST(ToHex, Array)
);
}
+TEST(ToHex, ArrayFromPod)
+{
+ std::array<char, 64> expected{{'5', 'f', '2', 'b', '0', '1'}};
+ std::fill(expected.begin() + 6, expected.end(), '0');
+
+ EXPECT_EQ(
+ expected,
+ (epee::to_hex::array(crypto::ec_point{{0x5F, 0x2B, 0x01, 0x00}}))
+ );
+}
+
TEST(ToHex, Ostream)
{
std::stringstream out;
diff --git a/tests/unit_tests/json_serialization.cpp b/tests/unit_tests/json_serialization.cpp
index 53d9f84c7..6f98d854d 100644
--- a/tests/unit_tests/json_serialization.cpp
+++ b/tests/unit_tests/json_serialization.cpp
@@ -3,6 +3,8 @@
#include <boost/range/adaptor/indexed.hpp>
#include <gtest/gtest.h>
#include <rapidjson/document.h>
+#include <rapidjson/stringbuffer.h>
+#include <rapidjson/writer.h>
#include <vector>
#include "crypto/hash.h"
@@ -80,6 +82,27 @@ namespace
return tx;
}
+
+ template<typename T>
+ T test_json(const T& value)
+ {
+ rapidjson::StringBuffer buffer;
+ {
+ rapidjson::Writer<rapidjson::StringBuffer> dest{buffer};
+ cryptonote::json::toJsonValue(dest, value);
+ }
+
+ rapidjson::Document doc;
+ doc.Parse(buffer.GetString());
+ if (doc.HasParseError() || !doc.IsObject())
+ {
+ throw cryptonote::json::PARSE_FAIL();
+ }
+
+ T out{};
+ cryptonote::json::fromJsonValue(doc, out);
+ return out;
+ }
} // anonymous
TEST(JsonSerialization, MinerTransaction)
@@ -91,11 +114,7 @@ TEST(JsonSerialization, MinerTransaction)
crypto::hash tx_hash{};
ASSERT_TRUE(cryptonote::get_transaction_hash(miner_tx, tx_hash));
- rapidjson::Document doc;
- cryptonote::json::toJsonValue(doc, miner_tx, doc);
-
- cryptonote::transaction miner_tx_copy;
- cryptonote::json::fromJsonValue(doc, miner_tx_copy);
+ cryptonote::transaction miner_tx_copy = test_json(miner_tx);
crypto::hash tx_copy_hash{};
ASSERT_TRUE(cryptonote::get_transaction_hash(miner_tx_copy, tx_copy_hash));
@@ -126,11 +145,7 @@ TEST(JsonSerialization, RegularTransaction)
crypto::hash tx_hash{};
ASSERT_TRUE(cryptonote::get_transaction_hash(tx, tx_hash));
- rapidjson::Document doc;
- cryptonote::json::toJsonValue(doc, tx, doc);
-
- cryptonote::transaction tx_copy;
- cryptonote::json::fromJsonValue(doc, tx_copy);
+ cryptonote::transaction tx_copy = test_json(tx);
crypto::hash tx_copy_hash{};
ASSERT_TRUE(cryptonote::get_transaction_hash(tx_copy, tx_copy_hash));
@@ -161,11 +176,7 @@ TEST(JsonSerialization, RingctTransaction)
crypto::hash tx_hash{};
ASSERT_TRUE(cryptonote::get_transaction_hash(tx, tx_hash));
- rapidjson::Document doc;
- cryptonote::json::toJsonValue(doc, tx, doc);
-
- cryptonote::transaction tx_copy;
- cryptonote::json::fromJsonValue(doc, tx_copy);
+ cryptonote::transaction tx_copy = test_json(tx);
crypto::hash tx_copy_hash{};
ASSERT_TRUE(cryptonote::get_transaction_hash(tx_copy, tx_copy_hash));
@@ -196,11 +207,7 @@ TEST(JsonSerialization, BulletproofTransaction)
crypto::hash tx_hash{};
ASSERT_TRUE(cryptonote::get_transaction_hash(tx, tx_hash));
- rapidjson::Document doc;
- cryptonote::json::toJsonValue(doc, tx, doc);
-
- cryptonote::transaction tx_copy;
- cryptonote::json::fromJsonValue(doc, tx_copy);
+ cryptonote::transaction tx_copy = test_json(tx);
crypto::hash tx_copy_hash{};
ASSERT_TRUE(cryptonote::get_transaction_hash(tx_copy, tx_copy_hash));
diff --git a/tests/unit_tests/levin.cpp b/tests/unit_tests/levin.cpp
index e5ca4e41e..38707f075 100644
--- a/tests/unit_tests/levin.cpp
+++ b/tests/unit_tests/levin.cpp
@@ -271,12 +271,12 @@ namespace
EXPECT_EQ(connection_ids_.size(), connections_->get_connections_count());
}
- cryptonote::levin::notify make_notifier(const std::size_t noise_size, bool is_public)
+ cryptonote::levin::notify make_notifier(const std::size_t noise_size, bool is_public, bool pad_txs)
{
epee::byte_slice noise = nullptr;
if (noise_size)
noise = epee::levin::make_noise_notify(noise_size);
- return cryptonote::levin::notify{io_service_, connections_, std::move(noise), is_public};
+ return cryptonote::levin::notify{io_service_, connections_, std::move(noise), is_public, pad_txs};
}
boost::uuids::random_generator random_generator_;
@@ -434,12 +434,16 @@ TEST_F(levin_notify, defaulted)
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
}
- EXPECT_FALSE(notifier.send_txs({}, random_generator_(), false));
+ EXPECT_TRUE(notifier.send_txs({}, random_generator_()));
+
+ std::vector<cryptonote::blobdata> txs(2);
+ txs[0].resize(100, 'e');
+ EXPECT_FALSE(notifier.send_txs(std::move(txs), random_generator_()));
}
-TEST_F(levin_notify, flood)
+TEST_F(levin_notify, fluff_without_padding)
{
- cryptonote::levin::notify notifier = make_notifier(0, true);
+ cryptonote::levin::notify notifier = make_notifier(0, true, false);
for (unsigned count = 0; count < 10; ++count)
add_connection(count % 2 == 0);
@@ -464,10 +468,13 @@ TEST_F(levin_notify, flood)
ASSERT_EQ(10u, contexts_.size());
{
auto context = contexts_.begin();
- EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), false));
+ EXPECT_TRUE(notifier.send_txs(txs, context->get_id()));
io_service_.reset();
ASSERT_LT(0u, io_service_.poll());
+ notifier.run_fluff();
+ ASSERT_LT(0u, io_service_.poll());
+
EXPECT_EQ(0u, context->process_send_queue());
for (++context; context != contexts_.end(); ++context)
EXPECT_EQ(1u, context->process_send_queue());
@@ -480,14 +487,42 @@ TEST_F(levin_notify, flood)
EXPECT_TRUE(notification._.empty());
}
}
+}
+
+TEST_F(levin_notify, fluff_with_padding)
+{
+ cryptonote::levin::notify notifier = make_notifier(0, true, true);
+
+ for (unsigned count = 0; count < 10; ++count)
+ add_connection(count % 2 == 0);
+
+ {
+ const auto status = notifier.get_status();
+ EXPECT_FALSE(status.has_noise);
+ EXPECT_FALSE(status.connections_filled);
+ }
+ notifier.new_out_connection();
+ io_service_.poll();
+ {
+ const auto status = notifier.get_status();
+ EXPECT_FALSE(status.has_noise);
+ EXPECT_FALSE(status.connections_filled); // not tracked
+ }
+
+ std::vector<cryptonote::blobdata> txs(2);
+ txs[0].resize(100, 'e');
+ txs[1].resize(200, 'f');
ASSERT_EQ(10u, contexts_.size());
{
auto context = contexts_.begin();
- EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), true));
+ EXPECT_TRUE(notifier.send_txs(txs, context->get_id()));
io_service_.reset();
ASSERT_LT(0u, io_service_.poll());
+ notifier.run_fluff();
+ ASSERT_LT(0u, io_service_.poll());
+
EXPECT_EQ(0u, context->process_send_queue());
for (++context; context != contexts_.end(); ++context)
EXPECT_EQ(1u, context->process_send_queue());
@@ -502,9 +537,9 @@ TEST_F(levin_notify, flood)
}
}
-TEST_F(levin_notify, private_flood)
+TEST_F(levin_notify, private_fluff_without_padding)
{
- cryptonote::levin::notify notifier = make_notifier(0, false);
+ cryptonote::levin::notify notifier = make_notifier(0, false, false);
for (unsigned count = 0; count < 10; ++count)
add_connection(count % 2 == 0);
@@ -529,10 +564,14 @@ TEST_F(levin_notify, private_flood)
ASSERT_EQ(10u, contexts_.size());
{
auto context = contexts_.begin();
- EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), false));
+ EXPECT_TRUE(notifier.send_txs(txs, context->get_id()));
io_service_.reset();
ASSERT_LT(0u, io_service_.poll());
+ notifier.run_fluff();
+ io_service_.reset();
+ ASSERT_LT(0u, io_service_.poll());
+
EXPECT_EQ(0u, context->process_send_queue());
for (++context; context != contexts_.end(); ++context)
{
@@ -548,14 +587,43 @@ TEST_F(levin_notify, private_flood)
EXPECT_TRUE(notification._.empty());
}
}
+}
+
+TEST_F(levin_notify, private_fluff_with_padding)
+{
+ cryptonote::levin::notify notifier = make_notifier(0, false, true);
+
+ for (unsigned count = 0; count < 10; ++count)
+ add_connection(count % 2 == 0);
+
+ {
+ const auto status = notifier.get_status();
+ EXPECT_FALSE(status.has_noise);
+ EXPECT_FALSE(status.connections_filled);
+ }
+ notifier.new_out_connection();
+ io_service_.poll();
+ {
+ const auto status = notifier.get_status();
+ EXPECT_FALSE(status.has_noise);
+ EXPECT_FALSE(status.connections_filled); // not tracked
+ }
+
+ std::vector<cryptonote::blobdata> txs(2);
+ txs[0].resize(100, 'e');
+ txs[1].resize(200, 'f');
ASSERT_EQ(10u, contexts_.size());
{
auto context = contexts_.begin();
- EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), true));
+ EXPECT_TRUE(notifier.send_txs(txs, context->get_id()));
io_service_.reset();
ASSERT_LT(0u, io_service_.poll());
+ notifier.run_fluff();
+ io_service_.reset();
+ ASSERT_LT(0u, io_service_.poll());
+
EXPECT_EQ(0u, context->process_send_queue());
for (++context; context != contexts_.end(); ++context)
{
@@ -582,7 +650,7 @@ TEST_F(levin_notify, noise)
txs[0].resize(1900, 'h');
const boost::uuids::uuid incoming_id = random_generator_();
- cryptonote::levin::notify notifier = make_notifier(2048, false);
+ cryptonote::levin::notify notifier = make_notifier(2048, false, true);
{
const auto status = notifier.get_status();
@@ -608,7 +676,7 @@ TEST_F(levin_notify, noise)
EXPECT_EQ(0u, receiver_.notified_size());
}
- EXPECT_TRUE(notifier.send_txs(txs, incoming_id, false));
+ EXPECT_TRUE(notifier.send_txs(txs, incoming_id));
notifier.run_stems();
io_service_.reset();
ASSERT_LT(0u, io_service_.poll());
@@ -627,7 +695,7 @@ TEST_F(levin_notify, noise)
}
txs[0].resize(3000, 'r');
- EXPECT_TRUE(notifier.send_txs(txs, incoming_id, true));
+ EXPECT_TRUE(notifier.send_txs(txs, incoming_id));
notifier.run_stems();
io_service_.reset();
ASSERT_LT(0u, io_service_.poll());
diff --git a/tests/unit_tests/net.cpp b/tests/unit_tests/net.cpp
index 9ef4cf706..250dc35f5 100644
--- a/tests/unit_tests/net.cpp
+++ b/tests/unit_tests/net.cpp
@@ -53,6 +53,7 @@
#include <memory>
#include <type_traits>
+#include "crypto/crypto.h"
#include "net/dandelionpp.h"
#include "net/error.h"
#include "net/i2p_address.h"
@@ -283,7 +284,7 @@ TEST(tor_address, epee_serializev_v2)
EXPECT_EQ(std::strlen(v2_onion), host.size());
host.push_back('k');
- EXPECT_TRUE(stg.set_value("host", host, stg.open_section("tor", nullptr, false)));
+ EXPECT_TRUE(stg.set_value("host", std::move(host), stg.open_section("tor", nullptr, false)));
EXPECT_TRUE(command.load(stg)); // poor error reporting from `KV_SERIALIZE`
}
@@ -334,7 +335,7 @@ TEST(tor_address, epee_serializev_v3)
EXPECT_EQ(std::strlen(v3_onion), host.size());
host.push_back('k');
- EXPECT_TRUE(stg.set_value("host", host, stg.open_section("tor", nullptr, false)));
+ EXPECT_TRUE(stg.set_value("host", std::move(host), stg.open_section("tor", nullptr, false)));
EXPECT_TRUE(command.load(stg)); // poor error reporting from `KV_SERIALIZE`
}
@@ -385,7 +386,7 @@ TEST(tor_address, epee_serialize_unknown)
EXPECT_EQ(std::strlen(net::tor_address::unknown_str()), host.size());
host.push_back('k');
- EXPECT_TRUE(stg.set_value("host", host, stg.open_section("tor", nullptr, false)));
+ EXPECT_TRUE(stg.set_value("host", std::move(host), stg.open_section("tor", nullptr, false)));
EXPECT_TRUE(command.load(stg)); // poor error reporting from `KV_SERIALIZE`
}
diff --git a/tests/unit_tests/node_server.cpp b/tests/unit_tests/node_server.cpp
index c92f70b97..bda606e1a 100644
--- a/tests/unit_tests/node_server.cpp
+++ b/tests/unit_tests/node_server.cpp
@@ -54,7 +54,6 @@ public:
bool init(const boost::program_options::variables_map& vm) {return true ;}
bool deinit(){return true;}
bool get_short_chain_history(std::list<crypto::hash>& ids) const { return true; }
- bool get_stat_info(cryptonote::core_stat_info& st_inf) const {return true;}
bool have_block(const crypto::hash& id) const {return true;}
void get_blockchain_top(uint64_t& height, crypto::hash& top_id)const{height=0;top_id=crypto::null_hash;}
bool handle_incoming_tx(const cryptonote::tx_blob_entry& tx_blob, cryptonote::tx_verification_context& tvc, cryptonote::relay_method tx_relay, bool relayed) { return true; }
diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp
index 23f028464..b711526e6 100644
--- a/tests/unit_tests/serialization.cpp
+++ b/tests/unit_tests/serialization.cpp
@@ -735,7 +735,6 @@ TEST(Serialization, portability_wallet)
auto address_book_row = w.m_address_book.begin();
ASSERT_TRUE(epee::string_tools::pod_to_hex(address_book_row->m_address.m_spend_public_key) == "9bc53a6ff7b0831c9470f71b6b972dbe5ad1e8606f72682868b1dda64e119fb3");
ASSERT_TRUE(epee::string_tools::pod_to_hex(address_book_row->m_address.m_view_public_key) == "49fece1ef97dc0c0f7a5e2106e75e96edd910f7e86b56e1e308cd0cf734df191");
- ASSERT_TRUE(epee::string_tools::pod_to_hex(address_book_row->m_payment_id) == "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef");
ASSERT_TRUE(address_book_row->m_description == "testnet wallet 9y52S6");
}
}