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

Fix fragile powerup_tests/weight_tests so that they can run under Savanna #101

Merged
merged 3 commits into from
Jun 14, 2024
Merged
Changes from all commits
Commits
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
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
Loading