Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_responses.cpp
Go to the documentation of this file.
1#define BOOST_TEST_MODULE trace_data_responses
2#include <boost/test/included/unit_test.hpp>
3
5
8
9using namespace sysio;
10using namespace sysio::trace_api;
11using namespace sysio::trace_api::test_common;
12
34
35 constexpr static auto default_mock_data_handler_v0 = [](const action_trace_v0& a, const yield_function&) ->std::tuple<fc::variant, std::optional<fc::variant>> {
36 return {fc::mutable_variant_object()("hex" , fc::to_hex(a.data.data(), a.data.size())),{}};
37 };
38
39 constexpr static auto default_mock_data_handler_v1 = [](const action_trace_v1& a, const yield_function&) -> std::tuple<fc::variant, std::optional<fc::variant>>{
40 return {fc::mutable_variant_object()("hex" , fc::to_hex(a.data.data(), a.data.size())), {fc::mutable_variant_object()("hex" , fc::to_hex(a.return_value.data(), a.return_value.size()))}};
41 };
42
47
48 template<typename ActionTrace>
49 std::tuple<fc::variant, std::optional<fc::variant>> serialize_to_variant(const ActionTrace & action, const yield_function& yield) {
50 if constexpr(std::is_same_v<ActionTrace, action_trace_v0>){
51 return fixture.mock_data_handler_v0(action, yield);
52 }
53 else if constexpr(std::is_same_v<ActionTrace, action_trace_v1>){
54 return fixture.mock_data_handler_v1(action, yield);
55 }
56 }
57
59 };
60
71
72 fc::variant get_block_trace( uint32_t block_height, const yield_function& yield = {} ) {
73 return response_impl.get_block_trace( block_height, yield );
74 }
75
76 // fixture data and methods
78 std::function<std::tuple<fc::variant, std::optional<fc::variant>>(const action_trace_v0&, const yield_function&)> mock_data_handler_v0 = default_mock_data_handler_v0;
79 std::function<std::tuple<fc::variant, std::optional<fc::variant>>(const action_trace_v1&, const yield_function&)> mock_data_handler_v1 = default_mock_data_handler_v1;
80
82
83};
84
85BOOST_AUTO_TEST_SUITE(trace_responses)
87 {
88 auto block_trace = block_trace_v1 {
89 {
90 "b000000000000000000000000000000000000000000000000000000000000001"_h,
91 1,
92 "0000000000000000000000000000000000000000000000000000000000000000"_h,
94 "bp.one"_n
95 },
96 "0000000000000000000000000000000000000000000000000000000000000000"_h,
97 "0000000000000000000000000000000000000000000000000000000000000000"_h,
98 0,
99 {}
100 };
101
102 fc::variant expected_response = fc::mutable_variant_object()
103 ("id", "b000000000000000000000000000000000000000000000000000000000000001")
104 ("number", 1)
105 ("previous_id", "0000000000000000000000000000000000000000000000000000000000000000")
106 ("status", "pending")
107 ("timestamp", "2000-01-01T00:00:00.000Z")
108 ("producer", "bp.one")
109 ("transaction_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
110 ("action_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
111 ("schedule_version", 0)
112 ("transactions", fc::variants() )
113 ;
114
115 mock_get_block = [&block_trace]( uint32_t height, const yield_function& ) -> get_block_t {
116 BOOST_TEST(height == 1);
117 return std::make_tuple(data_log_entry{block_trace}, false);
118 };
119
120 fc::variant actual_response = get_block_trace( 1 );
121
122 BOOST_TEST(to_kv(expected_response) == to_kv(actual_response), boost::test_tools::per_element());
123 }
124
126 {
128 0,
129 "receiver"_n, "contract"_n, "action"_n,
130 {{ "alice"_n, "active"_n }},
131 { 0x00, 0x01, 0x02, 0x03 }
132 };
133
135 "0000000000000000000000000000000000000000000000000000000000000001"_h,
136 {
138 }},
139 fc::enum_type<uint8_t, chain::transaction_receipt_header::status_enum>{chain::transaction_receipt_header::status_enum::executed},
140 10,
141 5,
142 std::vector<chain::signature_type>{ chain::signature_type() },
143 { chain::time_point(), 1, 0, 100, 50, 0 }
144 };
145
146 auto block_trace = block_trace_v1 {
147 {
148 "b000000000000000000000000000000000000000000000000000000000000001"_h,
149 1,
150 "0000000000000000000000000000000000000000000000000000000000000000"_h,
152 "bp.one"_n
153 },
154 "0000000000000000000000000000000000000000000000000000000000000000"_h,
155 "0000000000000000000000000000000000000000000000000000000000000000"_h,
156 0,
157 {
159 }
160 };
161
162 fc::variant expected_response = fc::mutable_variant_object()
163 ("id", "b000000000000000000000000000000000000000000000000000000000000001")
164 ("number", 1)
165 ("previous_id", "0000000000000000000000000000000000000000000000000000000000000000")
166 ("status", "pending")
167 ("timestamp", "2000-01-01T00:00:00.000Z")
168 ("producer", "bp.one")
169 ("transaction_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
170 ("action_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
171 ("schedule_version", 0)
172 ("transactions", fc::variants({
174 ("id", "0000000000000000000000000000000000000000000000000000000000000001")
175 ("actions", fc::variants({
177 ("global_sequence", 0)
178 ("receiver", "receiver")
179 ("account", "contract")
180 ("action", "action")
181 ("authorization", fc::variants({
183 ("account", "alice")
184 ("permission", "active")
185 }))
186 ("data", "00010203")
187 ("params", fc::mutable_variant_object()
188 ("hex", "00010203"))
189 }))
190 ("status", "executed")
191 ("cpu_usage_us", 10)
192 ("net_usage_words", 5)
193 ("signatures", fc::variants({"SIG_K1_111111111111111111111111111111111111111111111111111111111111111116uk5ne"}))
194 ("transaction_header", fc::mutable_variant_object()
195 ("expiration", "1970-01-01T00:00:00")
196 ("ref_block_num", 1)
197 ("ref_block_prefix", 0)
198 ("max_net_usage_words", 100)
199 ("max_cpu_usage_ms", 50)
200 ("delay_sec", 0)
201 )
202 }))
203 ;
204
205 mock_get_block = [&block_trace]( uint32_t height, const yield_function& ) -> get_block_t {
206 BOOST_TEST(height == 1);
207 return std::make_tuple(data_log_entry(block_trace), false);
208 };
209
210 fc::variant actual_response = get_block_trace( 1 );
211
212 BOOST_TEST(to_kv(expected_response) == to_kv(actual_response), boost::test_tools::per_element());
213 }
214
215 BOOST_FIXTURE_TEST_CASE(basic_block_response_no_params, response_test_fixture)
216 {
217 auto block_trace = block_trace_v1 {
218 {
219 "b000000000000000000000000000000000000000000000000000000000000001"_h,
220 1,
221 "0000000000000000000000000000000000000000000000000000000000000000"_h,
223 "bp.one"_n
224 },
225 "0000000000000000000000000000000000000000000000000000000000000000"_h,
226 "0000000000000000000000000000000000000000000000000000000000000000"_h,
227 0,
228 {
229 {
230 {
231 "0000000000000000000000000000000000000000000000000000000000000001"_h,
232 {
233 {
234 0,
235 "receiver"_n, "contract"_n, "action"_n,
236 {{ "alice"_n, "active"_n }},
237 { 0x00, 0x01, 0x02, 0x03 }
238 }
239 }
240 },
241 fc::enum_type<uint8_t, chain::transaction_receipt_header::status_enum>{chain::transaction_receipt_header::status_enum::executed},
242 10,
243 5,
244 std::vector<chain::signature_type>{ chain::signature_type() },
245 { chain::time_point(), 1, 0, 100, 50, 0 }
246 }
247 }
248 };
249
250 fc::variant expected_response = fc::mutable_variant_object()
251 ("id", "b000000000000000000000000000000000000000000000000000000000000001")
252 ("number", 1)
253 ("previous_id", "0000000000000000000000000000000000000000000000000000000000000000")
254 ("status", "pending")
255 ("timestamp", "2000-01-01T00:00:00.000Z")
256 ("producer", "bp.one")
257 ("transaction_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
258 ("action_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
259 ("schedule_version", 0)
260 ("transactions", fc::variants({
262 ("id", "0000000000000000000000000000000000000000000000000000000000000001")
263 ("actions", fc::variants({
265 ("global_sequence", 0)
266 ("receiver", "receiver")
267 ("account", "contract")
268 ("action", "action")
269 ("authorization", fc::variants({
271 ("account", "alice")
272 ("permission", "active")
273 }))
274 ("data", "00010203")
275 }))
276 ("status", "executed")
277 ("cpu_usage_us", 10)
278 ("net_usage_words", 5)
279 ("signatures", fc::variants({"SIG_K1_111111111111111111111111111111111111111111111111111111111111111116uk5ne"}))
280 ("transaction_header", fc::mutable_variant_object()
281 ("expiration", "1970-01-01T00:00:00")
282 ("ref_block_num", 1)
283 ("ref_block_prefix", 0)
284 ("max_net_usage_words", 100)
285 ("max_cpu_usage_ms", 50)
286 ("delay_sec", 0)
287 )
288 }))
289 ;
290
291 mock_get_block = [&block_trace]( uint32_t height, const yield_function& ) -> get_block_t {
292 BOOST_TEST(height == 1);
293 return std::make_tuple(data_log_entry(block_trace), false);
294 };
295
296 // simulate an inability to parse the parameters
297 mock_data_handler_v0 = [](const action_trace_v0&, const yield_function&) -> std::tuple<fc::variant, std::optional<fc::variant>> {
298 return {};
299 };
300
301 fc::variant actual_response = get_block_trace( 1 );
302
303 BOOST_TEST(to_kv(expected_response) == to_kv(actual_response), boost::test_tools::per_element());
304 }
305
306 BOOST_FIXTURE_TEST_CASE(basic_block_response_unsorted, response_test_fixture)
307 {
308 auto block_trace = block_trace_v1 {
309 {
310 "b000000000000000000000000000000000000000000000000000000000000001"_h,
311 1,
312 "0000000000000000000000000000000000000000000000000000000000000000"_h,
314 "bp.one"_n
315 },
316 "0000000000000000000000000000000000000000000000000000000000000000"_h,
317 "0000000000000000000000000000000000000000000000000000000000000000"_h,
318 0,
319 {
320 {
321 {
322 "0000000000000000000000000000000000000000000000000000000000000001"_h,
323 {
324 {
325 1,
326 "receiver"_n, "contract"_n, "action"_n,
327 {{ "alice"_n, "active"_n }},
328 { 0x01, 0x01, 0x01, 0x01 }
329 },
330 {
331 0,
332 "receiver"_n, "contract"_n, "action"_n,
333 {{ "alice"_n, "active"_n }},
334 { 0x00, 0x00, 0x00, 0x00 }
335 },
336 {
337 2,
338 "receiver"_n, "contract"_n, "action"_n,
339 {{ "alice"_n, "active"_n }},
340 { 0x02, 0x02, 0x02, 0x02 }
341 }
342 }
343 },
344 fc::enum_type<uint8_t, chain::transaction_receipt_header::status_enum>{chain::transaction_receipt_header::status_enum::executed},
345 10,
346 5,
348 { chain::time_point(), 1, 0, 100, 50, 0 }
349 }
350 }
351 };
352
353 fc::variant expected_response = fc::mutable_variant_object()
354 ("id", "b000000000000000000000000000000000000000000000000000000000000001")
355 ("number", 1)
356 ("previous_id", "0000000000000000000000000000000000000000000000000000000000000000")
357 ("status", "pending")
358 ("timestamp", "2000-01-01T00:00:00.000Z")
359 ("producer", "bp.one")
360 ("transaction_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
361 ("action_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
362 ("schedule_version", 0)
363 ("transactions", fc::variants({
365 ("id", "0000000000000000000000000000000000000000000000000000000000000001")
366 ("actions", fc::variants({
368 ("global_sequence", 0)
369 ("receiver", "receiver")
370 ("account", "contract")
371 ("action", "action")
372 ("authorization", fc::variants({
374 ("account", "alice")
375 ("permission", "active")
376 }))
377 ("data", "00000000")
378 ,
380 ("global_sequence", 1)
381 ("receiver", "receiver")
382 ("account", "contract")
383 ("action", "action")
384 ("authorization", fc::variants({
386 ("account", "alice")
387 ("permission", "active")
388 }))
389 ("data", "01010101")
390 ,
392 ("global_sequence", 2)
393 ("receiver", "receiver")
394 ("account", "contract")
395 ("action", "action")
396 ("authorization", fc::variants({
398 ("account", "alice")
399 ("permission", "active")
400 }))
401 ("data", "02020202")
402 }))
403 ("status", "executed")
404 ("cpu_usage_us", 10)
405 ("net_usage_words", 5)
406 ("signatures", fc::variants({"SIG_K1_111111111111111111111111111111111111111111111111111111111111111116uk5ne"}))
407 ("transaction_header", fc::mutable_variant_object()
408 ("expiration", "1970-01-01T00:00:00")
409 ("ref_block_num", 1)
410 ("ref_block_prefix", 0)
411 ("max_net_usage_words", 100)
412 ("max_cpu_usage_ms", 50)
413 ("delay_sec", 0)
414 )
415 }))
416 ;
417
418 mock_get_block = [&block_trace]( uint32_t height, const yield_function& ) -> get_block_t {
419 BOOST_TEST(height == 1);
420 return std::make_tuple(data_log_entry(block_trace), false);
421 };
422
423 // simulate an inability to parse the parameters
424 mock_data_handler_v0 = [](const action_trace_v0&, const yield_function&) -> std::tuple<fc::variant, std::optional<fc::variant>> {
425 return {};
426 };
427
428 fc::variant actual_response = get_block_trace( 1 );
429
430 BOOST_TEST(to_kv(expected_response) == to_kv(actual_response), boost::test_tools::per_element());
431 }
432
434 {
435 auto block_trace = block_trace_v1{
436 {
437 "b000000000000000000000000000000000000000000000000000000000000001"_h,
438 1,
439 "0000000000000000000000000000000000000000000000000000000000000000"_h,
441 "bp.one"_n
442 },
443 "0000000000000000000000000000000000000000000000000000000000000000"_h,
444 "0000000000000000000000000000000000000000000000000000000000000000"_h,
445 0,
446 {}
447 };
448
449 fc::variant expected_response = fc::mutable_variant_object()
450 ("id", "b000000000000000000000000000000000000000000000000000000000000001")
451 ("number", 1)
452 ("previous_id", "0000000000000000000000000000000000000000000000000000000000000000")
453 ("status", "irreversible")
454 ("timestamp", "2000-01-01T00:00:00.000Z")
455 ("producer", "bp.one")
456 ("transaction_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
457 ("action_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
458 ("schedule_version", 0)
459 ("transactions", fc::variants() )
460 ;
461
462 mock_get_block = [&block_trace]( uint32_t height, const yield_function& ) -> get_block_t {
463 BOOST_TEST(height == 1);
464 return std::make_tuple(data_log_entry(block_trace), true);
465 };
466
467 fc::variant response = get_block_trace( 1 );
468 BOOST_TEST(to_kv(expected_response) == to_kv(response), boost::test_tools::per_element());
469
470 }
471
473 {
474 mock_get_block = []( uint32_t height, const yield_function& ) -> get_block_t {
475 BOOST_TEST(height == 1);
476 throw bad_data_exception("mock exception");
477 };
478
479 BOOST_REQUIRE_THROW(get_block_trace( 1 ), bad_data_exception);
480 }
481
483 {
484 mock_get_block = []( uint32_t height, const yield_function& ) -> get_block_t {
485 BOOST_TEST(height == 1);
486 return {};
487 };
488
489 fc::variant null_response = get_block_trace( 1 );
490
491 BOOST_TEST(null_response.is_null());
492 }
493
495 {
496 auto block_trace = block_trace_v1 {
497 {
498 "b000000000000000000000000000000000000000000000000000000000000001"_h,
499 1,
500 "0000000000000000000000000000000000000000000000000000000000000000"_h,
502 "bp.one"_n
503 },
504 "0000000000000000000000000000000000000000000000000000000000000000"_h,
505 "0000000000000000000000000000000000000000000000000000000000000000"_h,
506 0,
507 {
508 {
509 {
510 "0000000000000000000000000000000000000000000000000000000000000001"_h,
511 {
512 {
513 0,
514 "receiver"_n, "contract"_n, "action"_n,
515 {{ "alice"_n, "active"_n }},
516 { 0x00, 0x01, 0x02, 0x03 }
517 }
518 }
519 },
520 fc::enum_type<uint8_t, chain::transaction_receipt_header::status_enum>{chain::transaction_receipt_header::status_enum::executed},
521 10,
522 5,
523 std::vector<chain::signature_type>{chain::signature_type()},
524 {chain::time_point(), 1, 0, 100, 50, 0}
525 }
526 }
527 };
528
529 mock_get_block = [&block_trace]( uint32_t height, const yield_function& ) -> get_block_t {
530 BOOST_TEST(height == 1);
531 return std::make_tuple(data_log_entry(block_trace), false);
532 };
533
534 int countdown = 3;
535 yield_function yield = [&]() {
536 if (countdown-- == 0) {
537 throw yield_exception("mock");
538 }
539 };
540
541 BOOST_REQUIRE_THROW(get_block_trace( 1, yield ), yield_exception);
542 }
543
544 BOOST_FIXTURE_TEST_CASE(yield_throws_from_get_block, response_test_fixture)
545 {
546 // no other yield calls will throw
547 yield_function yield = [&]() {
548 };
549
550 // simulate a yield throw inside get block
551 mock_get_block = []( uint32_t height, const yield_function& yield) -> get_block_t {
552 throw yield_exception("mock exception");
553 };
554
555
556 BOOST_REQUIRE_THROW(get_block_trace( 1, yield ), yield_exception);
557 }
558
560 {
561 auto block_trace = block_trace_v0 {
562 "b000000000000000000000000000000000000000000000000000000000000001"_h,
563 1,
564 "0000000000000000000000000000000000000000000000000000000000000000"_h,
566 "bp.one"_n,
567 {
568 {
569 "0000000000000000000000000000000000000000000000000000000000000001"_h,
570 {
571 {
572 0,
573 "receiver"_n, "contract"_n, "action"_n,
574 {{ "alice"_n, "active"_n }},
575 { 0x00, 0x01, 0x02, 0x03 }
576 }
577 }
578 }
579 }
580 };
581
582 fc::variant expected_response = fc::mutable_variant_object()
583 ("id", "b000000000000000000000000000000000000000000000000000000000000001")
584 ("number", 1)
585 ("previous_id", "0000000000000000000000000000000000000000000000000000000000000000")
586 ("status", "pending")
587 ("timestamp", "2000-01-01T00:00:00.000Z")
588 ("producer", "bp.one")
589 ("transactions", fc::variants({
591 ("id", "0000000000000000000000000000000000000000000000000000000000000001")
592 ("actions", fc::variants({
594 ("global_sequence", 0)
595 ("receiver", "receiver")
596 ("account", "contract")
597 ("action", "action")
598 ("authorization", fc::variants({
600 ("account", "alice")
601 ("permission", "active")
602 }))
603 ("data", "00010203")
604 ("params", fc::mutable_variant_object()
605 ("hex", "00010203")
606 )
607 }))
608 }))
609 ;
610
611 mock_get_block = [&block_trace]( uint32_t height, const yield_function& ) -> get_block_t {
612 BOOST_TEST(height == 1);
613 return std::make_tuple(data_log_entry(block_trace), false);
614 };
615
616 fc::variant actual_response = get_block_trace( 1 );
617
618 BOOST_TEST(to_kv(expected_response) == to_kv(actual_response), boost::test_tools::per_element());
619 }
620
621 BOOST_FIXTURE_TEST_CASE(basic_empty_block_response_v2, response_test_fixture)
622 {
623 auto block_trace = block_trace_v2 {
624 "b000000000000000000000000000000000000000000000000000000000000001"_h, // block id
625 1,
626 "0000000000000000000000000000000000000000000000000000000000000000"_h, // previous id
628 "bp.one"_n,
629 "0000000000000000000000000000000000000000000000000000000000000000"_h, // transaction mroot
630 "0000000000000000000000000000000000000000000000000000000000000000"_h, // action mroot
631 0, // schedule version
632 {} // transactions
633 };
634
635 fc::variant expected_response = fc::mutable_variant_object()
636 ("id", "b000000000000000000000000000000000000000000000000000000000000001")
637 ("number", 1)
638 ("previous_id", "0000000000000000000000000000000000000000000000000000000000000000")
639 ("status", "pending")
640 ("timestamp", "2000-01-01T00:00:00.000Z")
641 ("producer", "bp.one")
642 ("transaction_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
643 ("action_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
644 ("schedule_version", 0)
645 ("transactions", fc::variants() )
646 ;
647
648 mock_get_block = [&block_trace]( uint32_t height, const yield_function& ) -> get_block_t {
649 BOOST_TEST(height == 1);
650 return std::make_tuple(data_log_entry{block_trace}, false);
651 };
652
653 fc::variant actual_response = get_block_trace( 1 );
654
655 BOOST_TEST(to_kv(expected_response) == to_kv(actual_response), boost::test_tools::per_element());
656 }
657
659 {
661 {
662 0,
663 "receiver"_n, "contract"_n, "action"_n,
664 {{ "alice"_n, "active"_n }},
665 { 0x00, 0x01, 0x02, 0x03 }
666 },
667 { 0x04, 0x05, 0x06, 0x07 }
668 };
669
671 "0000000000000000000000000000000000000000000000000000000000000001"_h,
672 std::vector<action_trace_v1> {
674 },
675 fc::enum_type<uint8_t, chain::transaction_receipt_header::status_enum>{chain::transaction_receipt_header::status_enum::executed},
676 10, // cpu_usage_us
677 5, // net_usage_words
678 std::vector<chain::signature_type>{ chain::signature_type() }, // signatures
679 { chain::time_point(), 1, 0, 100, 50, 0 } // trx_header
680 };// trn end
681
682 auto block_trace = block_trace_v2 {
683 "b000000000000000000000000000000000000000000000000000000000000001"_h, // block id
684 1,
685 "0000000000000000000000000000000000000000000000000000000000000000"_h, // previous id
687 "bp.one"_n,
688 "0000000000000000000000000000000000000000000000000000000000000000"_h, // transaction mroot
689 "0000000000000000000000000000000000000000000000000000000000000000"_h, //action mroot
690 0, // schedule version
691 std::vector<transaction_trace_v2> {
693 }
694 };
695
696 fc::variant expected_response = fc::mutable_variant_object()
697 ("id", "b000000000000000000000000000000000000000000000000000000000000001")
698 ("number", 1)
699 ("previous_id", "0000000000000000000000000000000000000000000000000000000000000000")
700 ("status", "pending")
701 ("timestamp", "2000-01-01T00:00:00.000Z")
702 ("producer", "bp.one")
703 ("transaction_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
704 ("action_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
705 ("schedule_version", 0)
706 ("transactions", fc::variants({
708 ("id", "0000000000000000000000000000000000000000000000000000000000000001")
709 ("actions", fc::variants({
711 ("global_sequence", 0)
712 ("receiver", "receiver")
713 ("account", "contract")
714 ("action", "action")
715 ("authorization", fc::variants({
717 ("account", "alice")
718 ("permission", "active")
719 }))
720 ("data", "00010203")
721 ("return_value", "04050607")
722 ("params", fc::mutable_variant_object()
723 ("hex", "00010203"))
724 ("return_data", fc::mutable_variant_object()
725 ("hex", "04050607"))
726 }))
727 ("status", "executed")
728 ("cpu_usage_us", 10)
729 ("net_usage_words", 5)
730 ("signatures", fc::variants({"SIG_K1_111111111111111111111111111111111111111111111111111111111111111116uk5ne"}))
731 ("transaction_header", fc::mutable_variant_object()
732 ("expiration", "1970-01-01T00:00:00")
733 ("ref_block_num", 1)
734 ("ref_block_prefix", 0)
735 ("max_net_usage_words", 100)
736 ("max_cpu_usage_ms", 50)
737 ("delay_sec", 0)
738 )
739 }))
740 ;
741
742 mock_get_block = [&block_trace]( uint32_t height, const yield_function& ) -> get_block_t {
743 BOOST_TEST(height == 1);
744 return std::make_tuple(data_log_entry(block_trace), false);
745 };
746
747 fc::variant actual_response = get_block_trace( 1 );
748 BOOST_TEST(to_kv(expected_response) == to_kv(actual_response), boost::test_tools::per_element());
749 }
750
751 BOOST_FIXTURE_TEST_CASE(basic_block_response_no_params_v2, response_test_fixture)
752 {
754 {
755 0,
756 "receiver"_n, "contract"_n, "action"_n,
757 {{ "alice"_n, "active"_n }},
758 { 0x00, 0x01, 0x02, 0x03 }
759 },
760 { 0x04, 0x05, 0x06, 0x07 }
761 };
762
764 "0000000000000000000000000000000000000000000000000000000000000001"_h,
765 std::vector<action_trace_v1> {
767 },
768 fc::enum_type<uint8_t, chain::transaction_receipt_header::status_enum>{chain::transaction_receipt_header::status_enum::executed},
769 10,
770 5,
771 std::vector<chain::signature_type>{ chain::signature_type() },
772 { chain::time_point(), 1, 0, 100, 50, 0 }
773 };
774
775 auto block_trace = block_trace_v2 {
776 "b000000000000000000000000000000000000000000000000000000000000001"_h,
777 1,
778 "0000000000000000000000000000000000000000000000000000000000000000"_h,
780 "bp.one"_n,
781 "0000000000000000000000000000000000000000000000000000000000000000"_h,
782 "0000000000000000000000000000000000000000000000000000000000000000"_h,
783 0,
784 std::vector<transaction_trace_v2> {
786 }
787 };
788
789 fc::variant expected_response = fc::mutable_variant_object()
790 ("id", "b000000000000000000000000000000000000000000000000000000000000001")
791 ("number", 1)
792 ("previous_id", "0000000000000000000000000000000000000000000000000000000000000000")
793 ("status", "pending")
794 ("timestamp", "2000-01-01T00:00:00.000Z")
795 ("producer", "bp.one")
796 ("transaction_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
797 ("action_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
798 ("schedule_version", 0)
799 ("transactions", fc::variants({
801 ("id", "0000000000000000000000000000000000000000000000000000000000000001")
802 ("actions", fc::variants({
804 ("global_sequence", 0)
805 ("receiver", "receiver")
806 ("account", "contract")
807 ("action", "action")
808 ("authorization", fc::variants({
810 ("account", "alice")
811 ("permission", "active")
812 }))
813 ("data", "00010203")
814 ("return_value", "04050607")
815 }))
816 ("status", "executed")
817 ("cpu_usage_us", 10)
818 ("net_usage_words", 5)
819 ("signatures", fc::variants({"SIG_K1_111111111111111111111111111111111111111111111111111111111111111116uk5ne"}))
820 ("transaction_header", fc::mutable_variant_object()
821 ("expiration", "1970-01-01T00:00:00")
822 ("ref_block_num", 1)
823 ("ref_block_prefix", 0)
824 ("max_net_usage_words", 100)
825 ("max_cpu_usage_ms", 50)
826 ("delay_sec", 0))
827 })
828 );
829
830 mock_get_block = [&block_trace]( uint32_t height, const yield_function& ) -> get_block_t {
831 BOOST_TEST(height == 1);
832 return std::make_tuple(data_log_entry(block_trace), false);
833 };
834
835 // simulate an inability to parse the parameters and return_data
836 mock_data_handler_v1 = [](const action_trace_v1&, const yield_function&) -> std::tuple<fc::variant, std::optional<fc::variant>> {
837 return {};
838 };
839
840 fc::variant actual_response = get_block_trace( 1 );
841
842 BOOST_TEST(to_kv(expected_response) == to_kv(actual_response), boost::test_tools::per_element());
843 }
844
845 BOOST_FIXTURE_TEST_CASE(basic_block_response_unsorted_v2, response_test_fixture)
846 {
847 std::vector<action_trace_v1> actions = {
848 {
849 {
850 1,
851 "receiver"_n, "contract"_n, "action"_n,
852 {{ "alice"_n, "active"_n }},
853 { 0x01, 0x01, 0x01, 0x01 },
854 },
855 { 0x05, 0x05, 0x05, 0x05 }
856 },
857 {
858 {
859 0,
860 "receiver"_n, "contract"_n, "action"_n,
861 {{ "alice"_n, "active"_n }},
862 { 0x00, 0x00, 0x00, 0x00 }
863 },
864 { 0x04, 0x04, 0x04, 0x04}
865 },
866 {
867 {
868 2,
869 "receiver"_n, "contract"_n, "action"_n,
870 {{ "alice"_n, "active"_n }},
871 { 0x02, 0x02, 0x02, 0x02 }
872 },
873 { 0x06, 0x06, 0x06, 0x06 }
874 }
875 };
876
878 "0000000000000000000000000000000000000000000000000000000000000001"_h,
879 actions,
880 fc::enum_type<uint8_t, chain::transaction_receipt_header::status_enum>{chain::transaction_receipt_header::status_enum::executed},
881 10,
882 5,
884 { chain::time_point(), 1, 0, 100, 50, 0 }
885 };
886
887 auto block_trace = block_trace_v2 {
888 "b000000000000000000000000000000000000000000000000000000000000001"_h,
889 1,
890 "0000000000000000000000000000000000000000000000000000000000000000"_h,
892 "bp.one"_n,
893 "0000000000000000000000000000000000000000000000000000000000000000"_h,
894 "0000000000000000000000000000000000000000000000000000000000000000"_h,
895 0,
896 std::vector<transaction_trace_v2> {
898 }
899 };
900
901 fc::variant expected_response = fc::mutable_variant_object()
902 ("id", "b000000000000000000000000000000000000000000000000000000000000001")
903 ("number", 1)
904 ("previous_id", "0000000000000000000000000000000000000000000000000000000000000000")
905 ("status", "pending")
906 ("timestamp", "2000-01-01T00:00:00.000Z")
907 ("producer", "bp.one")
908 ("transaction_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
909 ("action_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
910 ("schedule_version", 0)
911 ("transactions", fc::variants({
913 ("id", "0000000000000000000000000000000000000000000000000000000000000001")
914 ("actions", fc::variants({
916 ("global_sequence", 0)
917 ("receiver", "receiver")
918 ("account", "contract")
919 ("action", "action")
920 ("authorization", fc::variants({
922 ("account", "alice")
923 ("permission", "active")
924 }))
925 ("data", "00000000")
926 ("return_value","04040404")
927 ,
929 ("global_sequence", 1)
930 ("receiver", "receiver")
931 ("account", "contract")
932 ("action", "action")
933 ("authorization", fc::variants({
935 ("account", "alice")
936 ("permission", "active")
937 }))
938 ("data", "01010101")
939 ("return_value", "05050505")
940 ,
942 ("global_sequence", 2)
943 ("receiver", "receiver")
944 ("account", "contract")
945 ("action", "action")
946 ("authorization", fc::variants({
948 ("account", "alice")
949 ("permission", "active")
950 }))
951 ("data", "02020202")
952 ("return_value", "06060606")
953 }))
954 ("status", "executed")
955 ("cpu_usage_us", 10)
956 ("net_usage_words", 5)
957 ("signatures", fc::variants({"SIG_K1_111111111111111111111111111111111111111111111111111111111111111116uk5ne"}))
958 ("transaction_header", fc::mutable_variant_object()
959 ("expiration", "1970-01-01T00:00:00")
960 ("ref_block_num", 1)
961 ("ref_block_prefix", 0)
962 ("max_net_usage_words", 100)
963 ("max_cpu_usage_ms", 50)
964 ("delay_sec", 0)
965 )
966 }))
967 ;
968
969 mock_get_block = [&block_trace]( uint32_t height, const yield_function& ) -> get_block_t {
970 BOOST_TEST(height == 1);
971 return std::make_tuple(data_log_entry(block_trace), false);
972 };
973
974 // simulate an inability to parse the parameters and return_data
975 mock_data_handler_v1 = [](const action_trace_v1&, const yield_function&) -> std::tuple<fc::variant, std::optional<fc::variant>> {
976 return {};
977 };
978
979 fc::variant actual_response = get_block_trace( 1 );
980
981 BOOST_TEST(to_kv(expected_response) == to_kv(actual_response), boost::test_tools::per_element());
982 }
983
985 {
986 auto block_trace = block_trace_v2 {
987 "b000000000000000000000000000000000000000000000000000000000000001"_h,
988 1,
989 "0000000000000000000000000000000000000000000000000000000000000000"_h,
991 "bp.one"_n,
992 "0000000000000000000000000000000000000000000000000000000000000000"_h,
993 "0000000000000000000000000000000000000000000000000000000000000000"_h,
994 0,
995 {}
996 };
997
998 fc::variant expected_response = fc::mutable_variant_object()
999 ("id", "b000000000000000000000000000000000000000000000000000000000000001")
1000 ("number", 1)
1001 ("previous_id", "0000000000000000000000000000000000000000000000000000000000000000")
1002 ("status", "irreversible")
1003 ("timestamp", "2000-01-01T00:00:00.000Z")
1004 ("producer", "bp.one")
1005 ("transaction_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
1006 ("action_mroot", "0000000000000000000000000000000000000000000000000000000000000000")
1007 ("schedule_version", 0)
1008 ("transactions", fc::variants() )
1009 ;
1010
1011 mock_get_block = [&block_trace]( uint32_t height, const yield_function& ) -> get_block_t {
1012 BOOST_TEST(height == 1);
1013 return std::make_tuple(data_log_entry(block_trace), true);
1014 };
1015
1016 fc::variant response = get_block_trace( 1 );
1017 BOOST_TEST(to_kv(expected_response) == to_kv(response), boost::test_tools::per_element());
1018
1019 }
1020
1022 {
1024 {
1025 0,
1026 "receiver"_n, "contract"_n, "action"_n,
1027 {{ "alice"_n, "active"_n }},
1028 { 0x00, 0x01, 0x02, 0x03 }
1029 },
1030 { 0x04, 0x05, 0x06, 0x07 }
1031 };
1032
1034 "0000000000000000000000000000000000000000000000000000000000000001"_h,
1035 std::vector<action_trace_v1> {
1037 },
1038 fc::enum_type<uint8_t, chain::transaction_receipt_header::status_enum>{chain::transaction_receipt_header::status_enum::executed},
1039 10,
1040 5,
1041 std::vector<chain::signature_type>{chain::signature_type()},
1042 {chain::time_point(), 1, 0, 100, 50, 0}
1043 };
1044
1045 auto block_trace = block_trace_v2 {
1046 "b000000000000000000000000000000000000000000000000000000000000001"_h,
1047 1,
1048 "0000000000000000000000000000000000000000000000000000000000000000"_h,
1050 "bp.one"_n,
1051 "0000000000000000000000000000000000000000000000000000000000000000"_h,
1052 "0000000000000000000000000000000000000000000000000000000000000000"_h,
1053 0,
1054 std::vector<transaction_trace_v2>{
1056 }
1057 };
1058
1059 mock_get_block = [&block_trace]( uint32_t height, const yield_function& ) -> get_block_t {
1060 BOOST_TEST(height == 1);
1061 return std::make_tuple(data_log_entry(block_trace), false);
1062 };
1063
1064 int countdown = 3;
1065 yield_function yield = [&]() {
1066 if (countdown-- == 0) {
1067 throw yield_exception("mock");
1068 }
1069 };
1070
1071 BOOST_REQUIRE_THROW(get_block_trace( 1, yield ), yield_exception);
1072 }
1073
1074BOOST_AUTO_TEST_SUITE_END()
static logger get(const fc::string &name=DEFAULT_LOGGER)
Definition logger.cpp:88
An order-preserving dictionary of variants.
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
bool is_null() const
Definition variant.cpp:309
fc::variant get_block_trace(uint32_t block_height, const yield_function &yield={})
#define DEFAULT_LOGGER
Definition logger.hpp:7
#define fc_dlog(LOGGER, FORMAT,...)
Definition logger.hpp:77
std::string string
Definition string.hpp:10
std::vector< fc::variant > variants
Definition variant.hpp:173
fc::string to_hex(const char *d, uint32_t s)
Definition hex.cpp:17
Definition name.hpp:106
auto to_kv(const fc::variant &v)
std::optional< std::tuple< data_log_entry, bool > > get_block_t
Definition common.hpp:49
std::variant< block_trace_v0, block_trace_v1, block_trace_v2 > data_log_entry
Definition data_log.hpp:9
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
unsigned int uint32_t
Definition stdint.h:126
mock_data_handler_provider(response_test_fixture &fixture)
std::tuple< fc::variant, std::optional< fc::variant > > serialize_to_variant(const ActionTrace &action, const yield_function &yield)
mock_logfile_provider(response_test_fixture &fixture)
get_block_t get_block(uint32_t height, const yield_function &yield={})
response_impl_type response_impl
std::function< std::tuple< fc::variant, std::optional< fc::variant > >(const action_trace_v1 &, const yield_function &)> mock_data_handler_v1
static constexpr auto default_mock_data_handler_v1
static constexpr auto default_mock_data_handler_v0
std::function< std::tuple< fc::variant, std::optional< fc::variant > >(const action_trace_v0 &, const yield_function &)> mock_data_handler_v0
std::function< get_block_t(uint32_t, const yield_function &)> mock_get_block
fc::variant get_block_trace(uint32_t block_height, const yield_function &yield={})
BOOST_FIXTURE_TEST_CASE(basic_empty_block_response, response_test_fixture)