From 9dcf83dad47c1cc546bd38b49698a36c373c6338 Mon Sep 17 00:00:00 2001 From: Waves Rider <108881461+ridev6@users.noreply.github.com> Date: Fri, 25 Aug 2023 18:13:29 +0500 Subject: [PATCH] update tests --- ride/boosting.ride | 4 +- test/components/boosting/_hooks.mjs | 7 ++- test/components/boosting/claimReward.mjs | 2 +- test/components/boosting/lock.mjs | 65 +++++++++++++++++++++++- test/components/boosting/unlock.mjs | 13 ++++- 5 files changed, 82 insertions(+), 9 deletions(-) diff --git a/ride/boosting.ride b/ride/boosting.ride index 40ac60f6..762e515e 100644 --- a/ride/boosting.ride +++ b/ride/boosting.ride @@ -575,8 +575,8 @@ func lockActions(i: Invocation, duration: Int) = { let lockStart = height if ((pmtAmount < minLockAmount) && userAddress != lpStakingPoolsContract) then throwErr("amount is less then minLockAmount=" + minLockAmount.toString()) else - if (duration < minLockDuration) then throwErr("passed duration is less then minLockDuration=" + minLockDuration.toString()) else - if (duration > maxLockDuration) then throwErr("passed duration is greater then maxLockDuration=" + maxLockDuration.toString()) else + if (duration < minLockDuration) then throwErr("passed duration is less than minLockDuration=" + minLockDuration.toString()) else + if (duration > maxLockDuration) then throwErr("passed duration is greater than maxLockDuration=" + maxLockDuration.toString()) else if (duration % lockStepBlocks != 0) then throwErr("duration must be multiple of lockStepBlocks=" + lockStepBlocks.toString()) else let gWxAmountStart = fraction(pmtAmount, duration, maxLockDuration) diff --git a/test/components/boosting/_hooks.mjs b/test/components/boosting/_hooks.mjs index 3421b899..464c6be8 100644 --- a/test/components/boosting/_hooks.mjs +++ b/test/components/boosting/_hooks.mjs @@ -100,12 +100,11 @@ export const mochaHooks = { ]); this.minLockAmount = 500000000; - this.minDuration = 2; - this.maxDuration = 2102400; + this.minLockDuration = 2; this.maxLockDuration = 2102400; this.blocksInPeriod = 1; - this.lockStepBlocks = 1; + this.lockStepBlocks = 2; const { height } = await api.blocks.fetchHeight(); this.releaseRate = 3805175038; @@ -143,7 +142,7 @@ export const mochaHooks = { managerVaultAddress: this.accounts.managerVault.addr, lockAssetId: this.wxAssetId, minLockAmount: this.minLockAmount, - minLockDuration: this.minDuration, + minLockDuration: this.minLockDuration, maxLockDuration: this.maxLockDuration, mathContract: this.accounts.gwx.addr, blocksInPeriod: this.blocksInPeriod, diff --git a/test/components/boosting/claimReward.mjs b/test/components/boosting/claimReward.mjs index f954ba60..502cbcdb 100644 --- a/test/components/boosting/claimReward.mjs +++ b/test/components/boosting/claimReward.mjs @@ -15,7 +15,7 @@ chai.use(chaiAsPromised); const { expect } = chai; describe('boosting: claimReward.mjs', /** @this {MochaSuiteModified} */() => { - const lockDuration = 3; + const lockDuration = 4; const lockWxAmount = 1e3 * 1e8; let lockHeight; diff --git a/test/components/boosting/lock.mjs b/test/components/boosting/lock.mjs index 7aa8c7e8..7e422a40 100644 --- a/test/components/boosting/lock.mjs +++ b/test/components/boosting/lock.mjs @@ -12,7 +12,7 @@ chai.use(chaiAsPromised); const { expect } = chai; describe('boosting: lock.mjs', /** @this {MochaSuiteModified} */() => { - it('should successfully lock', async function () { + it('lock step blocks error', async function () { const lockDuration = 3; const lockWxAmount = 1e3 * 1e8; @@ -24,6 +24,69 @@ describe('boosting: lock.mjs', /** @this {MochaSuiteModified} */() => { additionalFee: 4e5, }, this.accounts.emission.seed)); + return expect(boosting.lock({ + caller: this.accounts.user0.seed, + duration: lockDuration, + payments: [ + { assetId: this.wxAssetId, amount: lockWxAmount }, + ], + })).to.be.rejectedWith(`duration must be multiple of lockStepBlocks=${this.lockStepBlocks}`); + }); + + it('min lock duration error', async function () { + const lockDuration = this.minLockDuration - 1; + + const lockWxAmount = 1e3 * 1e8; + + await broadcastAndWait(transfer({ + recipient: this.accounts.user0.addr, + amount: lockWxAmount, + assetId: this.wxAssetId, + additionalFee: 4e5, + }, this.accounts.emission.seed)); + + return expect(boosting.lock({ + caller: this.accounts.user0.seed, + duration: lockDuration, + payments: [ + { assetId: this.wxAssetId, amount: lockWxAmount }, + ], + })).to.be.rejectedWith(`passed duration is less than minLockDuration=${this.minLockDuration}`); + }); + + it('max lock duration error', async function () { + const lockDuration = this.maxLockDuration + 1; + + const lockWxAmount = 1e3 * 1e8; + + await broadcastAndWait(transfer({ + recipient: this.accounts.user0.addr, + amount: lockWxAmount, + assetId: this.wxAssetId, + additionalFee: 4e5, + }, this.accounts.emission.seed)); + + return expect(boosting.lock({ + caller: this.accounts.user0.seed, + duration: lockDuration, + payments: [ + { assetId: this.wxAssetId, amount: lockWxAmount }, + ], + })).to.be.rejectedWith(`passed duration is greater than maxLockDuration=${this.maxLockDuration}`); + }); + + it('should successfully lock', async function () { + const lockDuration = 4; + + const lockWxAmount = 1e3 * 1e8; + + await broadcastAndWait(transfer({ + recipient: this.accounts.user0.addr, + amount: lockWxAmount, + assetId: this.wxAssetId, + additionalFee: 4e5, + }, this.accounts.emission.seed)); + const { stateChanges, id: lockTxId } = await boosting.lock({ caller: this.accounts.user0.seed, duration: lockDuration, diff --git a/test/components/boosting/unlock.mjs b/test/components/boosting/unlock.mjs index d454b484..30cccd75 100644 --- a/test/components/boosting/unlock.mjs +++ b/test/components/boosting/unlock.mjs @@ -14,7 +14,7 @@ chai.use(chaiAsPromised); const { expect } = chai; describe('boosting: unlock.mjs', /** @this {MochaSuiteModified} */() => { - const lockDuration = 3; + const lockDuration = 4; const lockWxAmount = 1e3 * 1e8; let lockTxId; let lockHeight; @@ -48,6 +48,17 @@ describe('boosting: unlock.mjs', /** @this {MochaSuiteModified} */() => { ); }); + it('nothing to unlock', async function () { + const { height: currentHeight } = await api.blocks.fetchHeight(); + + expect(currentHeight - lockHeight).to.equal(0); + + return expect(boosting.unlock({ + caller: this.accounts.user0.seed, + txId: lockTxId, + })).to.be.rejectedWith('nothing to unlock'); + }); + it('should successfully unlock', async function () { const { height: currentHeight } = await api.blocks.fetchHeight(); let heightDiff = currentHeight - lockHeight;