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

Fix dequeueProposalIfReady() for expired proposals. #10324

Merged
merged 3 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
8 changes: 7 additions & 1 deletion packages/protocol/contracts/governance/Governance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ contract Governance is
* @return Patch version of the contract.
*/
function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) {
return (1, 3, 1, 0);
return (1, 3, 2, 0);
}

/**
Expand Down Expand Up @@ -1265,6 +1265,12 @@ contract Governance is
// solhint-disable-next-line not-rely-on-time
if (now >= lastDequeue.add(dequeueFrequency)) {
Proposals.Proposal storage proposal = proposals[proposalId];

if (_isQueuedProposalExpired(proposal)) {
emit ProposalExpired(proposalId);
return isProposalDequeued;
}

// Updating refunds back to proposer
refundedDeposits[proposal.proposer] = refundedDeposits[proposal.proposer].add(
proposal.deposit
Expand Down
25 changes: 21 additions & 4 deletions packages/protocol/test/governance/network/governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3581,12 +3581,12 @@ contract('Governance', (accounts: string[]) => {
const nonExistentProposalId = 7
const originalLastDequeue = await governance.lastDequeue()
await timeTravel(dequeueFrequency, web3)
await assertRevert(governance.dequeueProposalIfReady(nonExistentProposalId))

await governance.dequeueProposalIfReady(nonExistentProposalId)
assert.equal((await governance.getQueueLength()).toNumber(), 0)
assert.equal((await governance.lastDequeue()).toNumber(), originalLastDequeue.toNumber())
})
describe('when a proposal exists', () => {
const proposalId = 1
beforeEach(async () => {
await governance.propose(
[transactionSuccess1.value],
Expand All @@ -3599,18 +3599,35 @@ contract('Governance', (accounts: string[]) => {
)
})

it('should not update `dequeued` when proposal has expired', async () => {
await timeTravel(queueExpiry, web3)
await governance.dequeueProposalIfReady(proposalId)
const dequeued = await governance.getDequeue()
assert.equal(dequeued.length, 0)
})

it('should update `dequeued` when proposal has not expired', async () => {
await timeTravel(dequeueFrequency, web3)
await governance.dequeueProposalIfReady(proposalId)
const dequeued = await governance.getDequeue()
assert.include(
dequeued.map((x) => x.toNumber()),
proposalId
)
})

it('should update lastDequeue', async () => {
const originalLastDequeue = await governance.lastDequeue()

await timeTravel(dequeueFrequency, web3)
await governance.dequeueProposalIfReady(1)
await governance.dequeueProposalIfReady(proposalId)

assert.equal((await governance.getQueueLength()).toNumber(), 0)
assert.isTrue((await governance.lastDequeue()).toNumber() > originalLastDequeue.toNumber())
})

it('should still be valid if not dequeued or expired', async () => {
await governance.dequeueProposalIfReady(1)
await governance.dequeueProposalIfReady(proposalId)
const isQueuedProposalExpired = await governance.isQueuedProposalExpired(1)
assert.isFalse(isQueuedProposalExpired)
})
Expand Down