Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default setup_policy of libtester to transition to Savanna #205

Merged
merged 33 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
864550b
Make default tester and validating_tester transition to Savanna by de…
linh2931 May 27, 2024
070b207
Update deep-mind test log file
linh2931 May 27, 2024
4e3cafc
Update finality_test_cluster to use setup_policy::full_except_do_not_…
linh2931 May 27, 2024
98c7afb
Update finality_tests to use validating_tester_not_transition_to_sava…
linh2931 May 27, 2024
46e81c2
Update finalizer_update_tests to use validating_tester_not_transition…
linh2931 May 27, 2024
285ce2b
Update producer_schedule_if_tests to use legacy_validating_tester bef…
linh2931 May 27, 2024
410838e
Update producer_schedule_tests to use legacy_validating_tester as tho…
linh2931 May 27, 2024
e451405
unittests/protocol_feature_tests.cpp
linh2931 May 27, 2024
3d91e0d
Update restart_chain_tests
linh2931 May 27, 2024
3fbc1a6
Keep using Legacy tester temporarily in eosio_system_tester until sys…
linh2931 May 27, 2024
8c64321
Use Legacy tester for forked_tests as they test Legacy forking
linh2931 May 27, 2024
9ff8d13
Keep using Legacy tester temporarily in state_history_tests until the…
linh2931 May 27, 2024
609a52c
Merge branch 'main' into default_tester
linh2931 May 27, 2024
f992317
Update deep-mind.log
linh2931 May 27, 2024
a41c1dc
Adapt producer_snapshot_tests to run under both Savanna and Legacy
linh2931 May 27, 2024
9d509b4
Temporarily use legacy_validating_tester for chain_tests/replace_prod…
linh2931 May 27, 2024
c94aac5
Merge branch 'main' into default_tester
linh2931 May 27, 2024
3e7c6f4
Split wasm_tests further so they can be finished under the CICD time …
linh2931 May 27, 2024
f720243
Merge branch 'main' into default_tester
linh2931 May 28, 2024
c2c7f44
Temporarily change referencecontracts target to fix_failures_by_defau…
linh2931 May 28, 2024
6756752
Further split api_tests so they can finish within CICD limits
linh2931 May 29, 2024
d1cc2b5
Merge branch 'main' into default_tester
linh2931 May 30, 2024
675cdd1
Fix a merging conflict
linh2931 May 30, 2024
449b8ff
Add a comment about why legacy_validating_tester is used and fix anot…
linh2931 May 30, 2024
d48fe41
Update applicable producer_schedule_tests to run under Legacy and Sav…
linh2931 May 30, 2024
e7fca35
Use a constexpr instead hardcoded values for base block nu,ber for Sa…
linh2931 May 30, 2024
4fa0af1
Split memory_trap_1_check_throw test
linh2931 May 31, 2024
faa9075
Add missing set property for memory_trap_1_check_throw_1 and memory_t…
linh2931 May 31, 2024
95a82f3
Merge branch 'main' into default_tester
linh2931 Jun 3, 2024
d03a45e
Add a comments about the tests in forked_tests are for Legacy only.
linh2931 Jun 3, 2024
9906718
Add a comment about why legacy_tester is used in state_history_tests…
linh2931 Jun 3, 2024
d40a1c5
Rename validating_tester_not_transition_to_savanna to legacy_validati…
linh2931 Jun 4, 2024
470da12
Update producer_snapshot_tests
linh2931 Jun 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cicd/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"prerelease":true
},
"referencecontracts":{
"ref":"main"
"ref":"fix_failures_by_default_tester"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to change back after merge.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done by #233

}
}
81 changes: 53 additions & 28 deletions libraries/testing/include/eosio/testing/tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ namespace eosio::testing {
preactivate_feature_and_new_bios,
old_wasm_parser,
full_except_do_not_disable_deferred_trx,
full_except_do_not_transition_to_savanna,
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
full
};

Expand Down Expand Up @@ -542,7 +543,6 @@ namespace eosio::testing {
vector<digest_type> protocol_features_to_be_activated_wo_preactivation;
signed_block_ptr lib_block; // updated via irreversible_block signal
block_id_type lib_id; // updated via irreversible_block signal
bool is_savanna{false};

private:
std::vector<builtin_protocol_feature_t> get_all_builtin_protocol_features();
Expand All @@ -551,13 +551,11 @@ namespace eosio::testing {

class tester : public base_tester {
public:
tester(setup_policy policy = setup_policy::full, db_read_mode read_mode = db_read_mode::HEAD, std::optional<uint32_t> genesis_max_inline_action_size = std::optional<uint32_t>{}, bool is_savanna = false) {
this->is_savanna = is_savanna;
tester(setup_policy policy = setup_policy::full, db_read_mode read_mode = db_read_mode::HEAD, std::optional<uint32_t> genesis_max_inline_action_size = std::optional<uint32_t>{}) {
init(policy, read_mode, genesis_max_inline_action_size);
}

tester(controller::config config, const genesis_state& genesis, bool is_savanna = false) {
this->is_savanna = is_savanna;
tester(controller::config config, const genesis_state& genesis) {
init(std::move(config), genesis);
}

Expand All @@ -569,8 +567,7 @@ namespace eosio::testing {
init(std::move(config), std::move(pfs), genesis);
}

tester(const fc::temp_directory& tempdir, bool use_genesis, bool is_savanna = false) {
this->is_savanna = is_savanna;
tester(const fc::temp_directory& tempdir, bool use_genesis) {
auto def_conf = default_config(tempdir);
cfg = def_conf.first;

Expand All @@ -583,8 +580,7 @@ namespace eosio::testing {
}

template <typename Lambda>
tester(const fc::temp_directory& tempdir, Lambda conf_edit, bool use_genesis, bool is_savanna = false) {
this->is_savanna = is_savanna;
tester(const fc::temp_directory& tempdir, Lambda conf_edit, bool use_genesis) {
auto def_conf = default_config(tempdir);
cfg = def_conf.first;
conf_edit(cfg);
Expand Down Expand Up @@ -623,19 +619,42 @@ namespace eosio::testing {

};

class savanna_tester : public tester {
// The behavior of tester_not_transition_to_savanna under setup_policy::full
// behaves as the legacy tester: activating all the protocol features but not
// transition to Savanna consensus.
// If needed, the tester can be transitioned to Savanna by explicitly calling
// set_finalizer host function only.
class tester_not_transition_to_savanna : public tester {
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
public:
savanna_tester(setup_policy policy = setup_policy::full, db_read_mode read_mode = db_read_mode::HEAD, std::optional<uint32_t> genesis_max_inline_action_size = std::optional<uint32_t>{});
savanna_tester(controller::config config, const genesis_state& genesis);
savanna_tester(const fc::temp_directory& tempdir, bool use_genesis);
tester_not_transition_to_savanna(setup_policy policy = setup_policy::full_except_do_not_transition_to_savanna, db_read_mode read_mode = db_read_mode::HEAD, std::optional<uint32_t> genesis_max_inline_action_size = std::optional<uint32_t>{})
: tester(policy == setup_policy::full ? setup_policy::full_except_do_not_transition_to_savanna
: policy,
read_mode, genesis_max_inline_action_size) {};

tester_not_transition_to_savanna(controller::config config, const genesis_state& genesis)
: tester(config, genesis) {};

tester_not_transition_to_savanna(const fc::temp_directory& tempdir, bool use_genesis)
: tester(tempdir, use_genesis) {};

template <typename Lambda>
savanna_tester(const fc::temp_directory& tempdir, Lambda conf_edit, bool use_genesis)
: tester(tempdir, conf_edit, use_genesis, true) { // true for is_savanna
}
tester_not_transition_to_savanna(const fc::temp_directory& tempdir, Lambda conf_edit, bool use_genesis)
: tester(tempdir, conf_edit, use_genesis) {};

tester_not_transition_to_savanna(const std::function<void(controller&)>& control_setup, setup_policy policy = setup_policy::full, db_read_mode read_mode = db_read_mode::HEAD)
: tester(control_setup,
policy == setup_policy::full ? setup_policy::full_except_do_not_transition_to_savanna
: policy,
read_mode) {};

// setup_policy::full does not not transition to Savanna consensus.
void execute_setup_policy(const setup_policy policy) {
tester::execute_setup_policy(policy == setup_policy::full ? setup_policy::full_except_do_not_transition_to_savanna : policy);
};
};

using legacy_tester = tester;
using legacy_tester = tester_not_transition_to_savanna;
using savanna_tester = tester;
using testers = boost::mpl::list<legacy_tester, savanna_tester>;

class tester_no_disable_deferred_trx : public tester {
Expand All @@ -662,9 +681,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 = is_savanna;

validating_tester(const flat_set<account_name>& trusted_producers = flat_set<account_name>(), deep_mind_handler* dmlog = nullptr, setup_policy p = setup_policy::full) {
auto def_conf = default_config(tempdir);

vcfg = def_conf.first;
Expand Down Expand Up @@ -704,8 +721,7 @@ namespace eosio::testing {
}

template <typename Lambda>
validating_tester(const fc::temp_directory& tempdir, Lambda conf_edit, bool use_genesis, bool is_savanna = false) {
this->is_savanna = false;
validating_tester(const fc::temp_directory& tempdir, Lambda conf_edit, bool use_genesis) {
auto def_conf = default_config(tempdir);
conf_edit(def_conf.first);
vcfg = def_conf.first;
Expand Down Expand Up @@ -780,17 +796,26 @@ namespace eosio::testing {
}
};

class savanna_validating_tester : public validating_tester {
// The behavior of validating_tester_not_transition_to_savanna under setup_policy::full
// behaves as the legacy validating_tester: activating all the protocol features but not
// transition to Savanna consensus.
// If needed, the tester can be transitioned to Savanna by explicitly calling
// set_finalizer host function only.
class validating_tester_not_transition_to_savanna : public validating_tester {
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
public:
savanna_validating_tester(const flat_set<account_name>& trusted_producers = flat_set<account_name>(), deep_mind_handler* dmlog = nullptr, setup_policy p = setup_policy::full);
validating_tester_not_transition_to_savanna(const flat_set<account_name>& trusted_producers = flat_set<account_name>(), deep_mind_handler* dmlog = nullptr, setup_policy p = setup_policy::full_except_do_not_transition_to_savanna)
: validating_tester(trusted_producers, dmlog, p == setup_policy::full ? setup_policy::full_except_do_not_transition_to_savanna : p) {};

validating_tester_not_transition_to_savanna(const fc::temp_directory& tempdir, bool use_genesis)
: validating_tester(tempdir, use_genesis) {};

template <typename Lambda>
savanna_validating_tester(const fc::temp_directory& tempdir, Lambda conf_edit, bool use_genesis)
: validating_tester(tempdir, conf_edit, use_genesis, true) { // true for is_savanna
}
validating_tester_not_transition_to_savanna(const fc::temp_directory& tempdir, Lambda conf_edit, bool use_genesis)
: validating_tester(tempdir, conf_edit, use_genesis) {};
};

using legacy_validating_tester = validating_tester;
using legacy_validating_tester = validating_tester_not_transition_to_savanna;
using savanna_validating_tester = validating_tester;
using validating_testers = boost::mpl::list<legacy_validating_tester, savanna_validating_tester>;

// -------------------------------------------------------------------------------------
Expand Down
29 changes: 9 additions & 20 deletions libraries/testing/tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,26 @@ namespace eosio::testing {
break;
}
case setup_policy::full:
case setup_policy::full_except_do_not_transition_to_savanna:
case setup_policy::full_except_do_not_disable_deferred_trx: {
schedule_preactivate_protocol_feature();
produce_block();
set_before_producer_authority_bios_contract();
if( policy == setup_policy::full ) {
preactivate_all_builtin_protocol_features();
} else {
if( policy == setup_policy::full_except_do_not_disable_deferred_trx ) {
preactivate_all_but_disable_deferred_trx();
} else {
preactivate_all_builtin_protocol_features();
}
produce_block();
set_bios_contract();
if( is_savanna ) {

// Do not transition to Savanna under full_except_do_not_transition_to_savanna or
// full_except_do_not_disable_deferred_trx
if( policy == setup_policy::full ) {
finalizer_keys fin_keys(*this, 4u /* num_keys */, 4u /* finset_size */);
fin_keys.activate_savanna(0u /* first_key_idx */);
}

break;
}
case setup_policy::none:
Expand Down Expand Up @@ -1400,18 +1405,6 @@ namespace eosio::testing {
execute_setup_policy(policy);
}

savanna_tester::savanna_tester(setup_policy policy, db_read_mode read_mode, std::optional<uint32_t> genesis_max_inline_action_size)
: tester(policy, read_mode, genesis_max_inline_action_size, true) { // true for is_savanna
}

savanna_tester::savanna_tester(controller::config config, const genesis_state& genesis)
: tester(config, genesis, true) { // true for is_savanna
}

savanna_tester::savanna_tester(const fc::temp_directory& tempdir, bool use_genesis)
: tester(tempdir, use_genesis, true) { // true for is_savanna
}

unique_ptr<controller> validating_tester::create_validating_node(controller::config vcfg, const genesis_state& genesis, bool use_genesis, deep_mind_handler* dmlog) {
unique_ptr<controller> validating_node = std::make_unique<controller>(vcfg, make_protocol_feature_set(), genesis.compute_chain_id());
validating_node->add_indices();
Expand All @@ -1429,10 +1422,6 @@ namespace eosio::testing {
return validating_node;
}

savanna_validating_tester::savanna_validating_tester(const flat_set<account_name>& trusted_producers, deep_mind_handler* dmlog, setup_policy p)
: validating_tester(trusted_producers, dmlog, p, true) { // true for is_savanna
}

bool fc_exception_message_is::operator()( const fc::exception& ex ) {
auto message = ex.get_log().at( 0 ).get_message();
bool match = (message == expected);
Expand Down
29 changes: 24 additions & 5 deletions tests/test_snapshot_information.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ BOOST_AUTO_TEST_SUITE(producer_snapshot_tests)

using next_t = pending_snapshot<snapshot_scheduler::snapshot_information>::next_t;

BOOST_AUTO_TEST_CASE_TEMPLATE(test_snapshot_information, SNAPSHOT_SUITE, snapshot_suites) {
tester chain;
template<typename TESTER, typename SNAPSHOT_SUITE>
void test_snapshot_information() {
TESTER chain;
const std::filesystem::path parent_path = chain.get_config().blocks_dir.parent_path();

chain.create_account("snapshot"_n);
Expand All @@ -30,13 +31,22 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(test_snapshot_information, SNAPSHOT_SUITE, snapsho
chain.set_abi("snapshot"_n, test_contracts::snapshot_test_abi());
chain.produce_blocks(1);

constexpr uint32_t savanna_base_block_num = 9;
auto block = chain.produce_block();
BOOST_REQUIRE_EQUAL(block->block_num(), 6u); // ensure that test setup stays consistent with original snapshot setup
if constexpr (std::is_same_v<TESTER, savanna_tester>) {
BOOST_REQUIRE_EQUAL(block->block_num(), 6u + savanna_base_block_num); // ensure that test setup stays consistent with original snapshot setup
} else {
BOOST_REQUIRE_EQUAL(block->block_num(), 6u); // ensure that test setup stays consistent with original snapshot setup
}
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
// undo the auto-pending from tester
chain.control->abort_block();

auto block2 = chain.produce_block();
BOOST_REQUIRE_EQUAL(block2->block_num(), 7u); // ensure that test setup stays consistent with original snapshot setup
if constexpr (std::is_same_v<TESTER, savanna_tester>) {
BOOST_REQUIRE_EQUAL(block2->block_num(), 7u + savanna_base_block_num); // ensure that test setup stays consistent with original snapshot setup
} else {
BOOST_REQUIRE_EQUAL(block2->block_num(), 7u); // ensure that test setup stays consistent with original snapshot setup
}
// undo the auto-pending from tester
chain.control->abort_block();

Expand All @@ -61,8 +71,17 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(test_snapshot_information, SNAPSHOT_SUITE, snapsho
next_t next;
pending_snapshot pending{ block2->previous, next, pending_path.generic_string(), final_path.generic_string() };
test_snap_info = pending.finalize(*chain.control);
BOOST_REQUIRE_EQUAL(test_snap_info.head_block_num, 6u);
if constexpr (std::is_same_v<TESTER, savanna_tester>) {
BOOST_REQUIRE_EQUAL(test_snap_info.head_block_num, 6u + savanna_base_block_num);
} else {
BOOST_REQUIRE_EQUAL(test_snap_info.head_block_num, 6u);
heifner marked this conversation as resolved.
Show resolved Hide resolved
}
BOOST_REQUIRE_EQUAL(test_snap_info.version, chain_snapshot_header::current_version);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(snapshot_information_test, SNAPSHOT_SUITE, snapshot_suites) {
test_snapshot_information<legacy_tester, SNAPSHOT_SUITE>();
test_snapshot_information<savanna_tester, SNAPSHOT_SUITE>();
}

BOOST_AUTO_TEST_SUITE_END()
2 changes: 1 addition & 1 deletion unittests/chain_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using namespace eosio::testing;
BOOST_AUTO_TEST_SUITE(chain_tests)

BOOST_AUTO_TEST_CASE( replace_producer_keys ) try {
validating_tester tester;
legacy_validating_tester tester;

const auto new_key = get_public_key(name("newkey"), config::active_name.to_string());

Expand Down
2 changes: 1 addition & 1 deletion unittests/eosio_system_tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using mvo = fc::mutable_variant_object;

namespace eosio_system {

template <typename T>
template<typename T>
class eosio_system_tester : public T {
public:

Expand Down
2 changes: 1 addition & 1 deletion unittests/finality_test_cluster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct finality_node_t : public eosio::testing::tester {
eosio::testing::finalizer_keys<tester> finkeys;
size_t cur_key{0}; // index of key used in current policy

finality_node_t() : finkeys(*this) {}
finality_node_t() : eosio::testing::tester(eosio::testing::setup_policy::full_except_do_not_transition_to_savanna), finkeys(*this) {}
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved

size_t last_vote_index() const {
assert(!votes.empty());
Expand Down
6 changes: 4 additions & 2 deletions unittests/finality_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ BOOST_AUTO_TEST_SUITE(finality_tests)

// test set_finalizer host function serialization and tester set_finalizers
BOOST_AUTO_TEST_CASE(initial_set_finalizer_test) { try {
validating_tester t;
// Do not transition to Savanna at constrution. Transition explicitly later.
validating_tester_not_transition_to_savanna t;

// Create finalizer keys
constexpr size_t num_finalizers = 21;
Expand Down Expand Up @@ -60,7 +61,8 @@ BOOST_AUTO_TEST_CASE(initial_set_finalizer_test) { try {
void test_finality_transition(const vector<account_name>& accounts,
const base_tester::finalizer_policy_input& input,
bool lib_advancing_expected) {
validating_tester t;
// Do not transition to Savanna at constrution. Transition explicitly later.
validating_tester_not_transition_to_savanna t;

t.produce_block();

Expand Down
6 changes: 4 additions & 2 deletions unittests/finalizer_update_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ static void ensure_next_block_finalizer_policy(validating_tester& t,
// to take effect.
// ---------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(savanna_set_finalizer_single_test) { try {
validating_tester t;
// Do not transition to Savanna at constrution. Transition explicitly later.
validating_tester_not_transition_to_savanna t;
size_t num_keys = 22u;
size_t finset_size = 21u;

Expand Down Expand Up @@ -67,7 +68,8 @@ BOOST_AUTO_TEST_CASE(savanna_set_finalizer_single_test) { try {
// at the same time.
// ---------------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(savanna_set_finalizer_multiple_test) { try {
validating_tester t;
// Do not transition to Savanna at constrution. Transition explicitly later.
validating_tester_not_transition_to_savanna t;
size_t num_keys = 50u;
size_t finset_size = 21u;

Expand Down
Loading
Loading