Skip to content

Commit

Permalink
GH-1039 Update tests for fork database not automatically read at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Nov 26, 2024
1 parent 90d255a commit ac8d2f0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions libraries/testing/include/eosio/testing/tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ namespace eosio::testing {
// producer become inactive
void produce_min_num_of_blocks_to_spend_time_wo_inactive_prod(const fc::microseconds target_elapsed_time = fc::microseconds());
void push_block(const signed_block_ptr& b);
void apply_blocks();

/**
* These transaction IDs represent transactions available in the head chain state as scheduled
Expand Down
10 changes: 8 additions & 2 deletions libraries/testing/tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,9 @@ namespace eosio::testing {
case block_signal::accepted_block:
// should get accepted_block signal after accepted_block_header signal
// or after accepted_block (on fork switch, accepted block signaled when block re-applied)
return present && (itr->second == block_signal::accepted_block_header ||
itr->second == block_signal::accepted_block);
// or first thing on restart if applying out of the forkdb
return !present || (present && (itr->second == block_signal::accepted_block_header ||
itr->second == block_signal::accepted_block));

case block_signal::irreversible_block:
// can be signaled on restart as the first thing since other signals happened before shutdown
Expand Down Expand Up @@ -460,6 +461,11 @@ namespace eosio::testing {
_check_for_vote_if_needed(*control, bh);
}

void base_tester::apply_blocks() {
while (control->apply_blocks( {}, {} ) == controller::apply_blocks_result::incomplete)
;
}

signed_block_ptr base_tester::_produce_block( fc::microseconds skip_time, bool skip_pending_trxs ) {
auto res = _produce_block( skip_time, skip_pending_trxs, false );
return res.block;
Expand Down
2 changes: 2 additions & 0 deletions unittests/blocks_log_replay_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ struct blog_replay_fixture {
// with last_irreversible_block_num and last_head_block_num
BOOST_CHECK(replay_chain_1.last_irreversible_block_num() == last_irreversible_block_num);
if (!remove_fork_db) {
replay_chain_1.apply_blocks();
BOOST_CHECK(replay_chain_1.head().block_num() == last_head_block_num);
} else {
BOOST_CHECK(replay_chain_1.head().block_num() == last_irreversible_block_num);
Expand Down Expand Up @@ -128,6 +129,7 @@ BOOST_FIXTURE_TEST_CASE(replay_through, blog_replay_fixture) try {
// Make sure replayed irreversible_block_num and head_block_num match
// with last_irreversible_block_num and last_head_block_num
BOOST_CHECK(replay_chain.last_irreversible_block_num() == last_irreversible_block_num);
replay_chain.apply_blocks();
BOOST_CHECK(replay_chain.head().block_num() == last_head_block_num);
} FC_LOG_AND_RETHROW()

Expand Down
3 changes: 2 additions & 1 deletion unittests/restart_chain_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( test_restart_from_block_log, T, testers ) {
remove_existing_states(copied_config);

tester from_block_log_chain(copied_config, *genesis);
from_block_log_chain.apply_blocks();

BOOST_REQUIRE_NO_THROW(from_block_log_chain.get_account("replay1"_n));
BOOST_REQUIRE_NO_THROW(from_block_log_chain.get_account("replay2"_n));
Expand Down Expand Up @@ -221,7 +222,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( test_light_validation_restart_from_block_log, T,
other_trace = t;
}
});

from_block_log_chain.apply_blocks();

BOOST_REQUIRE(other_trace);
BOOST_REQUIRE(other_trace->receipt);
Expand Down
1 change: 1 addition & 0 deletions unittests/savanna_cluster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ namespace savanna_cluster {
void open_from_snapshot(const std::string& snapshot) {
dlog("node ${i} - restoring from snapshot", ("i", _node_idx));
open(buffered_snapshot_suite::get_reader(snapshot));
apply_blocks();
}

std::vector<uint8_t> save_fsi() const {
Expand Down

0 comments on commit ac8d2f0

Please sign in to comment.