From b14c9f4b683c368fbf551ae955a180235515508f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Mon, 25 Feb 2019 14:41:26 -0300 Subject: [PATCH] Fix SafeERC20.safeApprove bug, improve test coverage. --- contracts/mocks/SafeERC20Helper.sol | 8 ++++---- contracts/token/ERC20/SafeERC20.sol | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/contracts/mocks/SafeERC20Helper.sol b/contracts/mocks/SafeERC20Helper.sol index 9b13eaa0a03..464b5b7231b 100644 --- a/contracts/mocks/SafeERC20Helper.sol +++ b/contracts/mocks/SafeERC20Helper.sol @@ -32,7 +32,7 @@ contract ERC20FailingMock { } contract ERC20SucceedingMock { - uint256 private _allowance; + mapping (address => uint256) private _allowances; // IERC20's functions are not pure, but these mock implementations are: to prevent Solidity from issuing warnings, // we write to a dummy state variable. @@ -54,11 +54,11 @@ contract ERC20SucceedingMock { } function setAllowance(uint256 allowance_) public { - _allowance = allowance_; + _allowances[msg.sender] = allowance_; } - function allowance(address, address) public view returns (uint256) { - return _allowance; + function allowance(address owner, address) public view returns (uint256) { + return _allowances[owner]; } } diff --git a/contracts/token/ERC20/SafeERC20.sol b/contracts/token/ERC20/SafeERC20.sol index 61641c35fd6..bc735e96a21 100644 --- a/contracts/token/ERC20/SafeERC20.sol +++ b/contracts/token/ERC20/SafeERC20.sol @@ -24,7 +24,7 @@ library SafeERC20 { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' - require((value == 0) || (token.allowance(msg.sender, spender) == 0)); + require((value == 0) || (token.allowance(address(this), spender) == 0)); require(token.approve(spender, value)); }