SafeERC20Helper.sol 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. pragma solidity ^0.4.18;
  2. import '../token/ERC20.sol';
  3. import '../token/SafeERC20.sol';
  4. contract ERC20FailingMock is ERC20 {
  5. function transfer(address, uint256) public returns (bool) {
  6. return false;
  7. }
  8. function transferFrom(address, address, uint256) public returns (bool) {
  9. return false;
  10. }
  11. function approve(address, uint256) public returns (bool) {
  12. return false;
  13. }
  14. function balanceOf(address) public constant returns (uint256) {
  15. return 0;
  16. }
  17. function allowance(address, address) public constant returns (uint256) {
  18. return 0;
  19. }
  20. }
  21. contract ERC20SucceedingMock is ERC20 {
  22. function transfer(address, uint256) public returns (bool) {
  23. return true;
  24. }
  25. function transferFrom(address, address, uint256) public returns (bool) {
  26. return true;
  27. }
  28. function approve(address, uint256) public returns (bool) {
  29. return true;
  30. }
  31. function balanceOf(address) public constant returns (uint256) {
  32. return 0;
  33. }
  34. function allowance(address, address) public constant returns (uint256) {
  35. return 0;
  36. }
  37. }
  38. contract SafeERC20Helper {
  39. using SafeERC20 for ERC20;
  40. ERC20 failing;
  41. ERC20 succeeding;
  42. function SafeERC20Helper() public {
  43. failing = new ERC20FailingMock();
  44. succeeding = new ERC20SucceedingMock();
  45. }
  46. function doFailingTransfer() public {
  47. failing.safeTransfer(0, 0);
  48. }
  49. function doFailingTransferFrom() public {
  50. failing.safeTransferFrom(0, 0, 0);
  51. }
  52. function doFailingApprove() public {
  53. failing.safeApprove(0, 0);
  54. }
  55. function doSucceedingTransfer() public {
  56. succeeding.safeTransfer(0, 0);
  57. }
  58. function doSucceedingTransferFrom() public {
  59. succeeding.safeTransferFrom(0, 0, 0);
  60. }
  61. function doSucceedingApprove() public {
  62. succeeding.safeApprove(0, 0);
  63. }
  64. }