diff options
author | Alexander Blair <snipa@jagtech.io> | 2021-01-07 17:53:40 -0800 |
---|---|---|
committer | Alexander Blair <snipa@jagtech.io> | 2021-01-07 17:54:02 -0800 |
commit | 747699541e32a4d81d8abc4751993857fdf2faa1 (patch) | |
tree | 6debcb34fcb76b2674efef8c8f3c4317d0f5679d /tests | |
parent | Merge pull request #7281 (diff) | |
parent | Command max_bytes moved from dynamic map to static switch (diff) | |
download | monero-747699541e32a4d81d8abc4751993857fdf2faa1.tar.xz |
Merge pull request #7285
927141bcc Command max_bytes moved from dynamic map to static switch (Lee Clagett)
Diffstat (limited to 'tests')
-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 dc854ef0c..53a7f7b67 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, epee::byte_slice& buff_out, cryptonote::levin::detail::p2p_context& context) override final { buff_out = nullptr; @@ -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()); +} |