From ddaa453d787c3e86541cdc53fa9dcc324ff65f8f Mon Sep 17 00:00:00 2001 From: Epic waves rider <108883923+epicwavesrider@users.noreply.github.com> Date: Tue, 20 Jun 2023 12:08:02 +0400 Subject: [PATCH] feat: split_51C --- ride/user_pools.ride | 2 +- .../createWithLongPriceAssetsValue.mjs | 140 ++++++++++++++++++ test/utils/utils.mjs | 12 +- 3 files changed, 148 insertions(+), 6 deletions(-) create mode 100644 test/components/user_pools/createWithLongPriceAssetsValue.mjs diff --git a/ride/user_pools.ride b/ride/user_pools.ride index 1589ac67..09c2402e 100644 --- a/ride/user_pools.ride +++ b/ride/user_pools.ride @@ -69,7 +69,7 @@ func getManagerVaultAddressOrThis() = { func getStringOrFail(key: String) = this.getString(key).valueOrErrorMessage(key + " is not defined") func stringOptionToList(stringOrUnit: String|Unit) = match stringOrUnit { - case s: String => if (s.size() == 0) then nil else s.split(SEP) + case s: String => if (s.size() == 0) then nil else s.split_51C(SEP) case _: Unit => nil } diff --git a/test/components/user_pools/createWithLongPriceAssetsValue.mjs b/test/components/user_pools/createWithLongPriceAssetsValue.mjs new file mode 100644 index 00000000..a1fef0c9 --- /dev/null +++ b/test/components/user_pools/createWithLongPriceAssetsValue.mjs @@ -0,0 +1,140 @@ +import chai from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +import { address } from '@waves/ts-lib-crypto'; +import { + invokeScript, issue, data, nodeInteraction, transfer, +} from '@waves/waves-transactions'; +import { create } from '@waves/node-api-js'; + +chai.use(chaiAsPromised); +const { expect } = chai; + +const { waitForTx } = nodeInteraction; + +const apiBase = process.env.API_NODE_URL; +const seed = 'waves private node seed with waves tokens'; +const chainId = 'R'; + +const api = create(apiBase); + +/** @typedef { + * Mocha.Suite & {accounts: Object., wxAssetId: string, usdnAssetId: string} + * } MochaSuiteModified + * */ + +describe('User Pools - Create', /** @this {MochaSuiteModified} */() => { + let userTokenId = ''; + before(async function () { + const constructorInvokeTx = invokeScript({ + dApp: address(this.accounts.pools, chainId), + call: { + function: 'constructor', + args: [ + { type: 'string', value: address(this.accounts.factory, chainId) }, // factoryV2Address + { type: 'string', value: address(this.accounts.store, chainId) }, // assetsStoreAddress + { type: 'string', value: address(this.accounts.emission, chainId) }, // emissionAddress + { type: 'list', value: [{ type: 'string', value: '1000' }] }, // priceAssetsMinAmount: List[String] + { type: 'integer', value: 1000 }, // amountAssetMinAmount + { type: 'string', value: this.wxAssetId }, // feeAssetId + { type: 'integer', value: 1000 }, // feeAmount + ], + }, + fee: 9e5, + chainId, + }, this.accounts.pools); + await api.transactions.broadcast(constructorInvokeTx, {}); + await waitForTx(constructorInvokeTx.id, { apiBase }); + + const userTokenIssueTx = issue({ + name: 'user token', + description: '', + quantity: 1e16, + decimals: 8, + chainId, + }, this.accounts.user); + await api.transactions.broadcast(userTokenIssueTx, {}); + await waitForTx(userTokenIssueTx.id, { apiBase }); + userTokenId = userTokenIssueTx.id; + + const statusVerified = 2; + const verifyTokenDataTx = data({ + data: [ + { key: `status_<${userTokenId}>`, type: 'integer', value: statusVerified }, + ], + chainId, + }, this.accounts.store); + await api.transactions.broadcast(verifyTokenDataTx, {}); + await waitForTx(verifyTokenDataTx.id, { apiBase }); + + const usdnTransferTx = transfer({ + amount: 1e8, + recipient: address(this.accounts.user, chainId), + assetId: this.usdnAssetId, + chainId, + }, seed); + await api.transactions.broadcast(usdnTransferTx, {}); + await waitForTx(usdnTransferTx.id, { apiBase }); + + const wxTransferTx = transfer({ + amount: 1e8, + recipient: address(this.accounts.user, chainId), + assetId: this.wxAssetId, + chainId, + }, seed); + await api.transactions.broadcast(wxTransferTx, {}); + await waitForTx(wxTransferTx.id, { apiBase }); + }); + + it('Create burns WX fee', async function () { + let logPriceAssetsValue = `${userTokenId}`; + + for (let i = 0; i < 200; i += 1) { + logPriceAssetsValue += `__priceAsset${i}`; + } + + const dataTx = data( + { + data: [ + { + key: '%s__priceAssets', + type: 'string', + value: logPriceAssetsValue, + }, + ], + chainId, + additionalFee: 4e5, + }, + this.accounts.pools, + ); + await api.transactions.broadcast(dataTx, {}); + await waitForTx(dataTx.id, { apiBase }); + + const createInvokeTx = invokeScript({ + dApp: address(this.accounts.pools, chainId), + call: { + function: 'create', + args: [], + }, + payment: [ + { amount: 1e8, assetId: userTokenId }, + { amount: 1e8, assetId: this.usdnAssetId }, + { amount: 1e3, assetId: this.wxAssetId }, + ], + fee: 9e5, + chainId, + }, this.accounts.user); + await api.transactions.broadcast(createInvokeTx, {}); + await waitForTx(createInvokeTx.id, { apiBase }); + + const { stateChanges } = await api.transactions.fetchInfo(createInvokeTx.id); + expect(stateChanges.invokes.map((item) => [item.dApp, item.call.function])) + .to.deep.include.members([ + [address(this.accounts.factory, chainId), 'poolExistsREADONLY'], + [address(this.accounts.emission, chainId), 'burn'], + ]); + expect(stateChanges.invokes[1].payment).to.deep.include({ + assetId: this.wxAssetId, + amount: 1e3, + }); + }); +}); diff --git a/test/utils/utils.mjs b/test/utils/utils.mjs index 7da45605..3559cc74 100644 --- a/test/utils/utils.mjs +++ b/test/utils/utils.mjs @@ -1,7 +1,6 @@ import { setScript, nodeInteraction } from '@waves/waves-transactions'; import { create } from '@waves/node-api-js'; import { readFile } from 'fs/promises'; -import ride from '@waves/ride-js'; const { waitForTx } = nodeInteraction; const apiBase = process.env.API_NODE_URL; @@ -12,14 +11,17 @@ const api = create(apiBase); /** * @param {string} path * @param {string} account - * @param {function(*): *} transform */ export const setScriptFromFile = async ( path, account, - transform = (content) => content, ) => { - const { base64, size } = ride.compile(transform(await readFile(path, { encoding: 'utf-8' }))).result; + const { script, error } = await api.utils.fetchCompileCode(await readFile(path, { encoding: 'utf-8' })); + if (error) throw new Error(error.message); + + const scriptWithoutBase64Prefix = script.replace('base64:', ''); + const size = Buffer.from(scriptWithoutBase64Prefix, 'base64').length; + const waveletsPerKilobyte = 1e5; const bitsInByte = 1024; const min = 1000000; @@ -29,7 +31,7 @@ export const setScriptFromFile = async ( } fee += 4e5; const ssTx = setScript({ - script: base64, + script, chainId, fee, }, account);