Skip to content

Commit

Permalink
Merge pull request #195 from AntelopeIO/savanna_validating_tester_fix
Browse files Browse the repository at this point in the history
Fix `savanna_validating_tester` not transition to Savanna
  • Loading branch information
linh2931 authored May 23, 2024
2 parents c3a1e97 + 93537ee commit a8463f3
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 17 deletions.
2 changes: 1 addition & 1 deletion libraries/testing/include/eosio/testing/tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ namespace eosio::testing {
controller::config vcfg;

validating_tester(const flat_set<account_name>& trusted_producers = flat_set<account_name>(), deep_mind_handler* dmlog = nullptr, setup_policy p = setup_policy::full, bool is_savanna = false) {
this->is_savanna = false;
this->is_savanna = is_savanna;

auto def_conf = default_config(tempdir);

Expand Down
5 changes: 4 additions & 1 deletion unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,14 @@ set(ctest_tests "'${ctest_tests}' -j8") # surround test list string in apostroph
# The following tests are known to take the longest, bump up their cost (priority) so that they'll run first
# even on fresh first time test runs before ctest auto-detects costs
foreach(RUNTIME ${EOSIO_WASM_RUNTIMES})
set_tests_properties(api_unit_test_${RUNTIME} PROPERTIES COST 5000)
set_tests_properties(api_part1_unit_test_${RUNTIME} PROPERTIES COST 5000)
set_tests_properties(api_part2_unit_test_${RUNTIME} PROPERTIES COST 5000)
set_tests_properties(api_part3_unit_test_${RUNTIME} PROPERTIES COST 5000)
set_tests_properties(wasm_part1_unit_test_${RUNTIME} PROPERTIES COST 4000)
set_tests_properties(wasm_part2_unit_test_${RUNTIME} PROPERTIES COST 4000)
set_tests_properties(wasm_config_part1_unit_test_${RUNTIME} PROPERTIES COST 4000)
set_tests_properties(wasm_config_part2_unit_test_${RUNTIME} PROPERTIES COST 4000)
set_tests_properties(wasm_config_part3_unit_test_${RUNTIME} PROPERTIES COST 4000)
set_tests_properties(delay_unit_test_${RUNTIME} PROPERTIES COST 3000)
endforeach()

Expand Down
13 changes: 11 additions & 2 deletions unittests/api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,10 @@ bool is_block_cpu_usage_exceeded(const block_cpu_usage_exceeded& e) { return tru
bool is_deadline_exception(const deadline_exception& e) { return true; }

/*
* register test suite `api_tests`
* Split the tests into multiple parts so that they can be finished within CICD time limit.
* Register test suite `api_part1_tests`
*/
BOOST_AUTO_TEST_SUITE(api_tests)
BOOST_AUTO_TEST_SUITE(api_part1_tests)

/*
* Print capturing stuff
Expand Down Expand Up @@ -1425,6 +1426,10 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(checktime_start, T, validating_testers) try {
deadline_exception, is_deadline_exception );
} FC_LOG_AND_RETHROW()

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(api_part2_tests)

/*************************************************************************************
* transaction_tests common function
*************************************************************************************/
Expand Down Expand Up @@ -2587,6 +2592,10 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(memory_tests, T, validating_testers) {
pushit("memset"_n, name());
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(api_part3_tests)

static const char cstr_wast[] = R"======(
(module
(import "env" "eosio_assert" (func $eosio_assert (param i32 i32)))
Expand Down
6 changes: 3 additions & 3 deletions unittests/block_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( block_with_invalid_tx_mroot_test, T, testers )
}

template <typename T>
std::pair<signed_block_ptr, signed_block_ptr> corrupt_trx_in_block(validating_tester& main, account_name act_name) {
std::pair<signed_block_ptr, signed_block_ptr> corrupt_trx_in_block(T& main, account_name act_name) {
// First we create a valid block with valid transaction
main.create_account(act_name);
signed_block_ptr b = main.produce_block_no_validation();
Expand All @@ -129,14 +129,14 @@ std::pair<signed_block_ptr, signed_block_ptr> corrupt_trx_in_block(validating_te
const auto& trxs = copy_b->transactions;
for( const auto& a : trxs )
trx_digests.emplace_back( a.digest() );
if constexpr (std::is_same_v<T, savanna_tester>) {
if constexpr (std::is_same_v<T, savanna_validating_tester>) {
copy_b->transaction_mroot = calculate_merkle( std::move(trx_digests) );
} else {
copy_b->transaction_mroot = calculate_merkle_legacy( std::move(trx_digests) );
}

// Re-sign the block
if constexpr (std::is_same_v<T, savanna_tester>) {
if constexpr (std::is_same_v<T, savanna_validating_tester>) {
copy_b->producer_signature = main.get_private_key(b->producer, "active").sign(copy_b->calculate_id());
} else {
auto header_bmroot = digest_type::hash( std::make_pair( copy_b->digest(), main.control->head_block_state_legacy()->blockroot_merkle.get_root() ) );
Expand Down
23 changes: 18 additions & 5 deletions unittests/database_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,32 @@ BOOST_AUTO_TEST_SUITE(database_tests)
BOOST_TEST(test.control->fetch_block_by_number(i + 1)->calculate_id() == block_ids.back());
}

// Check the last irreversible block number is set correctly, with one producer, irreversibility should only just 1 block before
const auto expected_last_irreversible_block_number = test.control->head_block_num() - 1;
BOOST_TEST(test.control->head_block_state_legacy()->dpos_irreversible_blocknum == expected_last_irreversible_block_number);
// Check the last irreversible block number is set correctly.
if constexpr (std::is_same_v<T, savanna_validating_tester>) {
// In Savanna, after 3-chain finality is achieved.
const auto expected_last_irreversible_block_number = test.control->head_block_num() - 3;
BOOST_TEST(test.control->last_irreversible_block_num() == expected_last_irreversible_block_number);
} else {
// With one producer, irreversibility should only just 1 block before
const auto expected_last_irreversible_block_number = test.control->head_block_num() - 1;
BOOST_TEST(test.control->head_block_state_legacy()->dpos_irreversible_blocknum == expected_last_irreversible_block_number);
}

// Ensure that future block doesn't exist
const auto nonexisting_future_block_num = test.control->head_block_num() + 1;
BOOST_TEST(test.control->fetch_block_by_number(nonexisting_future_block_num) == nullptr);

const uint32_t next_num_of_blocks_to_prod = 100;
test.produce_blocks(next_num_of_blocks_to_prod);

const auto next_expected_last_irreversible_block_number = test.control->head_block_num() - 1;
// Check the last irreversible block number is updated correctly
BOOST_TEST(test.control->head_block_state_legacy()->dpos_irreversible_blocknum == next_expected_last_irreversible_block_number);
if constexpr (std::is_same_v<T, savanna_validating_tester>) {
const auto next_expected_last_irreversible_block_number = test.control->head_block_num() - 3;
BOOST_TEST(test.control->last_irreversible_block_num() == next_expected_last_irreversible_block_number);
} else {
const auto next_expected_last_irreversible_block_number = test.control->head_block_num() - 1;
BOOST_TEST(test.control->head_block_state_legacy()->dpos_irreversible_blocknum == next_expected_last_irreversible_block_number);
}
// Previous nonexisting future block should exist by now
BOOST_CHECK_NO_THROW(test.control->fetch_block_by_number(nonexisting_future_block_num));
// Check the latest head block match
Expand Down
14 changes: 9 additions & 5 deletions unittests/wasm_config_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct old_wasm_tester : tester {
old_wasm_tester() : tester{setup_policy::old_wasm_parser} {}
};

// Split the tests into two parts so that they can be finished within CICD time limit
// Split the tests into multiple parts so that they can be finished within CICD time limit
BOOST_AUTO_TEST_SUITE(wasm_config_part1_tests)

template<typename T>
Expand Down Expand Up @@ -281,6 +281,10 @@ BOOST_DATA_TEST_CASE_F(wasm_config_tester<savanna_validating_tester>, max_sectio
test_max_section_elements_export(*this, n_elements, oversize);
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(wasm_config_part2_tests)

static const char max_linear_memory_wast[] = R"=====(
(module
(import "env" "eosio_assert" (func $$eosio_assert (param i32 i32)))
Expand Down Expand Up @@ -331,10 +335,6 @@ BOOST_DATA_TEST_CASE_F(wasm_config_tester<savanna_validating_tester>, max_linear
test_max_linear_memory_init(*this, n_init, oversize);
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(wasm_config_part2_tests)

static const std::vector<std::tuple<int, int, bool, bool>> func_local_params = {
// Default value of max_func_local_bytes
{8192, 0, false, true}, {4096, 4096, false, true}, {0, 8192, false, true},
Expand Down Expand Up @@ -599,6 +599,10 @@ BOOST_FIXTURE_TEST_CASE(max_func_local_bytes_mixed_old, old_wasm_tester) {
BOOST_CHECK_THROW(set_code("stackz"_n, code.c_str()), wasm_exception);
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(wasm_config_part3_tests)

template<typename T>
void test_max_table_elements(T& chain, int32_t max_table_elements, int32_t oversize) {
chain.produce_block();
Expand Down

0 comments on commit a8463f3

Please sign in to comment.