diff --git a/contracts/DecentralizedAutonomousTrust.sol b/contracts/DecentralizedAutonomousTrust.sol index cbee513b..4f9d5389 100644 --- a/contracts/DecentralizedAutonomousTrust.sol +++ b/contracts/DecentralizedAutonomousTrust.sol @@ -4,6 +4,7 @@ import "./Whitelist.sol"; import "hardlydifficult-ethereum-contracts/contracts/math/BigDiv.sol"; import "hardlydifficult-ethereum-contracts/contracts/math/Sqrt.sol"; import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/SafeERC20.sol"; import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Detailed.sol"; import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol"; @@ -23,6 +24,7 @@ contract DecentralizedAutonomousTrust is ERC20, ERC20Detailed { using SafeMath for uint; + using SafeERC20 for IERC20; /** * Events @@ -324,8 +326,7 @@ contract DecentralizedAutonomousTrust // currency is ERC20 require(_msgValue == 0, "DO_NOT_SEND_ETH"); - bool success = currency.transferFrom(_from, address(this), _quantityToInvest); - require(success, "ERC20_TRANSFER_FAILED"); + currency.safeTransferFrom(_from, address(this), _quantityToInvest); } } @@ -345,8 +346,7 @@ contract DecentralizedAutonomousTrust } else { - bool success = currency.transfer(_to, _amount); - require(success, "ERC20_TRANSFER_FAILED"); + currency.safeTransfer(_to, _amount); } } } diff --git a/test/dat/collectInvestment.js b/test/dat/collectInvestment.js new file mode 100644 index 00000000..cc071de2 --- /dev/null +++ b/test/dat/collectInvestment.js @@ -0,0 +1,28 @@ +/** + * Tests the ability to buy dat tokens + */ + +const { approveAll, deployDat } = require("../helpers"); +const { tokens } = require("hardlydifficult-ethereum-contracts"); +const { constants, shouldFail } = require("../helpers"); + +contract("dat / collectInvestment", accounts => { + it("shouldFail with DO_NOT_SEND_ETH", async () => { + const token = await tokens.dai.deploy(web3, accounts[0]); + const contracts = await deployDat(accounts, { currency: token.address }); + await approveAll(contracts, accounts); + await token.mint(accounts[1], constants.MAX_UINT, { + from: accounts[0] + }); + await token.approve(contracts.dat.address, constants.MAX_UINT, { + from: accounts[1] + }); + await shouldFail( + contracts.dat.buy(accounts[1], "100000000000000000000", 1, { + from: accounts[1], + value: 1 + }), + "DO_NOT_SEND_ETH" + ); + }); +});