Skip to content

Commit

Permalink
Fix start behaviour in listgovproposals (#1692)
Browse files Browse the repository at this point in the history
* Add tests for `including_start = False`

* Fix `start` behaviour

* Remove log

* Do not skip first entry

* Fix flaky test

* Simplify test
  • Loading branch information
shohamc1 authored Jan 16, 2023
1 parent 6e05124 commit c905f30
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/masternodes/rpc_proposals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,14 +793,17 @@ UniValue getgovproposal(const JSONRPCRequest &request) {
template <typename T>
void iterateProps(const T& list, UniValue& ret, const CPropId& start, bool including_start, size_t limit, const uint8_t type, const uint8_t status)
{
bool pastStart = false;
for (const auto &prop : list) {
if (status && status != prop.second.status) {
continue;
}
if (type && type != prop.second.type) {
continue;
}
if (start != CPropId{} && prop.first != start)
if (prop.first == start)
pastStart = true;
if (start != CPropId{} && prop.first != start && !pastStart)
continue;
if (!including_start) {
including_start = true;
Expand Down
18 changes: 17 additions & 1 deletion test/functional/feature_on_chain_government.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,11 @@ def run_test(self):
len(self.nodes[1].listgovproposalvotes({"proposalId": tx, "masternode": "all", "cycle": -1, "pagination": {"start": 0, "including_start": True, "limit": 0}})),
3)

# should return all entries if limit is 0
assert_equal(
len(self.nodes[1].listgovproposalvotes({"proposalId": tx, "masternode": "all", "cycle": -1, "pagination": {"start": 0, "including_start": False, "limit": 0}})),
2)

# should respect filters
assert_equal(len(self.nodes[1].listgovproposalvotes({"proposalId": tx, "masternode": mn1, "cycle": -1, "pagination": {"start": 0}})), 0)

Expand Down Expand Up @@ -662,5 +667,16 @@ def run_test(self):
assert_equal(self.nodes[0].listgovproposals({"status": "voting", "pagination": {"start": tx1, "including_start": True, "limit": 1}})[0]["proposalId"], tx1)
assert_equal(self.nodes[0].listgovproposals({"status": "voting", "pagination": {"start": tx3, "including_start": True, "limit": 1}})[0]["proposalId"], tx3)

allProposals = self.nodes[0].listgovproposals({"status": "voting"})
nextProposal = []
for i in range(len(allProposals)):
if allProposals[i]["proposalId"] == tx1:
if i < len(allProposals) - 1:
nextProposal = [allProposals[i + 1]]
# otherwise tx1 is the last proposal
break

assert_equal(self.nodes[0].listgovproposals({"status": "voting", "pagination": {"start": tx1, "including_start": False, "limit": 1}}), nextProposal)

if __name__ == '__main__':
OnChainGovernanceTest().main ()
OnChainGovernanceTest().main()

0 comments on commit c905f30

Please sign in to comment.