Browse Source

Tweak ERC20Votes revert reasons and documentation (#2696)

* adapt revert reason convention

* add whitespace

* tweak documentation

* fix tests
Francisco Giordano 4 years ago
parent
commit
adc50d465c

+ 15 - 7
contracts/token/ERC20/extensions/ERC20Votes.sol

@@ -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) {
     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);
         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!
      * 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");
+    function getPriorTotalSupply(uint256 blockNumber) external view override returns (uint256) {
+        require(blockNumber < block.number, "ERC20Votes: block not yet mined");
         return _checkpointsLookup(_totalSupplyCheckpoints, blockNumber);
         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)
     function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s)
         public virtual override
         public virtual override
     {
     {
-        require(block.timestamp <= expiry, "ERC20Votes::delegateBySig: signature expired");
+        require(block.timestamp <= expiry, "ERC20Votes: signature expired");
         address signer = ECDSA.recover(
         address signer = ECDSA.recover(
             _hashTypedDataV4(keccak256(abi.encode(
             _hashTypedDataV4(keccak256(abi.encode(
                 _DELEGATION_TYPEHASH,
                 _DELEGATION_TYPEHASH,
@@ -127,7 +135,7 @@ abstract contract ERC20Votes is IERC20Votes, ERC20Permit {
             ))),
             ))),
             v, r, s
             v, r, s
         );
         );
-        require(nonce == _useNonce(signer), "ERC20Votes::delegateBySig: invalid nonce");
+        require(nonce == _useNonce(signer), "ERC20Votes: invalid nonce");
         return _delegate(signer, delegatee);
         return _delegate(signer, delegatee);
     }
     }
 
 

+ 5 - 5
test/token/ERC20/extensions/ERC20Votes.test.js

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