Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
test_helper.hpp
Go to the documentation of this file.
1#pragma once
2#include "msgpack_impl.hpp"
3#include <string>
4
5/***
6 * Do a roundtrip test encode/decode of an object.
7 * @tparam T The object type.
8 * @param object The object. Can be a default-initialized object.
9 */
10template <typename T> std::pair<T, T> msgpack_roundtrip(const T& object)
11{
12 T result;
13 msgpack::sbuffer buffer;
14 msgpack::pack(buffer, object);
15 msgpack::unpack(buffer.data(), buffer.size()).get().convert(result);
16 return { object, result };
17}
18
19template <typename T> inline T call_msgpack_cbind(auto cbind_func, auto... test_args)
20{
21 auto [input, input_len] = msgpack_encode_buffer(std::make_tuple(test_args...));
22 uint8_t* output;
23 size_t output_len;
24 cbind_func(input, input_len, &output, &output_len);
25 T actual_ret;
26 msgpack::unpack((const char*)output, output_len).get().convert(actual_ret);
27 aligned_free(output);
28 return actual_ret;
29}
30
31// Running the end-to-end tests that msgpack bind creates
32// This should suffice in testing the binding interface, function tests can be separate
33inline auto call_func_and_wrapper(auto func, auto cbind_func, auto... test_args)
34{
35 auto expected_ret = func(test_args...);
36 auto actual_ret = call_msgpack_cbind<decltype(expected_ret)>(cbind_func, test_args...);
37 return std::make_pair(actual_ret, expected_ret);
38}
uint8_t buffer[RANDOM_BUFFER_SIZE]
Definition engine.cpp:34
std::pair< uint8_t *, size_t > msgpack_encode_buffer(auto &&obj)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::pair< T, T > msgpack_roundtrip(const T &object)
auto call_func_and_wrapper(auto func, auto cbind_func, auto... test_args)
T call_msgpack_cbind(auto cbind_func, auto... test_args)