This repository has been archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Konstantin Munichev <toobwn@gmail.com>
- Loading branch information
1 parent
1b1966b
commit c6eaa2d
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <memory> | ||
|
||
#include <gtest/gtest.h> | ||
#include <libfuzzer/libfuzzer_macro.h> | ||
|
||
#include "consensus/yac/transport/impl/network_impl.hpp" | ||
#include "module/irohad/consensus/yac/yac_mocks.hpp" | ||
|
||
using namespace testing; | ||
|
||
namespace fuzzing { | ||
struct ConsensusFixture { | ||
std::shared_ptr< | ||
NiceMock<iroha::consensus::yac::MockYacNetworkNotifications>> | ||
notifications_; | ||
std::shared_ptr<iroha::network::AsyncGrpcClient<google::protobuf::Empty>> | ||
async_call_; | ||
std::shared_ptr<iroha::consensus::yac::NetworkImpl> network_; | ||
|
||
ConsensusFixture() { | ||
spdlog::set_level(spdlog::level::critical); | ||
|
||
notifications_ = std::make_shared< | ||
NiceMock<iroha::consensus::yac::MockYacNetworkNotifications>>(); | ||
async_call_ = std::make_shared< | ||
iroha::network::AsyncGrpcClient<google::protobuf::Empty>>(); | ||
network_ = | ||
std::make_shared<iroha::consensus::yac::NetworkImpl>(async_call_); | ||
network_->subscribe(notifications_); | ||
} | ||
}; | ||
} // namespace fuzzing | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, std::size_t size) { | ||
static fuzzing::ConsensusFixture fixture; | ||
|
||
if (size < 1) { | ||
return 0; | ||
} | ||
|
||
iroha::consensus::yac::proto::State request; | ||
if (protobuf_mutator::libfuzzer::LoadProtoInput(true, data, size, &request)) { | ||
grpc::ServerContext context; | ||
google::protobuf::Empty response; | ||
fixture.network_->SendState(&context, &request, &response); | ||
} | ||
|
||
return 0; | ||
} |