Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_data_handlers.cpp
Go to the documentation of this file.
1#define BOOST_TEST_MODULE trace_data_handlers
2#include <boost/test/included/unit_test.hpp>
3
5
7
8using namespace sysio;
9using namespace sysio::trace_api;
10using namespace sysio::trace_api::test_common;
11
12BOOST_AUTO_TEST_SUITE(abi_data_handler_tests)
14 {
15 auto action = action_trace_v0 {
16 0, "alice"_n, "alice"_n, "foo"_n, {}, {}
17 };
18 std::variant<action_trace_v0, action_trace_v1> action_trace_t = action;
20
21 auto expected = fc::variant();
22 auto actual = handler.serialize_to_variant(action_trace_t, [](){});
23
24 BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element());
25 }
26
27 BOOST_AUTO_TEST_CASE(empty_data_v1)
28 {
29 auto action = action_trace_v1 {
30 {0, "alice"_n, "alice"_n, "foo"_n, {}, {}},
31 {}
32 };
33 std::variant<action_trace_v0, action_trace_v1> action_trace_t = action;
35
36 auto expected = fc::variant();
37 auto actual = handler.serialize_to_variant(action_trace_t, [](){});
38
39 BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element());
40 }
41
43 {
44 auto action = action_trace_v0 {
45 0, "alice"_n, "alice"_n, "foo"_n, {}, {0x00, 0x01, 0x02, 0x03}
46 };
47 std::variant<action_trace_v0, action_trace_v1> action_trace_t = action;
49
50 auto expected = fc::variant();
51 auto actual = handler.serialize_to_variant(action_trace_t, [](){});
52
53 BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element());
54 }
55
57 {
58 auto action = action_trace_v1 {
59 { 0, "alice"_n, "alice"_n, "foo"_n, {}, {0x00, 0x01, 0x02, 0x03}},
60 {0x04, 0x05, 0x06, 0x07}
61 };
62 std::variant<action_trace_v0, action_trace_v1> action_trace_t = action;
64
65 auto expected = fc::variant();
66 auto actual = handler.serialize_to_variant(action_trace_t, [](){});
67
68 BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element());
69 }
70
72 {
73 auto action = action_trace_v0 {
74 0, "alice"_n, "alice"_n, "foo"_n, {}, {0x00, 0x01, 0x02, 0x03}
75 };
76
77 std::variant<action_trace_v0, action_trace_v1> action_trace_t = action;
78
79 auto abi = chain::abi_def ( {},
80 {
81 { "foo", "", { {"a", "varuint32"}, {"b", "varuint32"}, {"c", "varuint32"}, {"d", "varuint32"} } }
82 },
83 {
84 { "foo"_n, "foo", ""}
85 },
86 {}, {}, {}
87 );
88 abi.version = "sysio::abi/1.";
89
91 handler.add_abi("alice"_n, abi);
92
94 ("a", 0)
95 ("b", 1)
96 ("c", 2)
97 ("d", 3);
98
99 auto actual = handler.serialize_to_variant(action_trace_t, [](){});
100
101 BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element());
102 }
103
105 {
106 auto action = action_trace_v1 {
107 { 0, "alice"_n, "alice"_n, "foo"_n, {}, {0x00, 0x01, 0x02, 0x03}},
108 {0x04, 0x05, 0x06, 0x07}
109 };
110
111 std::variant<action_trace_v0, action_trace_v1> action_trace_t = action;
112
113 auto abi = chain::abi_def ( {},
114 {
115 { "foo", "", { {"a", "varuint32"}, {"b", "varuint32"}, {"c", "varuint32"}, {"d", "varuint32"} } }
116 },
117 {
118 { "foo"_n, "foo", ""}
119 },
120 {}, {}, {}
121 );
122 abi.version = "sysio::abi/1.";
123
125 handler.add_abi("alice"_n, abi);
126
128 ("a", 0)
129 ("b", 1)
130 ("c", 2)
131 ("d", 3);
132
133 auto actual = handler.serialize_to_variant(action_trace_t, [](){});
134
135 BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element());
136 }
137
138 BOOST_AUTO_TEST_CASE(basic_abi_wrong_type)
139 {
140 auto action = action_trace_v0 {
141 0, "alice"_n, "alice"_n, "foo"_n, {}, {0x00, 0x01, 0x02, 0x03}
142 };
143
144 std::variant<action_trace_v0, action_trace_v1> action_trace_t = action;
145
146 auto abi = chain::abi_def ( {},
147 {
148 { "foo", "", { {"a", "varuint32"}, {"b", "varuint32"}, {"c", "varuint32"}, {"d", "varuint32"} } }
149 },
150 {
151 { "bar"_n, "foo", ""}
152 },
153 {}, {}, {}
154 );
155 abi.version = "sysio::abi/1.";
156
158 handler.add_abi("alice"_n, abi);
159
160 auto expected = fc::variant();
161
162 auto actual = handler.serialize_to_variant(action_trace_t, [](){});
163
164 BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element());
165 }
166
167 BOOST_AUTO_TEST_CASE(basic_abi_wrong_type_v1)
168 {
169 auto action = action_trace_v1 {
170 { 0, "alice"_n, "alice"_n, "foo"_n, {}, {0x00, 0x01, 0x02, 0x03}},
171 {0x04, 0x05, 0x06, 0x07}
172 };
173 std::variant<action_trace_v0, action_trace_v1> action_trace_t = action;
174
175 auto abi = chain::abi_def ( {},
176 {
177 { "foo", "", { {"a", "varuint32"}, {"b", "varuint32"}, {"c", "varuint32"}, {"d", "varuint32"} } }
178 },
179 {
180 { "bar"_n, "foo", ""}
181 },
182 {}, {}, {}
183 );
184 abi.version = "sysio::abi/1.";
185
187 handler.add_abi("alice"_n, abi);
188
189 auto expected = fc::variant();
190
191 auto actual = handler.serialize_to_variant(action_trace_t, [](){});
192
193 BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element());
194 }
195
196 BOOST_AUTO_TEST_CASE(basic_abi_insufficient_data)
197 {
198 auto action = action_trace_v0 {
199 0, "alice"_n, "alice"_n, "foo"_n, {}, {0x00, 0x01, 0x02}
200 };
201
202 std::variant<action_trace_v0, action_trace_v1> action_trace_t = action;
203
204 auto abi = chain::abi_def ( {},
205 {
206 { "foo", "", { {"a", "varuint32"}, {"b", "varuint32"}, {"c", "varuint32"}, {"d", "varuint32"} } }
207 },
208 {
209 { "foo"_n, "foo", ""}
210 },
211 {}, {}, {}
212 );
213 abi.version = "sysio::abi/1.";
214
215 bool log_called = false;
216 abi_data_handler handler([&log_called](const exception_with_context& ){log_called = true;});
217 handler.add_abi("alice"_n, abi);
218
219 auto expected = fc::variant();
220
221 auto actual = handler.serialize_to_variant(action_trace_t, [](){});
222
223 BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element());
224 BOOST_TEST(log_called);
225 }
226
227BOOST_AUTO_TEST_SUITE_END()
An order-preserving dictionary of variants.
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
void add_abi(const chain::name &name, const chain::abi_def &abi)
auto to_kv(const fc::variant &v)
std::tuple< const std::exception_ptr &, char const *, uint64_t, char const * > exception_with_context
Definition common.hpp:40
BOOST_AUTO_TEST_CASE(empty_data)