Removing more asserts in favor of require (#834)

* Removed asserts and replaced them in favor of require

* Adapted tests to work with requires
pull/889/head^2
Schneider Jakob 7 years ago committed by Francisco Giordano
parent 7e44204d9b
commit 85f079ee89
  1. 3
      contracts/ownership/HasNoEther.sol
  2. 6
      contracts/token/ERC20/SafeERC20.sol
  3. 8
      test/token/ERC20/SafeERC20.test.js

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

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

@ -1,4 +1,4 @@
import EVMThrow from '../../helpers/EVMThrow'; import EVMRevert from '../../helpers/EVMRevert';
require('chai') require('chai')
.use(require('chai-as-promised')) .use(require('chai-as-promised'))
@ -12,15 +12,15 @@ contract('SafeERC20', function () {
}); });
it('should throw on failed transfer', async 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 () { 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 () { 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 () { it('should not throw on succeeding transfer', async function () {

Loading…
Cancel
Save