Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
fix 15% percent error message and associated tests #3932
Browse files Browse the repository at this point in the history
  • Loading branch information
arhag committed Jun 7, 2018
1 parent f42d386 commit 245394a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
3 changes: 2 additions & 1 deletion contracts/eosio.system/delegate_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ namespace eosiosystem {
eosio_assert( asset() <= unstake_cpu_quantity, "must unstake a positive amount" );
eosio_assert( asset() <= unstake_net_quantity, "must unstake a positive amount" );
eosio_assert( asset() < unstake_cpu_quantity + unstake_net_quantity, "must unstake a positive amount" );
eosio_assert( _gstate.total_activated_stake >= min_activated_stake, "the chain has not been activated yet (less than 15% of all tokens have participated in voting)" );
eosio_assert( _gstate.total_activated_stake >= min_activated_stake,
"cannot undelegate bandwidth until the chain is activated (at least 15% of all tokens participate in voting)" );

changebw( from, receiver, -unstake_net_quantity, -unstake_cpu_quantity, false);
} // undelegatebw
Expand Down
13 changes: 7 additions & 6 deletions contracts/eosio.system/producer_pay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ namespace eosiosystem {
p.unpaid_blocks++;
});
}

/// only update block producers once every minute, block_timestamp is in half seconds
if( timestamp.slot - _gstate.last_producer_schedule_update.slot > 120 ) {
update_elected_producers( timestamp );

if( (timestamp.slot - _gstate.last_name_close.slot) > blocks_per_day ) {
name_bid_table bids(_self,_self);
auto idx = bids.get_index<N(highbid)>();
Expand All @@ -70,8 +70,9 @@ namespace eosiosystem {

const auto& prod = _producers.get( owner );
eosio_assert( prod.active(), "producer does not have an active key" );

eosio_assert( _gstate.total_activated_stake >= min_activated_stake, "the chain has not been activated yet (less than 15% of all tokens have participated in voting)" );

eosio_assert( _gstate.total_activated_stake >= min_activated_stake,
"cannot claim rewards until the chain is activated (at least 15% of all tokens participate in voting)" );

auto ct = current_time();

Expand Down Expand Up @@ -111,7 +112,7 @@ namespace eosiosystem {
producer_per_block_pay = (_gstate.perblock_bucket * prod.unpaid_blocks) / _gstate.total_unpaid_blocks;
}
int64_t producer_per_vote_pay = 0;
if( _gstate.total_producer_vote_weight > 0 ) {
if( _gstate.total_producer_vote_weight > 0 ) {
producer_per_vote_pay = int64_t((_gstate.pervote_bucket * prod.total_votes ) / _gstate.total_producer_vote_weight);
}
if( producer_per_vote_pay < min_pervote_daily_pay ) {
Expand All @@ -125,7 +126,7 @@ namespace eosiosystem {
p.last_claim_time = ct;
p.unpaid_blocks = 0;
});

if( producer_per_block_pay > 0 ) {
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {N(eosio.bpay),N(active)},
{ N(eosio.bpay), owner, asset(producer_per_block_pay), std::string("producer block pay") } );
Expand Down
10 changes: 6 additions & 4 deletions unittests/eosio.system_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,7 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni
BOOST_REQUIRE(prod_was_replaced);
}
}

{
BOOST_REQUIRE_EQUAL( wasm_assert_msg("producer not found"),
push_action( config::system_account_name, N(rmvproducer), mvo()("producer", "nonexistingp") ) );
Expand Down Expand Up @@ -1699,7 +1699,8 @@ BOOST_FIXTURE_TEST_CASE(producer_onblock_check, eosio_system_tester) try {
transfer(config::system_account_name, "producvotera", core_from_string("200000000.0000"), config::system_account_name);
BOOST_REQUIRE_EQUAL(success(), stake("producvotera", core_from_string("70000000.0000"), core_from_string("70000000.0000") ));
BOOST_REQUIRE_EQUAL(success(), vote( N(producvotera), vector<account_name>(producer_names.begin(), producer_names.begin()+10)));
BOOST_CHECK_EQUAL( wasm_assert_msg("not enough has been staked for users to unstake"), unstake( "producvotera", core_from_string("50.0000"), core_from_string("50.0000") ) );
BOOST_CHECK_EQUAL( wasm_assert_msg( "cannot undelegate bandwidth until the chain is activated (at least 15% of all tokens participate in voting)" ),
unstake( "producvotera", core_from_string("50.0000"), core_from_string("50.0000") ) );

// give a chance for everyone to produce blocks
{
Expand All @@ -1721,11 +1722,12 @@ BOOST_FIXTURE_TEST_CASE(producer_onblock_check, eosio_system_tester) try {
}

{
const char* claimrewards_activation_error_message = "cannot claim rewards until the chain is activated (at least 15% of all tokens participate in voting)";
BOOST_CHECK_EQUAL(0, get_global_state()["total_unpaid_blocks"].as<uint32_t>());
BOOST_REQUIRE_EQUAL(wasm_assert_msg("not enough has been staked for producers to claim rewards"),
BOOST_REQUIRE_EQUAL(wasm_assert_msg( claimrewards_activation_error_message ),
push_action(producer_names.front(), N(claimrewards), mvo()("owner", producer_names.front())));
BOOST_REQUIRE_EQUAL(0, get_balance(producer_names.front()).get_amount());
BOOST_REQUIRE_EQUAL(wasm_assert_msg("not enough has been staked for producers to claim rewards"),
BOOST_REQUIRE_EQUAL(wasm_assert_msg( claimrewards_activation_error_message ),
push_action(producer_names.back(), N(claimrewards), mvo()("owner", producer_names.back())));
BOOST_REQUIRE_EQUAL(0, get_balance(producer_names.back()).get_amount());
}
Expand Down

0 comments on commit 245394a

Please sign in to comment.