Skip to content
This repository was archived by the owner on Oct 4, 2019. It is now read-only.

Commit be5a552

Browse files
authored
Merge pull request #1357 from GolosChain/vote-author-promote-improve-and-tests
Vote author promote improve #1356 and tests #1355
2 parents 02e2976 + 37c20ee commit be5a552

3 files changed

Lines changed: 216 additions & 13 deletions

File tree

libraries/chain/database.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2364,7 +2364,16 @@ namespace golos { namespace chain {
23642364
try {
23652365
share_type unclaimed_rewards = max_rewards;
23662366

2367-
if (c.total_vote_weight > 0 && c.comment.allow_curation_rewards) {
2367+
if (!c.comment.allow_curation_rewards) {
2368+
modify(get_dynamic_global_properties(), [&](dynamic_global_property_object &props) {
2369+
props.total_reward_fund_steem += unclaimed_rewards;
2370+
});
2371+
2372+
unclaimed_rewards = 0;
2373+
return unclaimed_rewards;
2374+
}
2375+
2376+
if (c.total_vote_weight > 0) {
23682377
uint128_t total_weight(c.total_vote_weight);
23692378
uint128_t auction_window_reward = uint128_t(max_rewards.value) * c.auction_window_weight / total_weight;
23702379

@@ -2374,6 +2383,10 @@ namespace golos { namespace chain {
23742383
for (auto itr = c.vote_list.begin(); c.vote_list.end() != itr; ++itr) {
23752384
uint128_t weight(itr->weight);
23762385
uint64_t claim = ((max_rewards.value * weight) / total_weight).to_uint64();
2386+
if (has_hardfork(STEEMIT_HARDFORK_0_22__1014)) {
2387+
claim -= (uint128_t(claim) * (*itr->vote).author_promote_rate / STEEMIT_100_PERCENT).to_uint64();
2388+
}
2389+
23772390
// to_curators case
23782391
if (c.comment.auction_window_reward_destination == protocol::to_curators &&
23792392
itr->vote->auction_time == c.comment.auction_window_size
@@ -2390,9 +2403,6 @@ namespace golos { namespace chain {
23902403
}
23912404

23922405
if (claim > 0) { // min_amt is non-zero satoshis
2393-
if (has_hardfork(STEEMIT_HARDFORK_0_22__1014)) {
2394-
claim -= (uint128_t(claim) * (*itr->vote).author_promote_rate / STEEMIT_100_PERCENT).to_uint64();
2395-
}
23962406
unclaimed_rewards -= claim;
23972407
pay_curator(*itr->vote, claim, c.comment.author, to_string(c.comment.permlink));
23982408
} else {
@@ -2407,15 +2417,8 @@ namespace golos { namespace chain {
24072417
unclaimed_rewards = 0;
24082418
}
24092419
}
2410-
if (!c.comment.allow_curation_rewards) {
2411-
modify(get_dynamic_global_properties(), [&](dynamic_global_property_object &props) {
2412-
props.total_reward_fund_steem += unclaimed_rewards;
2413-
});
2414-
2415-
unclaimed_rewards = 0;
2416-
}
24172420
// Case: auction window destination is reward fund or there are not curator which can get the auw reward
2418-
else if (c.comment.auction_window_reward_destination != protocol::to_author && unclaimed_rewards > 0) {
2421+
if (c.comment.auction_window_reward_destination != protocol::to_author && unclaimed_rewards > 0) {
24192422
push_virtual_operation(auction_window_reward_operation(asset(unclaimed_rewards, STEEM_SYMBOL), c.comment.author, to_string(c.comment.permlink)));
24202423
modify(get_dynamic_global_properties(), [&](dynamic_global_property_object &props) {
24212424
props.total_reward_fund_steem += asset(unclaimed_rewards, STEEM_SYMBOL);

tests/common/comment_reward.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ namespace golos { namespace chain {
237237
BOOST_REQUIRE(vote_payout_map_.find(itr->vote->voter) == vote_payout_map_.end());
238238
auto weight = u256(itr->weight);
239239
uint64_t claim = static_cast<uint64_t>(weight * vote_rewards_fund_ / total_weight);
240+
if (db_.has_hardfork(STEEMIT_HARDFORK_0_22__1014)) {
241+
auto promote_reward = claim * itr->vote->author_promote_rate / STEEMIT_100_PERCENT;
242+
claim -= promote_reward;
243+
}
244+
240245
// to_curators case
241246
if (comment_.auction_window_reward_destination == protocol::to_curators &&
242247
(itr->vote->last_update >= auw_time || db_.get(itr->vote->voter).name == comment_.author)

tests/tests/operation_tests.cpp

Lines changed: 196 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7844,7 +7844,202 @@ BOOST_FIXTURE_TEST_SUITE(operation_tests, clean_database_fixture)
78447844

78457845
BOOST_AUTO_TEST_SUITE_END() // comment_curation_rewards_percent
78467846

7847-
BOOST_AUTO_TEST_SUITE_END()
7847+
BOOST_AUTO_TEST_SUITE(vote_options) // vote_options
7848+
7849+
BOOST_AUTO_TEST_CASE(vote_options_authorities) { try {
7850+
BOOST_TEST_MESSAGE("Testing: vote_options_authorities");
7851+
7852+
vote_options_operation op;
7853+
op.voter = "bob";
7854+
op.author = "alice";
7855+
op.permlink = "test";
7856+
CHECK_OP_AUTHS(op, account_name_set(), account_name_set(), account_name_set({"bob"}));
7857+
} FC_LOG_AND_RETHROW() }
7858+
7859+
BOOST_AUTO_TEST_CASE(vote_options_validate) { try {
7860+
BOOST_TEST_MESSAGE("Testing: vote_options_validate");
7861+
7862+
BOOST_TEST_MESSAGE("-- Normal case");
7863+
7864+
vote_options_operation op;
7865+
op.voter = "bob";
7866+
op.author = "alice";
7867+
op.permlink = "test";
7868+
CHECK_OP_VALID(op);
7869+
7870+
BOOST_TEST_MESSAGE("-- Incorrect account or permlink case");
7871+
7872+
CHECK_PARAM_INVALID(op, voter, "");
7873+
CHECK_PARAM_INVALID(op, author, "");
7874+
CHECK_PARAM_INVALID(op, permlink, std::string(STEEMIT_MAX_PERMLINK_LENGTH+1, ' '));
7875+
7876+
} FC_LOG_AND_RETHROW() }
7877+
7878+
BOOST_AUTO_TEST_CASE(author_promote_rate_validate) { try {
7879+
BOOST_TEST_MESSAGE("Testing: author_promote_rate_validate");
7880+
7881+
vote_options_operation op;
7882+
op.voter = "bob";
7883+
op.author = "alice";
7884+
op.permlink = "test";
7885+
7886+
BOOST_TEST_MESSAGE("-- Normal case with author_promote_rate");
7887+
7888+
vote_options_extensions_type op_exts;
7889+
op_exts.insert(vote_author_promote_rate(0));
7890+
CHECK_PARAM_VALID(op, extensions, op_exts);
7891+
7892+
op_exts.clear();
7893+
op_exts.insert(vote_author_promote_rate(STEEMIT_100_PERCENT));
7894+
CHECK_PARAM_VALID(op, extensions, op_exts);
7895+
7896+
BOOST_TEST_MESSAGE("-- author_promote_rate < 0");
7897+
7898+
op.extensions.clear();
7899+
op.extensions.insert(vote_author_promote_rate(-1));
7900+
GOLOS_CHECK_ERROR_PROPS(op.validate(),
7901+
CHECK_ERROR(invalid_parameter, "rate"));
7902+
7903+
BOOST_TEST_MESSAGE("-- author_promote_rate > 100%");
7904+
7905+
op.extensions.clear();
7906+
op.extensions.insert(vote_author_promote_rate(STEEMIT_100_PERCENT+1));
7907+
GOLOS_CHECK_ERROR_PROPS(op.validate(),
7908+
CHECK_ERROR(invalid_parameter, "rate"));
7909+
7910+
} FC_LOG_AND_RETHROW() }
7911+
7912+
BOOST_AUTO_TEST_CASE(vote_options_apply) { try {
7913+
BOOST_TEST_MESSAGE("Testing: vote_options_apply");
7914+
7915+
signed_transaction tx;
7916+
ACTORS((alice)(bob))
7917+
fund("alice", 10000);
7918+
vest("alice", 10000);
7919+
fund("bob", 10000);
7920+
vest("bob", 10000);
7921+
generate_block();
7922+
7923+
BOOST_TEST_MESSAGE("--- Testing without comment");
7924+
7925+
vote_options_operation op;
7926+
op.voter = "bob";
7927+
op.author = "alice";
7928+
op.permlink = "alice-test";
7929+
7930+
GOLOS_CHECK_ERROR_MISSING(comment, make_comment_id("alice", "alice-test"), bob_private_key, op);
7931+
7932+
BOOST_TEST_MESSAGE("--- Creating comment");
7933+
7934+
comment_create("alice", alice_private_key, "alice-test", "", "alice-test");
7935+
generate_block();
7936+
7937+
BOOST_TEST_MESSAGE("--- Testing without vote");
7938+
7939+
GOLOS_CHECK_ERROR_MISSING(comment_vote_object, fc::mutable_variant_object()("voter",op.voter)("author",op.author)("permlink",op.permlink),
7940+
bob_private_key, op);
7941+
7942+
BOOST_TEST_MESSAGE("--- Voting for comment");
7943+
7944+
vote_operation vote_op;
7945+
vote_op.voter = "bob";
7946+
vote_op.author = "alice";
7947+
vote_op.permlink = "alice-test";
7948+
vote_op.weight = 1000;
7949+
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, bob_private_key, vote_op));
7950+
generate_block();
7951+
7952+
BOOST_TEST_MESSAGE("--- Normal call without extensions");
7953+
7954+
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, bob_private_key, op));
7955+
generate_block();
7956+
7957+
validate_database();
7958+
} FC_LOG_AND_RETHROW() }
7959+
7960+
BOOST_AUTO_TEST_CASE(author_promote_rate_apply) { try {
7961+
BOOST_TEST_MESSAGE("Testing: author_promote_rate_apply");
7962+
7963+
signed_transaction tx;
7964+
ACTORS((alice)(bob))
7965+
fund("alice", 10000);
7966+
vest("alice", 10000);
7967+
fund("bob", 10000);
7968+
vest("bob", 10000);
7969+
generate_block();
7970+
7971+
auto& wso = db->get_witness_schedule_object();
7972+
BOOST_CHECK_EQUAL(wso.median_props.min_vote_author_promote_rate, GOLOS_MIN_VOTE_AUTHOR_PROMOTE_RATE);
7973+
BOOST_CHECK_EQUAL(wso.median_props.max_vote_author_promote_rate, GOLOS_MAX_VOTE_AUTHOR_PROMOTE_RATE);
7974+
7975+
set_price_feed(price(ASSET("1.000 GOLOS"), ASSET("1.000 GBG")));
7976+
7977+
BOOST_TEST_MESSAGE("--- Creating comment and voting for it");
7978+
7979+
comment_create("alice", alice_private_key, "alice-test", "", "alice-test");
7980+
generate_block();
7981+
vote_operation vote_op;
7982+
vote_op.voter = "bob";
7983+
vote_op.author = "alice";
7984+
vote_op.permlink = "alice-test";
7985+
vote_op.weight = 1000;
7986+
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, bob_private_key, vote_op));
7987+
generate_block();
7988+
7989+
{
7990+
auto vote = db->get<comment_vote_object, by_comment_voter>(std::make_tuple(db->get_comment("alice", string("alice-test")).id, db->get_account("bob").id));
7991+
BOOST_CHECK_EQUAL(vote.author_promote_rate, wso.median_props.min_vote_author_promote_rate);
7992+
}
7993+
7994+
BOOST_TEST_MESSAGE("--- Testing with normal value");
7995+
7996+
vote_options_operation op;
7997+
op.voter = "bob";
7998+
op.author = "alice";
7999+
op.permlink = "alice-test";
8000+
vote_author_promote_rate vapr(25 * STEEMIT_1_PERCENT);
8001+
op.extensions.insert(vapr);
8002+
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, bob_private_key, op));
8003+
generate_block();
8004+
{
8005+
auto vote = db->get<comment_vote_object, by_comment_voter>(std::make_tuple(db->get_comment("alice", string("alice-test")).id, db->get_account("bob").id));
8006+
BOOST_CHECK_EQUAL(vote.author_promote_rate, vapr.rate);
8007+
}
8008+
8009+
BOOST_TEST_MESSAGE("--- Checking that calling without extensions don't affect value");
8010+
8011+
op.extensions.clear();
8012+
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, bob_private_key, op));
8013+
generate_block();
8014+
{
8015+
auto vote = db->get<comment_vote_object, by_comment_voter>(std::make_tuple(db->get_comment("alice", string("alice-test")).id, db->get_account("bob").id));
8016+
BOOST_CHECK_EQUAL(vote.author_promote_rate, vapr.rate);
8017+
}
8018+
8019+
BOOST_TEST_MESSAGE("--- Starting rewards");
8020+
8021+
generate_blocks(db->get_comment("alice", string("alice-test")).cashout_time - STEEMIT_BLOCK_INTERVAL, false);
8022+
8023+
comment_fund total_comment_fund(*db);
8024+
comment_reward alice_comment_reward(*db, total_comment_fund, db->get_comment("alice", string("alice-test")));
8025+
8026+
generate_block();
8027+
8028+
BOOST_TEST_MESSAGE("--- Checking rewards");
8029+
8030+
auto& bob_account = db->get_account("bob");
8031+
auto cur_op = get_last_operations<curation_reward_operation>(1)[0];
8032+
BOOST_CHECK_EQUAL(cur_op.reward, alice_comment_reward.vote_payout(bob_account));
8033+
auto author_op = get_last_operations<author_reward_operation>(1)[0];
8034+
BOOST_CHECK_EQUAL(author_op.sbd_payout, alice_comment_reward.sbd_payout());
8035+
BOOST_CHECK_EQUAL(author_op.vesting_payout, alice_comment_reward.vesting_payout());
8036+
8037+
validate_database();
8038+
} FC_LOG_AND_RETHROW() }
8039+
8040+
BOOST_AUTO_TEST_SUITE_END() // vote_options
8041+
8042+
BOOST_AUTO_TEST_SUITE_END() // operation_tests
78488043

78498044

78508045
struct votes_extended_fixture : public golos::chain::clean_database_fixture {

0 commit comments

Comments
 (0)