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

Commit

Permalink
Added fixed test case for auction_window reward going to_reward_fund.…
Browse files Browse the repository at this point in the history
… Fixed comment_reward.hpp. #898
  • Loading branch information
AKorpusenko committed Oct 18, 2018
1 parent 6eb2301 commit 53ba008
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 39 deletions.
17 changes: 12 additions & 5 deletions tests/common/comment_reward.hpp
Expand Up @@ -181,10 +181,20 @@ namespace golos { namespace chain {

total_vote_rewards_ = 0;
total_vote_payouts_ = asset(0, VESTS_SYMBOL);

auto auction_window_reward = vote_rewards_fund_ * comment_.auction_window_weight / total_weight;
auto votes_after_auction_window_weight = total_weight - comment_.votes_in_auction_window_weight - comment_.auction_window_weight;

auto auw_time = comment_.created + comment_.auction_window_size;

for (; itr != vote_idx.end() && itr->comment == comment_.id; ++itr) {
BOOST_REQUIRE(vote_payout_map_.find(itr->voter) == vote_payout_map_.end());
auto weight = u256(itr->weight);
int64_t reward = static_cast<int64_t>(weight * vote_rewards_fund_ / total_weight);
// to_curators case
if (comment_.auction_window_reward_destination == protocol::to_curators && itr->last_update >= auw_time) {
reward += static_cast<int64_t>((auction_window_reward * weight) / votes_after_auction_window_weight);
}

total_vote_rewards_ += reward;
BOOST_REQUIRE_LE(total_vote_rewards_, vote_rewards_fund_);
Expand All @@ -194,16 +204,13 @@ namespace golos { namespace chain {
total_vote_payouts_ += payout;
}

if (db_.has_hardfork(STEEMIT_HARDFORK_0_19__898) && comment_.total_vote_weight > 0) {
auto reward_fund_claim = (vote_rewards_fund_ * comment_.auction_window_weight) / total_weight;

if (comment_.auction_window_reward_destination != protocol::to_author) {
auto reward_fund_claim = vote_rewards_fund_ - total_vote_rewards_;
comment_rewards_ -= reward_fund_claim;

auto tokes_back_to_reward_fund = asset(reward_fund_claim, STEEM_SYMBOL);
fund_.modify_reward_fund(tokes_back_to_reward_fund);
}


comment_rewards_ -= total_vote_rewards_;
}

Expand Down
80 changes: 46 additions & 34 deletions tests/tests/operation_tests.cpp
Expand Up @@ -16,6 +16,8 @@

#include "database_fixture.hpp"
#include "helpers.hpp"
#include "comment_reward.hpp"


#include <cmath>
#include <iostream>
Expand Down Expand Up @@ -7361,75 +7363,85 @@ BOOST_FIXTURE_TEST_SUITE(auction_window_tests, votes_extended_fixture)
try {
BOOST_TEST_MESSAGE("Auction window reward goes to reward fund.");

// Needed to be sured, that auction window's been already enabled.
generate_blocks(fc::time_point_sec(STEEMIT_HARDFORK_0_6_REVERSE_AUCTION_TIME), true);

auto &wso = db->get_witness_schedule_object();
db->modify(wso, [&](witness_schedule_object &w) {
w.median_props.auction_window_size = 2 * 60;
w.median_props.auction_window_size = 10 * 60;
});
generate_block();

generate_block();

ACTOR(alice);

comment_operation comment;
comment_options_operation cop;
signed_transaction tx;
set_price_feed(price(ASSET("1.000 GOLOS"), ASSET("1.000 GBG")));

BOOST_TEST_MESSAGE("Create a post.");
comment.author = "alice";
comment.permlink = "test_AUW";
comment.permlink = "testauw";
comment.parent_permlink = "test";
comment.title = "test";
comment.body = "Let's test auction window improvements!";

BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, alice_private_key, comment));
tx.operations.clear();
tx.signatures.clear();
GOLOS_CHECK_NO_THROW(push_tx_with_ops(tx, alice_private_key, comment));
generate_block();

protocol::comment_auction_window_reward_destination dest;
dest.destination = protocol::to_reward_fund;

cop.author = comment.author;
cop.permlink = comment.permlink;

cop.extensions.insert(dest);

tx.operations.clear();
tx.signatures.clear();

BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, alice_private_key, cop));
GOLOS_CHECK_NO_THROW(push_tx_with_ops(tx, alice_private_key, cop));
generate_block();

auto & alice_post = db->get<comment_object, by_permlink>(boost::make_tuple(comment.author, comment.permlink));

db->modify(alice_post, [&](comment_object &co) {
co.auction_window_size = 2 * 60;
});
generate_block();
std::cout << alice_post.created.to_iso_string() << std::endl;
std::cout << "alice_post.auction_window_size = " << alice_post.auction_window_size << std::endl;
generate_voters(20);

BOOST_TEST_MESSAGE("Create votes.");
// Just generate few votes in auction window and rest after it
// Then calculate the weights of votes in auction window. Calculate the sum of delta parts of votes
// max_vote_weight - real_vote_weight -> that would be a delta.
BOOST_CHECK_EQUAL(alice_post.cashout_time, alice_post.created + STEEMIT_CASHOUT_WINDOW_SECONDS);

generate_voters(10);
vote_sequence(comment.author, comment.permlink, 10, 5);
generate_blocks((alice_post.created + alice_post.auction_window_size), true);
vote_sequence(comment.author, comment.permlink, 10, 5);

BOOST_CHECK_EQUAL(alice_post.cashout_time, alice_post.created + STEEMIT_CASHOUT_WINDOW_SECONDS);

vote_sequence("alice", "test_AUW", 5, 1);

const auto &cvlupdidx = db->get_index<comment_vote_index>().indices().get<by_vote_last_update>();
auto itr = cvlupdidx.lower_bound(boost::make_tuple(0, alice_post.created));

for (; itr != cvlupdidx.end() && itr->comment == alice_post.id; itr++) {
auto& x = db->get<account_object, by_id>(itr->voter);
std::cout << "---vote_object---" << std::endl <<
"weight = " << itr->weight << std::endl <<
"sbd_balance = " << x.sbd_balance << std::endl <<
"vesting_shares = " << x.vesting_shares << std::endl <<
"delegated_vesting_shares = " << x.delegated_vesting_shares << std::endl <<
"received_vesting_shares = " << x.received_vesting_shares << std::endl <<
"balance = " << x.balance << std::endl <<
"savings_balance = " << x.savings_balance << std::endl <<
"------------------" << std::endl;
comment_fund total_comment_fund(*db);
comment_reward alice_post_reward(*db, total_comment_fund, alice_post);
auto& gpo = db->get_dynamic_global_properties();

generate_blocks((alice_post.cashout_time), true);

share_type rwd = 0;
for (int i = 0; i < 20; i++) {
std::string acc_name = "voter" + std::to_string(i);
auto& account = db->get_account(acc_name);
rwd += account.curation_rewards;
}
auto& alice_acc = db->get_account(alice_post.author);

double auw_tokens = (gpo.total_reward_fund_steem.amount.value);
double total_payout = (alice_acc.posting_rewards.value) * 100.0 / 75.0;
double voters_reward = (rwd.value);
double voters_reward_percent = (auw_tokens + voters_reward) / total_payout;
double modeled_voters_reward_percent = (total_comment_fund.reward_fund().amount.value + voters_reward) / total_payout;

double allowed_percent_delta = 0.01; // = 1e-2
double allowed_tokens_delta = 50;

BOOST_CHECK_EQUAL(fabs(0.25 - voters_reward_percent) < allowed_percent_delta, true);
BOOST_CHECK_EQUAL(abs(auw_tokens - total_comment_fund.reward_fund().amount.value) < allowed_tokens_delta, true);
BOOST_CHECK_EQUAL(fabs(0.25 - modeled_voters_reward_percent) < allowed_percent_delta, true);
}
FC_LOG_AND_RETHROW()
}
Expand Down

0 comments on commit 53ba008

Please sign in to comment.