Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

More fuzzing fixes #1984

Merged
merged 6 commits into from
Dec 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/fuzzing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ add_executable(send_batches_fuzz send_batches_fuzz.cpp)
target_link_libraries(send_batches_fuzz
gtest::gtest
gmock::gmock
ametsuchi
on_demand_ordering_service
on_demand_ordering_service_transport_grpc
protobuf-mutator
Expand Down Expand Up @@ -86,5 +87,6 @@ target_link_libraries(mst_fuzz
gtest::gtest
gmock::gmock
mst_transport
ametsuchi
protobuf-mutator
)
26 changes: 21 additions & 5 deletions test/fuzzing/mst_fuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
#include <gtest/gtest.h>
#include <libfuzzer/libfuzzer_macro.h>

#include "ametsuchi/impl/tx_presence_cache_impl.hpp"
#include "backend/protobuf/proto_transport_factory.hpp"
#include "interfaces/iroha_internal/transaction_batch_factory_impl.hpp"
#include "interfaces/iroha_internal/transaction_batch_parser_impl.hpp"
#include "module/irohad/ametsuchi/ametsuchi_mocks.hpp"
#include "module/irohad/multi_sig_transactions/mst_test_helpers.hpp"
#include "multi_sig_transactions/transport/mst_transport_grpc.hpp"
#include "validators/protobuf/proto_transaction_validator.hpp"

using namespace testing;
using namespace iroha::network;
Expand All @@ -22,27 +25,40 @@ namespace fuzzing {
std::shared_ptr<MstTransportGrpc> mst_transport_grpc_;

MstFixture() {
spdlog::set_level(spdlog::level::err);

auto async_call_ = std::make_shared<
iroha::network::AsyncGrpcClient<google::protobuf::Empty>>();
// TODO luckychess 25.12.2018 Component initialisation reuse
// IR-1886, IR-142
std::unique_ptr<shared_model::validation::AbstractValidator<
shared_model::interface::Transaction>>
// TODO luckychess 20.11.2018 Reuse validator from application.cpp IR-1886
tx_validator =
std::make_unique<shared_model::validation::
DefaultOptionalSignedTransactionValidator>();
interface_validator = std::make_unique<
shared_model::validation::DefaultUnsignedTransactionValidator>();
std::unique_ptr<shared_model::validation::AbstractValidator<
iroha::protocol::Transaction>>
tx_validator = std::make_unique<
shared_model::validation::ProtoTransactionValidator>();

auto tx_factory =
std::make_shared<shared_model::proto::ProtoTransportFactory<
shared_model::interface::Transaction,
shared_model::proto::Transaction>>(std::move(tx_validator));
shared_model::proto::Transaction>>(std::move(interface_validator),
std::move(tx_validator));
auto parser = std::make_shared<
shared_model::interface::TransactionBatchParserImpl>();
auto batch_factory = std::make_shared<
shared_model::interface::TransactionBatchFactoryImpl>();
auto storage =
std::make_shared<NiceMock<iroha::ametsuchi::MockStorage>>();
auto cache =
std::make_shared<iroha::ametsuchi::TxPresenceCacheImpl>(storage);
mst_transport_grpc_ = std::make_shared<MstTransportGrpc>(
async_call_,
std::move(tx_factory),
std::move(parser),
std::move(batch_factory),
std::move(cache),
shared_model::crypto::DefaultCryptoAlgorithmType::generateKeypair()
.publicKey());
}
Expand Down
16 changes: 7 additions & 9 deletions test/fuzzing/ordering_service_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ namespace fuzzing {
batch_parser_;
std::shared_ptr<NiceMock<MockTransactionBatchFactory>>
transaction_batch_factory_;
shared_model::validation::AbstractValidator<
shared_model::interface::Transaction> *transaction_validator_;

OrderingServiceFixture() {
// fuzzing target is intended to run many times (~millions) so any
Expand All @@ -46,19 +44,19 @@ namespace fuzzing {

std::unique_ptr<shared_model::validation::AbstractValidator<
shared_model::interface::Transaction>>
transaction_validator =
std::make_unique<shared_model::validation::
DefaultOptionalSignedTransactionValidator>();
transaction_validator_ = transaction_validator.get();
interface_transaction_validator =
std::make_unique<NiceMock<shared_model::validation::MockValidator<
shared_model::interface::Transaction>>>();
std::unique_ptr<shared_model::validation::AbstractValidator<
iroha::protocol::Transaction>>
proto_transaction_validator = std::make_unique<
shared_model::validation::ProtoTransactionValidator>();
proto_transaction_validator =
std::make_unique<NiceMock<shared_model::validation::MockValidator<
iroha::protocol::Transaction>>>();
transaction_factory_ =
std::make_shared<shared_model::proto::ProtoTransportFactory<
shared_model::interface::Transaction,
shared_model::proto::Transaction>>(
std::move(transaction_validator),
std::move(interface_transaction_validator),
std::move(proto_transaction_validator));

batch_parser_ = std::make_shared<
Expand Down
6 changes: 5 additions & 1 deletion test/fuzzing/send_batches_fuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "ametsuchi/impl/tx_presence_cache_impl.hpp"
#include "module/irohad/ametsuchi/ametsuchi_mocks.hpp"
#include "ordering_service_fixture.hpp"

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, std::size_t size) {
Expand All @@ -16,8 +18,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, std::size_t size) {
std::shared_ptr<OnDemandOsServerGrpc> server_;

auto proposal_factory = std::make_unique<MockUnsafeProposalFactory>();
auto storage = std::make_shared<NiceMock<iroha::ametsuchi::MockStorage>>();
auto cache = std::make_shared<iroha::ametsuchi::TxPresenceCacheImpl>(storage);
ordering_service_ = std::make_shared<OnDemandOrderingServiceImpl>(
data[0], std::move(proposal_factory));
data[0], std::move(proposal_factory), std::move(cache));
server_ = std::make_shared<OnDemandOsServerGrpc>(
ordering_service_,
fixture.transaction_factory_,
Expand Down