Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions contracts/governance/extensions/GovernorStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ abstract contract GovernorStorage is Governor {
function queue(uint256 proposalId) public virtual {
// here, using storage is more efficient than memory
ProposalDetails storage details = _proposalDetails[proposalId];
if (details.descriptionHash == 0) {
revert GovernorNonexistentProposal(proposalId);
}
queue(details.targets, details.values, details.calldatas, details.descriptionHash);
}

Expand All @@ -64,6 +67,9 @@ abstract contract GovernorStorage is Governor {
function execute(uint256 proposalId) public payable virtual {
// here, using storage is more efficient than memory
ProposalDetails storage details = _proposalDetails[proposalId];
if (details.descriptionHash == 0) {
revert GovernorNonexistentProposal(proposalId);
}
execute(details.targets, details.values, details.calldatas, details.descriptionHash);
}

Expand All @@ -73,6 +79,9 @@ abstract contract GovernorStorage is Governor {
function cancel(uint256 proposalId) public virtual {
// here, using storage is more efficient than memory
ProposalDetails storage details = _proposalDetails[proposalId];
if (details.descriptionHash == 0) {
revert GovernorNonexistentProposal(proposalId);
}
cancel(details.targets, details.values, details.calldatas, details.descriptionHash);
}

Expand Down
20 changes: 20 additions & 0 deletions test/governance/extensions/GovernorStorage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,26 @@ describe('GovernorStorage', function () {
.to.emit(this.mock, 'ProposalCanceled')
.withArgs(this.proposal.id);
});

describe('with non-existing proposalId', function () {
it('queue', async function () {
await expect(this.mock.queue(this.proposal.id))
.to.be.revertedWithCustomError(this.mock, 'GovernorNonexistentProposal')
.withArgs(this.proposal.id);
});

it('execute', async function () {
await expect(this.mock.execute(this.proposal.id))
.to.be.revertedWithCustomError(this.mock, 'GovernorNonexistentProposal')
.withArgs(this.proposal.id);
});

it('cancel', async function () {
await expect(this.mock.cancel(this.proposal.id))
.to.be.revertedWithCustomError(this.mock, 'GovernorNonexistentProposal')
.withArgs(this.proposal.id);
});
});
});
}
});
Loading