diff --git a/pbft/test/pbft_test.cpp b/pbft/test/pbft_test.cpp index 2f085c5e..a1fded9b 100644 --- a/pbft/test/pbft_test.cpp +++ b/pbft/test/pbft_test.cpp @@ -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()); + } TEST_F(pbft_test, test_ignored_when_not_primary) { diff --git a/pbft/test/pbft_test_common.cpp b/pbft/test/pbft_test_common.cpp index 61f1662a..06bb3907 100644 --- a/pbft/test/pbft_test_common.cpp +++ b/pbft/test/pbft_test_common.cpp @@ -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( @@ -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 json) { diff --git a/pbft/test/pbft_test_common.hpp b/pbft/test/pbft_test_common.hpp index 6b3510ff..ef8d8ab3 100644 --- a/pbft/test/pbft_test_common.hpp +++ b/pbft/test/pbft_test_common.hpp @@ -63,6 +63,7 @@ namespace bzn::test bzn::asio::wait_handler audit_heartbeat_timer_callback; std::function service_execute_handler; + bzn::message_handler message_handler; bzn::uuid_t uuid = TEST_NODE_UUID; @@ -77,6 +78,7 @@ namespace bzn::test pbft_msg extract_pbft_msg(std::shared_ptr json); + bzn::message wrap_pbft_msg(const pbft_msg& msg); bool is_preprepare(std::shared_ptr json); bool is_prepare(std::shared_ptr json); bool is_commit(std::shared_ptr json);