Tweak ERC20Votes revert reasons and documentation (#2696)

* adapt revert reason convention

* add whitespace

* tweak documentation

* fix tests
pull/2699/head
Francisco Giordano 4 years ago committed by GitHub
parent f6efd8aced
commit adc50d465c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      contracts/token/ERC20/extensions/ERC20Votes.sol
  2. 10
      test/token/ERC20/extensions/ERC20Votes.test.js

@ -59,19 +59,27 @@ abstract contract ERC20Votes is IERC20Votes, ERC20Permit {
}
/**
* @dev Determine the number of votes for `account` at the begining of `blockNumber`.
* @dev Retrieve the number of votes for `account` at the end of `blockNumber`.
*
* Requirements:
*
* - `blockNumber` must have been already mined
*/
function getPriorVotes(address account, uint256 blockNumber) external view override returns (uint256) {
require(blockNumber < block.number, "ERC20Votes::getPriorVotes: not yet determined");
require(blockNumber < block.number, "ERC20Votes: block not yet mined");
return _checkpointsLookup(_checkpoints[account], blockNumber);
}
/**
* @dev Determine the totalSupply at the begining of `blockNumber`. Note, this value is the sum of all balances.
* @dev Retrieve the `totalSupply` at the end of `blockNumber`. Note, this value is the sum of all balances.
* It is but NOT the sum of all the delegated votes!
*
* Requirements:
*
* - `blockNumber` must have been already mined
*/
function getPriorTotalSupply(uint256 blockNumber) external view override returns (uint256) {
require(blockNumber < block.number, "ERC20Votes::getPriorTotalSupply: not yet determined");
require(blockNumber < block.number, "ERC20Votes: block not yet mined");
return _checkpointsLookup(_totalSupplyCheckpoints, blockNumber);
}
@ -117,7 +125,7 @@ abstract contract ERC20Votes is IERC20Votes, ERC20Permit {
function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s)
public virtual override
{
require(block.timestamp <= expiry, "ERC20Votes::delegateBySig: signature expired");
require(block.timestamp <= expiry, "ERC20Votes: signature expired");
address signer = ECDSA.recover(
_hashTypedDataV4(keccak256(abi.encode(
_DELEGATION_TYPEHASH,
@ -127,7 +135,7 @@ abstract contract ERC20Votes is IERC20Votes, ERC20Permit {
))),
v, r, s
);
require(nonce == _useNonce(signer), "ERC20Votes::delegateBySig: invalid nonce");
require(nonce == _useNonce(signer), "ERC20Votes: invalid nonce");
return _delegate(signer, delegatee);
}

@ -192,7 +192,7 @@ contract('ERC20Votes', function (accounts) {
await expectRevert(
this.token.delegateBySig(delegatorAddress, nonce, MAX_UINT256, v, r, s),
'ERC20Votes::delegateBySig: invalid nonce',
'ERC20Votes: invalid nonce',
);
});
@ -224,7 +224,7 @@ contract('ERC20Votes', function (accounts) {
));
await expectRevert(
this.token.delegateBySig(delegatorAddress, nonce + 1, MAX_UINT256, v, r, s),
'ERC20Votes::delegateBySig: invalid nonce',
'ERC20Votes: invalid nonce',
);
});
@ -241,7 +241,7 @@ contract('ERC20Votes', function (accounts) {
await expectRevert(
this.token.delegateBySig(delegatorAddress, nonce, expiry, v, r, s),
'ERC20Votes::delegateBySig: signature expired',
'ERC20Votes: signature expired',
);
});
});
@ -411,7 +411,7 @@ contract('ERC20Votes', function (accounts) {
it('reverts if block number >= current block', async function () {
await expectRevert(
this.token.getPriorVotes(other1, 5e10),
'ERC20Votes::getPriorVotes: not yet determined',
'ERC20Votes: block not yet mined',
);
});
@ -473,7 +473,7 @@ contract('ERC20Votes', function (accounts) {
it('reverts if block number >= current block', async function () {
await expectRevert(
this.token.getPriorTotalSupply(5e10),
'ERC20Votes::getPriorTotalSupply: not yet determined',
'ERC20Votes: block not yet mined',
);
});

Loading…
Cancel
Save