Skip to content

Commit

Permalink
Update tests to that the setup policy is explicit.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg7mdp committed May 13, 2024
1 parent e044793 commit 5f0b736
Show file tree
Hide file tree
Showing 24 changed files with 118 additions and 100 deletions.
12 changes: 7 additions & 5 deletions libraries/testing/include/eosio/testing/tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ namespace eosio::testing {
preactivate_feature_only,
preactivate_feature_and_new_bios,
old_wasm_parser,
full_except_do_not_disable_deferred_trx,
full
full_pre_savanna_except_do_not_disable_deferred_trx,
full_pre_savanna,
full // savanna consensus activated
};

std::ostream& operator<<(std::ostream& os, setup_policy p);
Expand Down Expand Up @@ -538,7 +539,8 @@ 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>{}) {
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);
}

Expand Down Expand Up @@ -608,7 +610,7 @@ namespace eosio::testing {

class tester_no_disable_deferred_trx : public tester {
public:
tester_no_disable_deferred_trx(): tester(setup_policy::full_except_do_not_disable_deferred_trx) {
tester_no_disable_deferred_trx(): tester(setup_policy::full_pre_savanna_except_do_not_disable_deferred_trx) {
}
};

Expand Down Expand Up @@ -741,7 +743,7 @@ namespace eosio::testing {

class validating_tester_no_disable_deferred_trx : public validating_tester {
public:
validating_tester_no_disable_deferred_trx(): validating_tester({}, nullptr, setup_policy::full_except_do_not_disable_deferred_trx) {
validating_tester_no_disable_deferred_trx(): validating_tester({}, nullptr, setup_policy::full_pre_savanna_except_do_not_disable_deferred_trx) {
}
};

Expand Down
26 changes: 18 additions & 8 deletions libraries/testing/tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,22 +234,26 @@ namespace eosio::testing {
};

switch (policy) {
case setup_policy::old_bios_only: {
case setup_policy::old_bios_only:
{
set_before_preactivate_bios_contract();
break;
}
case setup_policy::preactivate_feature_only: {
case setup_policy::preactivate_feature_only:
{
schedule_preactivate_protocol_feature();
produce_block(); // block production is required to activate protocol feature
break;
}
case setup_policy::preactivate_feature_and_new_bios: {
case setup_policy::preactivate_feature_and_new_bios:
{
schedule_preactivate_protocol_feature();
produce_block();
set_before_producer_authority_bios_contract();
break;
}
case setup_policy::old_wasm_parser: {
case setup_policy::old_wasm_parser:
{
schedule_preactivate_protocol_feature();
produce_block();
set_before_producer_authority_bios_contract();
Expand All @@ -273,18 +277,24 @@ namespace eosio::testing {
set_bios_contract();
break;
}
case setup_policy::full_pre_savanna_except_do_not_disable_deferred_trx:
case setup_policy::full_pre_savanna:
case setup_policy::full:
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_pre_savanna_except_do_not_disable_deferred_trx) {
preactivate_all_but_disable_deferred_trx();
} else {
preactivate_all_builtin_protocol_features();
}
produce_block();
set_bios_contract();
if (policy == setup_policy::full) {
// Activate Savanna consensus
// --------------------------
}
break;
}
case setup_policy::none:
Expand Down
22 changes: 11 additions & 11 deletions unittests/api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ BOOST_FIXTURE_TEST_CASE(deferred_cfa_success, validating_tester_no_disable_defer
} FC_LOG_AND_RETHROW()

BOOST_AUTO_TEST_CASE(light_validation_skip_cfa) try {
tester chain(setup_policy::full);
tester chain(setup_policy::full_pre_savanna);

std::vector<signed_block_ptr> blocks;
blocks.push_back(chain.produce_block());
Expand Down Expand Up @@ -979,7 +979,7 @@ void call_test(Tester& test, T ac, uint32_t billed_cpu_time_us , uint32_t max_cp
}

BOOST_AUTO_TEST_CASE(checktime_fail_tests) { try {
validating_tester t;
validating_tester t{ {}, nullptr, setup_policy::full_pre_savanna };
t.produce_blocks(2);

ilog( "create account" );
Expand Down Expand Up @@ -1580,7 +1580,7 @@ BOOST_AUTO_TEST_CASE(transaction_tests_before_disable_trxs_protocol_features) {
* transaction tests after before disable_trxs_protocol_features are activated
*************************************************************************************/
BOOST_AUTO_TEST_CASE(transaction_tests_after_disable_trxs_protocol_features) { try {
validating_tester chain;
validating_tester chain{ {}, nullptr, setup_policy::full_pre_savanna };
transaction_tests<validating_tester>(chain);
} FC_LOG_AND_RETHROW() }

Expand All @@ -1590,7 +1590,7 @@ BOOST_AUTO_TEST_CASE(transaction_tests_after_disable_trxs_protocol_features) { t
BOOST_AUTO_TEST_CASE(inline_action_with_over_4k_limit) { try {
const uint32_t _4k = 4 * 1024;
tester chain(setup_policy::full, db_read_mode::HEAD, {_4k + 100});
tester chain2(setup_policy::full, db_read_mode::HEAD, {_4k + 100});
tester chain2(setup_policy::full_pre_savanna, db_read_mode::HEAD, {_4k + 100});
signed_block_ptr block;
for (int n=0; n < 2; ++n) {
block = chain.produce_block();
Expand All @@ -1617,7 +1617,7 @@ BOOST_AUTO_TEST_CASE(inline_action_with_over_4k_limit) { try {
*************************************************************************************/
BOOST_AUTO_TEST_CASE(inline_action_objective_limit) { try {
const uint32_t _4k = 4 * 1024;
tester chain(setup_policy::full, db_read_mode::HEAD, {_4k});
tester chain(setup_policy::full_pre_savanna, db_read_mode::HEAD, {_4k});
chain.produce_blocks(2);
chain.create_account( "testapi"_n );
chain.produce_blocks(100);
Expand All @@ -1639,8 +1639,8 @@ BOOST_AUTO_TEST_CASE(inline_action_objective_limit) { try {

BOOST_AUTO_TEST_CASE(deferred_inline_action_limit) { try {
const uint32_t _4k = 4 * 1024;
tester chain(setup_policy::full_except_do_not_disable_deferred_trx, db_read_mode::HEAD, {_4k + 100});
tester chain2(setup_policy::full_except_do_not_disable_deferred_trx, db_read_mode::HEAD, {_4k + 100});
tester chain(setup_policy::full_pre_savanna_except_do_not_disable_deferred_trx, db_read_mode::HEAD, {_4k + 100});
tester chain2(setup_policy::full_pre_savanna_except_do_not_disable_deferred_trx, db_read_mode::HEAD, {_4k + 100});
signed_block_ptr block;
for (int n=0; n < 2; ++n) {
block = chain.produce_block();
Expand Down Expand Up @@ -3714,7 +3714,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest3, validating_tester) { try {
} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE(action_results_tests) { try {
validating_tester t;
validating_tester t{ {}, nullptr, setup_policy::full_pre_savanna };
t.produce_blocks(2);
t.create_account( "test"_n );
t.set_code( "test"_n, test_contracts::action_results_wasm() );
Expand Down Expand Up @@ -3823,7 +3823,7 @@ static const char get_code_hash_wast[] = R"=====(
)=====";

BOOST_AUTO_TEST_CASE(get_code_hash_tests) { try {
validating_tester t;
validating_tester t{ {}, nullptr, setup_policy::full_pre_savanna };
t.produce_blocks(2);
t.create_account("gethash"_n);
t.create_account("test"_n);
Expand Down Expand Up @@ -3861,7 +3861,7 @@ BOOST_AUTO_TEST_CASE(get_code_hash_tests) { try {

// test set_finalizer host function serialization and tester set_finalizers
BOOST_AUTO_TEST_CASE(initial_set_finalizer_test) { try {
validating_tester t;
validating_tester t{ {}, nullptr, setup_policy::full_pre_savanna };

// Create finalizer keys
constexpr size_t num_finalizers = 21;
Expand Down Expand Up @@ -3911,7 +3911,7 @@ 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;
validating_tester t{ {}, nullptr, setup_policy::full_pre_savanna };

t.produce_block();

Expand Down
18 changes: 9 additions & 9 deletions unittests/auth_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ BOOST_FIXTURE_TEST_CASE( delegate_auth, validating_tester ) { try {

BOOST_AUTO_TEST_CASE(update_auths) {
try {
validating_tester chain;
validating_tester chain{ {}, nullptr, setup_policy::full_pre_savanna };
chain.create_account(name("alice"));
chain.create_account(name("bob"));

Expand Down Expand Up @@ -225,7 +225,7 @@ try {

BOOST_AUTO_TEST_CASE(update_auth_unknown_private_key) {
try {
validating_tester chain;
validating_tester chain{ {}, nullptr, setup_policy::full_pre_savanna };
chain.create_account(name("alice"));

// public key with no corresponding private key
Expand Down Expand Up @@ -259,7 +259,7 @@ BOOST_AUTO_TEST_CASE(update_auth_unknown_private_key) {
}

BOOST_AUTO_TEST_CASE(link_auths) { try {
validating_tester chain;
validating_tester chain{ {}, nullptr, setup_policy::full_pre_savanna };

chain.create_accounts({name("alice"),name("bob")});

Expand Down Expand Up @@ -302,7 +302,7 @@ BOOST_AUTO_TEST_CASE(link_auths) { try {
} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE(link_then_update_auth) { try {
validating_tester chain;
validating_tester chain{ {}, nullptr, setup_policy::full_pre_savanna };

chain.create_account(name("alice"));

Expand All @@ -329,7 +329,7 @@ BOOST_AUTO_TEST_CASE(link_then_update_auth) { try {

BOOST_AUTO_TEST_CASE(create_account) {
try {
validating_tester chain;
validating_tester chain{ {}, nullptr, setup_policy::full_pre_savanna };
chain.create_account(name("joe"));
chain.produce_block();

Expand Down Expand Up @@ -367,7 +367,7 @@ try {
} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE( any_auth ) { try {
validating_tester chain;
validating_tester chain{ {}, nullptr, setup_policy::full_pre_savanna };
chain.create_accounts( {name("alice"), name("bob")} );
chain.produce_block();

Expand Down Expand Up @@ -463,7 +463,7 @@ try {

BOOST_AUTO_TEST_CASE(stricter_auth) {
try {
validating_tester chain;
validating_tester chain{ {}, nullptr, setup_policy::full_pre_savanna };

chain.produce_block();

Expand Down Expand Up @@ -512,7 +512,7 @@ try {
} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE( linkauth_special ) { try {
validating_tester chain;
validating_tester chain{ {}, nullptr, setup_policy::full_pre_savanna };

const auto& tester_account = "tester"_n;
std::vector<transaction_id_type> ids;
Expand Down Expand Up @@ -553,7 +553,7 @@ BOOST_AUTO_TEST_CASE( linkauth_special ) { try {
} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE(delete_auth) { try {
validating_tester chain;
validating_tester chain{ {}, nullptr, setup_policy::full_pre_savanna };

const auto& tester_account = "tester"_n;

Expand Down
18 changes: 9 additions & 9 deletions unittests/block_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ BOOST_AUTO_TEST_SUITE(block_tests)

BOOST_AUTO_TEST_CASE(block_with_invalid_tx_test)
{
tester main;
tester main(setup_policy::full_pre_savanna);

// First we create a valid block with valid transaction
main.create_account("newacc"_n);
Expand Down Expand Up @@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE(block_with_invalid_tx_test)
copy_b->producer_signature = main.get_private_key(config::system_account_name, "active").sign(sig_digest);

// Push block with invalid transaction to other chain
tester validator;
tester validator(setup_policy::full_pre_savanna);
auto btf = validator.control->create_block_handle_future( copy_b->calculate_id(), copy_b );
validator.control->abort_block();
controller::block_report br;
Expand All @@ -56,7 +56,7 @@ BOOST_AUTO_TEST_CASE(block_with_invalid_tx_test)

BOOST_AUTO_TEST_CASE(block_with_invalid_tx_mroot_test)
{
tester main;
tester main(setup_policy::full_pre_savanna);

// First we create a valid block with valid transaction
main.create_account("newacc"_n);
Expand All @@ -82,7 +82,7 @@ BOOST_AUTO_TEST_CASE(block_with_invalid_tx_mroot_test)
copy_b->producer_signature = main.get_private_key(config::system_account_name, "active").sign(sig_digest);

// Push block with invalid transaction to other chain
tester validator;
tester validator(setup_policy::full_pre_savanna);
auto btf = validator.control->create_block_handle_future( copy_b->calculate_id(), copy_b );
validator.control->abort_block();
controller::block_report br;
Expand Down Expand Up @@ -128,7 +128,7 @@ std::pair<signed_block_ptr, signed_block_ptr> corrupt_trx_in_block(validating_te
BOOST_AUTO_TEST_CASE(trusted_producer_test)
{
flat_set<account_name> trusted_producers = { "defproducera"_n, "defproducerc"_n };
validating_tester main(trusted_producers);
validating_tester main(trusted_producers, nullptr, setup_policy::full_pre_savanna);
// only using validating_tester to keep the 2 chains in sync, not to validate that the validating_node matches the main node,
// since it won't be
main.skip_validate = true;
Expand All @@ -154,7 +154,7 @@ BOOST_AUTO_TEST_CASE(trusted_producer_test)
BOOST_AUTO_TEST_CASE(trusted_producer_verify_2nd_test)
{
flat_set<account_name> trusted_producers = { "defproducera"_n, "defproducerc"_n };
validating_tester main(trusted_producers);
validating_tester main(trusted_producers, nullptr, setup_policy::full_pre_savanna);
// only using validating_tester to keep the 2 chains in sync, not to validate that the validating_node matches the main node,
// since it won't be
main.skip_validate = true;
Expand All @@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE(trusted_producer_verify_2nd_test)
BOOST_AUTO_TEST_CASE(untrusted_producer_test)
{
flat_set<account_name> trusted_producers = { "defproducera"_n, "defproducerc"_n };
validating_tester main(trusted_producers);
validating_tester main(trusted_producers, nullptr, setup_policy::full_pre_savanna);
// only using validating_tester to keep the 2 chains in sync, not to validate that the validating_node matches the main node,
// since it won't be
main.skip_validate = true;
Expand Down Expand Up @@ -211,8 +211,8 @@ BOOST_AUTO_TEST_CASE(untrusted_producer_test)
BOOST_AUTO_TEST_CASE(broadcasted_block_test)
{

tester producer_node;
tester receiving_node;
tester producer_node(setup_policy::full_pre_savanna);
tester receiving_node(setup_policy::full_pre_savanna);

signed_block_ptr bcasted_blk_by_prod_node;
signed_block_ptr bcasted_blk_by_recv_node;
Expand Down
10 changes: 5 additions & 5 deletions 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;
validating_tester tester{ {}, nullptr, setup_policy::full_pre_savanna };

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

Expand Down Expand Up @@ -58,7 +58,7 @@ BOOST_AUTO_TEST_CASE( replace_producer_keys ) try {
} FC_LOG_AND_RETHROW()

BOOST_AUTO_TEST_CASE( replace_account_keys ) try {
validating_tester tester;
validating_tester tester{ {}, nullptr, setup_policy::full_pre_savanna };
const name usr = config::system_account_name;
const name active_permission = config::active_name;
const auto& rlm = tester.control->get_resource_limits_manager();
Expand All @@ -82,7 +82,7 @@ BOOST_AUTO_TEST_CASE( replace_account_keys ) try {
} FC_LOG_AND_RETHROW()

BOOST_AUTO_TEST_CASE( decompressed_size_over_limit ) try {
tester chain;
tester chain(setup_policy::full_pre_savanna);

// build a transaction, add cf data, sign
cf_action cfa;
Expand Down Expand Up @@ -151,8 +151,8 @@ BOOST_AUTO_TEST_CASE( decompressed_size_under_limit ) try {

// verify accepted_block signals validated blocks
BOOST_AUTO_TEST_CASE( signal_validated_blocks ) try {
tester chain;
tester validator;
tester chain(setup_policy::full_pre_savanna);
tester validator(setup_policy::full_pre_savanna);

signed_block_ptr accepted_block;
block_id_type accepted_id;
Expand Down
Loading

0 comments on commit 5f0b736

Please sign in to comment.