|
| 1 | +import chai from 'chai'; |
| 2 | +import chaiAsPromised from 'chai-as-promised'; |
| 3 | +import { address } from '@waves/ts-lib-crypto'; |
| 4 | +import { |
| 5 | + invokeScript, issue, data, nodeInteraction, transfer, |
| 6 | +} from '@waves/waves-transactions'; |
| 7 | +import { create } from '@waves/node-api-js'; |
| 8 | + |
| 9 | +chai.use(chaiAsPromised); |
| 10 | +const { expect } = chai; |
| 11 | + |
| 12 | +const { waitForTx } = nodeInteraction; |
| 13 | + |
| 14 | +const apiBase = process.env.API_NODE_URL; |
| 15 | +const seed = 'waves private node seed with waves tokens'; |
| 16 | +const chainId = 'R'; |
| 17 | + |
| 18 | +const api = create(apiBase); |
| 19 | + |
| 20 | +/** @typedef { |
| 21 | + * Mocha.Suite & {accounts: Object.<string, number>, wxAssetId: string, usdnAssetId: string} |
| 22 | + * } MochaSuiteModified |
| 23 | + * */ |
| 24 | + |
| 25 | +describe('User Pools - Create', /** @this {MochaSuiteModified} */() => { |
| 26 | + let userTokenId = ''; |
| 27 | + before(async function () { |
| 28 | + const constructorInvokeTx = invokeScript({ |
| 29 | + dApp: address(this.accounts.pools, chainId), |
| 30 | + call: { |
| 31 | + function: 'constructor', |
| 32 | + args: [ |
| 33 | + { type: 'string', value: address(this.accounts.factory, chainId) }, // factoryV2Address |
| 34 | + { type: 'string', value: address(this.accounts.store, chainId) }, // assetsStoreAddress |
| 35 | + { type: 'string', value: address(this.accounts.emission, chainId) }, // emissionAddress |
| 36 | + { type: 'list', value: [{ type: 'string', value: '1000' }] }, // priceAssetsMinAmount: List[String] |
| 37 | + { type: 'integer', value: 1000 }, // amountAssetMinAmount |
| 38 | + { type: 'string', value: this.wxAssetId }, // feeAssetId |
| 39 | + { type: 'integer', value: 1000 }, // feeAmount |
| 40 | + ], |
| 41 | + }, |
| 42 | + fee: 9e5, |
| 43 | + chainId, |
| 44 | + }, this.accounts.pools); |
| 45 | + await api.transactions.broadcast(constructorInvokeTx, {}); |
| 46 | + await waitForTx(constructorInvokeTx.id, { apiBase }); |
| 47 | + |
| 48 | + const userTokenIssueTx = issue({ |
| 49 | + name: 'user token', |
| 50 | + description: '', |
| 51 | + quantity: 1e16, |
| 52 | + decimals: 8, |
| 53 | + chainId, |
| 54 | + }, this.accounts.user); |
| 55 | + await api.transactions.broadcast(userTokenIssueTx, {}); |
| 56 | + await waitForTx(userTokenIssueTx.id, { apiBase }); |
| 57 | + userTokenId = userTokenIssueTx.id; |
| 58 | + |
| 59 | + const statusVerified = 2; |
| 60 | + const verifyTokenDataTx = data({ |
| 61 | + data: [ |
| 62 | + { key: `status_<${userTokenId}>`, type: 'integer', value: statusVerified }, |
| 63 | + ], |
| 64 | + chainId, |
| 65 | + }, this.accounts.store); |
| 66 | + await api.transactions.broadcast(verifyTokenDataTx, {}); |
| 67 | + await waitForTx(verifyTokenDataTx.id, { apiBase }); |
| 68 | + |
| 69 | + const usdnTransferTx = transfer({ |
| 70 | + amount: 1e8, |
| 71 | + recipient: address(this.accounts.user, chainId), |
| 72 | + assetId: this.usdnAssetId, |
| 73 | + chainId, |
| 74 | + }, seed); |
| 75 | + await api.transactions.broadcast(usdnTransferTx, {}); |
| 76 | + await waitForTx(usdnTransferTx.id, { apiBase }); |
| 77 | + |
| 78 | + const wxTransferTx = transfer({ |
| 79 | + amount: 1e8, |
| 80 | + recipient: address(this.accounts.user, chainId), |
| 81 | + assetId: this.wxAssetId, |
| 82 | + chainId, |
| 83 | + }, seed); |
| 84 | + await api.transactions.broadcast(wxTransferTx, {}); |
| 85 | + await waitForTx(wxTransferTx.id, { apiBase }); |
| 86 | + }); |
| 87 | + |
| 88 | + it('Create burns WX fee', async function () { |
| 89 | + let logPriceAssetsValue = `${userTokenId}`; |
| 90 | + |
| 91 | + for (let i = 0; i < 200; i += 1) { |
| 92 | + logPriceAssetsValue += `__priceAsset${i}`; |
| 93 | + } |
| 94 | + |
| 95 | + const dataTx = data( |
| 96 | + { |
| 97 | + data: [ |
| 98 | + { |
| 99 | + key: '%s__priceAssets', |
| 100 | + type: 'string', |
| 101 | + value: logPriceAssetsValue, |
| 102 | + }, |
| 103 | + ], |
| 104 | + chainId, |
| 105 | + additionalFee: 4e5, |
| 106 | + }, |
| 107 | + this.accounts.pools, |
| 108 | + ); |
| 109 | + await api.transactions.broadcast(dataTx, {}); |
| 110 | + await waitForTx(dataTx.id, { apiBase }); |
| 111 | + |
| 112 | + const createInvokeTx = invokeScript({ |
| 113 | + dApp: address(this.accounts.pools, chainId), |
| 114 | + call: { |
| 115 | + function: 'create', |
| 116 | + args: [], |
| 117 | + }, |
| 118 | + payment: [ |
| 119 | + { amount: 1e8, assetId: userTokenId }, |
| 120 | + { amount: 1e8, assetId: this.usdnAssetId }, |
| 121 | + { amount: 1e3, assetId: this.wxAssetId }, |
| 122 | + ], |
| 123 | + fee: 9e5, |
| 124 | + chainId, |
| 125 | + }, this.accounts.user); |
| 126 | + await api.transactions.broadcast(createInvokeTx, {}); |
| 127 | + await waitForTx(createInvokeTx.id, { apiBase }); |
| 128 | + |
| 129 | + const { stateChanges } = await api.transactions.fetchInfo(createInvokeTx.id); |
| 130 | + expect(stateChanges.invokes.map((item) => [item.dApp, item.call.function])) |
| 131 | + .to.deep.include.members([ |
| 132 | + [address(this.accounts.factory, chainId), 'poolExistsREADONLY'], |
| 133 | + [address(this.accounts.emission, chainId), 'burn'], |
| 134 | + ]); |
| 135 | + expect(stateChanges.invokes[1].payment).to.deep.include({ |
| 136 | + assetId: this.wxAssetId, |
| 137 | + amount: 1e3, |
| 138 | + }); |
| 139 | + }); |
| 140 | +}); |
0 commit comments