Skip to content

Commit 589d192

Browse files
feat: split_51C
1 parent d4d19fe commit 589d192

File tree

3 files changed

+148
-22
lines changed

3 files changed

+148
-22
lines changed

ride/user_pools.ride

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func getManagerVaultAddressOrThis() = {
6969

7070
func getStringOrFail(key: String) = this.getString(key).valueOrErrorMessage(key + " is not defined")
7171
func stringOptionToList(stringOrUnit: String|Unit) = match stringOrUnit {
72-
case s: String => if (s.size() == 0) then nil else s.split(SEP)
72+
case s: String => if (s.size() == 0) then nil else s.split_51C(SEP)
7373
case _: Unit => nil
7474
}
7575

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
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+
});

test/utils/utils.mjs

+7-21
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,26 @@
1-
import { setScript, nodeInteraction } from '@waves/waves-transactions';
2-
import { create } from '@waves/node-api-js';
1+
import { setScript } from '@waves/waves-transactions';
32
import { readFile } from 'fs/promises';
4-
import ride from '@waves/ride-js';
53

6-
const { waitForTx } = nodeInteraction;
7-
const apiBase = process.env.API_NODE_URL;
4+
import { api, broadcastAndWait } from './api.mjs';
85

96
const chainId = 'R';
10-
const api = create(apiBase);
117

128
/**
139
* @param {string} path
1410
* @param {string} account
15-
* @param {function(*): *} transform
1611
*/
1712
export const setScriptFromFile = async (
1813
path,
1914
account,
20-
transform = (content) => content,
2115
) => {
22-
const { base64, size } = ride.compile(transform(await readFile(path, { encoding: 'utf-8' }))).result;
23-
const waveletsPerKilobyte = 1e5;
24-
const bitsInByte = 1024;
25-
const min = 1000000;
26-
let fee = Math.ceil(size / bitsInByte) * waveletsPerKilobyte;
27-
if (fee < min) {
28-
fee = min;
29-
}
30-
fee += 4e5;
16+
const { script, extraFee, error } = await api.utils.fetchCompileCode(await readFile(path, { encoding: 'utf-8' }));
17+
if (error) throw new Error(error.message);
3118
const ssTx = setScript({
32-
script: base64,
19+
script,
3320
chainId,
34-
fee,
21+
additionalFee: extraFee,
3522
}, account);
36-
await api.transactions.broadcast(ssTx, {});
37-
await waitForTx(ssTx.id, { apiBase });
23+
return broadcastAndWait(ssTx);
3824
};
3925

4026
export const checkStateChanges = async (

0 commit comments

Comments
 (0)