diff options
author | Lee Clagett <code@leeclagett.com> | 2021-01-06 11:47:09 -0500 |
---|---|---|
committer | Lee Clagett <code@leeclagett.com> | 2020-12-23 23:53:27 +0000 |
commit | ba3c627c57e3aebd56c35b45ec8bd310995fa467 (patch) | |
tree | ed1972e6578cf5ab1a91534222b14da3b5fd3bd6 /tests/unit_tests/levin.cpp | |
parent | Merge pull request #7282 (diff) | |
download | monero-ba3c627c57e3aebd56c35b45ec8bd310995fa467.tar.xz |
Command max_bytes moved from dynamic map to static switch
Diffstat (limited to '')
-rw-r--r-- | tests/unit_tests/levin.cpp | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/tests/unit_tests/levin.cpp b/tests/unit_tests/levin.cpp index 76e3282e0..4d8c5225e 100644 --- a/tests/unit_tests/levin.cpp +++ b/tests/unit_tests/levin.cpp @@ -183,13 +183,12 @@ namespace } //\return Number of messages processed - std::size_t process_send_queue() + std::size_t process_send_queue(const bool valid = true) { std::size_t count = 0; for ( ; !endpoint_.send_queue_.empty(); ++count, endpoint_.send_queue_.pop_front()) { - // invalid messages shoudn't be possible in this test; - EXPECT_TRUE(handler_.handle_recv(endpoint_.send_queue_.front().data(), endpoint_.send_queue_.front().size())); + EXPECT_EQ(valid, handler_.handle_recv(endpoint_.send_queue_.front().data(), endpoint_.send_queue_.front().size())); } return count; } @@ -239,6 +238,13 @@ namespace return {connection, std::move(request)}; } + static received_message get_raw_message(std::deque<received_message>& queue) + { + received_message out{std::move(queue.front())}; + queue.pop_front(); + return out; + } + 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 { buff_out.clear(); @@ -295,6 +301,11 @@ namespace { return get_message<T>(notified_); } + + received_message get_raw_notification() + { + return get_raw_message(notified_); + } }; class levin_notify : public ::testing::Test @@ -323,6 +334,8 @@ namespace EXPECT_EQ(0u, events_.relayed_method_size()); } + cryptonote::levin::connections& get_connections() noexcept { return *connections_; } + void add_connection(const bool is_incoming) { contexts_.emplace_back(io_service_, *connections_, random_generator_, is_incoming); @@ -2141,3 +2154,27 @@ TEST_F(levin_notify, noise_stem) } } } + +TEST_F(levin_notify, command_max_bytes) +{ + static constexpr int ping_command = nodetool::COMMAND_PING::ID; + + add_connection(true); + + std::string bytes(4096, 'h'); + + EXPECT_EQ(1, get_connections().notify(ping_command, epee::strspan<std::uint8_t>(bytes), contexts_.front().get_id())); + EXPECT_EQ(1u, contexts_.front().process_send_queue(true)); + EXPECT_EQ(1u, receiver_.notified_size()); + + const received_message msg = receiver_.get_raw_notification(); + EXPECT_EQ(ping_command, msg.command); + EXPECT_EQ(contexts_.front().get_id(), msg.connection); + EXPECT_EQ(bytes, msg.payload); + + bytes.push_back('e'); + + EXPECT_EQ(1, get_connections().notify(ping_command, epee::strspan<std::uint8_t>(bytes), contexts_.front().get_id())); + EXPECT_EQ(1u, contexts_.front().process_send_queue(false)); + EXPECT_EQ(0u, receiver_.notified_size()); +} |