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

Commit

Permalink
Merge pull request #1326 from GolosChain/1324-worker-test-premade-tec…
Browse files Browse the repository at this point in the history
…hspecs

Test premade techspecs and techspecs with preset worker #1324
  • Loading branch information
afalaleev authored Jun 6, 2019
2 parents 2b90695 + c74de2a commit 9368965
Show file tree
Hide file tree
Showing 3 changed files with 287 additions and 41 deletions.
63 changes: 40 additions & 23 deletions tests/common/worker_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,6 @@ struct worker_fixture : public clean_database_fixture {
startup();
}

private_key_type create_approvers(uint16_t first, uint16_t count) {
auto private_key = generate_private_key("test");
auto post_key = generate_private_key("test_post");
for (auto i = first; i < count; ++i) {
const auto name = "approver" + std::to_string(i);
GOLOS_CHECK_NO_THROW(account_create(name, private_key.get_public_key(), post_key.get_public_key()));
GOLOS_CHECK_NO_THROW(witness_create(name, private_key, "foo.bar", private_key.get_public_key(), 1000));
}
return private_key;
}

void push_approvers_top19(const account_name_type& voter, const private_key_type& voter_key, uint16_t first, uint16_t count, bool up) {
signed_transaction tx;
for (auto i = first; i < count; ++i) {
const auto name = "approver" + std::to_string(i);
account_witness_vote_operation awvop;
awvop.account = voter;
awvop.witness = name;
awvop.approve = up;
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, voter_key, awvop));
}
}

const worker_proposal_object& worker_proposal(
const string& author, const private_key_type& author_key, const string& permlink, worker_proposal_type type) {
signed_transaction tx;
Expand Down Expand Up @@ -130,6 +107,46 @@ struct worker_fixture : public clean_database_fixture {
const auto& gpo = db->get_dynamic_global_properties();
BOOST_CHECK_EQUAL(gpo.worker_consumption_per_day, consumption_after_close);
}

private_key_type create_approvers(uint16_t first, uint16_t count) {
auto private_key = generate_private_key("test");
auto post_key = generate_private_key("test_post");
for (auto i = first; i < count; ++i) {
const auto name = "approver" + std::to_string(i);
GOLOS_CHECK_NO_THROW(account_create(name, private_key.get_public_key(), post_key.get_public_key()));
GOLOS_CHECK_NO_THROW(witness_create(name, private_key, "foo.bar", private_key.get_public_key(), 1000));
}
return private_key;
}

void push_approvers_top19(const account_name_type& voter, const private_key_type& voter_key, uint16_t first, uint16_t count, bool up) {
signed_transaction tx;
for (auto i = first; i < count; ++i) {
const auto name = "approver" + std::to_string(i);
account_witness_vote_operation awvop;
awvop.account = voter;
awvop.witness = name;
awvop.approve = up;
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, voter_key, awvop));
}
}

fc::time_point_sec approve_techspec_final(const string& author, const string& permlink, const private_key_type& key) {
fc::time_point_sec now;

for (auto i = 0; i < STEEMIT_MAJOR_VOTED_WITNESSES; ++i) {
const auto& wto = db->get_worker_techspec(db->get_comment(author, permlink).id);
BOOST_CHECK(wto.state == worker_techspec_state::created);
BOOST_CHECK_EQUAL(wto.next_cashout_time, time_point_sec::maximum());

now = db->head_block_time();

worker_techspec_approve("approver" + std::to_string(i), key, author, permlink, worker_techspec_approve_state::approve);
generate_block();
}

return now;
}
};

} } // golos:chain
79 changes: 68 additions & 11 deletions tests/plugin_tests/worker_api_techspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ BOOST_AUTO_TEST_CASE(worker_techspec_delete) {
BOOST_AUTO_TEST_CASE(worker_techspec_approve) {
BOOST_TEST_MESSAGE("Testing: worker_techspec_approve");

ACTORS((alice)(bob)(approver))
ACTORS((alice)(bob)(carol)(dave))
auto approver_key = create_approvers(0, STEEMIT_MAJOR_VOTED_WITNESSES);
generate_block();

signed_transaction tx;
Expand Down Expand Up @@ -295,18 +296,16 @@ BOOST_AUTO_TEST_CASE(worker_techspec_approve) {
BOOST_CHECK_EQUAL(wtmo_itr->approves, 0);
BOOST_CHECK_EQUAL(wtmo_itr->disapproves, 0);

witness_create("approver", approver_private_key, "foo.bar", approver_private_key.get_public_key(), 1000);

generate_blocks(STEEMIT_MAX_WITNESSES); // Enough for approvers to reach TOP-19 and not leave it

BOOST_TEST_MESSAGE("-- Approving worker techspec (after abstain)");

worker_techspec_approve_operation op;
op.approver = "approver";
op.approver = "approver0";
op.author = "bob";
op.permlink = "bob-techspec";
op.state = worker_techspec_approve_state::approve;
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, approver_private_key, op));
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, approver_key, op));

wtmo_itr = wtmo_idx.find(wto_post.id);
BOOST_CHECK_EQUAL(wtmo_itr->approves, 1);
Expand All @@ -315,7 +314,7 @@ BOOST_AUTO_TEST_CASE(worker_techspec_approve) {
BOOST_TEST_MESSAGE("-- Disapproving worker techspec (after approve)");

op.state = worker_techspec_approve_state::disapprove;
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, approver_private_key, op));
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, approver_key, op));

wtmo_itr = wtmo_idx.find(wto_post.id);
BOOST_CHECK_EQUAL(wtmo_itr->approves, 0);
Expand All @@ -324,7 +323,7 @@ BOOST_AUTO_TEST_CASE(worker_techspec_approve) {
BOOST_TEST_MESSAGE("-- Abstaining worker techspec (after disapprove)");

op.state = worker_techspec_approve_state::abstain;
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, approver_private_key, op));
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, approver_key, op));

wtmo_itr = wtmo_idx.find(wto_post.id);
BOOST_CHECK_EQUAL(wtmo_itr->approves, 0);
Expand All @@ -335,7 +334,7 @@ BOOST_AUTO_TEST_CASE(worker_techspec_approve) {
BOOST_TEST_MESSAGE("-- Disapproving worker techspec (after abstain)");

op.state = worker_techspec_approve_state::disapprove;
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, approver_private_key, op));
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, approver_key, op));

wtmo_itr = wtmo_idx.find(wto_post.id);
BOOST_CHECK_EQUAL(wtmo_itr->approves, 0);
Expand All @@ -344,7 +343,7 @@ BOOST_AUTO_TEST_CASE(worker_techspec_approve) {
BOOST_TEST_MESSAGE("-- Approving worker techspec (after disapprove)");

op.state = worker_techspec_approve_state::approve;
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, approver_private_key, op));
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, approver_key, op));

wtmo_itr = wtmo_idx.find(wto_post.id);
BOOST_CHECK_EQUAL(wtmo_itr->approves, 1);
Expand All @@ -353,17 +352,75 @@ BOOST_AUTO_TEST_CASE(worker_techspec_approve) {
BOOST_TEST_MESSAGE("-- Abstaining worker techspec (after approve)");

op.state = worker_techspec_approve_state::abstain;
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, approver_private_key, op));
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, approver_key, op));

wtmo_itr = wtmo_idx.find(wto_post.id);
BOOST_CHECK_EQUAL(wtmo_itr->approves, 0);
BOOST_CHECK_EQUAL(wtmo_itr->disapproves, 0);

generate_block();
{
BOOST_TEST_MESSAGE("-- Approving techspec with preset worker and checking metadata fields");

comment_create("carol", carol_private_key, "carol-proposal", "", "carol-proposal");
worker_proposal("carol", carol_private_key, "carol-proposal", worker_proposal_type::task);

comment_create("dave", dave_private_key, "dave-techspec", "", "dave-techspec");

wtop.author = "dave";
wtop.permlink = "dave-techspec";
wtop.worker_proposal_author = "carol";
wtop.worker_proposal_permlink = "carol-proposal";
wtop.worker = "dave";
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, dave_private_key, wtop));
generate_block();

auto now = approve_techspec_final("dave", "dave-techspec", approver_key);

wtmo_itr = wtmo_idx.find(db->get_comment("dave", string("dave-techspec")).id);
BOOST_CHECK_EQUAL(wtmo_itr->work_beginning_time, now);
BOOST_CHECK_EQUAL(wtmo_itr->payment_beginning_time, fc::time_point_sec::min());
}

validate_database();
}

BOOST_AUTO_TEST_CASE(worker_techspec_approve_premade) {
BOOST_TEST_MESSAGE("Testing: worker_techspec_approve_premade");

ACTORS((alice)(bob))
generate_block();

signed_transaction tx;

const auto& wtmo_idx = db->get_index<worker_techspec_metadata_index, by_post>();

comment_create("alice", alice_private_key, "alice-premade", "", "alice-premade");
worker_proposal("alice", alice_private_key, "alice-premade", worker_proposal_type::premade_work);

worker_techspec_operation wtop;
wtop.author = "alice";
wtop.permlink = "alice-premade";
wtop.worker_proposal_author = "alice";
wtop.worker_proposal_permlink = "alice-premade";
wtop.specification_cost = ASSET_GOLOS(6);
wtop.development_cost = ASSET_GOLOS(60);
wtop.payments_interval = 60*60*24;
wtop.payments_count = 40;
wtop.worker = "bob";
BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, alice_private_key, wtop));
generate_block();

BOOST_TEST_MESSAGE("-- Approving techspec and checking metadata fields");

auto approver_key = create_approvers(0, STEEMIT_MAJOR_VOTED_WITNESSES);
generate_blocks(STEEMIT_MAX_WITNESSES);
auto now = approve_techspec_final("alice", "alice-premade", approver_key);

auto wtmo_itr = wtmo_idx.find(db->get_comment("alice", string("alice-premade")).id);
BOOST_CHECK_EQUAL(wtmo_itr->work_beginning_time, fc::time_point_sec::min());
BOOST_CHECK_EQUAL(wtmo_itr->payment_beginning_time, now + wtop.payments_interval);
}

BOOST_AUTO_TEST_CASE(worker_assign) {
BOOST_TEST_MESSAGE("Testing: worker_assign");

Expand Down
Loading

0 comments on commit 9368965

Please sign in to comment.