Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
msgpack_schema.test.cpp
Go to the documentation of this file.
3
4#include <gtest/gtest.h>
5
6using namespace bb;
7
8// Sanity checking for msgpack
9
15
21
27
29 std::vector<int> a;
31
32 MSGPACK_FIELDS(b); // Type mismatch, expect 'a', will catch at compile-time
34
38 void msgpack(auto ar)
39 {
40 BadExampleOutOfObject other_object;
41 ar("a", other_object.a, "b", other_object.b);
42 }
44
45// TODO eventually move to barretenberg
46TEST(msgpack_tests, msgpack_sanity_sanity)
47{
50 "Overlap in BadExampleOverlap MSGPACK_FIELDS() params detected!");
52 "Incomplete BadExampleIncomplete MSGPACK_FIELDS() params! Not all of object specified.");
53
54 // If we actually try to msgpack BadExampleCompileTimeError we will statically error
55 // This is great, but we need to check the underlying facility *somehow*
56 auto checker = [&](auto&... values) {
57 std::string incomplete_msgpack_status = "error";
58 if constexpr (msgpack_concepts::MsgpackConstructible<BadExampleCompileTimeError, decltype(values)...>) {
59 incomplete_msgpack_status = "";
60 }
61 EXPECT_EQ(incomplete_msgpack_status, "error");
62 };
63 bad_example_compile_time_error.msgpack(checker);
64
66 "Some BadExampleOutOfObject MSGPACK_FIELDS() params don't exist in object!");
67}
68
76
77TEST(msgpack_tests, msgpack_schema_sanity)
78{
79 EXPECT_EQ(
81 "{\"__typename\":\"GoodExample\",\"a\":[\"alias\",[\"fr\",\"bin32\"]],\"b\":[\"alias\",[\"fr\",\"bin32\"]]}\n");
83 "{\"__typename\":\"ComplicatedSchema\",\"array\":[\"vector\",[[\"array\",[[\"alias\",[\"fr\",\"bin32\"]],"
84 "20]]]],\"good_or_not\":[\"optional\",[{\"__typename\":\"GoodExample\",\"a\":[\"alias\",[\"fr\","
85 "\"bin32\"]],\"b\":[\"alias\",[\"fr\",\"bin32\"]]}]],\"bare\":[\"alias\",[\"fr\",\"bin32\"]],\"huh\":["
86 "\"variant\",[[\"alias\",[\"fr\",\"bin32\"]],\"GoodExample\"]]}\n");
87}
struct ComplicatedSchema complicated_schema
struct BadExampleOutOfObject bad_example_out_of_object
struct BadExampleOverlap bad_example_overlap
struct GoodExample good_example
struct BadExampleIncomplete bad_example_incomplete
struct BadExampleCompileTimeError bad_example_compile_time_error
Entry point for Barretenberg command-line interface.
TEST(MegaCircuitBuilder, CopyConstructor)
std::string check_msgpack_method(const T &object)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string msgpack_schema_to_string(const auto &obj)
Print's an object's derived msgpack schema as a string.
std::variant< bb::fr, GoodExample > huh
std::optional< GoodExample > good_or_not
std::vector< std::array< fr, 20 > > array
MSGPACK_FIELDS(array, good_or_not, bare, huh)
MSGPACK_FIELDS(a, b)