| 807 | } |
| 808 | |
| 809 | void chainman_reindex_test(TestDirectory& test_directory) |
| 810 | { |
| 811 | auto notifications{std::make_shared<TestKernelNotifications>()}; |
| 812 | auto context{create_context(notifications, ChainType::MAINNET)}; |
| 813 | auto chainman{create_chainman( |
| 814 | test_directory, /*reindex=*/true, /*wipe_chainstate=*/false, |
| 815 | /*block_tree_db_in_memory=*/false, /*chainstate_db_in_memory=*/false, context)}; |
| 816 | |
| 817 | std::vector<std::string> import_files; |
| 818 | BOOST_CHECK(chainman->ImportBlocks(import_files)); |
| 819 | |
| 820 | // Sanity check some block retrievals |
| 821 | auto chain{chainman->GetChain()}; |
| 822 | BOOST_CHECK_THROW(chain.GetByHeight(1000), std::runtime_error); |
| 823 | auto genesis_index{chain.Entries().front()}; |
| 824 | BOOST_CHECK(!genesis_index.GetPrevious()); |
| 825 | auto genesis_block_raw{chainman->ReadBlock(genesis_index).value().ToBytes()}; |
| 826 | auto first_index{chain.GetByHeight(0)}; |
| 827 | auto first_block_raw{chainman->ReadBlock(genesis_index).value().ToBytes()}; |
| 828 | check_equal(genesis_block_raw, first_block_raw); |
| 829 | auto height{first_index.GetHeight()}; |
| 830 | BOOST_CHECK_EQUAL(height, 0); |
| 831 | |
| 832 | auto next_index{chain.GetByHeight(first_index.GetHeight() + 1)}; |
| 833 | BOOST_CHECK(chain.Contains(next_index)); |
| 834 | auto next_block_data{chainman->ReadBlock(next_index).value().ToBytes()}; |
| 835 | auto tip_index{chain.Entries().back()}; |
| 836 | auto tip_block_data{chainman->ReadBlock(tip_index).value().ToBytes()}; |
| 837 | auto second_index{chain.GetByHeight(1)}; |
| 838 | auto second_block{chainman->ReadBlock(second_index).value()}; |
| 839 | auto second_block_data{second_block.ToBytes()}; |
| 840 | auto second_height{second_index.GetHeight()}; |
| 841 | BOOST_CHECK_EQUAL(second_height, 1); |
| 842 | check_equal(next_block_data, tip_block_data); |
| 843 | check_equal(next_block_data, second_block_data); |
| 844 | |
| 845 | auto second_hash{second_index.GetHash()}; |
| 846 | auto another_second_index{chainman->GetBlockTreeEntry(second_hash)}; |
| 847 | BOOST_CHECK(another_second_index); |
| 848 | auto another_second_height{another_second_index->GetHeight()}; |
| 849 | auto second_block_hash{second_block.GetHash()}; |
| 850 | check_equal(second_block_hash.ToBytes(), second_hash.ToBytes()); |
| 851 | BOOST_CHECK_EQUAL(second_height, another_second_height); |
| 852 | } |
| 853 | |
| 854 | void chainman_reindex_chainstate_test(TestDirectory& test_directory) |
| 855 | { |
no test coverage detected