aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/fuzz/http-client.cpp3
-rw-r--r--tests/fuzz/levin.cpp9
-rw-r--r--tests/net_load_tests/net_load_tests.h2
-rw-r--r--tests/unit_tests/epee_levin_protocol_handler_async.cpp9
-rw-r--r--tests/unit_tests/levin.cpp4
-rw-r--r--tests/unit_tests/net.cpp30
-rw-r--r--tests/unit_tests/test_protocol_pack.cpp4
7 files changed, 30 insertions, 31 deletions
diff --git a/tests/fuzz/http-client.cpp b/tests/fuzz/http-client.cpp
index 4b12b36bb..65df24a3f 100644
--- a/tests/fuzz/http-client.cpp
+++ b/tests/fuzz/http-client.cpp
@@ -26,6 +26,7 @@
// 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.
+#include <boost/utility/string_ref.hpp>
#include "include_base_utils.h"
#include "file_io_utils.h"
#include "net/http_client.h"
@@ -38,7 +39,7 @@ public:
bool connect(const std::string& addr, int port, std::chrono::milliseconds timeout, bool ssl = false, const std::string& bind_ip = "0.0.0.0") { return true; }
bool connect(const std::string& addr, const std::string& port, std::chrono::milliseconds timeout, bool ssl = false, const std::string& bind_ip = "0.0.0.0") { return true; }
bool disconnect() { return true; }
- bool send(const std::string& buff, std::chrono::milliseconds timeout) { return true; }
+ bool send(const boost::string_ref buff, std::chrono::milliseconds timeout) { return true; }
bool send(const void* data, size_t sz) { return true; }
bool is_connected() { return true; }
bool recv(std::string& buff, std::chrono::milliseconds timeout)
diff --git a/tests/fuzz/levin.cpp b/tests/fuzz/levin.cpp
index 012d05f36..b090c350b 100644
--- a/tests/fuzz/levin.cpp
+++ b/tests/fuzz/levin.cpp
@@ -65,13 +65,13 @@ namespace
{
}
- virtual int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, test_levin_connection_context& context)
+ virtual int invoke(int command, const epee::span<const uint8_t> in_buff, epee::byte_slice& 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 = std::string((const char*)in_buff.data(), in_buff.size());
- buff_out = m_invoke_out_buf;
+ buff_out = m_invoke_out_buf.clone();
return m_return_code;
}
@@ -111,8 +111,7 @@ namespace
int return_code() const { return m_return_code; }
void return_code(int v) { m_return_code = v; }
- const std::string& invoke_out_buf() const { return m_invoke_out_buf; }
- void invoke_out_buf(const std::string& v) { m_invoke_out_buf = v; }
+ void invoke_out_buf(std::string v) { m_invoke_out_buf = epee::byte_slice{std::move(v)}; }
int last_command() const { return m_last_command; }
const std::string& last_in_buf() const { return m_last_in_buf; }
@@ -127,7 +126,7 @@ namespace
boost::mutex m_mutex;
int m_return_code;
- std::string m_invoke_out_buf;
+ epee::byte_slice m_invoke_out_buf;
int m_last_command;
std::string m_last_in_buf;
diff --git a/tests/net_load_tests/net_load_tests.h b/tests/net_load_tests/net_load_tests.h
index 882d42c02..e7e0ee247 100644
--- a/tests/net_load_tests/net_load_tests.h
+++ b/tests/net_load_tests/net_load_tests.h
@@ -64,7 +64,7 @@ namespace net_load_tests
{
}
- virtual int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, test_connection_context& context)
+ virtual int invoke(int command, const epee::span<const uint8_t> in_buff, epee::byte_slice& buff_out, test_connection_context& context)
{
//m_invoke_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 314fcf9f2..ab6791324 100644
--- a/tests/unit_tests/epee_levin_protocol_handler_async.cpp
+++ b/tests/unit_tests/epee_levin_protocol_handler_async.cpp
@@ -56,13 +56,13 @@ namespace
{
}
- virtual int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, test_levin_connection_context& context)
+ virtual int invoke(int command, const epee::span<const uint8_t> in_buff, epee::byte_slice& 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 = std::string((const char*)in_buff.data(), in_buff.size());
- buff_out = m_invoke_out_buf;
+ buff_out = m_invoke_out_buf.clone();
return m_return_code;
}
@@ -102,8 +102,7 @@ namespace
int return_code() const { return m_return_code; }
void return_code(int v) { m_return_code = v; }
- const std::string& invoke_out_buf() const { return m_invoke_out_buf; }
- void invoke_out_buf(const std::string& v) { m_invoke_out_buf = v; }
+ void invoke_out_buf(std::string v) { m_invoke_out_buf = epee::byte_slice{std::move(v)}; }
int last_command() const { return m_last_command; }
const std::string& last_in_buf() const { return m_last_in_buf; }
@@ -118,7 +117,7 @@ namespace
boost::mutex m_mutex;
int m_return_code;
- std::string m_invoke_out_buf;
+ epee::byte_slice m_invoke_out_buf;
int m_last_command;
std::string m_last_in_buf;
diff --git a/tests/unit_tests/levin.cpp b/tests/unit_tests/levin.cpp
index 22638942d..2ad149afe 100644
--- a/tests/unit_tests/levin.cpp
+++ b/tests/unit_tests/levin.cpp
@@ -238,9 +238,9 @@ namespace
return {connection, std::move(request)};
}
- virtual int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, cryptonote::levin::detail::p2p_context& context) override final
+ virtual int invoke(int command, const epee::span<const uint8_t> in_buff, epee::byte_slice& buff_out, cryptonote::levin::detail::p2p_context& context) override final
{
- buff_out.clear();
+ buff_out = nullptr;
invoked_.push_back(
{context.m_connection_id, command, std::string{reinterpret_cast<const char*>(in_buff.data()), in_buff.size()}}
);
diff --git a/tests/unit_tests/net.cpp b/tests/unit_tests/net.cpp
index f5aef4796..dffda5e4e 100644
--- a/tests/unit_tests/net.cpp
+++ b/tests/unit_tests/net.cpp
@@ -245,7 +245,7 @@ namespace
TEST(tor_address, epee_serializev_v2)
{
- std::string buffer{};
+ epee::byte_slice buffer{};
{
test_command_tor command{MONERO_UNWRAP(net::tor_address::make(v2_onion, 10))};
EXPECT_FALSE(command.tor.is_unknown());
@@ -266,7 +266,7 @@ TEST(tor_address, epee_serializev_v2)
EXPECT_EQ(0u, command.tor.port());
epee::serialization::portable_storage stg{};
- EXPECT_TRUE(stg.load_from_binary(buffer));
+ EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer)));
EXPECT_TRUE(command.load(stg));
}
EXPECT_FALSE(command.tor.is_unknown());
@@ -277,7 +277,7 @@ TEST(tor_address, epee_serializev_v2)
// make sure that exceeding max buffer doesn't destroy tor_address::_load
{
epee::serialization::portable_storage stg{};
- stg.load_from_binary(buffer);
+ stg.load_from_binary(epee::to_span(buffer));
std::string host{};
ASSERT_TRUE(stg.get_value("host", host, stg.open_section("tor", nullptr, false)));
@@ -296,7 +296,7 @@ TEST(tor_address, epee_serializev_v2)
TEST(tor_address, epee_serializev_v3)
{
- std::string buffer{};
+ epee::byte_slice buffer{};
{
test_command_tor command{MONERO_UNWRAP(net::tor_address::make(v3_onion, 10))};
EXPECT_FALSE(command.tor.is_unknown());
@@ -317,7 +317,7 @@ TEST(tor_address, epee_serializev_v3)
EXPECT_EQ(0u, command.tor.port());
epee::serialization::portable_storage stg{};
- EXPECT_TRUE(stg.load_from_binary(buffer));
+ EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer)));
EXPECT_TRUE(command.load(stg));
}
EXPECT_FALSE(command.tor.is_unknown());
@@ -328,7 +328,7 @@ TEST(tor_address, epee_serializev_v3)
// make sure that exceeding max buffer doesn't destroy tor_address::_load
{
epee::serialization::portable_storage stg{};
- stg.load_from_binary(buffer);
+ stg.load_from_binary(epee::to_span(buffer));
std::string host{};
ASSERT_TRUE(stg.get_value("host", host, stg.open_section("tor", nullptr, false)));
@@ -347,7 +347,7 @@ TEST(tor_address, epee_serializev_v3)
TEST(tor_address, epee_serialize_unknown)
{
- std::string buffer{};
+ epee::byte_slice buffer{};
{
test_command_tor command{net::tor_address::unknown()};
EXPECT_TRUE(command.tor.is_unknown());
@@ -368,7 +368,7 @@ TEST(tor_address, epee_serialize_unknown)
EXPECT_EQ(0u, command.tor.port());
epee::serialization::portable_storage stg{};
- EXPECT_TRUE(stg.load_from_binary(buffer));
+ EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer)));
EXPECT_TRUE(command.load(stg));
}
EXPECT_TRUE(command.tor.is_unknown());
@@ -379,7 +379,7 @@ TEST(tor_address, epee_serialize_unknown)
// make sure that exceeding max buffer doesn't destroy tor_address::_load
{
epee::serialization::portable_storage stg{};
- stg.load_from_binary(buffer);
+ stg.load_from_binary(epee::to_span(buffer));
std::string host{};
ASSERT_TRUE(stg.get_value("host", host, stg.open_section("tor", nullptr, false)));
@@ -700,7 +700,7 @@ namespace
TEST(i2p_address, epee_serializev_b32)
{
- std::string buffer{};
+ epee::byte_slice buffer{};
{
test_command_i2p command{MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 10))};
EXPECT_FALSE(command.i2p.is_unknown());
@@ -721,7 +721,7 @@ TEST(i2p_address, epee_serializev_b32)
EXPECT_EQ(0u, command.i2p.port());
epee::serialization::portable_storage stg{};
- EXPECT_TRUE(stg.load_from_binary(buffer));
+ EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer)));
EXPECT_TRUE(command.load(stg));
}
EXPECT_FALSE(command.i2p.is_unknown());
@@ -732,7 +732,7 @@ TEST(i2p_address, epee_serializev_b32)
// make sure that exceeding max buffer doesn't destroy i2p_address::_load
{
epee::serialization::portable_storage stg{};
- stg.load_from_binary(buffer);
+ stg.load_from_binary(epee::to_span(buffer));
std::string host{};
ASSERT_TRUE(stg.get_value("host", host, stg.open_section("i2p", nullptr, false)));
@@ -751,7 +751,7 @@ TEST(i2p_address, epee_serializev_b32)
TEST(i2p_address, epee_serialize_unknown)
{
- std::string buffer{};
+ epee::byte_slice buffer{};
{
test_command_i2p command{net::i2p_address::unknown()};
EXPECT_TRUE(command.i2p.is_unknown());
@@ -772,7 +772,7 @@ TEST(i2p_address, epee_serialize_unknown)
EXPECT_EQ(0u, command.i2p.port());
epee::serialization::portable_storage stg{};
- EXPECT_TRUE(stg.load_from_binary(buffer));
+ EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer)));
EXPECT_TRUE(command.load(stg));
}
EXPECT_TRUE(command.i2p.is_unknown());
@@ -783,7 +783,7 @@ TEST(i2p_address, epee_serialize_unknown)
// make sure that exceeding max buffer doesn't destroy i2p_address::_load
{
epee::serialization::portable_storage stg{};
- stg.load_from_binary(buffer);
+ stg.load_from_binary(epee::to_span(buffer));
std::string host{};
ASSERT_TRUE(stg.get_value("host", host, stg.open_section("i2p", nullptr, false)));
diff --git a/tests/unit_tests/test_protocol_pack.cpp b/tests/unit_tests/test_protocol_pack.cpp
index 312f18dfe..1a4fd30f8 100644
--- a/tests/unit_tests/test_protocol_pack.cpp
+++ b/tests/unit_tests/test_protocol_pack.cpp
@@ -36,7 +36,7 @@
TEST(protocol_pack, protocol_pack_command)
{
- std::string buff;
+ epee::byte_slice buff;
cryptonote::NOTIFY_RESPONSE_CHAIN_ENTRY::request r;
r.start_height = 1;
r.total_height = 3;
@@ -47,7 +47,7 @@ TEST(protocol_pack, protocol_pack_command)
ASSERT_TRUE(res);
cryptonote::NOTIFY_RESPONSE_CHAIN_ENTRY::request r2;
- res = epee::serialization::load_t_from_binary(r2, buff);
+ res = epee::serialization::load_t_from_binary(r2, epee::to_span(buff));
ASSERT_TRUE(res);
ASSERT_TRUE(r.m_block_ids.size() == i);
ASSERT_TRUE(r.start_height == 1);