3#include "barretenberg/bbapi/generated/bb_dispatch.hpp"
4#include "barretenberg/bbapi/generated/bb_types.hpp"
6#include <gtest/gtest.h>
13#ifndef BB_NO_EXCEPTIONS
18template <
typename WireCmd> std::vector<uint8_t> pack_wire_command(
const WireCmd& cmd)
21 msgpack::packer<msgpack::sbuffer> pk(buf);
24 pk.pack(std::string(WireCmd::MSGPACK_SCHEMA_NAME));
26 return std::vector<uint8_t>(buf.data(), buf.data() + buf.size());
30std::string response_type_name(
const std::vector<uint8_t>& bytes)
32 auto unpacked = msgpack::unpack(
reinterpret_cast<const char*
>(bytes.data()), bytes.size());
33 auto obj = unpacked.get();
34 if (obj.type != msgpack::type::ARRAY || obj.via.array.size != 2) {
37 const auto& name_obj = obj.via.array.ptr[0];
38 return std::string(name_obj.via.str.ptr, name_obj.via.str.size);
42std::string response_error_message(
const std::vector<uint8_t>& bytes)
44 auto unpacked = msgpack::unpack(
reinterpret_cast<const char*
>(bytes.data()), bytes.size());
45 auto obj = unpacked.get();
46 bbapi::wire::ErrorResponse err;
47 obj.via.array.ptr[1].convert(err);
54TEST(CBind, CatchesExceptionAndReturnsErrorResponse)
57 bbapi::wire::SrsInitSrs cmd{ .points_buf = std::vector<uint8_t>(10, 0),
59 .g2_point = std::vector<uint8_t>(10, 0) };
62 auto handler = bbapi::make_bb_handler(request);
63 auto response = handler(pack_wire_command(cmd));
65 EXPECT_EQ(response_type_name(response),
"ErrorResponse");
66 auto msg = response_error_message(response);
67 EXPECT_FALSE(msg.empty()) <<
"Error message should not be empty";
68 std::cout <<
"Successfully caught exception with message: " << msg <<
'\n';
71TEST(CBind, ValidOperationReturnsSuccess)
73 bbapi::wire::Blake2s cmd{ .data = std::vector<uint8_t>{ 1, 2, 3 } };
76 auto handler = bbapi::make_bb_handler(request);
78 auto response = handler(pack_wire_command(cmd));
79 EXPECT_EQ(response_type_name(response),
"Blake2sResponse");
83TEST(CBind, ExceptionsDisabled)
85 GTEST_SKIP() <<
"Skipping exception handling tests when BB_NO_EXCEPTIONS is defined";
Non-template handler declarations for the bb service.
Shared type definitions for the Barretenberg RPC API.
TEST(CBind, CatchesExceptionAndReturnsErrorResponse)
Entry point for Barretenberg command-line interface.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept