Skip to content

Commit

Permalink
Add tests for transaction processor
Browse files Browse the repository at this point in the history
  • Loading branch information
muratovv committed Jul 13, 2017
1 parent 5ab2123 commit 9a6888f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 15 deletions.
14 changes: 3 additions & 11 deletions test/module/irohad/torii/processor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
# Testing of transaction processor
add_executable(transaction_processor_test transaction_processor_test.cpp)

target_link_libraries(
transaction_processor_test
addtest(transaction_processor_test transaction_processor_test.cpp)
target_link_libraries(transaction_processor_test
processors
gtest
)

add_test(
NAME transaction_processor_test
COMMAND $<TARGET_FILE:transaction_processor_test>
)
)
73 changes: 69 additions & 4 deletions test/module/irohad/torii/processor/transaction_processor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,85 @@
*/

#include <gtest/gtest.h>
#include <iostream>
#include <gmock/gmock.h>

#include <torii/processor/transaction_processor_stub.hpp>

using namespace iroha;
using ::testing::Return;
using ::testing::_;

/**
* Mock for stateless validation
*/
class StatelessValidationMock : public validation::StatelessValidator {
public:
MOCK_CONST_METHOD1(validate, bool(
const model::Transaction &transaction));
};

/**
* Mock for peer communication service
*/
class PcsMock : public network::PeerCommunicationService {
public:
MOCK_METHOD0(on_proposal, rxcpp::observable<model::Proposal>());
MOCK_METHOD0(on_commit,
rxcpp::observable<rxcpp::observable<model::Block>>());
};

/**
* Mock for ordering service
*/
class OsMock : public ordering::OrderingService {
public:
MOCK_METHOD1(propagate_transaction, void(
const model::Transaction &transaction));
MOCK_METHOD0(on_proposal, rxcpp::observable<model::Proposal>());
};

/**
* Transaction processor test case, when handling stateless valid transaction
*/
TEST(TransactionProcessorTest,
TransactionProcessorWhereInvokeValidTransaction) {
std::cout << "processor test - valid" << std::endl;

PcsMock pcs;

OsMock os;
EXPECT_CALL(os, propagate_transaction(_)).Times(1);

StatelessValidationMock validation;
EXPECT_CALL(validation, validate(_)).WillRepeatedly(Return(true));

iroha::torii::TransactionProcessorStub tp(pcs, os, validation);
model::Transaction tx;
tp.transaction_notifier().subscribe([](auto response) {
auto resp = static_cast<model::StatelessResponse &>(*response);
ASSERT_EQ(resp.passed, true);
});
tp.transaction_handle(model::Client(), tx);
}

/**
* Transaction processor test case, when handling invalid transaction
*/
TEST(TransactionProcessorTest,
TransactionProcessorWhereInvokeInvalidTransaction) {
std::cout << "processor test - fail" << std::endl;
}

PcsMock pcs;

OsMock os;
EXPECT_CALL(os, propagate_transaction(_)).Times(0);

StatelessValidationMock validation;
EXPECT_CALL(validation, validate(_)).WillRepeatedly(Return(false));

iroha::torii::TransactionProcessorStub tp(pcs, os, validation);
model::Transaction tx;
tp.transaction_notifier().subscribe([](auto response) {
auto resp = static_cast<model::StatelessResponse &>(*response);
ASSERT_EQ(resp.passed, false);
});
tp.transaction_handle(model::Client(), tx);
}

0 comments on commit 9a6888f

Please sign in to comment.