Skip to content

Commit

Permalink
Merge pull request #1112 from AntelopeIO/GH-259-test-cleanup
Browse files Browse the repository at this point in the history
Tests: misc cleanup
  • Loading branch information
heifner authored May 1, 2023
2 parents 57d5546 + 32ce272 commit 324ff33
Show file tree
Hide file tree
Showing 23 changed files with 279 additions and 374 deletions.
6 changes: 4 additions & 2 deletions libraries/testing/include/eosio/testing/tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ namespace eosio { namespace testing {
full
};

std::ostream& operator<<(std::ostream& os, setup_policy p);

std::vector<uint8_t> read_wasm( const char* fn );
std::vector<char> read_abi( const char* fn );
std::string read_wast( const char* fn );
Expand Down Expand Up @@ -528,7 +530,7 @@ namespace eosio { namespace testing {
}
controller::config vcfg;

validating_tester(const flat_set<account_name>& trusted_producers = flat_set<account_name>(), deep_mind_handler* dmlog = nullptr) {
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 All @@ -538,7 +540,7 @@ namespace eosio { namespace testing {
validating_node = create_validating_node(vcfg, def_conf.second, true, dmlog);

init(def_conf.first, def_conf.second);
execute_setup_policy(setup_policy::full);
execute_setup_policy(p);
}

static void config_validator(controller::config& vcfg) {
Expand Down
29 changes: 29 additions & 0 deletions libraries/testing/tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,35 @@ eosio::chain::asset core_from_string(const std::string& s) {
}

namespace eosio { namespace testing {

// required by boost::unit_test::data
std::ostream& operator<<(std::ostream& os, setup_policy p) {
switch(p) {
case setup_policy::none:
os << "none";
break;
case setup_policy::old_bios_only:
os << "old_bios_only";
break;
case setup_policy::preactivate_feature_only:
os << "preactivate_feature_only";
break;
case setup_policy::preactivate_feature_and_new_bios:
os << "preactivate_feature_and_new_bios";
break;
case setup_policy::old_wasm_parser:
os << "old_wasm_parser";
break;
case setup_policy::full:
os << "full";
break;
default:
FC_ASSERT(false, "Unknown setup_policy");
}
return os;
}


std::string read_wast( const char* fn ) {
std::ifstream wast_file(fn);
FC_ASSERT( wast_file.is_open(), "wast file cannot be found" );
Expand Down
12 changes: 3 additions & 9 deletions plugins/chain_plugin/test/test_account_query_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
#include <eosio/chain_plugin/account_query_db.hpp>
#include <eosio/chain/thread_utils.hpp>

#ifdef NON_VALIDATING_TEST
#define TESTER tester
#else
#define TESTER validating_tester
#endif

using namespace eosio;
using namespace eosio::chain;
using namespace eosio::testing;
Expand All @@ -39,7 +33,7 @@ bool find_account_auth(results rst, account_name name, permission_name perm){

BOOST_AUTO_TEST_SUITE(account_query_db_tests)

BOOST_FIXTURE_TEST_CASE(newaccount_test, TESTER) { try {
BOOST_FIXTURE_TEST_CASE(newaccount_test, validating_tester) { try {

// instantiate an account_query_db
auto aq_db = account_query_db(*control);
Expand All @@ -64,7 +58,7 @@ BOOST_FIXTURE_TEST_CASE(newaccount_test, TESTER) { try {

} FC_LOG_AND_RETHROW() }

BOOST_FIXTURE_TEST_CASE(updateauth_test, TESTER) { try {
BOOST_FIXTURE_TEST_CASE(updateauth_test, validating_tester) { try {

// instantiate an account_query_db
auto aq_db = account_query_db(*control);
Expand Down Expand Up @@ -98,7 +92,7 @@ BOOST_FIXTURE_TEST_CASE(updateauth_test, TESTER) { try {

} FC_LOG_AND_RETHROW() }

BOOST_FIXTURE_TEST_CASE(updateauth_test_multi_threaded, TESTER) { try {
BOOST_FIXTURE_TEST_CASE(updateauth_test_multi_threaded, validating_tester) { try {

// instantiate an account_query_db
auto aq_db = account_query_db(*control);
Expand Down
12 changes: 3 additions & 9 deletions tests/chain_plugin_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
#include <array>
#include <utility>

#ifdef NON_VALIDATING_TEST
#define TESTER tester
#else
#define TESTER validating_tester
#endif

using namespace eosio;
using namespace eosio::chain;
using namespace eosio::testing;
Expand All @@ -41,7 +35,7 @@ static auto get_account_full = [](chain_apis::read_only& plugin,

BOOST_AUTO_TEST_SUITE(chain_plugin_tests)

BOOST_FIXTURE_TEST_CASE( get_block_with_invalid_abi, TESTER ) try {
BOOST_FIXTURE_TEST_CASE( get_block_with_invalid_abi, validating_tester ) try {
produce_blocks(2);

create_accounts( {"asserter"_n} );
Expand Down Expand Up @@ -136,7 +130,7 @@ BOOST_FIXTURE_TEST_CASE( get_block_with_invalid_abi, TESTER ) try {

} FC_LOG_AND_RETHROW() /// get_block_with_invalid_abi

BOOST_FIXTURE_TEST_CASE( get_consensus_parameters, TESTER ) try {
BOOST_FIXTURE_TEST_CASE( get_consensus_parameters, validating_tester ) try {
produce_blocks(1);

chain_apis::read_only plugin(*(this->control), {}, fc::microseconds::maximum(), fc::microseconds::maximum(), nullptr);
Expand Down Expand Up @@ -178,7 +172,7 @@ BOOST_FIXTURE_TEST_CASE( get_consensus_parameters, TESTER ) try {

} FC_LOG_AND_RETHROW() //get_consensus_parameters

BOOST_FIXTURE_TEST_CASE( get_account, TESTER ) try {
BOOST_FIXTURE_TEST_CASE( get_account, validating_tester ) try {
produce_blocks(2);

std::vector<account_name> accs{{ "alice"_n, "bob"_n, "cindy"_n}};
Expand Down
8 changes: 1 addition & 7 deletions tests/get_table_seckey_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
#include <array>
#include <utility>

#ifdef NON_VALIDATING_TEST
#define TESTER tester
#else
#define TESTER validating_tester
#endif

using namespace eosio;
using namespace eosio::chain;
using namespace eosio::testing;
Expand All @@ -41,7 +35,7 @@ static auto get_table_rows_full = [](chain_apis::read_only& plugin,

BOOST_AUTO_TEST_SUITE(get_table_seckey_tests)

BOOST_FIXTURE_TEST_CASE( get_table_next_key_test, TESTER ) try {
BOOST_FIXTURE_TEST_CASE( get_table_next_key_test, validating_tester ) try {
create_account("test"_n);

// setup contract and abi
Expand Down
16 changes: 5 additions & 11 deletions tests/get_table_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
#include <array>
#include <utility>

#ifdef NON_VALIDATING_TEST
#define TESTER tester
#else
#define TESTER validating_tester
#endif

using namespace eosio;
using namespace eosio::chain;
using namespace eosio::testing;
Expand All @@ -42,7 +36,7 @@ static auto get_table_rows_full = [](chain_apis::read_only& plugin,
BOOST_AUTO_TEST_SUITE(get_table_tests)

transaction_trace_ptr
issue_tokens( TESTER& t, account_name issuer, account_name to, const asset& amount,
issue_tokens( validating_tester& t, account_name issuer, account_name to, const asset& amount,
std::string memo = "", account_name token_contract = "eosio.token"_n )
{
signed_transaction trx;
Expand All @@ -69,7 +63,7 @@ issue_tokens( TESTER& t, account_name issuer, account_name to, const asset& amou
return t.push_transaction( trx );
}

BOOST_FIXTURE_TEST_CASE( get_scope_test, TESTER ) try {
BOOST_FIXTURE_TEST_CASE( get_scope_test, validating_tester ) try {
produce_blocks(2);

create_accounts({ "eosio.token"_n, "eosio.ram"_n, "eosio.ramfee"_n, "eosio.stake"_n,
Expand Down Expand Up @@ -141,7 +135,7 @@ BOOST_FIXTURE_TEST_CASE( get_scope_test, TESTER ) try {

} FC_LOG_AND_RETHROW() /// get_scope_test

BOOST_FIXTURE_TEST_CASE( get_table_test, TESTER ) try {
BOOST_FIXTURE_TEST_CASE( get_table_test, validating_tester ) try {
produce_blocks(2);

create_accounts({ "eosio.token"_n, "eosio.ram"_n, "eosio.ramfee"_n, "eosio.stake"_n,
Expand Down Expand Up @@ -321,7 +315,7 @@ BOOST_FIXTURE_TEST_CASE( get_table_test, TESTER ) try {

} FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE( get_table_by_seckey_test, TESTER ) try {
BOOST_FIXTURE_TEST_CASE( get_table_by_seckey_test, validating_tester ) try {
produce_blocks(2);

create_accounts({ "eosio.token"_n, "eosio.ram"_n, "eosio.ramfee"_n, "eosio.stake"_n,
Expand Down Expand Up @@ -457,7 +451,7 @@ BOOST_FIXTURE_TEST_CASE( get_table_by_seckey_test, TESTER ) try {
} FC_LOG_AND_RETHROW()


BOOST_FIXTURE_TEST_CASE( get_table_next_key_test, TESTER ) try {
BOOST_FIXTURE_TEST_CASE( get_table_next_key_test, validating_tester ) try {
create_account("test"_n);

// setup contract and abi
Expand Down
10 changes: 2 additions & 8 deletions tests/test_chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
#include <fc/log/logger.hpp>
#include <eosio/chain/exceptions.hpp>

#ifdef NON_VALIDATING_TEST
#define TESTER tester
#else
#define TESTER validating_tester
#endif

using namespace eosio;
using namespace eosio::chain;
using namespace eosio::chain_apis;
Expand All @@ -29,7 +23,7 @@ using namespace fc;

using mvo = fc::mutable_variant_object;

class chain_plugin_tester : public TESTER {
class chain_plugin_tester : public validating_tester {
public:

action_result push_action( const account_name& signer, const action_name &name, const variant_object &data, bool auth = true ) {
Expand Down Expand Up @@ -324,7 +318,7 @@ class chain_plugin_tester : public TESTER {
}
produce_blocks( 250);

auto trace_auth = TESTER::push_action(config::system_account_name, updateauth::get_name(), config::system_account_name, mvo()
auto trace_auth = validating_tester::push_action(config::system_account_name, updateauth::get_name(), config::system_account_name, mvo()
("account", name(config::system_account_name).to_string())
("permission", name(config::active_name).to_string())
("parent", name(config::owner_name).to_string())
Expand Down
Loading

0 comments on commit 324ff33

Please sign in to comment.