Skip to content

Commit

Permalink
boosting unlock all test
Browse files Browse the repository at this point in the history
  • Loading branch information
ridev6 committed Aug 24, 2023
1 parent 2c7dbd5 commit 9ed69d7
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions test/components/boosting/unlock_all.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';

import {
transfer,
} from '@waves/waves-transactions';

import {
broadcastAndWait, chainId, waitForHeight,
} from '../../utils/api.mjs';
import { boosting, parseLockParams, keyLock } from './contract/boosting.mjs';

chai.use(chaiAsPromised);
const { expect } = chai;

describe('boosting: unlock_all.mjs', /** @this {MochaSuiteModified} */() => {
const lockDuration = 2;
const lockWxAmount = 1e3 * 1e8;
let lockTxId;
let lockHeight;

before(async function () {
await broadcastAndWait(transfer({
recipient: this.accounts.user0.addr,
amount: lockWxAmount,
assetId: this.wxAssetId,
additionalFee: 4e5,
}, this.accounts.emission.seed));

({ id: lockTxId, height: lockHeight } = await boosting.lock({
caller: this.accounts.user0.seed,
duration: lockDuration,
payments: [
{ assetId: this.wxAssetId, amount: lockWxAmount },
],
chainId,
}));
});

it('should successfully unlock', async function () {
await waitForHeight(lockHeight + lockDuration + 1);
const { stateChanges } = await boosting.unlock({
caller: this.accounts.user0.seed,
txId: lockTxId,
});
const boostingDataChanges = Object.fromEntries(
stateChanges.data.map(({ key, value }) => [key, value]),
);

const lockKey = keyLock(this.accounts.user0.addr, lockTxId);
const lockParams = parseLockParams(
boostingDataChanges[lockKey],
);

const gwxAmountStart = boosting.calcGwxAmountStart({
wxAmount: lockWxAmount,
duration: lockDuration,
});

expect(lockParams.wxClaimed).to.equal(lockWxAmount, 'wxClaimed');
expect(lockParams.gwxAmount).to.equal(gwxAmountStart, 'gwxAmount');
});
});

0 comments on commit 9ed69d7

Please sign in to comment.