Skip to content

Commit 0bfb2ef

Browse files
authored
Merge pull request #47 from fei-protocol/POZ-Consistent-Error-Msg
Consistent error message format
2 parents 4adb873 + c48d772 commit 0bfb2ef

File tree

3 files changed

+61
-61
lines changed

3 files changed

+61
-61
lines changed

contracts/dao/GovernorAlpha.sol

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,16 @@ contract GovernorAlpha {
137137
}
138138

139139
function propose(address[] memory targets, uint[] memory values, string[] memory signatures, bytes[] memory calldatas, string memory description) public returns (uint) {
140-
require(tribe.getPriorVotes(msg.sender, sub256(block.number, 1)) > proposalThreshold(), "GovernorAlpha::propose: proposer votes below proposal threshold");
141-
require(targets.length == values.length && targets.length == signatures.length && targets.length == calldatas.length, "GovernorAlpha::propose: proposal function information arity mismatch");
142-
require(targets.length != 0, "GovernorAlpha::propose: must provide actions");
143-
require(targets.length <= proposalMaxOperations(), "GovernorAlpha::propose: too many actions");
140+
require(tribe.getPriorVotes(msg.sender, sub256(block.number, 1)) > proposalThreshold(), "GovernorAlpha: proposer votes below proposal threshold");
141+
require(targets.length == values.length && targets.length == signatures.length && targets.length == calldatas.length, "GovernorAlpha: proposal function information arity mismatch");
142+
require(targets.length != 0, "GovernorAlpha: must provide actions");
143+
require(targets.length <= proposalMaxOperations(), "GovernorAlpha: too many actions");
144144

145145
uint latestProposalId = latestProposalIds[msg.sender];
146146
if (latestProposalId != 0) {
147147
ProposalState proposersLatestProposalState = state(latestProposalId);
148-
require(proposersLatestProposalState != ProposalState.Active, "GovernorAlpha::propose: one live proposal per proposer, found an already active proposal");
149-
require(proposersLatestProposalState != ProposalState.Pending, "GovernorAlpha::propose: one live proposal per proposer, found an already pending proposal");
148+
require(proposersLatestProposalState != ProposalState.Active, "GovernorAlpha: one live proposal per proposer, found an already active proposal");
149+
require(proposersLatestProposalState != ProposalState.Pending, "GovernorAlpha: one live proposal per proposer, found an already pending proposal");
150150
}
151151

152152
uint startBlock = add256(block.number, votingDelay());
@@ -177,7 +177,7 @@ contract GovernorAlpha {
177177
}
178178

179179
function queue(uint proposalId) public {
180-
require(state(proposalId) == ProposalState.Succeeded, "GovernorAlpha::queue: proposal can only be queued if it is succeeded");
180+
require(state(proposalId) == ProposalState.Succeeded, "GovernorAlpha: proposal can only be queued if it is succeeded");
181181
Proposal storage proposal = proposals[proposalId];
182182
// solhint-disable-next-line not-rely-on-time
183183
uint eta = add256(block.timestamp, timelock.delay());
@@ -189,12 +189,12 @@ contract GovernorAlpha {
189189
}
190190

191191
function _queueOrRevert(address target, uint value, string memory signature, bytes memory data, uint eta) internal {
192-
require(!timelock.queuedTransactions(keccak256(abi.encode(target, value, signature, data, eta))), "GovernorAlpha::_queueOrRevert: proposal action already queued at eta");
192+
require(!timelock.queuedTransactions(keccak256(abi.encode(target, value, signature, data, eta))), "GovernorAlpha: proposal action already queued at eta");
193193
timelock.queueTransaction(target, value, signature, data, eta);
194194
}
195195

196196
function execute(uint proposalId) public payable {
197-
require(state(proposalId) == ProposalState.Queued, "GovernorAlpha::execute: proposal can only be executed if it is queued");
197+
require(state(proposalId) == ProposalState.Queued, "GovernorAlpha: proposal can only be executed if it is queued");
198198
Proposal storage proposal = proposals[proposalId];
199199
proposal.executed = true;
200200
for (uint i = 0; i < proposal.targets.length; i++) {
@@ -205,10 +205,10 @@ contract GovernorAlpha {
205205

206206
function cancel(uint proposalId) public {
207207
ProposalState state = state(proposalId);
208-
require(state != ProposalState.Executed, "GovernorAlpha::cancel: cannot cancel executed proposal");
208+
require(state != ProposalState.Executed, "GovernorAlpha: cannot cancel executed proposal");
209209

210210
Proposal storage proposal = proposals[proposalId];
211-
require(msg.sender == guardian || tribe.getPriorVotes(proposal.proposer, sub256(block.number, 1)) < proposalThreshold(), "GovernorAlpha::cancel: proposer above threshold");
211+
require(msg.sender == guardian || tribe.getPriorVotes(proposal.proposer, sub256(block.number, 1)) < proposalThreshold(), "GovernorAlpha: proposer above threshold");
212212

213213
proposal.canceled = true;
214214
for (uint i = 0; i < proposal.targets.length; i++) {
@@ -228,7 +228,7 @@ contract GovernorAlpha {
228228
}
229229

230230
function state(uint proposalId) public view returns (ProposalState) {
231-
require(proposalCount >= proposalId && proposalId > 0, "GovernorAlpha::state: invalid proposal id");
231+
require(proposalCount >= proposalId && proposalId > 0, "GovernorAlpha: invalid proposal id");
232232
Proposal storage proposal = proposals[proposalId];
233233
if (proposal.canceled) {
234234
return ProposalState.Canceled;
@@ -259,15 +259,15 @@ contract GovernorAlpha {
259259
bytes32 structHash = keccak256(abi.encode(BALLOT_TYPEHASH, proposalId, support));
260260
bytes32 digest = keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
261261
address signatory = ecrecover(digest, v, r, s);
262-
require(signatory != address(0), "GovernorAlpha::castVoteBySig: invalid signature");
262+
require(signatory != address(0), "GovernorAlpha: invalid signature");
263263
return _castVote(signatory, proposalId, support);
264264
}
265265

266266
function _castVote(address voter, uint proposalId, bool support) internal {
267-
require(state(proposalId) == ProposalState.Active, "GovernorAlpha::_castVote: voting is closed");
267+
require(state(proposalId) == ProposalState.Active, "GovernorAlpha: voting is closed");
268268
Proposal storage proposal = proposals[proposalId];
269269
Receipt storage receipt = proposal.receipts[voter];
270-
require(receipt.hasVoted == false, "GovernorAlpha::_castVote: voter already voted");
270+
require(receipt.hasVoted == false, "GovernorAlpha: voter already voted");
271271
uint96 votes = tribe.getPriorVotes(voter, proposal.startBlock);
272272

273273
if (support) {
@@ -284,22 +284,22 @@ contract GovernorAlpha {
284284
}
285285

286286
function __acceptAdmin() public {
287-
require(msg.sender == guardian, "GovernorAlpha::__acceptAdmin: sender must be gov guardian");
287+
require(msg.sender == guardian, "GovernorAlpha: sender must be gov guardian");
288288
timelock.acceptAdmin();
289289
}
290290

291291
function __abdicate() public {
292-
require(msg.sender == guardian, "GovernorAlpha::__abdicate: sender must be gov guardian");
292+
require(msg.sender == guardian, "GovernorAlpha: sender must be gov guardian");
293293
guardian = address(0);
294294
}
295295

296296
function __queueSetTimelockPendingAdmin(address newPendingAdmin, uint eta) public {
297-
require(msg.sender == guardian, "GovernorAlpha::__queueSetTimelockPendingAdmin: sender must be gov guardian");
297+
require(msg.sender == guardian, "GovernorAlpha: sender must be gov guardian");
298298
timelock.queueTransaction(address(timelock), 0, "setPendingAdmin(address)", abi.encode(newPendingAdmin), eta);
299299
}
300300

301301
function __executeSetTimelockPendingAdmin(address newPendingAdmin, uint eta) public {
302-
require(msg.sender == guardian, "GovernorAlpha::__executeSetTimelockPendingAdmin: sender must be gov guardian");
302+
require(msg.sender == guardian, "GovernorAlpha: sender must be gov guardian");
303303
timelock.executeTransaction(address(timelock), 0, "setPendingAdmin(address)", abi.encode(newPendingAdmin), eta);
304304
}
305305

contracts/dao/Timelock.sol

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ contract Timelock {
2626

2727

2828
constructor(address admin_, uint delay_) public {
29-
require(delay_ >= MINIMUM_DELAY, "Timelock::constructor: Delay must exceed minimum delay.");
30-
require(delay_ <= MAXIMUM_DELAY, "Timelock::setDelay: Delay must not exceed maximum delay.");
31-
require(admin_ != address(0), "Timelock::constructor: Admin must not be 0 address");
29+
require(delay_ >= MINIMUM_DELAY, "Timelock: Delay must exceed minimum delay.");
30+
require(delay_ <= MAXIMUM_DELAY, "Timelock: Delay must not exceed maximum delay.");
31+
require(admin_ != address(0), "Timelock: Admin must not be 0 address");
3232

3333
admin = admin_;
3434
delay = delay_;
@@ -37,32 +37,32 @@ contract Timelock {
3737
receive() external payable { }
3838

3939
function setDelay(uint delay_) public {
40-
require(msg.sender == address(this), "Timelock::setDelay: Call must come from Timelock.");
41-
require(delay_ >= MINIMUM_DELAY, "Timelock::setDelay: Delay must exceed minimum delay.");
42-
require(delay_ <= MAXIMUM_DELAY, "Timelock::setDelay: Delay must not exceed maximum delay.");
40+
require(msg.sender == address(this), "Timelock: Call must come from Timelock.");
41+
require(delay_ >= MINIMUM_DELAY, "Timelock: Delay must exceed minimum delay.");
42+
require(delay_ <= MAXIMUM_DELAY, "Timelock: Delay must not exceed maximum delay.");
4343
delay = delay_;
4444

4545
emit NewDelay(delay);
4646
}
4747

4848
function acceptAdmin() public {
49-
require(msg.sender == pendingAdmin, "Timelock::acceptAdmin: Call must come from pendingAdmin.");
49+
require(msg.sender == pendingAdmin, "Timelock: Call must come from pendingAdmin.");
5050
admin = msg.sender;
5151
pendingAdmin = address(0);
5252

5353
emit NewAdmin(admin);
5454
}
5555

5656
function setPendingAdmin(address pendingAdmin_) public {
57-
require(msg.sender == address(this), "Timelock::setPendingAdmin: Call must come from Timelock.");
57+
require(msg.sender == address(this), "Timelock: Call must come from Timelock.");
5858
pendingAdmin = pendingAdmin_;
5959

6060
emit NewPendingAdmin(pendingAdmin);
6161
}
6262

6363
function queueTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public returns (bytes32) {
64-
require(msg.sender == admin, "Timelock::queueTransaction: Call must come from admin.");
65-
require(eta >= getBlockTimestamp().add(delay), "Timelock::queueTransaction: Estimated execution block must satisfy delay.");
64+
require(msg.sender == admin, "Timelock: Call must come from admin.");
65+
require(eta >= getBlockTimestamp().add(delay), "Timelock: Estimated execution block must satisfy delay.");
6666

6767
bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
6868
queuedTransactions[txHash] = true;
@@ -72,7 +72,7 @@ contract Timelock {
7272
}
7373

7474
function cancelTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public {
75-
require(msg.sender == admin, "Timelock::cancelTransaction: Call must come from admin.");
75+
require(msg.sender == admin, "Timelock: Call must come from admin.");
7676

7777
bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
7878
queuedTransactions[txHash] = false;
@@ -81,12 +81,12 @@ contract Timelock {
8181
}
8282

8383
function executeTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public payable returns (bytes memory) {
84-
require(msg.sender == admin, "Timelock::executeTransaction: Call must come from admin.");
84+
require(msg.sender == admin, "Timelock: Call must come from admin.");
8585

8686
bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
87-
require(queuedTransactions[txHash], "Timelock::executeTransaction: Transaction hasn't been queued.");
88-
require(getBlockTimestamp() >= eta, "Timelock::executeTransaction: Transaction hasn't surpassed time lock.");
89-
require(getBlockTimestamp() <= eta.add(GRACE_PERIOD), "Timelock::executeTransaction: Transaction is stale.");
87+
require(queuedTransactions[txHash], "Timelock: Transaction hasn't been queued.");
88+
require(getBlockTimestamp() >= eta, "Timelock: Transaction hasn't surpassed time lock.");
89+
require(getBlockTimestamp() <= eta.add(GRACE_PERIOD), "Timelock: Transaction is stale.");
9090

9191
queuedTransactions[txHash] = false;
9292

@@ -100,7 +100,7 @@ contract Timelock {
100100

101101
// solhint-disable-next-line avoid-low-level-calls
102102
(bool success, bytes memory returnData) = target.call{value: value}(callData); //solhint-disable avoid-call-value
103-
require(success, "Timelock::executeTransaction: Transaction execution reverted.");
103+
require(success, "Timelock: Transaction execution reverted.");
104104

105105
emit ExecuteTransaction(txHash, target, value, signature, data, eta);
106106

0 commit comments

Comments
 (0)