diff --git a/contracts/DecentralizedAutonomousTrust.sol b/contracts/DecentralizedAutonomousTrust.sol index cbee513b..7b2f438e 100644 --- a/contracts/DecentralizedAutonomousTrust.sol +++ b/contracts/DecentralizedAutonomousTrust.sol @@ -892,7 +892,7 @@ contract DecentralizedAutonomousTrust buySlopeNum * totalSupply(), totalSupply(), buySlopeDen ); - /// Math: this if condition avoids a potential overflow + // Math: this if condition avoids a potential overflow if(exitFee <= reserve) { exitFee = 0; @@ -938,7 +938,7 @@ contract DecentralizedAutonomousTrust } else { - require(false, "INVALID_STATE"); + revert("INVALID_STATE"); } emit Close(exitFee); diff --git a/test/wiki/close/close.js b/test/wiki/close/close.js index 962103b5..dd5945fb 100644 --- a/test/wiki/close/close.js +++ b/test/wiki/close/close.js @@ -40,7 +40,8 @@ contract("wiki / close / close", accounts => { contracts.dat.close({ from: await contracts.dat.beneficiary(), value: "10000000000000000000000" - }) + }), + "INVALID_STATE" ); }); }); diff --git a/test/wiki/close/init.js b/test/wiki/close/init.js index 17d7419a..c35b61ae 100644 --- a/test/wiki/close/init.js +++ b/test/wiki/close/init.js @@ -24,6 +24,11 @@ contract("wiki / close / init", accounts => { assert.equal(state.toString(), constants.STATE.INIT); }); + it("exitFee estimate is 0", async () => { + const fee = await contracts.dat.estimateExitFee(0); + assert.equal(fee, 0); + }); + describe("on close", () => { beforeEach(async () => { await contracts.dat.close({ diff --git a/test/wiki/close/run.js b/test/wiki/close/run.js index 3cf155d6..b1ae213f 100644 --- a/test/wiki/close/run.js +++ b/test/wiki/close/run.js @@ -1,3 +1,5 @@ +const { tokens } = require("hardlydifficult-ethereum-contracts"); + const sleep = require("sleep"); const BigNumber = require("bignumber.js"); const { @@ -163,4 +165,21 @@ contract("wiki / close / run", accounts => { ); }); }); + + describe("when reserve is high", () => { + beforeEach(async () => { + // Redeploy using an ERC-20 + const token = await tokens.dai.deploy(web3, accounts[0]); + contracts = await deployDat(accounts, { currency: token.address }); + await approveAll(contracts, accounts); + await token.mint(contracts.dat.address, constants.MAX_UINT, { + from: accounts[0] + }); + }); + + it("exitFee is 0", async () => { + const exitFee = new BigNumber(await contracts.dat.estimateExitFee(0)); + assert.equal(exitFee, 0); + }); + }); });