aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/core_tests/chaingen_main.cpp8
-rw-r--r--tests/core_tests/multisig.cpp8
-rw-r--r--tests/core_tests/multisig.h16
-rw-r--r--tests/functional_tests/transactions_flow_test.cpp1
-rw-r--r--tests/fuzz/levin.cpp8
-rw-r--r--tests/net_load_tests/net_load_tests.h5
-rw-r--r--tests/unit_tests/epee_levin_protocol_handler_async.cpp8
-rw-r--r--tests/unit_tests/epee_utils.cpp69
-rw-r--r--tests/unit_tests/notify.cpp21
-rw-r--r--tests/unit_tests/test_peerlist.cpp6
-rw-r--r--tests/unit_tests/testdb.h6
11 files changed, 119 insertions, 37 deletions
diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp
index 84254cfdb..455bb1efa 100644
--- a/tests/core_tests/chaingen_main.cpp
+++ b/tests/core_tests/chaingen_main.cpp
@@ -229,10 +229,10 @@ int main(int argc, char* argv[])
GENERATE_AND_PLAY(gen_multisig_tx_valid_25_1_2_many_inputs);
GENERATE_AND_PLAY(gen_multisig_tx_valid_48_1_234);
GENERATE_AND_PLAY(gen_multisig_tx_valid_48_1_234_many_inputs);
- GENERATE_AND_PLAY(gen_multisig_tx_valid_24_1_no_signers);
- GENERATE_AND_PLAY(gen_multisig_tx_valid_25_1_no_signers);
- GENERATE_AND_PLAY(gen_multisig_tx_valid_48_1_no_signers);
- GENERATE_AND_PLAY(gen_multisig_tx_valid_48_1_23_no_threshold);
+ GENERATE_AND_PLAY(gen_multisig_tx_invalid_24_1_no_signers);
+ GENERATE_AND_PLAY(gen_multisig_tx_invalid_25_1_no_signers);
+ GENERATE_AND_PLAY(gen_multisig_tx_invalid_48_1_no_signers);
+ GENERATE_AND_PLAY(gen_multisig_tx_invalid_48_1_23_no_threshold);
GENERATE_AND_PLAY(gen_bp_tx_valid_1);
GENERATE_AND_PLAY(gen_bp_tx_invalid_1_1);
diff --git a/tests/core_tests/multisig.cpp b/tests/core_tests/multisig.cpp
index fe5feb942..46ba997be 100644
--- a/tests/core_tests/multisig.cpp
+++ b/tests/core_tests/multisig.cpp
@@ -644,28 +644,28 @@ bool gen_multisig_tx_invalid_45_5_23_no_threshold::generate(std::vector<test_eve
return generate_with(events, 2, mixin, amount_paid, false, 4, 5, 5, {2, 3}, NULL, NULL);
}
-bool gen_multisig_tx_valid_24_1_no_signers::generate(std::vector<test_event_entry>& events) const
+bool gen_multisig_tx_invalid_24_1_no_signers::generate(std::vector<test_event_entry>& events) const
{
const size_t mixin = 4;
const uint64_t amount_paid = 10000;
return generate_with(events, 2, mixin, amount_paid, false, 2, 4, 1, {}, NULL, NULL);
}
-bool gen_multisig_tx_valid_25_1_no_signers::generate(std::vector<test_event_entry>& events) const
+bool gen_multisig_tx_invalid_25_1_no_signers::generate(std::vector<test_event_entry>& events) const
{
const size_t mixin = 4;
const uint64_t amount_paid = 10000;
return generate_with(events, 2, mixin, amount_paid, false, 2, 5, 1, {}, NULL, NULL);
}
-bool gen_multisig_tx_valid_48_1_no_signers::generate(std::vector<test_event_entry>& events) const
+bool gen_multisig_tx_invalid_48_1_no_signers::generate(std::vector<test_event_entry>& events) const
{
const size_t mixin = 4;
const uint64_t amount_paid = 10000;
return generate_with(events, 2, mixin, amount_paid, false, 4, 8, 1, {}, NULL, NULL);
}
-bool gen_multisig_tx_valid_48_1_23_no_threshold::generate(std::vector<test_event_entry>& events) const
+bool gen_multisig_tx_invalid_48_1_23_no_threshold::generate(std::vector<test_event_entry>& events) const
{
const size_t mixin = 4;
const uint64_t amount_paid = 10000;
diff --git a/tests/core_tests/multisig.h b/tests/core_tests/multisig.h
index 9e4cb3a23..e0d227840 100644
--- a/tests/core_tests/multisig.h
+++ b/tests/core_tests/multisig.h
@@ -234,26 +234,26 @@ struct gen_multisig_tx_invalid_45_5_23_no_threshold: public gen_multisig_tx_vali
};
template<> struct get_test_options<gen_multisig_tx_invalid_45_5_23_no_threshold>: public get_test_options<gen_multisig_tx_validation_base> {};
-struct gen_multisig_tx_valid_24_1_no_signers: public gen_multisig_tx_validation_base
+struct gen_multisig_tx_invalid_24_1_no_signers: public gen_multisig_tx_validation_base
{
bool generate(std::vector<test_event_entry>& events) const;
};
-template<> struct get_test_options<gen_multisig_tx_valid_24_1_no_signers>: public get_test_options<gen_multisig_tx_validation_base> {};
+template<> struct get_test_options<gen_multisig_tx_invalid_24_1_no_signers>: public get_test_options<gen_multisig_tx_validation_base> {};
-struct gen_multisig_tx_valid_25_1_no_signers: public gen_multisig_tx_validation_base
+struct gen_multisig_tx_invalid_25_1_no_signers: public gen_multisig_tx_validation_base
{
bool generate(std::vector<test_event_entry>& events) const;
};
-template<> struct get_test_options<gen_multisig_tx_valid_25_1_no_signers>: public get_test_options<gen_multisig_tx_validation_base> {};
+template<> struct get_test_options<gen_multisig_tx_invalid_25_1_no_signers>: public get_test_options<gen_multisig_tx_validation_base> {};
-struct gen_multisig_tx_valid_48_1_no_signers: public gen_multisig_tx_validation_base
+struct gen_multisig_tx_invalid_48_1_no_signers: public gen_multisig_tx_validation_base
{
bool generate(std::vector<test_event_entry>& events) const;
};
-template<> struct get_test_options<gen_multisig_tx_valid_48_1_no_signers>: public get_test_options<gen_multisig_tx_validation_base> {};
+template<> struct get_test_options<gen_multisig_tx_invalid_48_1_no_signers>: public get_test_options<gen_multisig_tx_validation_base> {};
-struct gen_multisig_tx_valid_48_1_23_no_threshold: public gen_multisig_tx_validation_base
+struct gen_multisig_tx_invalid_48_1_23_no_threshold: public gen_multisig_tx_validation_base
{
bool generate(std::vector<test_event_entry>& events) const;
};
-template<> struct get_test_options<gen_multisig_tx_valid_48_1_23_no_threshold>: public get_test_options<gen_multisig_tx_validation_base> {};
+template<> struct get_test_options<gen_multisig_tx_invalid_48_1_23_no_threshold>: public get_test_options<gen_multisig_tx_validation_base> {};
diff --git a/tests/functional_tests/transactions_flow_test.cpp b/tests/functional_tests/transactions_flow_test.cpp
index ffe500d21..7e5b73415 100644
--- a/tests/functional_tests/transactions_flow_test.cpp
+++ b/tests/functional_tests/transactions_flow_test.cpp
@@ -29,6 +29,7 @@
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
#include <boost/uuid/uuid.hpp>
+#include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/random_generator.hpp>
#include <unordered_map>
diff --git a/tests/fuzz/levin.cpp b/tests/fuzz/levin.cpp
index d0c5803f5..573abd1d3 100644
--- a/tests/fuzz/levin.cpp
+++ b/tests/fuzz/levin.cpp
@@ -65,22 +65,22 @@ namespace
{
}
- virtual int invoke(int command, const std::string& in_buff, std::string& buff_out, test_levin_connection_context& context)
+ virtual int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, test_levin_connection_context& context)
{
m_invoke_counter.inc();
boost::unique_lock<boost::mutex> lock(m_mutex);
m_last_command = command;
- m_last_in_buf = in_buff;
+ m_last_in_buf = std::string((const char*)in_buff.data(), in_buff.size());
buff_out = m_invoke_out_buf;
return m_return_code;
}
- virtual int notify(int command, const std::string& in_buff, test_levin_connection_context& context)
+ virtual int notify(int command, const epee::span<const uint8_t> in_buff, test_levin_connection_context& context)
{
m_notify_counter.inc();
boost::unique_lock<boost::mutex> lock(m_mutex);
m_last_command = command;
- m_last_in_buf = in_buff;
+ m_last_in_buf = std::string((const char*)in_buff.data(), in_buff.size());
return m_return_code;
}
diff --git a/tests/net_load_tests/net_load_tests.h b/tests/net_load_tests/net_load_tests.h
index 7e92c21b9..6c4f7cb76 100644
--- a/tests/net_load_tests/net_load_tests.h
+++ b/tests/net_load_tests/net_load_tests.h
@@ -33,6 +33,7 @@
#include <atomic>
#include <boost/asio/io_service.hpp>
+#include <boost/uuid/uuid_io.hpp>
#include "include_base_utils.h"
#include "string_tools.h"
@@ -62,7 +63,7 @@ namespace net_load_tests
{
}
- virtual int invoke(int command, const std::string& in_buff, std::string& buff_out, test_connection_context& context)
+ virtual int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, test_connection_context& context)
{
//m_invoke_counter.inc();
//std::unique_lock<std::mutex> lock(m_mutex);
@@ -73,7 +74,7 @@ namespace net_load_tests
return LEVIN_OK;
}
- virtual int notify(int command, const std::string& in_buff, test_connection_context& context)
+ virtual int notify(int command, const epee::span<const uint8_t> in_buff, test_connection_context& context)
{
//m_notify_counter.inc();
//std::unique_lock<std::mutex> lock(m_mutex);
diff --git a/tests/unit_tests/epee_levin_protocol_handler_async.cpp b/tests/unit_tests/epee_levin_protocol_handler_async.cpp
index 10e62c167..9ea71875b 100644
--- a/tests/unit_tests/epee_levin_protocol_handler_async.cpp
+++ b/tests/unit_tests/epee_levin_protocol_handler_async.cpp
@@ -56,22 +56,22 @@ namespace
{
}
- virtual int invoke(int command, const std::string& in_buff, std::string& buff_out, test_levin_connection_context& context)
+ virtual int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, test_levin_connection_context& context)
{
m_invoke_counter.inc();
boost::unique_lock<boost::mutex> lock(m_mutex);
m_last_command = command;
- m_last_in_buf = in_buff;
+ m_last_in_buf = std::string((const char*)in_buff.data(), in_buff.size());
buff_out = m_invoke_out_buf;
return m_return_code;
}
- virtual int notify(int command, const std::string& in_buff, test_levin_connection_context& context)
+ virtual int notify(int command, const epee::span<const uint8_t> in_buff, test_levin_connection_context& context)
{
m_notify_counter.inc();
boost::unique_lock<boost::mutex> lock(m_mutex);
m_last_command = command;
- m_last_in_buf = in_buff;
+ m_last_in_buf = std::string((const char*)in_buff.data(), in_buff.size());
return m_return_code;
}
diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp
index c384ce9a5..75cf2fdd4 100644
--- a/tests/unit_tests/epee_utils.cpp
+++ b/tests/unit_tests/epee_utils.cpp
@@ -46,6 +46,7 @@
#include "hex.h"
#include "net/net_utils_base.h"
#include "net/local_ip.h"
+#include "net/buffer.h"
#include "p2p/net_peerlist_boost_serialization.h"
#include "span.h"
#include "string_tools.h"
@@ -764,3 +765,71 @@ TEST(NetUtils, PrivateRanges)
ASSERT_EQ(is_local("0.0.30.172"), false);
ASSERT_EQ(is_local("0.0.30.127"), false);
}
+
+TEST(net_buffer, basic)
+{
+ epee::net_utils::buffer buf;
+
+ ASSERT_EQ(buf.size(), 0);
+ EXPECT_THROW(buf.span(1), std::runtime_error);
+ buf.append("a", 1);
+ epee::span<const uint8_t> span = buf.span(1);
+ ASSERT_EQ(span.size(), 1);
+ ASSERT_EQ(span.data()[0], 'a');
+ EXPECT_THROW(buf.span(2), std::runtime_error);
+ buf.append("bc", 2);
+ buf.erase(1);
+ EXPECT_THROW(buf.span(3), std::runtime_error);
+ span = buf.span(2);
+ ASSERT_EQ(span.size(), 2);
+ ASSERT_EQ(span.data()[0], 'b');
+ ASSERT_EQ(span.data()[1], 'c');
+ buf.erase(1);
+ EXPECT_THROW(buf.span(2), std::runtime_error);
+ span = buf.span(1);
+ ASSERT_EQ(span.size(), 1);
+ ASSERT_EQ(span.data()[0], 'c');
+ EXPECT_THROW(buf.erase(2), std::runtime_error);
+ buf.erase(1);
+ EXPECT_EQ(buf.size(), 0);
+ EXPECT_THROW(buf.span(1), std::runtime_error);
+}
+
+TEST(net_buffer, existing_capacity)
+{
+ epee::net_utils::buffer buf;
+
+ buf.append("123456789", 9);
+ buf.erase(9);
+ buf.append("abc", 3);
+ buf.append("def", 3);
+ ASSERT_EQ(buf.size(), 6);
+ epee::span<const uint8_t> span = buf.span(6);
+ ASSERT_TRUE(!memcmp(span.data(), "abcdef", 6));
+}
+
+TEST(net_buffer, reallocate)
+{
+ epee::net_utils::buffer buf;
+
+ buf.append(std::string(4000, ' ').c_str(), 4000);
+ buf.append(std::string(8000, '0').c_str(), 8000);
+ ASSERT_EQ(buf.size(), 12000);
+ epee::span<const uint8_t> span = buf.span(12000);
+ ASSERT_TRUE(!memcmp(span.data(), std::string(4000, ' ').c_str(), 4000));
+ ASSERT_TRUE(!memcmp(span.data() + 4000, std::string(8000, '0').c_str(), 8000));
+}
+
+TEST(net_buffer, move)
+{
+ epee::net_utils::buffer buf;
+
+ buf.append(std::string(400, ' ').c_str(), 400);
+ buf.erase(399);
+ buf.append(std::string(4000, '0').c_str(), 4000);
+ ASSERT_EQ(buf.size(), 4001);
+ epee::span<const uint8_t> span = buf.span(4001);
+ ASSERT_TRUE(!memcmp(span.data(), std::string(1, ' ').c_str(), 1));
+ ASSERT_TRUE(!memcmp(span.data() + 1, std::string(4000, '0').c_str(), 4000));
+}
+
diff --git a/tests/unit_tests/notify.cpp b/tests/unit_tests/notify.cpp
index 105d21ca8..cd70b7739 100644
--- a/tests/unit_tests/notify.cpp
+++ b/tests/unit_tests/notify.cpp
@@ -69,11 +69,22 @@ TEST(notify, works)
tools::Notify notify(spec.c_str());
notify.notify("1111111111111111111111111111111111111111111111111111111111111111");
- epee::misc_utils::sleep_no_w(100);
-
- std::string s;
- ASSERT_TRUE(epee::file_io_utils::load_file_to_string(name_template, s));
- ASSERT_TRUE(s == "1111111111111111111111111111111111111111111111111111111111111111");
+ bool ok = false;
+ for (int i = 0; i < 10; ++i)
+ {
+ epee::misc_utils::sleep_no_w(100);
+ std::string s;
+ if (epee::file_io_utils::load_file_to_string(name_template, s))
+ {
+ if (s == "1111111111111111111111111111111111111111111111111111111111111111")
+ {
+ ok = true;
+ break;
+ }
+ std::cout << "got: [" << s << "]" << std::endl;
+ }
+ }
boost::filesystem::remove(name_template);
+ ASSERT_TRUE(ok);
}
diff --git a/tests/unit_tests/test_peerlist.cpp b/tests/unit_tests/test_peerlist.cpp
index c6572c6c2..f638c6251 100644
--- a/tests/unit_tests/test_peerlist.cpp
+++ b/tests/unit_tests/test_peerlist.cpp
@@ -42,7 +42,7 @@ TEST(peer_list, peer_list_general)
#define ADD_GRAY_NODE(addr_, id_, last_seen_) { nodetool::peerlist_entry ple; ple.last_seen=last_seen_;ple.adr = addr_; ple.id = id_;plm.append_with_peer_gray(ple);}
#define ADD_WHITE_NODE(addr_, id_, last_seen_) { nodetool::peerlist_entry ple;ple.last_seen=last_seen_; ple.adr = addr_; ple.id = id_;plm.append_with_peer_white(ple);}
-#define PRINT_HEAD(step) {std::list<nodetool::peerlist_entry> bs_head; bool r = plm.get_peerlist_head(bs_head, 100);std::cout << "step " << step << ": " << bs_head.size() << std::endl;}
+#define PRINT_HEAD(step) {std::vector<nodetool::peerlist_entry> bs_head; bool r = plm.get_peerlist_head(bs_head, 100);std::cout << "step " << step << ": " << bs_head.size() << std::endl;}
ADD_GRAY_NODE(MAKE_IPV4_ADDRESS(123,43,12,1, 8080), 121241, 34345);
ADD_GRAY_NODE(MAKE_IPV4_ADDRESS(123,43,12,2, 8080), 121241, 34345);
@@ -58,7 +58,7 @@ TEST(peer_list, peer_list_general)
size_t gray_list_size = plm.get_gray_peers_count();
ASSERT_EQ(gray_list_size, 1);
- std::list<nodetool::peerlist_entry> bs_head;
+ std::vector<nodetool::peerlist_entry> bs_head;
bool r = plm.get_peerlist_head(bs_head, 100);
std::cout << bs_head.size() << std::endl;
ASSERT_TRUE(r);
@@ -78,7 +78,7 @@ TEST(peer_list, merge_peer_lists)
//ADD_NODE_TO_PL("\2", \3, 0x\1, (1353346618 -(\4*60*60*24+\5*60*60+\6*60+\7 )));\n
nodetool::peerlist_manager plm;
plm.init(false);
- std::list<nodetool::peerlist_entry> outer_bs;
+ std::vector<nodetool::peerlist_entry> outer_bs;
#define ADD_NODE_TO_PL(ip_, port_, id_, timestamp_) { nodetool::peerlist_entry ple; epee::string_tools::get_ip_int32_from_string(ple.adr.ip, ip_); ple.last_seen = timestamp_; ple.adr.port = port_; ple.id = id_;outer_bs.push_back(ple);}
diff --git a/tests/unit_tests/testdb.h b/tests/unit_tests/testdb.h
index 5d9ba5833..b8fef8ed3 100644
--- a/tests/unit_tests/testdb.h
+++ b/tests/unit_tests/testdb.h
@@ -89,14 +89,14 @@ public:
virtual uint64_t get_tx_block_height(const crypto::hash& h) const { return 0; }
virtual uint64_t get_num_outputs(const uint64_t& amount) const { return 1; }
virtual uint64_t get_indexing_base() const { return 0; }
- virtual cryptonote::output_data_t get_output_key(const uint64_t& amount, const uint64_t& index) { return cryptonote::output_data_t(); }
+ virtual cryptonote::output_data_t get_output_key(const uint64_t& amount, const uint64_t& index) const { return cryptonote::output_data_t(); }
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 epee::span<const uint64_t> &amounts, 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) const {}
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>(); }
+ virtual std::vector<std::vector<uint64_t>> get_tx_amount_output_indices(const uint64_t tx_index, size_t n_txes) const { return std::vector<std::vector<uint64_t>>(); }
virtual bool has_key_image(const crypto::key_image& img) const { return false; }
virtual void remove_block() { }
virtual uint64_t add_transaction_data(const crypto::hash& blk_hash, const cryptonote::transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prunable_hash) {return 0;}