From 736505f000d7cf109b4a02800048c8151c412084 Mon Sep 17 00:00:00 2001 From: im2620493 <108935058+im2620493@users.noreply.github.com> Date: Mon, 15 Aug 2022 19:05:56 +0300 Subject: [PATCH] wip(test): extend test cases --- test/lp_stable/doublePutOneTkn.mjs | 126 +++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 test/lp_stable/doublePutOneTkn.mjs diff --git a/test/lp_stable/doublePutOneTkn.mjs b/test/lp_stable/doublePutOneTkn.mjs new file mode 100644 index 000000000..d23b54332 --- /dev/null +++ b/test/lp_stable/doublePutOneTkn.mjs @@ -0,0 +1,126 @@ +import chai from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +import { address } from '@waves/ts-lib-crypto'; +import { invokeScript, nodeInteraction as ni } from '@waves/waves-transactions'; +import { create } from '@waves/node-api-js'; + +chai.use(chaiAsPromised); +const { expect } = chai; + +const apiBase = process.env.API_NODE_URL; +const chainId = 'R'; + +const api = create(apiBase); + +describe('lp_stable: doublePutOneTkn.mjs', /** @this {MochaSuiteModified} */() => { + it('should successfully putOneTkn with autoStake false', async function () { + const amAssetPart = 1e8; + const prAssetPart = 1e8; + const outLp = 1e10; + const slippage = 1e3; + const autoStake = false; + const usdtAmount = 1e8; + const usdnAmount = 1e8; + const shouldAutoStake = false; + + const expectedPriceLast = 1e8; + const expectedPriceHistory = 1e8; + const expectedWriteAmAmt = 1e8; + const expectedWritePrAmt = 0; + const expectedEmitLpAmt = 1e10; + const expectedSlippageCalc = 1e3; + const expectedAmDiff = 0; + const expectedPrDiff = 0; + + const lpStable = address(this.accounts.lpStable, chainId); + + const put = invokeScript({ + dApp: lpStable, + payment: [ + { assetId: this.usdtAssetId, amount: usdtAmount }, + { assetId: this.usdnAssetId, amount: usdnAmount }, + ], + call: { + function: 'put', + args: [ + { type: 'integer', value: 0 }, + { type: 'boolean', value: shouldAutoStake }, + ], + }, + chainId, + }, this.accounts.user1); + await api.transactions.broadcast(put, {}); + await ni.waitForTx(put.id, { apiBase }); + + const firstPutOneTkn = invokeScript({ + dApp: lpStable, + payment: [ + { assetId: this.usdtAssetId, amount: usdtAmount }, + ], + call: { + function: 'putOneTkn', + args: [ + { type: 'integer', value: amAssetPart }, + { type: 'integer', value: prAssetPart }, + { type: 'integer', value: outLp }, + { type: 'integer', value: slippage }, + { type: 'boolean', value: autoStake }, + ], + }, + chainId, + }, this.accounts.user1); + await api.transactions.broadcast(firstPutOneTkn, {}); + await ni.waitForTx(firstPutOneTkn.id, { apiBase }); + + const secondPutOneTkn = invokeScript({ + dApp: lpStable, + payment: [ + { assetId: this.usdtAssetId, amount: usdtAmount }, + ], + call: { + function: 'putOneTkn', + args: [ + { type: 'integer', value: amAssetPart }, + { type: 'integer', value: prAssetPart }, + { type: 'integer', value: outLp }, + { type: 'integer', value: slippage }, + { type: 'boolean', value: autoStake }, + ], + }, + chainId, + }, this.accounts.user1); + await api.transactions.broadcast(secondPutOneTkn, {}); + const { height, stateChanges, id } = await ni.waitForTx(secondPutOneTkn.id, { apiBase }); + + const { timestamp } = await api.blocks.fetchHeadersAt(height); + const keyPriceHistory = `%s%s%d%d__price__history__${height}__${timestamp}`; + + expect(stateChanges.data).to.eql([{ + key: '%s%s__price__last', + type: 'integer', + value: expectedPriceLast, + }, { + key: keyPriceHistory, + type: 'integer', + value: expectedPriceHistory, + }, { + key: `%s%s%s__P__${address(this.accounts.user1, chainId)}__${id}`, + type: 'string', + value: `%d%d%d%d%d%d%d%d%d%d__${expectedWriteAmAmt}__${expectedWritePrAmt}__${expectedEmitLpAmt}__${expectedPriceLast}__${slippage}__${expectedSlippageCalc}__${height}__${timestamp}__${expectedAmDiff}__${expectedPrDiff}`, + }]); + + expect(stateChanges.transfers).to.eql([{ + address: address(this.accounts.user1, chainId), + asset: this.lpStableAssetId, + amount: outLp, + }]); + + expect(stateChanges.invokes.map((item) => [item.dApp, item.call.function])) + .to.deep.include.members([ + [address(this.accounts.lpStableAddon, chainId), 'ensureCanPutOneTkn'], + [address(this.accounts.gwxReward, chainId), 'calcD'], + [address(this.accounts.gwxReward, chainId), 'calcD'], + [address(this.accounts.factoryV2, chainId), 'emit'], + ]); + }); +});