Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: split_51C #367

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ride/user_pools.ride
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
140 changes: 140 additions & 0 deletions test/components/user_pools/createWithLongPriceAssetsValue.mjs
Original file line number Diff line number Diff line change
@@ -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.<string, number>, 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,
});
});
});
12 changes: 7 additions & 5 deletions test/utils/utils.mjs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -29,7 +31,7 @@ export const setScriptFromFile = async (
}
fee += 4e5;
const ssTx = setScript({
script: base64,
script,
chainId,
fee,
}, account);
Expand Down