1#define BOOST_TEST_MODULE trace_trace_file
2#include <boost/test/included/unit_test.hpp>
6#include <boost/filesystem.hpp>
17 std::vector<action_trace_v1> actions = {
21 "receiver"_n,
"contract"_n,
"action"_n,
22 {{
"alice"_n,
"active"_n }},
23 { 0x01, 0x01, 0x01, 0x01 }
25 { 0x05, 0x05, 0x05, 0x05 }
30 "receiver"_n,
"contract"_n,
"action"_n,
31 {{
"alice"_n,
"active"_n }},
32 { 0x00, 0x00, 0x00, 0x00 }
34 { 0x04, 0x04, 0x04, 0x04}
39 "receiver"_n,
"contract"_n,
"action"_n,
40 {{
"alice"_n,
"active"_n }},
41 { 0x02, 0x02, 0x02, 0x02 }
43 { 0x06, 0x06, 0x06, 0x06 }
48 "0000000000000000000000000000000000000000000000000000000000000001"_h,
58 "b000000000000000000000000000000000000000000000000000000000000001"_h,
60 "0000000000000000000000000000000000000000000000000000000000000000"_h,
63 "0000000000000000000000000000000000000000000000000000000000000000"_h,
64 "0000000000000000000000000000000000000000000000000000000000000000"_h,
66 std::vector<transaction_trace_v2> {
72 "b000000000000000000000000000000000000000000000000000000000000001"_h,
74 "0000000000000000000000000000000000000000000000000000000000000000"_h,
77 "0000000000000000000000000000000000000000000000000000000000000000"_h,
78 "0000000000000000000000000000000000000000000000000000000000000000"_h,
80 std::vector<transaction_trace_v2> {
87 "0000000000000000000000000000000000000000000000000000000000000001"_h,
89 "0000000000000000000000000000000000000000000000000000000000000003"_h,
94 "0000000000000000000000000000000000000000000000000000000000000000"_h,
95 "0000000000000000000000000000000000000000000000000000000000000000"_h,
100 "0000000000000000000000000000000000000000000000000000000000000001"_h,
104 "sysio.token"_n,
"sysio.token"_n,
"transfer"_n,
105 {{
"alice"_n,
"active"_n }},
110 "alice"_n,
"sysio.token"_n,
"transfer"_n,
111 {{
"alice"_n,
"active"_n }},
116 "bob"_n,
"sysio.token"_n,
"transfer"_n,
117 {{
"alice"_n,
"active"_n }},
133 "0000000000000000000000000000000000000000000000000000000000000002"_h,
135 "0000000000000000000000000000000000000000000000000000000000000005"_h,
139 "0000000000000000000000000000000000000000000000000000000000000000"_h,
140 "0000000000000000000000000000000000000000000000000000000000000000"_h,
145 "f000000000000000000000000000000000000000000000000000000000000004"_h,
158 "0000000000000000000000000000000000000000000000000000000000000001"_h,
160 "0000000000000000000000000000000000000000000000000000000000000003"_h,
165 "0000000000000000000000000000000000000000000000000000000000000001"_h,
169 "sysio.token"_n,
"sysio.token"_n,
"transfer"_n,
170 {{
"alice"_n,
"active"_n }},
175 "alice"_n,
"sysio.token"_n,
"transfer"_n,
176 {{
"alice"_n,
"active"_n }},
181 "bob"_n,
"sysio.token"_n,
"transfer"_n,
182 {{
"alice"_n,
"active"_n }},
191 "b000000000000000000000000000000000000000000000000000000000000001"_h, 5, 0
195 "b000000000000000000000000000000000000000000000000000000000000002"_h, 7, 0
200 const uint8_t bad_which = 0x7F;
202 file.write(
reinterpret_cast<const char*
>(&bad_which),
sizeof(
uint8_t));
211 test_store_provider(
const bfs::path& slice_dir,
uint32_t width, std::optional<uint32_t> minimum_irreversible_history_blocks = std::optional<uint32_t>(), std::optional<uint32_t> minimum_uncompressed_irreversible_history_blocks = std::optional<uint32_t>(),
size_t compression_seek_point_stride = 0)
212 :
store_provider(slice_dir,
width, minimum_irreversible_history_blocks, minimum_uncompressed_irreversible_history_blocks, compression_seek_point_stride) {
218 class vslice_datastream;
221 enum mode { read_mode, write_mode};
222 vslice(mode m = write_mode) : _mode(m) {}
223 unsigned long tellp()
const {
227 void seek(
unsigned long loc ) {
228 if (_mode == read_mode) {
229 if (loc > _buffer.size()) {
230 throw std::ios_base::failure(
"read vslice unable to seek to: " + std::to_string(loc) +
", end is at: " + std::to_string(_buffer.size()));
236 void seek_end(
long loc ) {
237 _pos = _buffer.size();
240 void read(
char*
d,
size_t n ) {
241 if( _pos + n > _buffer.size() ) {
242 throw std::ios_base::failure(
"vslice unable to read " + std::to_string( n ) +
" bytes; only can read " + std::to_string( _buffer.size() - _pos ) );
244 std::memcpy(
d, _buffer.data() + _pos, n);
248 void write(
const char*
d,
size_t n ) {
249 if (_mode == read_mode) {
250 throw std::ios_base::failure(
"read vslice should not have write called" );
252 if (_buffer.size() < _pos + n) {
253 _buffer.resize(_pos + n);
255 std::memcpy( _buffer.data() + _pos,
d, n);
267 vslice_datastream create_datastream();
269 std::vector<char> _buffer;
270 mode _mode = write_mode;
271 unsigned long _pos = 0lu;
276 class vslice_datastream {
278 explicit vslice_datastream( vslice& vs ) : _vs(vs) {}
280 void skip(
size_t s ) {
281 std::vector<char>
d(
s );
285 bool read(
char*
d,
size_t s ) {
290 bool get(
unsigned char& c ) {
return get( *(
char*)&c ); }
292 bool get(
char& c ) {
return read(&c, 1); }
298 inline vslice_datastream vslice::create_datastream() {
299 return vslice_datastream(*
this);
303BOOST_AUTO_TEST_SUITE(slice_tests)
307 const auto offset = append_store(bt_v1, vs );
308 BOOST_REQUIRE_EQUAL(offset,0);
310 const auto offset2 = append_store(bt2_v1, vs );
311 BOOST_REQUIRE(offset < offset2);
314 const auto bt_returned = extract_store<block_trace_v1>( vs );
315 BOOST_REQUIRE(bt_returned == bt_v1);
318 const auto bt_returned2 = extract_store<block_trace_v1>( vs );
319 BOOST_REQUIRE(bt_returned2 == bt2_v1);
325 const auto offset = append_store(bt_v0, vs );
326 BOOST_REQUIRE_EQUAL(offset,0);
328 const auto offset2 = append_store(bt_v1, vs );
329 BOOST_REQUIRE(offset < offset2);
331 const auto offset3 = append_store(block_trace1_v2, vs );
332 BOOST_REQUIRE(offset2 < offset3);
335 const auto bt_returned = extract_store<block_trace_v0>( vs );
336 BOOST_REQUIRE(bt_returned == bt_v0);
339 const auto bt_returned2 = extract_store<block_trace_v1>( vs );
340 BOOST_REQUIRE(bt_returned2 == bt_v1);
343 const auto bt_returned3 = extract_store<block_trace_v2>( vs );
344 BOOST_REQUIRE(bt_returned3 == block_trace1_v2);
350 const auto offset = append_store( be1, vs );
351 auto next_offset = vs._pos;
352 BOOST_REQUIRE(offset < next_offset);
353 const auto offset2 = append_store( le1, vs );
354 BOOST_REQUIRE(next_offset <= offset2);
355 BOOST_REQUIRE(offset2 < vs._pos);
356 next_offset = vs._pos;
357 const auto offset3 = append_store( be2, vs );
358 BOOST_REQUIRE(next_offset <= offset3);
359 BOOST_REQUIRE(offset3 < vs._pos);
360 next_offset = vs._pos;
361 const auto offset4 = append_store( le2, vs );
362 BOOST_REQUIRE(next_offset <= offset4);
363 BOOST_REQUIRE(offset4 < vs._pos);
366 const auto be_returned1 = extract_store<metadata_log_entry>( vs );
367 BOOST_REQUIRE(std::holds_alternative<block_entry_v0>(be_returned1));
368 const auto real_be_returned1 = std::get<block_entry_v0>(be_returned1);
369 const auto real_be1 = std::get<block_entry_v0>(be1);
370 BOOST_REQUIRE(real_be_returned1 == real_be1);
373 const auto le_returned1 = extract_store<metadata_log_entry>( vs );
374 BOOST_REQUIRE(std::holds_alternative<lib_entry_v0>(le_returned1));
375 const auto real_le_returned1 = std::get<lib_entry_v0>(le_returned1);
376 const auto real_le1 = std::get<lib_entry_v0>(le1);
377 BOOST_REQUIRE(real_le_returned1 == real_le1);
380 const auto be_returned2 = extract_store<metadata_log_entry>( vs );
381 BOOST_REQUIRE(std::holds_alternative<block_entry_v0>(be_returned2));
382 const auto real_be_returned2 = std::get<block_entry_v0>(be_returned2);
383 const auto real_be2 = std::get<block_entry_v0>(be2);
384 BOOST_REQUIRE(real_be_returned2 == real_be2);
387 const auto le_returned2 = extract_store<metadata_log_entry>( vs );
388 BOOST_REQUIRE(std::holds_alternative<lib_entry_v0>(le_returned2));
389 const auto real_le_returned2 = std::get<lib_entry_v0>(le_returned2);
390 const auto real_le2 = std::get<lib_entry_v0>(le2);
391 BOOST_REQUIRE(real_le_returned2 == real_le2);
397 slice_directory sd(tempdir.
path(), 100, std::optional<uint32_t>(), std::optional<uint32_t>(), 0);
401 slice_directory sd2(tempdir.
path(), 0x10, std::optional<uint32_t>(), std::optional<uint32_t>(), 0);
410 slice_directory sd(tempdir.
path(), 100, std::optional<uint32_t>(), std::optional<uint32_t>(), 0);
414 for (uint i = 0; i < 9; ++i) {
416 BOOST_REQUIRE(!found);
418 BOOST_REQUIRE_EQUAL(fp.parent_path().generic_string(), tempdir.
path().
generic_string());
419 const std::string expected_filename =
"trace_0000000" + std::to_string(i) +
"00-0000000" + std::to_string(i+1) +
"00.log";
420 BOOST_REQUIRE_EQUAL(fp.filename().generic_string(), expected_filename);
421 BOOST_REQUIRE(slice.
is_open());
422 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), 0);
423 BOOST_REQUIRE_EQUAL(slice.
tellp(), 0);
428 for (uint i = 0; i < 9; ++i) {
430 BOOST_REQUIRE(!found);
433 const std::string expected_filename =
"trace_index_0000000" + std::to_string(i) +
"00-0000000" + std::to_string(i+1) +
"00.log";
435 BOOST_REQUIRE(slice.
is_open());
438 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), data.size());
439 BOOST_REQUIRE_EQUAL(slice.
tellp(), data.size());
445 BOOST_REQUIRE(found);
448 std::string expected_filename =
"trace_0000000000-0000000100.log";
450 BOOST_REQUIRE(slice.
is_open());
451 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), 0);
452 BOOST_REQUIRE_EQUAL(slice.
tellp(), 0);
453 uint64_t offset = append_store(bt_v1, slice);
454 BOOST_REQUIRE_EQUAL(offset, 0);
456 BOOST_REQUIRE(slice.
tellp() > 0);
457 BOOST_REQUIRE_EQUAL(data.size(), slice.
tellp());
458 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), slice.
tellp());
459 uint64_t trace_file_size = bfs::file_size(fp);
464 BOOST_REQUIRE(found);
467 BOOST_REQUIRE(slice.
is_open());
468 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), trace_file_size);
469 BOOST_REQUIRE_EQUAL(slice.
tellp(), 0);
474 BOOST_REQUIRE(found);
477 BOOST_REQUIRE(slice.
is_open());
478 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), trace_file_size);
479 BOOST_REQUIRE_EQUAL(slice.
tellp(), trace_file_size);
484 BOOST_REQUIRE(found);
487 expected_filename =
"trace_index_0000000100-0000000200.log";
489 BOOST_REQUIRE(slice.
is_open());
492 const uint64_t header_size = data.size();
493 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), header_size);
494 BOOST_REQUIRE_EQUAL(slice.
tellp(), header_size);
495 offset = append_store(be1, slice);
496 BOOST_REQUIRE_EQUAL(offset, header_size);
498 const auto be1_size = data.size();
499 BOOST_REQUIRE_EQUAL(header_size + be1_size, slice.
tellp());
500 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), slice.
tellp());
504 BOOST_REQUIRE(found);
507 BOOST_REQUIRE(slice.
is_open());
508 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), header_size + be1_size);
509 BOOST_REQUIRE_EQUAL(slice.
tellp(), header_size);
513 BOOST_REQUIRE(found);
516 BOOST_REQUIRE(slice.
is_open());
517 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), header_size + be1_size);
518 BOOST_REQUIRE_EQUAL(slice.
tellp(), header_size + be1_size);
519 offset = append_store(le1, slice);
520 BOOST_REQUIRE_EQUAL(offset, header_size + be1_size);
522 const auto le1_size = data.size();
523 BOOST_REQUIRE_EQUAL(header_size + be1_size + le1_size, slice.
tellp());
524 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), slice.
tellp());
528 BOOST_REQUIRE(found);
531 BOOST_REQUIRE(slice.
is_open());
532 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), header_size + be1_size + le1_size);
533 BOOST_REQUIRE_EQUAL(slice.
tellp(), header_size);
540 slice_directory sd(tempdir.
path(), 100, std::optional<uint32_t>(), std::optional<uint32_t>(), 0);
545 BOOST_REQUIRE(!found);
547 BOOST_REQUIRE_EQUAL(fp.parent_path().generic_string(), tempdir.
path().
generic_string());
548 const std::string expected_filename =
"trace_0000000100-0000000200.log";
549 BOOST_REQUIRE_EQUAL(fp.filename().generic_string(), expected_filename);
550 BOOST_REQUIRE(slice.
is_open());
551 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), 0);
552 BOOST_REQUIRE_EQUAL(slice.
tellp(), 0);
557 BOOST_REQUIRE(found);
559 BOOST_REQUIRE_EQUAL(fp.parent_path().generic_string(), tempdir.
path().
generic_string());
560 BOOST_REQUIRE_EQUAL(fp.filename().generic_string(), expected_filename);
561 BOOST_REQUIRE(slice.
is_open());
562 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), 0);
567 BOOST_REQUIRE(found);
569 BOOST_REQUIRE_EQUAL(fp.parent_path().generic_string(), tempdir.
path().
generic_string());
570 BOOST_REQUIRE_EQUAL(fp.filename().generic_string(), expected_filename);
571 BOOST_REQUIRE(!slice.
is_open());
572 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), 0);
577 std::set<bfs::path> unexpected_files;
579 const auto filename = itr->path().filename();
580 if (expected_files.erase(filename) < 1) {
581 unexpected_files.insert(filename);
584 if (expected_files.size() + unexpected_files.size() == 0)
588 if (expected_files.size()) {
589 msg +=
" Expected the following files to be present, but were not:";
592 for(
auto file : expected_files) {
595 msg +=
" " + file.generic_string();
597 if (unexpected_files.size()) {
598 msg +=
" Did not expect the following files to be present, but they were:";
600 for(
auto file : expected_files) {
603 msg +=
" " + file.generic_string();
612 const uint32_t min_saved_blocks = 5;
618 std::set<bfs::path> files;
620 files.insert(file.get_file_path().filename());
623 files.insert(file.get_file_path().filename());
625 files.insert(file.get_file_path().filename());
627 files.insert(file.get_file_path().filename());
629 files.insert(file.get_file_path().filename());
631 const auto index4 = file.get_file_path().filename();
632 files.insert(index4);
634 const auto trace4 = file.get_file_path().filename();
635 files.insert(trace4);
637 const auto index5 = file.get_file_path().filename();
638 files.insert(index5);
640 const auto trace6 = file.get_file_path().filename();
641 files.insert(trace6);
648 std::set<bfs::path> files2;
649 files2.insert(index5);
650 files2.insert(trace6);
654 lib += min_saved_blocks - 1;
661 std::set<bfs::path> files3;
662 files3.insert(trace6);
680 const uint32_t min_uncompressed_blocks = 5;
681 slice_directory sd(tempdir.
path(),
width, std::optional<uint32_t>(), std::optional<uint32_t>(min_uncompressed_blocks), 8);
684 using file_vector_t = std::vector<std::tuple<bfs::path, bfs::path, bfs::path>>;
685 file_vector_t file_paths;
686 for (
int i = 0; i < 7 ; i++) {
688 auto index_name = file.get_file_path().filename();
689 BOOST_REQUIRE(create_non_empty_trace_slice(sd, i, file));
690 auto trace_name = file.get_file_path().filename();
691 auto compressed_trace_name = trace_name;
692 compressed_trace_name.replace_extension(
".clog");
693 file_paths.emplace_back(index_name, trace_name, compressed_trace_name);
697 std::set<bfs::path> files;
698 for (
const auto& e: file_paths) {
699 files.insert(std::get<0>(e));
700 files.insert(std::get<1>(e));
708 for (std::size_t reps = 0; reps < file_paths.size(); reps++) {
711 files.erase(std::get<1>(file_paths.at(reps)));
712 files.insert(std::get<2>(file_paths.at(reps)));
723 for (
const auto& e: file_paths) {
724 BOOST_REQUIRE_EQUAL(files.count(std::get<0>(e)), 1);
725 BOOST_REQUIRE_EQUAL(files.count(std::get<1>(e)), 0);
726 BOOST_REQUIRE_EQUAL(files.count(std::get<2>(e)), 1);
734 const uint32_t min_uncompressed_blocks = 5;
735 const uint32_t min_saved_blocks = min_uncompressed_blocks +
width;
736 slice_directory sd(tempdir.
path(),
width, std::optional<uint32_t>(min_saved_blocks), std::optional<uint32_t>(min_uncompressed_blocks), 8);
739 using file_vector_t = std::vector<std::tuple<bfs::path, bfs::path, bfs::path>>;
740 file_vector_t file_paths;
741 for (
int i = 0; i < 7 ; i++) {
743 auto index_name = file.get_file_path().filename();
744 BOOST_REQUIRE(create_non_empty_trace_slice(sd, i, file));
745 auto trace_name = file.get_file_path().filename();
746 auto compressed_trace_name = trace_name;
747 compressed_trace_name.replace_extension(
".clog");
748 file_paths.emplace_back(index_name, trace_name, compressed_trace_name);
752 std::set<bfs::path> files;
753 for (
const auto& e: file_paths) {
754 files.insert(std::get<0>(e));
755 files.insert(std::get<1>(e));
763 for (std::size_t reps = 0; reps < file_paths.size() + 1; reps++) {
766 if (reps < file_paths.size()) {
767 files.erase(std::get<1>(file_paths.at(reps)));
768 files.insert(std::get<2>(file_paths.at(reps)));
773 files.erase(std::get<0>(file_paths.at(reps-1)));
774 files.erase(std::get<2>(file_paths.at(reps-1)));
785 BOOST_REQUIRE_EQUAL(files.size(), 0);
791 test_store_provider sp(tempdir.
path(), 100);
795 const uint32_t bt_bn = bt_v1.number;
796 bool found_block =
false;
797 bool lib_seen =
false;
799 if (std::holds_alternative<block_entry_v0>(e)) {
800 const auto& block = std::get<block_entry_v0>(e);
801 if (block.number == bt_bn) {
802 BOOST_REQUIRE(!found_block);
805 }
else if (std::holds_alternative<lib_entry_v0>(e)) {
806 auto best_lib = std::get<lib_entry_v0>(e);
807 BOOST_REQUIRE(!lib_seen);
808 BOOST_REQUIRE_EQUAL(best_lib.lib, 54);
814 BOOST_REQUIRE(found_block);
815 BOOST_REQUIRE(lib_seen);
817 std::vector<uint32_t> block_nums;
818 std::vector<uint64_t> block_offsets;
821 if (std::holds_alternative<block_entry_v0>(e)) {
822 const auto& block = std::get<block_entry_v0>(e);
823 block_nums.push_back(block.number);
824 block_offsets.push_back(block.offset);
825 }
else if (std::holds_alternative<lib_entry_v0>(e)) {
826 auto best_lib = std::get<lib_entry_v0>(e);
827 BOOST_REQUIRE(!lib_seen);
828 BOOST_REQUIRE_EQUAL(best_lib.lib, 54);
833 BOOST_REQUIRE(lib_seen);
834 BOOST_REQUIRE_EQUAL(block_nums.size(), 2);
835 BOOST_REQUIRE_EQUAL(block_nums[0], bt_v1.number);
836 BOOST_REQUIRE_EQUAL(block_nums[1], bt2_v1.number);
837 BOOST_REQUIRE_EQUAL(block_offsets.size(), 2);
838 BOOST_REQUIRE(block_offsets[0] < block_offsets[1]);
839 BOOST_REQUIRE(first_offset < offset);
841 std::optional<data_log_entry> bt_data = sp.read_data_log(block_nums[0], block_offsets[0]);
842 BOOST_REQUIRE_EQUAL(std::get<block_trace_v1>(*bt_data), bt_v1);
844 bt_data = sp.read_data_log(block_nums[1], block_offsets[1]);
845 BOOST_REQUIRE(bt_data);
846 auto v = std::variant<block_trace_v0, block_trace_v1, block_trace_v2>(*bt_data);
847 BOOST_REQUIRE_EQUAL(std::get<block_trace_v1>(v), bt2_v1);
850 block_offsets.clear();
855 if (std::holds_alternative<block_entry_v0>(e)) {
856 const auto& block = std::get<block_entry_v0>(e);
857 block_nums.push_back(block.number);
858 block_offsets.push_back(block.offset);
859 }
else if (std::holds_alternative<lib_entry_v0>(e)) {
860 auto best_lib = std::get<lib_entry_v0>(e);
861 BOOST_REQUIRE(!lib_seen);
862 BOOST_REQUIRE_EQUAL(best_lib.lib, 54);
867 if( ++counter == 3 ) {
871 BOOST_FAIL(
"Should not have completed scan");
874 BOOST_REQUIRE(lib_seen);
875 BOOST_REQUIRE_EQUAL(block_nums.size(), 1);
876 BOOST_REQUIRE_EQUAL(block_nums[0], bt_v1.number);
877 BOOST_REQUIRE_EQUAL(block_offsets.size(), 1);
878 BOOST_REQUIRE(first_offset < offset);
884 test_store_provider sp(tempdir.
path(), 100);
885 sp.append(block_trace1_v2);
887 sp.append(block_trace2_v2);
888 const uint32_t bt_bn = block_trace1_v2.number;
889 bool found_block =
false;
890 bool lib_seen =
false;
892 if (std::holds_alternative<block_entry_v0>(e)) {
893 const auto& block = std::get<block_entry_v0>(e);
894 if (block.number == bt_bn) {
895 BOOST_REQUIRE(!found_block);
898 }
else if (std::holds_alternative<lib_entry_v0>(e)) {
899 auto best_lib = std::get<lib_entry_v0>(e);
900 BOOST_REQUIRE(!lib_seen);
901 BOOST_REQUIRE_EQUAL(best_lib.lib, 54);
907 BOOST_REQUIRE(found_block);
908 BOOST_REQUIRE(lib_seen);
910 std::vector<uint32_t> block_nums;
911 std::vector<uint64_t> block_offsets;
914 if (std::holds_alternative<block_entry_v0>(e)) {
915 const auto& block = std::get<block_entry_v0>(e);
916 block_nums.push_back(block.number);
917 block_offsets.push_back(block.offset);
918 }
else if (std::holds_alternative<lib_entry_v0>(e)) {
919 auto best_lib = std::get<lib_entry_v0>(e);
920 BOOST_REQUIRE(!lib_seen);
921 BOOST_REQUIRE_EQUAL(best_lib.lib, 54);
926 BOOST_REQUIRE(lib_seen);
927 BOOST_REQUIRE_EQUAL(block_nums.size(), 2);
928 BOOST_REQUIRE_EQUAL(block_nums[0], block_trace1_v2.number);
929 BOOST_REQUIRE_EQUAL(block_nums[1], block_trace2_v2.number);
930 BOOST_REQUIRE_EQUAL(block_offsets.size(), 2);
931 BOOST_REQUIRE(block_offsets[0] < block_offsets[1]);
932 BOOST_REQUIRE(first_offset < offset);
934 std::optional<data_log_entry> bt_data = sp.read_data_log(block_nums[0], block_offsets[0]);
935 BOOST_REQUIRE_EQUAL(std::get<block_trace_v2>(*bt_data), block_trace1_v2);
937 bt_data = sp.read_data_log(block_nums[1], block_offsets[1]);
938 BOOST_REQUIRE(bt_data);
940 BOOST_REQUIRE_EQUAL(std::get<block_trace_v2>(v), block_trace2_v2);
943 block_offsets.clear();
948 if (std::holds_alternative<block_entry_v0>(e)) {
949 const auto& block = std::get<block_entry_v0>(e);
950 block_nums.push_back(block.number);
951 block_offsets.push_back(block.offset);
952 }
else if (std::holds_alternative<lib_entry_v0>(e)) {
953 auto best_lib = std::get<lib_entry_v0>(e);
954 BOOST_REQUIRE(!lib_seen);
955 BOOST_REQUIRE_EQUAL(best_lib.lib, 54);
960 if( ++counter == 3 ) {
964 BOOST_FAIL(
"Should not have completed scan");
967 BOOST_REQUIRE(lib_seen);
968 BOOST_REQUIRE_EQUAL(block_nums.size(), 1);
969 BOOST_REQUIRE_EQUAL(block_nums[0], block_trace1_v2.number);
970 BOOST_REQUIRE_EQUAL(block_offsets.size(), 1);
971 BOOST_REQUIRE(first_offset < offset);
977 store_provider sp(tempdir.
path(), 100, std::optional<uint32_t>(), std::optional<uint32_t>(), 0);
987 BOOST_REQUIRE(block1);
988 BOOST_REQUIRE(std::get<1>(*block1));
989 const auto block1_bt = std::get<0>(*block1);
990 BOOST_REQUIRE_EQUAL(std::get<block_trace_v1>(block1_bt), bt_v1);
998 BOOST_REQUIRE(block2);
999 BOOST_REQUIRE(!std::get<1>(*block2));
1000 const auto block2_bt = std::get<0>(*block2);
1001 BOOST_REQUIRE_EQUAL(std::get<block_trace_v1>(block2_bt), bt2_v1);
1005 sp.get_block(5,[&
count]() {
1010 BOOST_FAIL(
"Should not have completed scan");
1015 block2 = sp.get_block(2,[&
count]() {
1020 BOOST_REQUIRE(!block2);
1026 store_provider sp(tempdir.
path(), 100, std::optional<uint32_t>(), std::optional<uint32_t>(), 0);
1027 sp.append(block_trace1_v2);
1029 sp.append(block_trace2_v2);
1036 BOOST_REQUIRE(block1);
1037 BOOST_REQUIRE(std::get<1>(*block1));
1038 const auto block1_bt = std::get<0>(*block1);
1039 BOOST_REQUIRE_EQUAL(std::get<block_trace_v2>(block1_bt), block_trace1_v2);
1047 BOOST_REQUIRE(block2);
1048 BOOST_REQUIRE(!std::get<1>(*block2));
1049 const auto block2_bt = std::get<0>(*block2);
1050 BOOST_REQUIRE_EQUAL(std::get<block_trace_v2>(block2_bt), block_trace2_v2);
1054 sp.get_block(5,[&
count]() {
1059 BOOST_FAIL(
"Should not have completed scan");
1064 block2 = sp.get_block(2,[&
count]() {
1069 BOOST_REQUIRE(!block2);
1073BOOST_AUTO_TEST_SUITE_END()
fc::path get_file_path() const
wraps boost::filesystem::path to provide platform independent path manipulation.
fc::path parent_path() const
fc::path filename() const
std::string generic_string() const
const fc::path & path() const
bool find_or_create_index_slice(uint32_t slice_number, open_state state, fc::cfile &index_file) const
bool find_trace_slice(uint32_t slice_number, open_state state, fc::cfile &trace_file, bool open_file=true) const
bool find_or_create_trace_slice(uint32_t slice_number, open_state state, fc::cfile &trace_file) const
uint32_t slice_number(uint32_t block_height) const
void run_maintenance_tasks(uint32_t lib, const log_handler &log)
uint64_t scan_metadata_log_from(uint32_t block_height, uint64_t offset, Fn &&fn, const yield_function &yield)
std::optional< data_log_entry > read_data_log(uint32_t block_height, uint64_t offset)
void pack(Stream &s, const std::deque< T > &value)
chain::bytes make_transfer_data(chain::name from, chain::name to, chain::asset quantity, std::string &&memo)
std::optional< std::tuple< data_log_entry, bool > > get_block_t
std::variant< block_entry_v0, lib_entry_v0, block_trxs_entry > metadata_log_entry
std::variant< block_trace_v0, block_trace_v1, block_trace_v2 > data_log_entry
unsigned __int64 uint64_t
BOOST_FIXTURE_TEST_CASE(write_data_trace, test_fixture)
void verify_directory_contents(const bfs::path &tempdir, std::set< bfs::path > expected_files)