Forráskód Böngészése

Removing more asserts in favor of require (#834)

* Removed asserts and replaced them in favor of require

* Adapted tests to work with requires
Schneider Jakob 7 éve
szülő
commit
85f079ee89

+ 1 - 2
contracts/ownership/HasNoEther.sol

@@ -36,7 +36,6 @@ contract HasNoEther is Ownable {
    * @dev Transfer all Ether held by the contract to the owner.
    */
   function reclaimEther() external onlyOwner {
-    // solium-disable-next-line security/no-send
-    assert(owner.send(address(this).balance));
+    owner.transfer(this.balance);
   }
 }

+ 3 - 3
contracts/token/ERC20/SafeERC20.sol

@@ -12,7 +12,7 @@ import "./ERC20.sol";
  */
 library SafeERC20 {
   function safeTransfer(ERC20Basic token, address to, uint256 value) internal {
-    assert(token.transfer(to, value));
+    require(token.transfer(to, value));
   }
 
   function safeTransferFrom(
@@ -23,10 +23,10 @@ library SafeERC20 {
   )
     internal
   {
-    assert(token.transferFrom(from, to, value));
+    require(token.transferFrom(from, to, value));
   }
 
   function safeApprove(ERC20 token, address spender, uint256 value) internal {
-    assert(token.approve(spender, value));
+    require(token.approve(spender, value));
   }
 }

+ 4 - 4
test/token/ERC20/SafeERC20.test.js

@@ -1,4 +1,4 @@
-import EVMThrow from '../../helpers/EVMThrow';
+import EVMRevert from '../../helpers/EVMRevert';
 
 require('chai')
   .use(require('chai-as-promised'))
@@ -12,15 +12,15 @@ contract('SafeERC20', function () {
   });
 
   it('should throw on failed transfer', async function () {
-    await this.helper.doFailingTransfer().should.be.rejectedWith(EVMThrow);
+    await this.helper.doFailingTransfer().should.be.rejectedWith(EVMRevert);
   });
 
   it('should throw on failed transferFrom', async function () {
-    await this.helper.doFailingTransferFrom().should.be.rejectedWith(EVMThrow);
+    await this.helper.doFailingTransferFrom().should.be.rejectedWith(EVMRevert);
   });
 
   it('should throw on failed approve', async function () {
-    await this.helper.doFailingApprove().should.be.rejectedWith(EVMThrow);
+    await this.helper.doFailingApprove().should.be.rejectedWith(EVMRevert);
   });
 
   it('should not throw on succeeding transfer', async function () {