Skip to content

Commit

Permalink
add schedule with 0% annual rate
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed May 4, 2024
1 parent 812ffa6 commit 6e79c48
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion contracts/eosio.system/src/eosio.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,8 @@ namespace eosiosystem {
bool system_contract::execute_next_schedule()
{
auto itr = _schedules.begin();
if ( itr->annual_rate == 0 ) return false; // row is empty
if (itr == _schedules.end()) return false; // no schedules to execute

if ( current_time_point().sec_since_epoch() >= itr->start_time.sec_since_epoch() ) {
_gstate4.continuous_rate = get_continuous_rate(itr->annual_rate);
_schedules.erase( itr );
Expand Down
7 changes: 6 additions & 1 deletion tests/eosio.system_schedules_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ BOOST_FIXTURE_TEST_CASE(set_schedules, eosio_system_tester) try {
BOOST_REQUIRE_EQUAL( success(), setschedule(start_time, 200) ); // allow override existing schedules
BOOST_REQUIRE_EQUAL( success(), delschedule(start_time) );

// set 3 future schedules
// set 4 future schedules
BOOST_REQUIRE_EQUAL( success(), setschedule(time_point_sec(start_time), 200) );
BOOST_REQUIRE_EQUAL( success(), setschedule(time_point_sec(initial_start_time + YEAR * 4), 100) );
BOOST_REQUIRE_EQUAL( success(), setschedule(time_point_sec(initial_start_time + YEAR * 8), 50) );
BOOST_REQUIRE_EQUAL( success(), setschedule(time_point_sec(initial_start_time + YEAR * 12), 0) );

// current state prior to first schedule
const double before = get_global_state4()["continuous_rate"].as_double();
Expand All @@ -49,6 +50,10 @@ BOOST_FIXTURE_TEST_CASE(set_schedules, eosio_system_tester) try {
BOOST_REQUIRE_EQUAL( success(), execschedule(alice) );
BOOST_REQUIRE_EQUAL( get_global_state4()["continuous_rate"].as_double(), 0.0049875415110390738 ); // 0.5% annual rate

produce_block( fc::days(365 * 4) ); // advanced to year 16
BOOST_REQUIRE_EQUAL( success(), execschedule(alice) );
BOOST_REQUIRE_EQUAL( get_global_state4()["continuous_rate"].as_double(), 0.0 ); // 0% annual rate

} FC_LOG_AND_RETHROW()

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 6e79c48

Please sign in to comment.