Skip to content

Commit

Permalink
unlock gwx burned check
Browse files Browse the repository at this point in the history
  • Loading branch information
ridev6 committed Aug 22, 2023
1 parent c349b88 commit cd4df15
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions test/components/boosting/unlock.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('boosting: unlock.mjs', /** @this {MochaSuiteModified} */() => {
const lockWxAmount = 1e3 * 1e8;
let lockTxId;
let lockHeight;
let lockParamsPrev;

before(async function () {
await broadcastAndWait(transfer({
Expand All @@ -27,7 +28,8 @@ describe('boosting: unlock.mjs', /** @this {MochaSuiteModified} */() => {
additionalFee: 4e5,
}, this.accounts.emission.seed));

({ id: lockTxId, height: lockHeight } = await boosting.lock({
let stateChanges;
({ id: lockTxId, height: lockHeight, stateChanges } = await boosting.lock({
dApp: this.accounts.boosting.addr,
caller: this.accounts.user0.seed,
duration: lockDuration,
Expand All @@ -36,6 +38,15 @@ describe('boosting: unlock.mjs', /** @this {MochaSuiteModified} */() => {
],
chainId,
}));

const boostingDataChanges = Object.fromEntries(
stateChanges.data.map(({ key, value }) => [key, value]),
);

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

it('should successfully unlock', async function () {
Expand Down Expand Up @@ -63,7 +74,16 @@ describe('boosting: unlock.mjs', /** @this {MochaSuiteModified} */() => {
const exponent = (t * 8 * this.blocksInPeriod) / lockDuration;
// if height > lockEnd then userAmount
const wxWithdrawable = Math.floor(lockWxAmount * (1 - 0.5 ** exponent));
const gwxAmountStart = Math.floor((lockWxAmount * lockDuration) / this.maxLockDuration);
const gwxAmountPrev = lockParamsPrev.gwxAmount;
const gwxBurned = Math.min(
Math.floor(
(t * this.blocksInPeriod * gwxAmountStart) / this.maxLockDuration,
),
gwxAmountPrev,
);

expect(lockParams.wxClaimed).to.equal(wxWithdrawable);
expect(lockParams.wxClaimed).to.equal(wxWithdrawable, 'wxClaimed');
expect(lockParams.gwxAmount).to.equal(gwxAmountPrev - gwxBurned, 'gwxAmount');
});
});

0 comments on commit cd4df15

Please sign in to comment.