git.delta.rocks / unique-network / refs/commits / 681fe40c30ae

difftreelog

refactor use playgrounds in opal xcm tests

Daniel Shiposha2022-10-11parent: #7921115.patch.diff
in: master

1 file changed

modifiedtests/src/xcm/xcmOpal.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';
18import {executeTransaction} from './../substrate/substrate-api';
19import {bigIntToDecimals, getGenericResult, paraSiblingSovereignAccount} from './../deprecated-helpers/helpers';18import {bigIntToDecimals, paraSiblingSovereignAccount} from './../deprecated-helpers/helpers';
20import getBalance from './../substrate/get-balance';
21import {itSub, expect, describeXcm, usingPlaygrounds} from '../util/playgrounds';19import {itSub, expect, describeXcm, usingPlaygrounds, usingWestmintPlaygrounds, usingRelayPlaygrounds} from '../util/playgrounds';
2220
23const STATEMINE_CHAIN = 1000;21const STATEMINE_CHAIN = 1000;
24const UNIQUE_CHAIN = 2095;22const UNIQUE_CHAIN = 2095;
68 bob = privateKey('//Bob'); // funds donor66 bob = privateKey('//Bob'); // funds donor
69 });67 });
7068
71 await usingPlaygrounds.atUrl(statemineUrl, async (helper) => {69 await usingWestmintPlaygrounds(statemineUrl, async (helper) => {
72 const api = helper.getApi();
73
74 // 350.00 (three hundred fifty) DOT70 // 350.00 (three hundred fifty) DOT
75 const fundingAmount = 3_500_000_000_000; 71 const fundingAmount = 3_500_000_000_000n;
7672
77 const tx = api.tx.assets.create(ASSET_ID, alice.addressRaw, ASSET_METADATA_MINIMAL_BALANCE);73 await helper.assets.create(alice, ASSET_ID, alice.address, ASSET_METADATA_MINIMAL_BALANCE);
78 const events = await executeTransaction(api, alice, tx);
79 const result = getGenericResult(events);
80 expect(result.success).to.be.true;
81
82 // set metadata
83 const tx2 = api.tx.assets.setMetadata(ASSET_ID, ASSET_METADATA_NAME, ASSET_METADATA_DESCRIPTION, ASSET_METADATA_DECIMALS);74 await helper.assets.setMetadata(alice, ASSET_ID, ASSET_METADATA_NAME, ASSET_METADATA_DESCRIPTION, ASSET_METADATA_DECIMALS);
84 const events2 = await executeTransaction(api, alice, tx2);
85 const result2 = getGenericResult(events2);
86 expect(result2.success).to.be.true;
87
88 // mint some amount of asset
89 const tx3 = api.tx.assets.mint(ASSET_ID, alice.addressRaw, ASSET_AMOUNT);75 await helper.assets.mint(alice, ASSET_ID, alice.address, ASSET_AMOUNT);
90 const events3 = await executeTransaction(api, alice, tx3);
91 const result3 = getGenericResult(events3);
92 expect(result3.success).to.be.true;
9376
94 // funding parachain sovereing account (Parachain: 2095)77 // funding parachain sovereing account (Parachain: 2095)
95 const parachainSovereingAccount = await paraSiblingSovereignAccount(UNIQUE_CHAIN);78 const parachainSovereingAccount = await paraSiblingSovereignAccount(UNIQUE_CHAIN);
96 const tx4 = api.tx.balances.transfer(parachainSovereingAccount, fundingAmount);79 await helper.balance.transferToSubstrate(bob, parachainSovereingAccount, fundingAmount);
97 const events4 = await executeTransaction(api, bob, tx4);
98 const result4 = getGenericResult(events4);
99 expect(result4.success).to.be.true;
100
101 });80 });
10281
127 minimalBalance: ASSET_METADATA_MINIMAL_BALANCE,106 minimalBalance: ASSET_METADATA_MINIMAL_BALANCE,
128 };107 };
129 await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata);108 await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata);
130 // const tx = api.tx.foreignAssets.registerForeignAsset(alice.addressRaw, location, metadata);
131 // const sudoTx = api.tx.sudo.sudo(tx as any);
132 // const events = await executeTransaction(api, alice, sudoTx);
133 // const result = getGenericResult(events);
134 // expect(result.success).to.be.true;
135
136 // [balanceOpalBefore] = await getBalance(api, [alice.address]);
137 balanceOpalBefore = await helper.balance.getSubstrate(alice.address);109 balanceOpalBefore = await helper.balance.getSubstrate(alice.address);
138
139 });110 });
140111
141112
142 // Providing the relay currency to the unique sender account113 // Providing the relay currency to the unique sender account
143 await usingPlaygrounds.atUrl(relayUrl, async (helper) => {114 await usingRelayPlaygrounds(relayUrl, async (helper) => {
144 const api = helper.getApi();
145
146 const destination = {115 const destination = {
147 V1: {116 V1: {
182151
183 const feeAssetItem = 0;152 const feeAssetItem = 0;
184
185 const weightLimit = {153 const weightLimit = 5_000_000_000;
186 Limited: 5_000_000_000,
187 };
188154
189 const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);155 await helper.xcm.limitedReserveTransferAssets(alice, destination, beneficiary, assets, feeAssetItem, weightLimit);
190 const events = await executeTransaction(api, alice, tx);
191 const result = getGenericResult(events);
192 expect(result.success).to.be.true;
193 });156 });
194 157
195 });158 });
196159
197 itSub('Should connect and send USDT from Westmint to Opal', async ({helper}) => {160 itSub('Should connect and send USDT from Westmint to Opal', async ({helper}) => {
198 await usingPlaygrounds.atUrl(statemineUrl, async (helper) => {161 await usingWestmintPlaygrounds(statemineUrl, async (helper) => {
199 const api = helper.getApi();
200
201 const dest = {162 const dest = {
202 V1: {163 V1: {
245206
246 const feeAssetItem = 0;207 const feeAssetItem = 0;
247
248 const weightLimit = {208 const weightLimit = 5000000000;
249 Limited: 5000000000,
250 };
251209
252 [balanceStmnBefore] = await getBalance(api, [alice.address]);210 balanceStmnBefore = await helper.balance.getSubstrate(alice.address);
253
254 const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(dest, beneficiary, assets, feeAssetItem, weightLimit);211 await helper.xcm.limitedReserveTransferAssets(alice, dest, beneficiary, assets, feeAssetItem, weightLimit);
255 const events = await executeTransaction(api, alice, tx);
256 const result = getGenericResult(events);
257 expect(result.success).to.be.true;
258212
259 [balanceStmnAfter] = await getBalance(api, [alice.address]);213 balanceStmnAfter = await helper.balance.getSubstrate(alice.address);
260214
261 // common good parachain take commission in it native token215 // common good parachain take commission in it native token
262 console.log(216 console.log(
269223
270224
271 // ensure that asset has been delivered225 // ensure that asset has been delivered
272 // await waitNewBlocks(api, 3);
273 await helper.wait.newBlocks(3);226 await helper.wait.newBlocks(3);
274227
275 // expext collection id will be with id 1228 // expext collection id will be with id 1
276 // const free = (await api.query.fungible.balance(1, normalizeAccountId(alice.address))).toBigInt();
277 const free = await helper.ft.getBalance(1, {Substrate: alice.address});229 const free = await helper.ft.getBalance(1, {Substrate: alice.address});
278230
279 // [balanceOpalAfter] = await getBalance(api, [alice.address]);
280 balanceOpalAfter = await helper.balance.getSubstrate(alice.address);231 balanceOpalAfter = await helper.balance.getSubstrate(alice.address);
281232
282 // commission has not paid in USDT token233 // commission has not paid in USDT token
294 });245 });
295246
296 itSub('Should connect and send USDT from Unique to Statemine back', async ({helper}) => {247 itSub('Should connect and send USDT from Unique to Statemine back', async ({helper}) => {
297 const api = helper.getApi();
298
299 const destination = {248 const destination = {
300 V1: {249 V1: {
332 const feeItem = 1;281 const feeItem = 1;
333 const destWeight = 500000000000;282 const destWeight = 500000000000;
334283
335 const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);284 await helper.xTokens.transferMulticurrencies(alice, currencies, feeItem, destination, destWeight);
336 const events = await executeTransaction(api, alice, tx);285
337 const result = getGenericResult(events);
338 expect(result.success).to.be.true;
339
340 // the commission has been paid in parachain native token286 // the commission has been paid in parachain native token
341 [balanceOpalFinal] = await getBalance(api, [alice.address]);287 balanceOpalFinal = await helper.balance.getSubstrate(alice.address);
342 expect(balanceOpalAfter > balanceOpalFinal).to.be.true;288 expect(balanceOpalAfter > balanceOpalFinal).to.be.true;
343289
344 await usingPlaygrounds.atUrl(statemineUrl, async (helper) => {290 await usingWestmintPlaygrounds(statemineUrl, async (helper) => {
345 // await waitNewBlocks(api, 3);
346 await helper.wait.newBlocks(3);291 await helper.wait.newBlocks(3);
347292
348 const api = helper.getApi();
349
350 // The USDT token never paid fees. Its amount not changed from begin value.293 // The USDT token never paid fees. Its amount not changed from begin value.
351 // Also check that xcm transfer has been succeeded 294 // Also check that xcm transfer has been succeeded
352 const free = ((await api.query.assets.account(100, alice.address)).toHuman()) as any;
353 expect(BigInt(free.balance.replace(/,/g, '')) == ASSET_AMOUNT).to.be.true;295 expect((await helper.assets.account(ASSET_ID, alice.address))! == ASSET_AMOUNT).to.be.true;
354 });296 });
355 });297 });
356298
357 itSub('Should connect and send Relay token to Unique', async ({helper}) => {299 itSub('Should connect and send Relay token to Unique', async ({helper}) => {
358 const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;300 const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;
359301
360 // [balanceBobBefore] = await getBalance(api, [bob.address]);
361 // balanceBobRelayTokenBefore = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);
362 balanceBobBefore = await helper.balance.getSubstrate(bob.address);302 balanceBobBefore = await helper.balance.getSubstrate(bob.address);
363
364 // TODO
365 balanceBobRelayTokenBefore = BigInt(((await helper.getApi().query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);303 balanceBobRelayTokenBefore = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});
366304
367 // Providing the relay currency to the unique sender account305 // Providing the relay currency to the unique sender account
368 await usingPlaygrounds.atUrl(relayUrl, async (helper) => {306 await usingRelayPlaygrounds(relayUrl, async (helper) => {
369 const api = helper.getApi();
370
371 const destination = {307 const destination = {
372 V1: {308 V1: {
407343
408 const feeAssetItem = 0;344 const feeAssetItem = 0;
409
410 const weightLimit = {345 const weightLimit = 5_000_000_000;
411 Limited: 5_000_000_000,
412 };
413346
414 const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);347 await helper.xcm.limitedReserveTransferAssets(bob, destination, beneficiary, assets, feeAssetItem, weightLimit);
415 const events = await executeTransaction(api, bob, tx);
416 const result = getGenericResult(events);
417 expect(result.success).to.be.true;
418 });348 });
419 349
420
421 // await waitNewBlocks(api, 3);
422 await helper.wait.newBlocks(3);350 await helper.wait.newBlocks(3);
423351
424 // [balanceBobAfter] = await getBalance(api, [bob.address]);
425 // balanceBobRelayTokenAfter = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);
426 balanceBobAfter = await helper.balance.getSubstrate(bob.address);352 balanceBobAfter = await helper.balance.getSubstrate(bob.address);
427
428 // TODO
429 balanceBobRelayTokenAfter = BigInt(((await helper.getApi().query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);353 balanceBobRelayTokenAfter = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});
430354
431 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore; 355 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore;
432 console.log(356 console.log(
471 const feeItem = 0;395 const feeItem = 0;
472 const destWeight = 500000000000;396 const destWeight = 500000000000;
473397
474 // TODO
475 const api = helper.getApi();
476 const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);398 await helper.xTokens.transferMulticurrencies(bob, currencies, feeItem, destination, destWeight);
477 const events = await executeTransaction(api, bob, tx);399
478 const result = getGenericResult(events);
479 expect(result.success).to.be.true;
480
481 // [balanceBobFinal] = await getBalance(api, [bob.address]);
482 balanceBobFinal = await helper.balance.getSubstrate(bob.address);400 balanceBobFinal = await helper.balance.getSubstrate(bob.address);
483 console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobFinal);401 console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobFinal);
484 });402 });