Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
one more test for good measure
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelsavannah committed Aug 31, 2018
1 parent 4ac0325 commit adf1bea
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pbft/test/pbft_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ namespace bzn::test
pbft->handle_message(request_msg);
}

TEST_F(pbft_test, test_wrapped_message)
{
this->build_pbft();
EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_preprepare, Eq(true))))
.Times(Exactly(TEST_PEER_LIST.size()));

this->message_handler(wrap_pbft_msg(request_msg), std::shared_ptr<session_base>());
}

TEST_F(pbft_test, test_ignored_when_not_primary)
{
Expand Down
19 changes: 19 additions & 0 deletions pbft/test/pbft_test_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ namespace bzn::test
// This pattern copied from audit_test, to allow us to declare expectations on the timer that pbft will
// construct

EXPECT_CALL(*(this->mock_node), register_for_message("pbft", _))
.Times(Exactly(1))
.WillOnce(
Invoke(
[&](const auto&, auto handler)
{
this->message_handler = handler;
return true;
}
));

EXPECT_CALL(*(this->mock_io_context), make_unique_steady_timer())
.Times(AtMost(1))
.WillOnce(
Expand Down Expand Up @@ -91,6 +102,14 @@ namespace bzn::test
return result;
}

bzn::message
wrap_pbft_msg(const pbft_msg& msg)
{
bzn::message result;
result["pbft-data"] = boost::beast::detail::base64_encode(msg.SerializeAsString());
return result;
}

bool
is_preprepare(std::shared_ptr<bzn::message> json)
{
Expand Down
2 changes: 2 additions & 0 deletions pbft/test/pbft_test_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace bzn::test
bzn::asio::wait_handler audit_heartbeat_timer_callback;

std::function<void(const pbft_request&, uint64_t)> service_execute_handler;
bzn::message_handler message_handler;

bzn::uuid_t uuid = TEST_NODE_UUID;

Expand All @@ -77,6 +78,7 @@ namespace bzn::test


pbft_msg extract_pbft_msg(std::shared_ptr<bzn::message> json);
bzn::message wrap_pbft_msg(const pbft_msg& msg);
bool is_preprepare(std::shared_ptr<bzn::message> json);
bool is_prepare(std::shared_ptr<bzn::message> json);
bool is_commit(std::shared_ptr<bzn::message> json);
Expand Down

0 comments on commit adf1bea

Please sign in to comment.