From 625bfc2ba9dc0a27b620ee6f206ffcc015867d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Fingen?= Date: Thu, 16 Jul 2020 11:09:32 +0200 Subject: [PATCH] Add tests for total supply zero scenario MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If total supply is zero during reward period, reward tokens corresponding to the time while that happens would be lost. It is a very unlikely scenario, and it has an easy workaround: the account providing the rewards can make sure that doesn’t happen by staking a tiny amount. But it’s better to be aware of it. --- test/Unipool.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/Unipool.js b/test/Unipool.js index 0da3918..1783d08 100644 --- a/test/Unipool.js +++ b/test/Unipool.js @@ -223,5 +223,50 @@ contract('Unipool', function ([_, wallet1, wallet2, wallet3, wallet4]) { expect(await this.pool.earned(wallet1)).to.be.bignumber.almostEqualDiv1e18(web3.utils.toWei('2500')); expect(await this.pool.earned(wallet2)).to.be.bignumber.almostEqualDiv1e18(web3.utils.toWei('7500')); }); + + // TODO: if for some period the total supply is zero, rewards for that period are lost! + it('stake late solo', async function () { + // reward + await this.pool.notifyRewardAmount(web3.utils.toWei('70000'), { from: wallet1 }); + expect(await this.pool.earned(wallet2)).to.be.bignumber.equal('0'); + + // day 4 + await timeIncreaseTo(this.started.add(time.duration.days(4))); + // stake + await this.pool.stake(web3.utils.toWei('1'), { from: wallet2 }); + expect(await this.pool.earned(wallet2)).to.be.bignumber.equal('0'); + + // day 7 + await timeIncreaseTo(this.started.add(time.duration.days(7))); + expect(await this.pool.earned(wallet2)).to.be.bignumber.almostEqualDiv1e18(web3.utils.toWei('30000')); + + // day 10 + await timeIncreaseTo(this.started.add(time.duration.days(10))); + expect(await this.pool.earned(wallet2)).to.be.bignumber.almostEqualDiv1e18(web3.utils.toWei('30000')); + }); + + it('withdraw early solo', async function () { + // stake + await this.pool.stake(web3.utils.toWei('1'), { from: wallet2 }); + // reward + await this.pool.notifyRewardAmount(web3.utils.toWei('70000'), { from: wallet1 }); + expect(await this.pool.earned(wallet2)).to.be.bignumber.equal('0'); + + // day 3 + await timeIncreaseTo(this.started.add(time.duration.days(3))); + expect(await this.pool.earned(wallet2)).to.be.bignumber.almostEqualDiv1e18(web3.utils.toWei('30000')); + + // withdraw + await this.pool.withdraw(web3.utils.toWei('1'), { from: wallet2 }); + expect(await this.pool.earned(wallet2)).to.be.bignumber.almostEqualDiv1e18(web3.utils.toWei('30000')); + + // day 7 + await timeIncreaseTo(this.started.add(time.duration.days(7))); + expect(await this.pool.earned(wallet2)).to.be.bignumber.almostEqualDiv1e18(web3.utils.toWei('30000')); + + // day 10 + await timeIncreaseTo(this.started.add(time.duration.days(10))); + expect(await this.pool.earned(wallet2)).to.be.bignumber.almostEqualDiv1e18(web3.utils.toWei('30000')); + }); }); });