Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal changes #1577

Merged
merged 15 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add missing fields in getgovproposal and remove ends fields
  • Loading branch information
dcorral committed Nov 17, 2022
commit 15863f71e323576561a6ea441de325e61d1e77b9
29 changes: 11 additions & 18 deletions src/masternodes/rpc_proposals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,19 @@ UniValue getgovproposal(const JSONRPCRequest& request)
ret.pushKV("proposalId", propId.GetHex());
ret.pushKV("title", prop->title);
ret.pushKV("context", prop->context);
if (!prop->contextHash.empty())
ret.pushKV("contextHash", prop->contextHash);
ret.pushKV("contextHash", prop->contextHash);
auto type = static_cast<CPropType>(prop->type);
ret.pushKV("type", CPropTypeToString(type));
if (valid && votes >= majorityThreshold) {
ret.pushKV("status", "Approved");
} else {
ret.pushKV("status", "Rejected");
}
ret.pushKV("currentCycle", static_cast<int32_t>(prop->cycle));
ret.pushKV("totalCycles", static_cast<int32_t>(prop->nCycles));
ret.pushKV("cycleEndHeight", static_cast<int32_t>(prop->cycleEndHeight));
ret.pushKV("proposalEndHeight", static_cast<int32_t>(prop->proposalEndHeight));
ret.pushKV("payoutAddress", ScriptToString(prop->address));

if (prop->options)
{
Expand All @@ -576,25 +585,9 @@ UniValue getgovproposal(const JSONRPCRequest& request)
ret.pushKV("options", array);
}

if (valid && votes >= majorityThreshold) {
ret.pushKV("status", "Approved");
} else {
ret.pushKV("status", "Rejected");
}

ret.pushKV("votes", strprintf("%d.%02d of %d.%02d%%", votes / 100, votes % 100, majorityThreshold / 100, majorityThreshold % 100));
ret.pushKV("votingPercent", strprintf("%d.%02d of %d.%02d%%", allVotes / 100, allVotes % 100, quorum / 100, quorum % 100));

auto target = Params().GetConsensus().pos.nTargetSpacing;
auto blocks = prop->proposalEndHeight - targetHeight;

if (blocks > Params().GetConsensus().blocksPerDay()) {
ret.pushKV("ends", strprintf("%d days", blocks * target / 60 / 60 / 24));
} else if (blocks > Params().GetConsensus().blocksPerDay() / 24) {
ret.pushKV("ends", strprintf("%d hours", blocks * target / 60 / 60));
} else {
ret.pushKV("ends", strprintf("%d minutes", blocks * target / 60));
}
return ret;
}

Expand Down
24 changes: 22 additions & 2 deletions test/functional/feature_on_chain_government.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def run_test(self):
self.nodes[3].sendrawtransaction(raw_tx)
self.nodes[3].generate(1)
self.sync_blocks()
creationHeight = self.nodes[0].getblockcount()

# Check burn fee increment
assert_equal(self.nodes[0].getburninfo()['feeburn'], Decimal('7.50000000'))
Expand All @@ -270,6 +271,8 @@ def run_test(self):
self.nodes[3].generate(1)
self.sync_blocks()

cycle1 = creationHeight + (votingPeriod - creationHeight % votingPeriod) + votingPeriod
proposalEndHeight = cycle1 + votingPeriod
# Check results
result = self.nodes[0].getgovproposal(tx)
assert_equal(result["proposalId"], tx)
Expand All @@ -278,7 +281,13 @@ def run_test(self):
assert_equal(result["type"], "VoteOfConfidence")
assert_equal(result["status"], "Approved")
assert_equal(result["votes"], "75.00 of 66.67%")
assert_equal(result["ends"], "1 days")
assert_equal(result["contextHash"], "")
assert_equal(result["currentCycle"], 1)
assert_equal(result["cycleEndHeight"], cycle1)
assert_equal(result["payoutAddress"], '')
assert_equal(result["totalCycles"], 2)
assert_equal(result["votingPercent"], "100.00 of 1.00%")
assert_equal(result["proposalEndHeight"], proposalEndHeight)

assert_equal(len(self.nodes[0].listgovproposals("all", "voting")), 1)
assert_equal(self.nodes[0].listgovproposals("all", "completed"), [])
Expand All @@ -289,6 +298,7 @@ def run_test(self):
'v0/gov/proposals/cfp_fee':'0.25',
'v0/gov/proposals/voting_period':'100',
}})
votingPeriod = 100

self.nodes[0].generate(1)
self.sync_blocks()
Expand Down Expand Up @@ -426,6 +436,7 @@ def run_test(self):
tx = self.nodes[0].creategovvoc({"title": title, "context": context, "emergency": True})
self.nodes[0].generate(1)
self.sync_blocks()
creationHeight = self.nodes[0].getblockcount()

# Check burn fee increment
assert_equal(self.nodes[0].getburninfo()['feeburn'], Decimal('23.750000000'))
Expand All @@ -447,6 +458,8 @@ def run_test(self):
self.nodes[3].generate(1)
self.sync_blocks()

cycle1 = creationHeight + (emergencyPeriod - creationHeight % emergencyPeriod) + emergencyPeriod
proposalEndHeight = creationHeight + emergencyPeriod
# Check results
result = self.nodes[0].getgovproposal(tx)
assert_equal(result["proposalId"], tx)
Expand All @@ -455,7 +468,14 @@ def run_test(self):
assert_equal(result["type"], "VoteOfConfidence")
assert_equal(result["status"], "Approved")
assert_equal(result["votes"], "50.00 of 49.99%")
assert_equal(result["ends"], "3 hours")
assert_equal(result["contextHash"], "")
assert_equal(result["currentCycle"], 1)
assert_equal(result["cycleEndHeight"], cycle1)
assert_equal(result["payoutAddress"], '')
assert_equal(result["totalCycles"], 1)
assert_equal(result["votingPercent"], "100.00 of 1.00%")
assert_equal(result["options"], ["Emergency"])
assert_equal(result["proposalEndHeight"], proposalEndHeight)

assert_equal(len(self.nodes[0].listgovproposals("all", "voting")), 1)
assert_equal(len(self.nodes[0].listgovproposals("all", "completed")), 0)
Expand Down