From 604890d0e90da85ae982a5c27742dfcb5bfe9417 Mon Sep 17 00:00:00 2001 From: Joey Santoro Date: Wed, 27 Jan 2021 18:23:11 -0800 Subject: [PATCH] subtract total committed emergency exit --- contracts/genesis/GenesisGroup.sol | 8 +++++--- test/genesis/GenesisGroup.test.js | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/contracts/genesis/GenesisGroup.sol b/contracts/genesis/GenesisGroup.sol index 42a73a325..10fd20efb 100644 --- a/contracts/genesis/GenesisGroup.sol +++ b/contracts/genesis/GenesisGroup.sol @@ -175,15 +175,17 @@ contract GenesisGroup is IGenesisGroup, CoreRef, ERC20, ERC20Burnable, Timed { function emergencyExit(address from, address to) external { require(now > (startTime + duration + 3 days), "GenesisGroup: Not in exit window"); - uint amountFGEN = balanceOf(from); - uint total = amountFGEN + committedFGEN[from]; + uint heldFGEN = balanceOf(from); + uint committed = committedFGEN[from]; + uint total = heldFGEN + committed; require(total != 0, "GenesisGroup: No FGEN or committed balance"); require(address(this).balance >= total, "GenesisGroup: Not enough ETH to redeem"); require(msg.sender == from || allowance(from, msg.sender) >= total, "GenesisGroup: Not approved for emergency withdrawal"); - burnFrom(from, amountFGEN); + burnFrom(from, heldFGEN); committedFGEN[from] = 0; + totalCommittedFGEN -= committed; payable(to).transfer(total); } diff --git a/test/genesis/GenesisGroup.test.js b/test/genesis/GenesisGroup.test.js index ab9119176..63bdd20d0 100644 --- a/test/genesis/GenesisGroup.test.js +++ b/test/genesis/GenesisGroup.test.js @@ -185,6 +185,21 @@ describe('GenesisGroup', function () { expect(await this.genesisGroup.committedFGEN(userAddress)).to.be.bignumber.equal('500'); expect(await this.genesisGroup.totalCommittedFGEN()).to.be.bignumber.equal('500'); }); + + describe('Exit', function() { + beforeEach(async function() { + await time.increase('300000'); + await this.genesisGroup.emergencyExit(userAddress, userAddress, {from: userAddress}); + }); + + it('decrements user committed', async function() { + expect(await this.genesisGroup.committedFGEN(userAddress)).to.be.bignumber.equal(new BN('0')); + }); + + it('decrements total committed', async function() { + expect(await this.genesisGroup.totalCommittedFGEN()).to.be.bignumber.equal(new BN('0')); + }); + }); }); describe('Commit other', async function() {