Skip to content

Commit

Permalink
merged main incorporating token split tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ericpassmore committed Jun 14, 2024
2 parents 1157964 + 3908cfb commit 09e8c4f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 53 deletions.
25 changes: 14 additions & 11 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,18 @@ foreach(TEST_SUITE ${UNIT_TESTS}) # create an independent target for each test s
COMMAND
bash -c
"grep -E 'BOOST_AUTO_TEST_SUITE\\s*[(]' ${TEST_SUITE} | grep -vE '//.*BOOST_AUTO_TEST_SUITE\\s*[(]' | cut -d ')' -f 1 | cut -d '(' -f 2"
OUTPUT_VARIABLE SUITE_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE) # get the test suite name from the *.cpp file
if(NOT "" STREQUAL "${SUITE_NAME}") # ignore empty lines
execute_process(
COMMAND bash -c "echo ${SUITE_NAME} | sed -e 's/s$//' | sed -e 's/_test$//'"
OUTPUT_VARIABLE TRIMMED_SUITE_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE) # trim "_test" or "_tests" from the end of ${SUITE_NAME}
# to run unit_test with all log from blockchain displayed, put "--verbose" after "--", i.e. "unit_test -- --verbose"
add_test(NAME ${TRIMMED_SUITE_NAME}_unit_test COMMAND unit_test --run_test=${SUITE_NAME} --report_level=detailed
--color_output)
endif()
OUTPUT_VARIABLE SUITE_NAMES
OUTPUT_STRIP_TRAILING_WHITESPACE) # get all the test suite names from each *.cpp file
string(REPLACE "\n" ";" SUITE_NAMES "${SUITE_NAMES}")
foreach(SUITE_NAME IN LISTS SUITE_NAMES)
if(NOT "" STREQUAL "${SUITE_NAME}") # ignore empty lines
execute_process(
COMMAND bash -c "echo ${SUITE_NAME} | sed -e 's/s$//' | sed -e 's/_test$//'"
OUTPUT_VARIABLE TRIMMED_SUITE_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE) # trim "_test" or "_tests" from the end of ${SUITE_NAME}
# to run unit_test with all log from blockchain displayed, put "--verbose" after "--", i.e. "unit_test -- --verbose"
add_test(NAME ${TRIMMED_SUITE_NAME}_unit_test COMMAND unit_test --run_test=${SUITE_NAME} --report_level=detailed
--color_output)
endif()
endforeach(SUITE_NAME)
endforeach(TEST_SUITE)
42 changes: 25 additions & 17 deletions tests/eosio.powerup_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ using namespace eosio_system;

struct powerup_tester : eosio_system_tester {

// Use full_except_do_not_transition_to_savanna for now until
// https://github.com/AntelopeIO/reference-contracts/issues/91 is resolved
powerup_tester()
: eosio_system_tester(setup_level::full, setup_policy::full_except_do_not_transition_to_savanna) {
powerup_tester() {
create_accounts_with_resources({ "eosio.reserv"_n });
}

Expand Down Expand Up @@ -102,7 +99,7 @@ struct powerup_tester : eosio_system_tester {
config.net.current_weight_ratio = powerup_frac;
config.net.target_weight_ratio = powerup_frac / 100;
config.net.assumed_stake_weight = stake_weight;
config.net.target_timestamp = time_point_sec(control->head_block_time() + fc::days(100));
config.net.target_timestamp = time_point_sec(control->pending_block_time() + fc::days(100));
config.net.exponent = 2;
config.net.decay_secs = fc::days(1).to_seconds();
config.net.min_price = asset::from_string("0.0000 TST");
Expand All @@ -111,7 +108,7 @@ struct powerup_tester : eosio_system_tester {
config.cpu.current_weight_ratio = powerup_frac;
config.cpu.target_weight_ratio = powerup_frac / 100;
config.cpu.assumed_stake_weight = stake_weight;
config.cpu.target_timestamp = time_point_sec(control->head_block_time() + fc::days(100));
config.cpu.target_timestamp = time_point_sec(control->pending_block_time() + fc::days(100));
config.cpu.exponent = 2;
config.cpu.decay_secs = fc::days(1).to_seconds();
config.cpu.min_price = asset::from_string("0.0000 TST");
Expand Down Expand Up @@ -292,9 +289,9 @@ BOOST_FIXTURE_TEST_CASE(config_tests, powerup_tester) try {
BOOST_REQUIRE_EQUAL(wasm_assert_msg("target_timestamp does not have a default value"),
configbw(make_config([&](auto& c) { c.net.target_timestamp = {}; })));
BOOST_REQUIRE_EQUAL(wasm_assert_msg("target_timestamp must be in the future"),
configbw(make_config([&](auto& c) { c.net.target_timestamp = time_point_sec(control->head_block_time()); })));
configbw(make_config([&](auto& c) { c.net.target_timestamp = time_point_sec(control->pending_block_time()); })));
BOOST_REQUIRE_EQUAL(wasm_assert_msg("target_timestamp must be in the future"), configbw(make_config([&](auto& c) {
c.net.target_timestamp = time_point_sec(control->head_block_time() - fc::seconds(1));
c.net.target_timestamp = time_point_sec(control->pending_block_time() - fc::seconds(1));
})));
BOOST_REQUIRE_EQUAL(wasm_assert_msg("exponent must be >= 1"),
configbw(make_config([&](auto& c) { c.net.exponent = .999; })));
Expand Down Expand Up @@ -337,9 +334,9 @@ BOOST_FIXTURE_TEST_CASE(config_tests, powerup_tester) try {
BOOST_REQUIRE_EQUAL(wasm_assert_msg("target_timestamp does not have a default value"),
configbw(make_config([&](auto& c) { c.cpu.target_timestamp = {}; })));
BOOST_REQUIRE_EQUAL(wasm_assert_msg("target_timestamp must be in the future"),
configbw(make_config([&](auto& c) { c.cpu.target_timestamp = time_point_sec(control->head_block_time()); })));
configbw(make_config([&](auto& c) { c.cpu.target_timestamp = time_point_sec(control->pending_block_time()); })));
BOOST_REQUIRE_EQUAL(wasm_assert_msg("target_timestamp must be in the future"), configbw(make_config([&](auto& c) {
c.cpu.target_timestamp = time_point_sec(control->head_block_time() - fc::seconds(1));
c.cpu.target_timestamp = time_point_sec(control->pending_block_time() - fc::seconds(1));
})));
BOOST_REQUIRE_EQUAL(wasm_assert_msg("exponent must be >= 1"),
configbw(make_config([&](auto& c) { c.cpu.exponent = .999; })));
Expand Down Expand Up @@ -379,12 +376,12 @@ BOOST_FIXTURE_TEST_CASE(weight_tests, powerup_tester) try {
config.net.current_weight_ratio = net_start;
config.net.target_weight_ratio = net_target;
config.net.assumed_stake_weight = stake_weight;
config.net.target_timestamp = time_point_sec(control->head_block_time() + fc::days(10));
config.net.target_timestamp = time_point_sec(control->pending_block_time() + fc::days(10));

config.cpu.current_weight_ratio = cpu_start;
config.cpu.target_weight_ratio = cpu_target;
config.cpu.assumed_stake_weight = stake_weight;
config.cpu.target_timestamp = time_point_sec(control->head_block_time() + fc::days(20));
config.cpu.target_timestamp = time_point_sec(control->pending_block_time() + fc::days(20));
})));

int64_t net;
Expand Down Expand Up @@ -420,8 +417,8 @@ BOOST_FIXTURE_TEST_CASE(weight_tests, powerup_tester) try {
int i = 7;
produce_block(fc::days(1) - fc::milliseconds(500));
BOOST_REQUIRE_EQUAL("", configbw(make_default_config([&](powerup_config& config) {
config.net.target_timestamp = time_point_sec(control->head_block_time() + fc::days(30));
config.cpu.target_timestamp = time_point_sec(control->head_block_time() + fc::days(40));
config.net.target_timestamp = time_point_sec(control->pending_block_time() + fc::days(30));
config.cpu.target_timestamp = time_point_sec(control->pending_block_time() + fc::days(40));
})));
net_start = net = net_start + i * (net_target - net_start) / 10;
cpu_start = cpu = cpu_start + i * (cpu_target - cpu_start) / 20;
Expand Down Expand Up @@ -476,7 +473,7 @@ BOOST_FIXTURE_TEST_CASE(weight_tests, powerup_tester) try {
// Move transition time to immediate future
{
produce_block(fc::days(1) - fc::milliseconds(500));
time_point_sec tps(control->head_block_time() + fc::milliseconds(1000));
time_point_sec tps(control->pending_block_time() + fc::milliseconds(1000));
BOOST_REQUIRE_EQUAL("", configbw(make_default_config([&](powerup_config& config) {
config.net.target_timestamp = tps;
config.cpu.target_timestamp = tps;
Expand All @@ -498,7 +495,12 @@ FC_LOG_AND_RETHROW()
BOOST_AUTO_TEST_CASE(rent_tests) try {
{
powerup_tester t;
t.produce_block();
// This test is flaky. It only passes when head block time is on the second.
// https://github.com/AntelopeIO/reference-contracts/issues/104 tracks this issue.
if ((t.control->head_block_time().time_since_epoch().count() % 1000000ll) != 0) {
t.produce_block();
BOOST_REQUIRE_EQUAL((t.control->head_block_time().time_since_epoch().count() % 1000000ll), 0);
}

BOOST_REQUIRE_EQUAL(t.wasm_assert_msg("powerup hasn't been initialized"), //
t.powerup("bob111111111"_n, "alice1111111"_n, 30, powerup_frac / 4, powerup_frac / 8,
Expand Down Expand Up @@ -582,7 +584,13 @@ BOOST_AUTO_TEST_CASE(rent_tests) try {
}

auto init = [](auto& t, bool rex) {
t.produce_block();
// This test is flaky. It only passes when head block time is on the second.
// https://github.com/AntelopeIO/reference-contracts/issues/104 tracks this issue.
if ((t.control->head_block_time().time_since_epoch().count() % 1000000ll) != 0) {
t.produce_block();
BOOST_REQUIRE_EQUAL((t.control->head_block_time().time_since_epoch().count() % 1000000ll), 0);
}

BOOST_REQUIRE_EQUAL("", t.configbw(t.make_config([&](auto& config) {
// weight = stake_weight * 3
config.net.current_weight_ratio = powerup_frac / 4;
Expand Down
11 changes: 6 additions & 5 deletions tests/eosio.system_tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class eosio_system_tester : public validating_tester {
public:

void basic_setup() {
produce_blocks( 2 );
produce_block();

create_accounts({ "eosio.token"_n, "eosio.ram"_n, "eosio.ramfee"_n, "eosio.stake"_n,
"eosio.bpay"_n, "eosio.vpay"_n, "eosio.saving"_n, "eosio.names"_n, "eosio.rex"_n, "eosio.fees"_n });


produce_blocks( 100 );
produce_block();
set_code( "eosio.token"_n, contracts::token_wasm());
set_code( "eosio.fees"_n, contracts::fees_wasm());
set_abi( "eosio.token"_n, contracts::token_abi().data() );
Expand Down Expand Up @@ -66,7 +66,7 @@ class eosio_system_tester : public validating_tester {
}

void remaining_setup() {
produce_blocks();
produce_block();

// Assumes previous setup steps were done with core token symbol set to CORE_SYM
create_account_with_resources( "alice1111111"_n, config::system_account_name, core_sym::from_string("1.0000"), false );
Expand Down Expand Up @@ -1386,7 +1386,8 @@ class eosio_system_tester : public validating_tester {
BOOST_REQUIRE_EQUAL( success(), regproducer(p) );
}
}
produce_blocks( 250);
produce_block();
produce_block(fc::seconds(1000));

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())
Expand All @@ -1412,7 +1413,7 @@ class eosio_system_tester : public validating_tester {
)
);
}
produce_blocks( 250 );
produce_blocks( 2 * 21 ); // This is minimum number of blocks required by ram_gift in system_tests

auto producer_schedule = control->active_producers();
BOOST_REQUIRE_EQUAL( 21, producer_schedule.producers.size() );
Expand Down
51 changes: 31 additions & 20 deletions tests/eosio.system_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ using namespace eosio_system;
bool within_error(int64_t a, int64_t b, int64_t err) { return std::abs(a - b) <= err; };
bool within_one(int64_t a, int64_t b) { return within_error(a, b, 1); }

// Split the tests into multiple suites so that they can be finished within CICD time limit.
// Each suite takes approximately same amount of time.
BOOST_AUTO_TEST_SUITE(eosio_system_part1_tests)
// Split the tests into multiple suites so that they can run in parallel in CICD to
// reduce overall CICD time..
// Each suite is grouped by functionality and takes approximately the same amount of time.

BOOST_AUTO_TEST_SUITE(eosio_system_stake_tests)

BOOST_FIXTURE_TEST_CASE( buysell, eosio_system_tester ) try {

Expand Down Expand Up @@ -745,6 +747,9 @@ BOOST_FIXTURE_TEST_CASE( stake_to_another_user_not_from_refund, eosio_system_tes

} FC_LOG_AND_RETHROW()

BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(eosio_system_producer_tests)

// Tests for voting
BOOST_FIXTURE_TEST_CASE( producer_register_unregister, eosio_system_tester ) try {
issue_and_transfer( "alice1111111", core_sym::from_string("1000.0000"), config::system_account_name );
Expand Down Expand Up @@ -1664,7 +1669,7 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester, * boost::unit_test::t
} FC_LOG_AND_RETHROW()

BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(eosio_system_part2_tests)
BOOST_AUTO_TEST_SUITE(eosio_system_inflation_tests)

BOOST_FIXTURE_TEST_CASE(change_inflation, eosio_system_tester) try {

Expand Down Expand Up @@ -1813,7 +1818,7 @@ BOOST_AUTO_TEST_CASE(extreme_inflation) try {
} FC_LOG_AND_RETHROW()

BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(eosio_system_part3_tests)
BOOST_AUTO_TEST_SUITE(eosio_system_multiple_producer_pay_tests)

BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::unit_test::tolerance(1e-10)) try {

Expand Down Expand Up @@ -2194,6 +2199,9 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni
} FC_LOG_AND_RETHROW()


BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(eosio_system_votepay_tests)

BOOST_FIXTURE_TEST_CASE(multiple_producer_votepay_share, eosio_system_tester, * boost::unit_test::tolerance(1e-10)) try {

const asset net = core_sym::from_string("80.0000");
Expand Down Expand Up @@ -2892,9 +2900,6 @@ BOOST_FIXTURE_TEST_CASE(producers_upgrade_system_contract, eosio_system_tester)
BOOST_REQUIRE( bool(trace) );
BOOST_REQUIRE_EQUAL( 1, trace->action_traces.size() );
BOOST_REQUIRE_EQUAL( transaction_receipt::executed, trace->receipt->status );

produce_blocks( 250 );

} FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE(producer_onblock_check, eosio_system_tester) try {
Expand Down Expand Up @@ -3290,6 +3295,9 @@ BOOST_FIXTURE_TEST_CASE( elect_producers /*_and_parameters*/, eosio_system_teste
} FC_LOG_AND_RETHROW()


BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(eosio_system_name_tests)

BOOST_FIXTURE_TEST_CASE( buyname, eosio_system_tester ) try {
create_accounts_with_resources( { "dan"_n, "sam"_n } );
transfer( config::system_account_name, "dan", core_sym::from_string( "10000.0000" ) );
Expand Down Expand Up @@ -3936,6 +3944,9 @@ BOOST_FIXTURE_TEST_CASE( ram_gift, eosio_system_tester ) try {

} FC_LOG_AND_RETHROW()

BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(eosio_system_rex_tests)

BOOST_FIXTURE_TEST_CASE( rex_rounding_issue, eosio_system_tester ) try {
const std::vector<name> whales { "whale1"_n, "whale2"_n, "whale3"_n, "whale4"_n , "whale5"_n };
const name bob{ "bob"_n }, alice{ "alice"_n };
Expand Down Expand Up @@ -5516,8 +5527,8 @@ BOOST_FIXTURE_TEST_CASE( donate_to_rex, eosio_system_tester ) try {
donatetorex( bob, core_sym::from_string("-100.0000"), "") );

BOOST_REQUIRE_EQUAL( success(), donatetorex( bob, core_sym::from_string("100.0000"), "") );


for (int i = 0; i < 4; ++i) {
const asset rex_balance = get_balance("eosio.rex"_n);
const int64_t rex_proceeds = get_rex_return_pool()["proceeds"].as<int64_t>();
Expand Down Expand Up @@ -5614,13 +5625,13 @@ BOOST_FIXTURE_TEST_CASE( b1_vesting, eosio_system_tester ) try {
BOOST_REQUIRE_EQUAL( error("missing authority of eosio"), vote( b1, { }, "proxyaccount"_n ) );

// Can't take what isn't vested
BOOST_REQUIRE_EQUAL(
BOOST_REQUIRE_EQUAL(
wasm_assert_msg("b1 can only claim what has already vested"),
unstake( b1, b1, stake_amount, stake_amount )
unstake( b1, b1, stake_amount, stake_amount )
);
BOOST_REQUIRE_EQUAL(
BOOST_REQUIRE_EQUAL(
wasm_assert_msg("b1 can only claim what has already vested"),
unstake( b1, b1, stake_amount, zero )
unstake( b1, b1, stake_amount, zero )
);

// Taking the vested amount - 1 token
Expand All @@ -5631,15 +5642,15 @@ BOOST_FIXTURE_TEST_CASE( b1_vesting, eosio_system_tester ) try {
get_voter_info( b1 )["staked"].as<int64_t>() );

// Can't take 2 tokens, only 1 is vested
BOOST_REQUIRE_EQUAL(
BOOST_REQUIRE_EQUAL(
wasm_assert_msg("b1 can only claim what has already vested"),
unstake( b1, b1, oneToken, oneToken )
unstake( b1, b1, oneToken, oneToken )
);

// Can't unvest the 1 token, as it's already unvested
BOOST_REQUIRE_EQUAL(
BOOST_REQUIRE_EQUAL(
wasm_assert_msg("can only unvest what is not already vested"),
unvest( b1, (stake_amount - vested) + oneToken, stake_amount )
unvest( b1, (stake_amount - vested) + oneToken, stake_amount )
);

auto supply_before = get_token_supply();
Expand All @@ -5649,8 +5660,8 @@ BOOST_FIXTURE_TEST_CASE( b1_vesting, eosio_system_tester ) try {
BOOST_REQUIRE_EQUAL(oneToken.get_amount(), get_voter_info( b1 )["staked"].as<int64_t>() );

// Should have retired the unvestable tokens
BOOST_REQUIRE_EQUAL(
get_token_supply(),
BOOST_REQUIRE_EQUAL(
get_token_supply(),
supply_before-unvestable
);

Expand Down

0 comments on commit 09e8c4f

Please sign in to comment.