Skip to content

Commit

Permalink
fix warnings from clang-tidy
Browse files Browse the repository at this point in the history
fix compilation in fuzzer test engine
  • Loading branch information
canepat committed Jan 21, 2024
1 parent 960c05f commit 8708d6e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
18 changes: 9 additions & 9 deletions cmd/test/fuzzer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include <nlohmann/json.hpp>

#include <silkworm/rpc/http/channel.hpp>
#include <silkworm/rpc/test/api_test_database.hpp>

#include "address_sanitizer_fix.hpp"
Expand All @@ -28,19 +27,20 @@ using namespace silkworm::rpc::test;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) {
static auto context = TestDatabaseContext();

auto request_str = std::string(reinterpret_cast<const char*>(Data), Size);
if (!nlohmann::json::accept(request_str)) {
auto request = std::string(reinterpret_cast<const char*>(Data), Size);
if (!nlohmann::json::accept(request)) {
return -1;
}
const auto request_json = nlohmann::json::parse(request);

auto request_handler = RpcApiTestBase<RequestHandler_ForTest>(context.db);
auto request_json = nlohmann::json::parse(request_str);
silkworm::rpc::Channel::Response reply;
request_handler.run<&RequestHandler_ForTest::handle_request>(request_str, reply);
std::string reply;
request_handler.run<&RequestHandler_ForTest::handle_request>(request, reply);

if (reply.status == silkworm::rpc::Channel::ResponseStatus::ok) {
return 0;
if (!nlohmann::json::accept(reply)) {
return -1;
}
const auto reply_json = nlohmann::json::parse(reply);

return -1;
return 0;
}
2 changes: 1 addition & 1 deletion silkworm/rpc/http/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Connection : public Channel {
//! Start the asynchronous read loop for the connection.
Task<void> read_loop();

Task<void> write_rsp(const std::string& response) override;
Task<void> write_rsp(const std::string& content) override;
Task<void> open_stream() override;
Task<std::size_t> write(std::string_view content) override;
Task<void> close() override { co_return; }
Expand Down
10 changes: 5 additions & 5 deletions silkworm/rpc/test/api_test_database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ChannelForTest : public Channel {
Task<std::size_t> write(std::string_view /* content */) override { co_return 0; }
Task<void> close() override { co_return; }

const std::string& get_response() { return response_; }
const std::string& response() { return response_; }

private:
std::string response_;
Expand All @@ -73,15 +73,15 @@ class RequestHandler_ForTest : public http::RequestHandler {
RequestHandler_ForTest(ChannelForTest* channel,
commands::RpcApi& rpc_api,
const commands::RpcApiTable& rpc_api_table)
: http::RequestHandler(channel, rpc_api, rpc_api_table) {}
: http::RequestHandler(channel, rpc_api, rpc_api_table), channel_{channel} {}

Task<void> request_and_create_reply(const nlohmann::json& request_json, std::string& response) {
co_await RequestHandler::handle_request_and_create_reply(request_json, response);
}

Task<void> handle_request(const std::string& request_str, std::string& response) {
co_await RequestHandler::handle(request_str);
response = std::move(channel_->get_response());
Task<void> handle_request(const std::string& request, std::string& response) {
co_await RequestHandler::handle(request);
response = channel_->response();
}

private:
Expand Down

0 comments on commit 8708d6e

Please sign in to comment.