Skip to content

Commit

Permalink
Add missed test
Browse files Browse the repository at this point in the history
  • Loading branch information
muratovv committed Aug 1, 2017
1 parent 9b15ccb commit 04f15aa
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions test/module/irohad/consensus/yac/yac_gate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,77 @@ class BlockCreatorStub : public iroha::simulator::BlockCreator {
};

TEST(YacGateTest, YacGateSubscribtionTest) {
cout << "----------| BlockCreator (block)=> YacHate (vote)=> "
"HashGate (commit) => YacGate => on_commit() |----------" << endl;

// expected values
YacHash expected_hash("proposal", "block");
iroha::model::Block expected_block;
expected_block.created_ts = 100500;
VoteMessage message;
message.hash = expected_hash;
CommitMessage commit_message({message});
auto expected_commit = rxcpp::observable<>::just(commit_message);

// yac consensus
unique_ptr<HashGate> hash_gate =
make_unique<HashGateMock>();
auto hash_gate_raw = hash_gate.get();

EXPECT_CALL(*static_cast<HashGateMock *>(hash_gate_raw),
vote(expected_hash, _)).Times(1);

EXPECT_CALL(*static_cast<HashGateMock *>(hash_gate_raw),
on_commit()).WillOnce(Return(expected_commit));

// generate order of peers
unique_ptr<YacPeerOrderer> peer_orderer =
make_unique<YacPeerOrdererMock>();
auto peer_orderer_raw = peer_orderer.get();

EXPECT_CALL(*static_cast<YacPeerOrdererMock *>(peer_orderer_raw),
getOrdering(_))
.WillOnce(Return(ClusterOrdering()));

// make hash from block
shared_ptr<YacHashProvider> hash_provider =
make_shared<YacHashProviderMock>();

EXPECT_CALL(
*static_cast<YacHashProviderMock *>(hash_provider.get()), makeHash(_))
.WillOnce(Return(expected_hash));

// make blocks
shared_ptr<iroha::simulator::BlockCreator> block_creator =
make_shared<BlockCreatorStub>();

YacGateImpl gate(std::move(hash_gate), std::move(peer_orderer),
hash_provider, block_creator);

// verify that yac gate subscribed for block_creator
TestObservable<iroha::model::Block> block_wrapper(block_creator->on_block());
block_wrapper.test_subscriber(
std::make_unique<CallExact<iroha::model::Block>>
(CallExact<iroha::model::Block>(1)), [](auto block) {});

auto val = static_cast<BlockCreatorStub *>(block_creator.get());

// initialize chain
val->subject.get_subscriber().on_next(expected_block);
ASSERT_EQ(true, block_wrapper.validate());

// verify that yac gate emit expected block
TestObservable<iroha::model::Block> gate_wrapper(gate.on_commit());
gate_wrapper.test_subscriber(
std::make_unique<CallExact<iroha::model::Block>>
(CallExact<iroha::model::Block>(1)), [expected_block](auto block) {
ASSERT_EQ(block, expected_block);
});

ASSERT_EQ(true, gate_wrapper.validate());
}

TEST(YacGateTest, YacGateSubscribtionTestFailCase) {
cout << "----------| Fail case of retrieving cluster order |----------"
<< endl;

Expand Down

0 comments on commit 04f15aa

Please sign in to comment.