forked from AntelopeIO/leap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request AntelopeIO#535 from eosnetworkfoundation/add-extra…
…ct-blocks-to-eosio-blocklog-tool [3.2] Add extract-blocks option to eosio-blocklog
- Loading branch information
Showing
5 changed files
with
184 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#include <boost/test/unit_test.hpp> | ||
|
||
#include <fc/bitutil.hpp> | ||
|
||
#include <eosio/chain/block_log.hpp> | ||
#include <eosio/chain/block.hpp> | ||
|
||
using namespace eosio::chain; | ||
|
||
struct block_log_extract_fixture { | ||
block_log_extract_fixture() { | ||
log.emplace(dir.path(), std::optional<block_log_prune_config>()); | ||
log->reset(genesis_state(), std::make_shared<signed_block>()); | ||
BOOST_REQUIRE_EQUAL(log->first_block_num(), 1); | ||
BOOST_REQUIRE_EQUAL(log->head()->block_num(), 1); | ||
for(uint32_t i = 2; i < 13; ++i) { | ||
add(i); | ||
} | ||
BOOST_REQUIRE_EQUAL(log->head()->block_num(), 12); | ||
}; | ||
|
||
void add(uint32_t index) { | ||
signed_block_ptr p = std::make_shared<signed_block>(); | ||
p->previous._hash[0] = fc::endian_reverse_u32(index-1); | ||
log->append(p); | ||
} | ||
|
||
genesis_state gs; | ||
fc::temp_directory dir; | ||
std::optional<block_log> log; | ||
}; | ||
|
||
BOOST_AUTO_TEST_SUITE(block_log_extraction_tests) | ||
|
||
BOOST_FIXTURE_TEST_CASE(extract_from_middle, block_log_extract_fixture) try { | ||
|
||
fc::temp_directory output_dir; | ||
block_num_type start=3, end=7; | ||
block_log::extract_block_range(dir.path(), output_dir.path(), start, end); | ||
|
||
block_log new_log(output_dir.path(), std::optional<block_log_prune_config>()); | ||
|
||
auto id = gs.compute_chain_id(); | ||
BOOST_REQUIRE_EQUAL(new_log.extract_chain_id(output_dir.path()), id); | ||
BOOST_REQUIRE_EQUAL(new_log.first_block_num(), 3); | ||
BOOST_REQUIRE_EQUAL(new_log.head()->block_num(), 7); | ||
|
||
|
||
} FC_LOG_AND_RETHROW() | ||
|
||
BOOST_FIXTURE_TEST_CASE(extract_from_start, block_log_extract_fixture) try { | ||
|
||
fc::temp_directory output_dir; | ||
block_num_type start=0, end=7; | ||
block_log::extract_block_range(dir.path(), output_dir.path(), start, end); | ||
|
||
block_log new_log(output_dir.path(), std::optional<block_log_prune_config>()); | ||
|
||
auto id = gs.compute_chain_id(); | ||
BOOST_REQUIRE_EQUAL(new_log.extract_chain_id(output_dir.path()), id); | ||
BOOST_REQUIRE_EQUAL(new_log.first_block_num(), 1); | ||
BOOST_REQUIRE_EQUAL(new_log.head()->block_num(), 7); | ||
|
||
} FC_LOG_AND_RETHROW() | ||
|
||
BOOST_FIXTURE_TEST_CASE(reextract_from_start, block_log_extract_fixture) try { | ||
|
||
fc::temp_directory output_dir; | ||
block_num_type start=0, end=9; | ||
block_log::extract_block_range(dir.path(), output_dir.path(), start, end); | ||
|
||
fc::temp_directory output_dir2; | ||
end=6; | ||
block_log::extract_block_range(output_dir.path(), output_dir2.path(), start, end); | ||
|
||
block_log new_log(output_dir2.path(), std::optional<block_log_prune_config>()); | ||
|
||
auto id = gs.compute_chain_id(); | ||
BOOST_REQUIRE_EQUAL(new_log.extract_chain_id(output_dir2.path()), id); | ||
BOOST_REQUIRE_EQUAL(new_log.first_block_num(), 1); | ||
BOOST_REQUIRE_EQUAL(new_log.head()->block_num(), 6); | ||
|
||
} FC_LOG_AND_RETHROW() | ||
|
||
BOOST_FIXTURE_TEST_CASE(extract_to_end, block_log_extract_fixture) try { | ||
|
||
fc::temp_directory output_dir; | ||
block_num_type start=5, end=std::numeric_limits<block_num_type>::max(); | ||
block_log::extract_block_range(dir.path(), output_dir.path(), start, end); | ||
|
||
block_log new_log(output_dir.path(), std::optional<block_log_prune_config>()); | ||
|
||
auto id = gs.compute_chain_id(); | ||
BOOST_REQUIRE_EQUAL(new_log.extract_chain_id(output_dir.path()), id); | ||
BOOST_REQUIRE_EQUAL(new_log.first_block_num(), 5); | ||
BOOST_REQUIRE_EQUAL(new_log.head()->block_num(), 12); | ||
|
||
} FC_LOG_AND_RETHROW() | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters