Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ridev6 committed Aug 25, 2023
1 parent 9ed69d7 commit 9dcf83d
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ride/boosting.ride
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions test/components/boosting/_hooks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/components/boosting/claimReward.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
65 changes: 64 additions & 1 deletion test/components/boosting/lock.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
13 changes: 12 additions & 1 deletion test/components/boosting/unlock.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9dcf83d

Please sign in to comment.