Skip to content

Commit

Permalink
updated #428
Browse files Browse the repository at this point in the history
  • Loading branch information
kudzinp authored and adedkov committed Feb 8, 2019
1 parent 3307e29 commit 1876ced
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
39 changes: 21 additions & 18 deletions tests/golos.publication_rewards_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,10 @@ class reward_calcs_tester : public extended_tester {
bool vestpayment = false
) {
auto ret = post.create_msg(author, permlink, parentacc, parentprmlnk, beneficiaries, tokenprop, vestpayment);
message_key key{author, permlink};
uint64_t id = 1;
if (!_state.pools.back().messages.empty())
id = _state.pools.back().messages.rbegin()->key.id + 1;
message_key key{author, id};

auto reward_weight = 0.0;
string ret_str = ret;
Expand All @@ -478,7 +481,7 @@ class reward_calcs_tester : public extended_tester {
static_cast<double>(cur_time().to_seconds()),
beneficiaries, reward_weight));
} else {
key.permlink = std::string();
key.id = 0;
}
return ret;
}
Expand All @@ -487,14 +490,14 @@ class reward_calcs_tester : public extended_tester {
return post.delete_msg(author, permlink);
}

action_result addvote(account_name voter, account_name author, string permlink, int32_t weight) {
action_result addvote(account_name voter, account_name author, string permlink, int32_t weight, uint64_t id) {
auto ret = weight == 0
? post.unvote(voter, author, permlink)
: weight > 0
? post.upvote(voter, author, permlink, weight)
: post.downvote(voter, author, permlink, -weight);

message_key msg_key{author, permlink};
message_key msg_key{author, id};

string ret_str = ret;
if ((ret == success()) || (ret_str.find("forum::apply_limits:") != string::npos)) {
Expand Down Expand Up @@ -572,30 +575,30 @@ BOOST_FIXTURE_TEST_CASE(basic_tests, reward_calcs_tester) try {
BOOST_CHECK_EQUAL(success(), create_message(N(alice), "permlink1"));
check();
BOOST_TEST_MESSAGE("--- alice1 voted for alice");
BOOST_CHECK_EQUAL(success(), addvote(N(alice1), N(alice), "permlink", 100));
BOOST_CHECK_EQUAL(success(), addvote(N(alice1), N(alice), "permlink", 100, 1));
check();
BOOST_TEST_MESSAGE("--- trying to delete alice's message");
BOOST_CHECK_EQUAL(err.delete_upvoted, delete_message(N(alice), "permlink"));
BOOST_TEST_MESSAGE("--- bob1 voted (1%) for bob");
BOOST_CHECK_EQUAL(success(), addvote(N(bob1), N(bob), "permlink1", 100));
BOOST_CHECK_EQUAL(success(), addvote(N(bob1), N(bob), "permlink1", 100, 2));
check();
BOOST_TEST_MESSAGE("--- bob1 revoted (-50%) against bob");
BOOST_CHECK_EQUAL(success(), addvote(N(bob1), N(bob), "permlink1", -5000));
BOOST_CHECK_EQUAL(success(), addvote(N(bob1), N(bob), "permlink1", -5000, 2));
check();
BOOST_TEST_MESSAGE("--- bob2 voted (100%) for bob");
BOOST_CHECK_EQUAL(success(), addvote(N(bob2), N(bob), "permlink1", 10000));
BOOST_CHECK_EQUAL(success(), addvote(N(bob2), N(bob), "permlink1", 10000, 2));
check();
BOOST_TEST_MESSAGE("--- alice2 voted (100%) for alice (1)");
BOOST_CHECK_EQUAL(success(), addvote(N(alice2), N(alice), "permlink1", 10000));
BOOST_CHECK_EQUAL(success(), addvote(N(alice2), N(alice), "permlink1", 10000, 3));
check();
BOOST_TEST_MESSAGE("--- alice3 flagged (80%) against bob");
BOOST_CHECK_EQUAL(success(), addvote(N(alice3), N(bob), "permlink1", -8000));
BOOST_CHECK_EQUAL(success(), addvote(N(alice3), N(bob), "permlink1", -8000, 2));
check();
BOOST_TEST_MESSAGE("--- alice4 voted (30%) for alice (1)");
BOOST_CHECK_EQUAL(success(), addvote(N(alice4), N(alice), "permlink1", 3000));
BOOST_CHECK_EQUAL(success(), addvote(N(alice4), N(alice), "permlink1", 3000, 3));
check();
BOOST_TEST_MESSAGE("--- alice4 revoted (100%) for alice (1)");
BOOST_CHECK_EQUAL(success(), addvote(N(alice4), N(alice), "permlink1", 10000));
BOOST_CHECK_EQUAL(success(), addvote(N(alice4), N(alice), "permlink1", 10000, 3));
check();

BOOST_TEST_MESSAGE("--- add_funds_to_forum");
Expand All @@ -613,7 +616,7 @@ BOOST_FIXTURE_TEST_CASE(basic_tests, reward_calcs_tester) try {
BOOST_CHECK_EQUAL(success(), add_funds_to_forum(100000));
check();
BOOST_TEST_MESSAGE("--- why voted (100%) for why");
BOOST_CHECK_EQUAL(success(), addvote(N(why), N(why), "why not", 10000));
BOOST_CHECK_EQUAL(success(), addvote(N(why), N(why), "why not", 10000, 1));
step(); // push transactions before run() call
check();
run(seconds(99)); // TODO: remove magic number
Expand All @@ -639,7 +642,7 @@ BOOST_FIXTURE_TEST_CASE(timepenalty_test, reward_calcs_tester) try {
check();
BOOST_TEST_MESSAGE("--- voting");
for (size_t i = 0; i < 6; i++) { // TODO: remove magic number, 6 must be derived from some constant used in rules
BOOST_CHECK_EQUAL(success(), addvote(_users[i], N(bob), "permlink", 10000));
BOOST_CHECK_EQUAL(success(), addvote(_users[i], N(bob), "permlink", 10000, 1));
check();
run(seconds(3)); // TODO: remove magic number
}
Expand Down Expand Up @@ -687,8 +690,8 @@ BOOST_FIXTURE_TEST_CASE(limits_test, reward_calcs_tester) try {
BOOST_CHECK_EQUAL(success(), create_message(N(bob), "I can pay for posting", N(), "", {}, 5000, true));
BOOST_CHECK_EQUAL(err.limit_no_power,
create_message(N(bob), "only if it is not a comment", N(bob), "permlink", {}, 5000, true));
BOOST_CHECK_EQUAL(success(), addvote(N(alice), N(bob), "I can pay for posting", 10000));
BOOST_CHECK_EQUAL(success(), addvote(N(bob), N(bob), "I can pay for posting", 10000)); //He can also vote
BOOST_CHECK_EQUAL(success(), addvote(N(alice), N(bob), "I can pay for posting", 10000, 13));
BOOST_CHECK_EQUAL(success(), addvote(N(bob), N(bob), "I can pay for posting", 10000, 13)); //He can also vote
BOOST_CHECK_EQUAL(success(), create_message(N(bob1), "permlink"));
step(); // push transactions before run() call

Expand Down Expand Up @@ -746,7 +749,7 @@ BOOST_FIXTURE_TEST_CASE(rshares_sum_overflow_test, reward_calcs_tester) try {
BOOST_CHECK_EQUAL(success(), create_message(_users[i], "permlink"));
check();
BOOST_TEST_MESSAGE("--- " << name{_users[i]}.to_string() << " voted for self");
BOOST_CHECK_EQUAL(success(), addvote(_users[i], _users[i], "permlink", 10000));
BOOST_CHECK_EQUAL(success(), addvote(_users[i], _users[i], "permlink", 10000, i+1));
check();
}
} FC_LOG_AND_RETHROW()
Expand All @@ -773,7 +776,7 @@ BOOST_FIXTURE_TEST_CASE(golos_curation_test, reward_calcs_tester) try {

for (size_t i = 0; i < 10; i++) {
BOOST_TEST_MESSAGE("--- " << name{_users[i]}.to_string() << " voted");
BOOST_CHECK_EQUAL(success(), addvote(_users[i], _users[0], "permlink", 10000));
BOOST_CHECK_EQUAL(success(), addvote(_users[i], _users[0], "permlink", 10000, 1));
check();
}
run(seconds(170));
Expand Down
6 changes: 3 additions & 3 deletions tests/golos.publication_rewards_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ inline double get_prop(int64_t arg) {

struct message_key {
account_name author;
std::string permlink;
uint64_t id;
bool operator ==(const message_key& rhs) const {
return author == rhs.author && permlink == rhs.permlink;
}
Expand Down Expand Up @@ -94,10 +94,10 @@ struct statemap : public std::map<std::string, aprox_val_t> {
return "balance of " + acc.to_string() + ": ";
}
static std::string get_message_str(const message_key& msg) {
return "message of " + msg.author.to_string() + " #" + msg.permlink + ": ";
return "message of " + msg.author.to_string() + " #" + std::to_string(msg.id) + ": ";
}
static std::string get_vote_str(account_name voter, const message_key& msg) {
return "vote of " + voter.to_string() + " for message of " + msg.author.to_string() + " #" + msg.permlink + ": ";
return "vote of " + voter.to_string() + " for message of " + msg.author.to_string() + " #" + std::to_string(msg.id) + ": ";
}
void set_pool(uint64_t id, const pool_data& data = {}) {
auto prefix = get_pool_str(id);
Expand Down

0 comments on commit 1876ced

Please sign in to comment.