Skip to content

Commit

Permalink
Use OZ safeTransfer in genericTransfer (#9025)
Browse files Browse the repository at this point in the history
* Use OZ safeTransfer in genericTransfer

* Add unit test for safeTransfer revert
  • Loading branch information
yorhodes authored Nov 30, 2021
1 parent d196b00 commit 2538345
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/protocol/contracts/governance/ReleaseGold.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pragma solidity ^0.5.13;

import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
import "openzeppelin-solidity/contracts/token/ERC20/SafeERC20.sol";
import "openzeppelin-solidity/contracts/utils/Address.sol";

import "./interfaces/IReleaseGold.sol";
Expand Down Expand Up @@ -191,7 +192,7 @@ contract ReleaseGold is UsingRegistry, ReentrancyGuard, IReleaseGold, Initializa
erc20 != registry.getAddressForOrDie(GOLD_TOKEN_REGISTRY_ID),
"Transfer must not target celo balance"
);
IERC20(erc20).transfer(to, value);
SafeERC20.safeTransfer(IERC20(erc20), to, value);
}

/**
Expand Down
15 changes: 15 additions & 0 deletions packages/protocol/test/governance/voting/release_gold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,21 @@ contract('ReleaseGold', (accounts: string[]) => {
assertEqualBN(endBalanceTo, startBalanceTo.plus(transferAmount))
})

it('should emit safeTransfer logs on erc20 revert', async () => {
const startBalanceFrom = await mockStableToken.balanceOf(releaseGoldInstance.address)
await assertRevert(
releaseGoldInstance.genericTransfer(
mockStableToken.address,
receiver,
startBalanceFrom.plus(1),
{
from: beneficiary,
}
),
'SafeERC20: ERC20 operation did not succeed'
)
})

it('should revert when attempting transfer of goldtoken from the release gold instance', async () => {
await assertRevert(
releaseGoldInstance.genericTransfer(goldTokenInstance.address, receiver, transferAmount, {
Expand Down

0 comments on commit 2538345

Please sign in to comment.