git.delta.rocks / unique-network / refs/commits / cafc9078ea8d

difftreelog

fix XCM tests

Daniel Shiposha2023-10-23parent: #05427f7.patch.diff
in: master

6 files changed

modifiedjs-packages/playgrounds/types.xcm.tsdiffbeforeafterboth
28 },28 },
29}29}
3030
31export interface IForeignAssetMetadata {
32 name?: number | Uint8Array,
33 symbol?: string,
34 decimals?: number,
35 minimalBalance?: bigint,
36}
modifiedjs-packages/playgrounds/unique.xcm.tsdiffbeforeafterboth
2import type {IKeyringPair} from '@polkadot/types/types';2import type {IKeyringPair} from '@polkadot/types/types';
3import {ChainHelperBase, EthereumBalanceGroup, HelperGroup, SubstrateBalanceGroup, UniqueHelper} from './unique.js';3import {ChainHelperBase, EthereumBalanceGroup, HelperGroup, SubstrateBalanceGroup, UniqueHelper} from './unique.js';
4import type {ILogger, TSigner, TSubstrateAccount} from './types.js';4import type {ILogger, TSigner, TSubstrateAccount} from './types.js';
5import type {AcalaAssetMetadata, DemocracyStandardAccountVote, IForeignAssetMetadata, MoonbeamAssetInfo} from './types.xcm.js';5import type {AcalaAssetMetadata, DemocracyStandardAccountVote, MoonbeamAssetInfo} from './types.xcm.js';
66
77
8export class XcmChainHelper extends ChainHelperBase {8export class XcmChainHelper extends ChainHelperBase {
104}104}
105105
106export class ForeignAssetsGroup extends HelperGroup<UniqueHelper> {106export class ForeignAssetsGroup extends HelperGroup<UniqueHelper> {
107 async register(signer: TSigner, ownerAddress: TSubstrateAccount, location: any, metadata: IForeignAssetMetadata) {107 async register(signer: TSigner, location: any, name: string, tokenPrefix: string, mode: 'NFT' | { Fungible: number }) {
108 await this.helper.executeExtrinsic(108 await this.helper.executeExtrinsic(
109 signer,109 signer,
110 'api.tx.foreignAssets.registerForeignAsset',110 'api.tx.foreignAssets.forceRegisterForeignAsset',
111 [ownerAddress, location, metadata],111 [location, this.helper.util.str2vec(name), tokenPrefix, mode],
112 true,112 true,
113 );113 );
114 }114 }
115115
116 async update(signer: TSigner, foreignAssetId: number, location: any, metadata: IForeignAssetMetadata) {116 async foreignCollectionId(location: any) {
117 await this.helper.executeExtrinsic(117 return (await this.helper.callRpc('api.query.foreignAssets.foreignReserveLocationToCollection', [location])).toJSON();
118 signer,
119 'api.tx.foreignAssets.updateForeignAsset',
120 [foreignAssetId, location, metadata],
121 true,
122 );
123 }118 }
124}119}
256 await this.helper.executeExtrinsic(signer, 'api.tx.assets.mint', [assetId, beneficiary, amount], true);251 await this.helper.executeExtrinsic(signer, 'api.tx.assets.mint', [assetId, beneficiary, amount], true);
257 }252 }
253
254 async assetInfo(assetId: number | bigint) {
255 return (await this.helper.callRpc('api.query.assets.asset', [assetId])).toJSON();
256 }
258257
259 async account(assetId: string | number | bigint, address: string) {258 async account(assetId: string | number | bigint, address: string) {
260 const accountAsset = (259 const accountAsset = (
modifiedjs-packages/tests/xcm/xcm.types.tsdiffbeforeafterboth
506 });506 });
507 }507 }
508
509 async registerRelayNativeTokenOnUnique(alice: IKeyringPair) {
510 return await usingPlaygrounds(async (helper) => {
511 const relayLocation = {
512 parents: 1,
513 interior: 'Here',
514 };
515
516 const relayCollectionId = await helper.foreignAssets.foreignCollectionId(relayLocation);
517 if(relayCollectionId == null) {
518 const name = 'Relay Tokens';
519 const tokenPrefix = 'xDOT';
520 const decimals = 10;
521 await helper.getSudo().foreignAssets.register(alice, relayLocation, name, tokenPrefix, {Fungible: decimals});
522
523 return await helper.foreignAssets.foreignCollectionId(relayLocation);
524 } else {
525 console.log('Relay foreign collection is already registered');
526 return relayCollectionId;
527 }
528 });
529 }
508}530}
509531
modifiedjs-packages/tests/xcm/xcmOpal.test.tsdiffbeforeafterboth
17import type {IKeyringPair} from '@polkadot/types/types';17import type {IKeyringPair} from '@polkadot/types/types';
18import config from '../config.js';18import config from '../config.js';
19import {itSub, expect, describeXCM, usingPlaygrounds, usingWestmintPlaygrounds, usingRelayPlaygrounds} from '../util/index.js';19import {itSub, expect, describeXCM, usingPlaygrounds, usingWestmintPlaygrounds, usingRelayPlaygrounds} from '../util/index.js';
20import {XcmTestHelper} from './xcm.types';
2021
21const STATEMINE_CHAIN = +(process.env.RELAY_WESTMINT_ID || 1000);22const STATEMINE_CHAIN = +(process.env.RELAY_WESTMINT_ID || 1000);
22const UNIQUE_CHAIN = +(process.env.RELAY_OPAL_ID || 2095);23const UNIQUE_CHAIN = +(process.env.RELAY_OPAL_ID || 2095);
25const westmintUrl = config.westmintUrl;26const westmintUrl = config.westmintUrl;
2627
27const STATEMINE_PALLET_INSTANCE = 50;28const STATEMINE_PALLET_INSTANCE = 50;
28const ASSET_ID = 100;29const USDT_ASSET_ID = 100;
29const ASSET_METADATA_DECIMALS = 18;30const USDT_ASSET_METADATA_DECIMALS = 18;
30const ASSET_METADATA_NAME = 'USDT';31const USDT_ASSET_METADATA_NAME = 'USDT';
31const ASSET_METADATA_DESCRIPTION = 'USDT';32const USDT_ASSET_METADATA_DESCRIPTION = 'USDT';
32const ASSET_METADATA_MINIMAL_BALANCE = 1n;33const USDT_ASSET_METADATA_MINIMAL_BALANCE = 1n;
3334
34const RELAY_DECIMALS = 12;35const RELAY_DECIMALS = 12;
35const WESTMINT_DECIMALS = 12;36const WESTMINT_DECIMALS = 12;
3637
37const TRANSFER_AMOUNT = 1_000_000_000_000_000_000n;38const TRANSFER_AMOUNT = 1_000_000_000_000_000_000n;
3839
39// 10,000.00 (ten thousands) USDT40// 10,000.00 (ten thousands) USDT
40const ASSET_AMOUNT = 1_000_000_000_000_000_000_000n;41const USDT_ASSET_AMOUNT = 1_000_000_000_000_000_000_000n;
42
43const testHelper = new XcmTestHelper('opal');
4144
42describeXCM('[XCM] Integration test: Exchanging USDT with Westmint', () => {45describeXCM('[XCM] Integration test: Exchanging USDT with Westmint', () => {
43 let alice: IKeyringPair;46 let alice: IKeyringPair;
57 let balanceBobRelayTokenBefore: bigint;60 let balanceBobRelayTokenBefore: bigint;
58 let balanceBobRelayTokenAfter: bigint;61 let balanceBobRelayTokenAfter: bigint;
5962
63 let usdtCollectionId: number;
64 let relayCollectionId: number;
6065
61 before(async () => {66 before(async () => {
62 await usingPlaygrounds(async (_helper, privateKey) => {67 await usingPlaygrounds(async (_helper, privateKey) => {
63 alice = await privateKey('//Alice');68 alice = await privateKey('//Alice');
64 bob = await privateKey('//Bob'); // funds donor69 bob = await privateKey('//Bob'); // funds donor
70
71 relayCollectionId = await testHelper.registerRelayNativeTokenOnUnique(alice);
65 });72 });
6673
67 await usingWestmintPlaygrounds(westmintUrl, async (helper) => {74 await usingWestmintPlaygrounds(westmintUrl, async (helper) => {
68 // 350.00 (three hundred fifty) DOT
69 const fundingAmount = 3_500_000_000_000n;75 const assetInfo = await helper.assets.assetInfo(USDT_ASSET_ID);
7076 if(assetInfo == null) {
71 await helper.assets.create(alice, ASSET_ID, alice.address, ASSET_METADATA_MINIMAL_BALANCE);77 await helper.assets.create(
78 alice,
79 USDT_ASSET_ID,
80 alice.address,
81 USDT_ASSET_METADATA_MINIMAL_BALANCE,
82 );
72 await helper.assets.setMetadata(alice, ASSET_ID, ASSET_METADATA_NAME, ASSET_METADATA_DESCRIPTION, ASSET_METADATA_DECIMALS);83 await helper.assets.setMetadata(
84 alice,
85 USDT_ASSET_ID,
86 USDT_ASSET_METADATA_NAME,
87 USDT_ASSET_METADATA_DESCRIPTION,
88 USDT_ASSET_METADATA_DECIMALS,
89 );
90 } else {
91 console.log('The USDT asset is already registered on AssetHub');
92 }
93
73 await helper.assets.mint(alice, ASSET_ID, alice.address, ASSET_AMOUNT);94 await helper.assets.mint(
95 alice,
96 USDT_ASSET_ID,
97 alice.address,
98 USDT_ASSET_AMOUNT,
99 );
100
101 const sovereignFundingAmount = 3_500_000_000n;
74102
75 // funding parachain sovereing account (Parachain: 2095)103 // funding parachain sovereing account (Parachain: 2095)
76 const parachainSovereingAccount = helper.address.paraSiblingSovereignAccount(UNIQUE_CHAIN);104 const parachainSovereingAccount = helper.address.paraSiblingSovereignAccount(UNIQUE_CHAIN);
77 await helper.balance.transferToSubstrate(bob, parachainSovereingAccount, fundingAmount);105 await helper.balance.transferToSubstrate(bob, parachainSovereingAccount, sovereignFundingAmount);
78 });106 });
79
80107
81 await usingPlaygrounds(async (helper) => {108 await usingPlaygrounds(async (helper) => {
82 const location = {109 const location = {
83 V2: {
84 parents: 1,110 parents: 1,
85 interior: {X3: [111 interior: {X3: [
86 {112 {
90 PalletInstance: STATEMINE_PALLET_INSTANCE,116 PalletInstance: STATEMINE_PALLET_INSTANCE,
91 },117 },
92 {118 {
93 GeneralIndex: ASSET_ID,119 GeneralIndex: USDT_ASSET_ID,
94 },120 },
95 ]},121 ]},
96 },
97 };122 };
98123
124 if(await helper.foreignAssets.foreignCollectionId(location) == null) {
99 const metadata =125 const tokenPrefix = USDT_ASSET_METADATA_NAME;
100 {
101 name: ASSET_ID,
102 symbol: ASSET_METADATA_NAME,
103 decimals: ASSET_METADATA_DECIMALS,
104 minimalBalance: ASSET_METADATA_MINIMAL_BALANCE,
105 };
106 await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata);126 await helper.getSudo().foreignAssets.register(alice, location, USDT_ASSET_METADATA_NAME, tokenPrefix, {Fungible: USDT_ASSET_METADATA_DECIMALS});
127 } else {
128 console.log('Foreign collection is already registered on Opal');
129 }
130
107 balanceOpalBefore = await helper.balance.getSubstrate(alice.address);131 balanceOpalBefore = await helper.balance.getSubstrate(alice.address);
132 usdtCollectionId = await helper.foreignAssets.foreignCollectionId(location);
108 });133 });
109
110134
189 PalletInstance: STATEMINE_PALLET_INSTANCE,213 PalletInstance: STATEMINE_PALLET_INSTANCE,
190 },214 },
191 {215 {
192 GeneralIndex: ASSET_ID,216 GeneralIndex: USDT_ASSET_ID,
193 },217 },
194 ]},218 ]},
195 },219 },
221 // ensure that asset has been delivered244 // ensure that asset has been delivered
222 await helper.wait.newBlocks(3);245 await helper.wait.newBlocks(3);
223246
224 // expext collection id will be with id 1
225 const free = await helper.ft.getBalance(1, {Substrate: alice.address});247 const free = await helper.ft.getBalance(usdtCollectionId, {Substrate: alice.address});
226248
227 balanceOpalAfter = await helper.balance.getSubstrate(alice.address);249 balanceOpalAfter = await helper.balance.getSubstrate(alice.address);
228250
229 console.log(251 console.log(
230 '[Westmint -> Opal] transaction fees on Opal: %s USDT',252 '[Westmint -> Opal] transaction fees on Opal: %s USDT',
231 helper.util.bigIntToDecimals(TRANSFER_AMOUNT - free, ASSET_METADATA_DECIMALS),253 helper.util.bigIntToDecimals(TRANSFER_AMOUNT - free, USDT_ASSET_METADATA_DECIMALS),
232 );254 );
233 console.log(255 console.log(
234 '[Westmint -> Opal] transaction fees on Opal: %s OPL',256 '[Westmint -> Opal] transaction fees on Opal: %s OPL',
261283
262 const currencies: [any, bigint][] = [284 const currencies: [any, bigint][] = [
263 [285 [
264 {
265 ForeignAssetId: 0,
266 },286 usdtCollectionId,
267 //10_000_000_000_000_000n,
268 TRANSFER_AMOUNT,287 TRANSFER_AMOUNT,
269 ],288 ],
270 [289 [
271 {
272 NativeAssetId: 'Parent',
273 },290 relayCollectionId,
274 400_000_000_000_000n,291 400_000_000_000_000n,
275 ],292 ],
276 ];293 ];
288305
289 // The USDT token never paid fees. Its amount not changed from begin value.306 // The USDT token never paid fees. Its amount not changed from begin value.
290 // Also check that xcm transfer has been succeeded307 // Also check that xcm transfer has been succeeded
291 expect((await helper.assets.account(ASSET_ID, alice.address))! == ASSET_AMOUNT).to.be.true;308 expect((await helper.assets.account(USDT_ASSET_ID, alice.address))! == USDT_ASSET_AMOUNT).to.be.true;
292 });309 });
293 });310 });
294311
295 itSub('Should connect and send Relay token to Unique', async ({helper}) => {312 itSub('Should connect and send Relay token to Unique', async ({helper}) => {
296 const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;313 const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;
297314
298 balanceBobBefore = await helper.balance.getSubstrate(bob.address);315 balanceBobBefore = await helper.balance.getSubstrate(bob.address);
299 balanceBobRelayTokenBefore = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});316 balanceBobRelayTokenBefore = await helper.ft.getBalance(relayCollectionId, {Substrate: bob.address});
300317
301 // Providing the relay currency to the unique sender account318 // Providing the relay currency to the unique sender account
302 await usingRelayPlaygrounds(relayUrl, async (helper) => {319 await usingRelayPlaygrounds(relayUrl, async (helper) => {
345 await helper.wait.newBlocks(3);362 await helper.wait.newBlocks(3);
346363
347 balanceBobAfter = await helper.balance.getSubstrate(bob.address);364 balanceBobAfter = await helper.balance.getSubstrate(bob.address);
348 balanceBobRelayTokenAfter = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});365 balanceBobRelayTokenAfter = await helper.ft.getBalance(relayCollectionId, {Substrate: bob.address});
349366
350 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore;367 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore;
351 console.log(368 console.log(
383400
384 const currencies: any = [401 const currencies: any = [
385 [402 [
386 {
387 NativeAssetId: 'Parent',
388 },403 relayCollectionId,
389 50_000_000_000_000_000n,404 50_000_000_000_000_000n,
390 ],405 ],
391 ];406 ];
modifiedjs-packages/tests/xcm/xcmQuartz.test.tsdiffbeforeafterboth
19import {DevUniqueHelper, Event} from '@unique/playgrounds/unique.dev.js';19import {DevUniqueHelper, Event} from '@unique/playgrounds/unique.dev.js';
20import {STATEMINE_CHAIN, QUARTZ_CHAIN, KARURA_CHAIN, MOONRIVER_CHAIN, SHIDEN_CHAIN, STATEMINE_DECIMALS, KARURA_DECIMALS, QTZ_DECIMALS, RELAY_DECIMALS, SHIDEN_DECIMALS, karuraUrl, moonriverUrl, relayUrl, shidenUrl, statemineUrl} from './xcm.types.js';20import {STATEMINE_CHAIN, QUARTZ_CHAIN, KARURA_CHAIN, MOONRIVER_CHAIN, SHIDEN_CHAIN, STATEMINE_DECIMALS, KARURA_DECIMALS, QTZ_DECIMALS, RELAY_DECIMALS, SHIDEN_DECIMALS, karuraUrl, moonriverUrl, relayUrl, shidenUrl, statemineUrl} from './xcm.types.js';
21import {hexToString} from '@polkadot/util';21import {hexToString} from '@polkadot/util';
2222import {XcmTestHelper} from './xcm.types';
23
2423
25const STATEMINE_PALLET_INSTANCE = 50;24const STATEMINE_PALLET_INSTANCE = 50;
3938
40const SAFE_XCM_VERSION = 2;39const SAFE_XCM_VERSION = 2;
40
41const testHelper = new XcmTestHelper('quartz');
4142
42describeXCM('[XCM] Integration test: Exchanging USDT with Statemine', () => {43describeXCM('[XCM] Integration test: Exchanging USDT with Statemine', () => {
43 let alice: IKeyringPair;44 let alice: IKeyringPair;
57 let balanceBobRelayTokenBefore: bigint;58 let balanceBobRelayTokenBefore: bigint;
58 let balanceBobRelayTokenAfter: bigint;59 let balanceBobRelayTokenAfter: bigint;
5960
61 let usdtCollectionId: number;
62 let relayCollectionId: number;
6063
61 before(async () => {64 before(async () => {
62 await usingPlaygrounds(async (helper, privateKey) => {65 await usingPlaygrounds(async (helper, privateKey) => {
66 // Set the default version to wrap the first message to other chains.69 // Set the default version to wrap the first message to other chains.
67 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);70 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);
71
72 relayCollectionId = await testHelper.registerRelayNativeTokenOnUnique(alice);
68 });73 });
6974
70 await usingRelayPlaygrounds(relayUrl, async (helper) => {75 await usingRelayPlaygrounds(relayUrl, async (helper) => {
74 });79 });
7580
76 await usingStateminePlaygrounds(statemineUrl, async (helper) => {81 await usingStateminePlaygrounds(statemineUrl, async (helper) => {
77 const sovereignFundingAmount = 3_500_000_000n;82 const assetInfo = await helper.assets.assetInfo(USDT_ASSET_ID);
7883 if(assetInfo == null) {
79 await helper.assets.create(84 await helper.assets.create(
80 alice,85 alice,
81 USDT_ASSET_ID,86 USDT_ASSET_ID,
89 USDT_ASSET_METADATA_DESCRIPTION,94 USDT_ASSET_METADATA_DESCRIPTION,
90 USDT_ASSET_METADATA_DECIMALS,95 USDT_ASSET_METADATA_DECIMALS,
91 );96 );
97 } else {
98 console.log('The USDT asset is already registered on AssetHub');
99 }
100
92 await helper.assets.mint(101 await helper.assets.mint(
93 alice,102 alice,
96 USDT_ASSET_AMOUNT,105 USDT_ASSET_AMOUNT,
97 );106 );
107
108 const sovereignFundingAmount = 3_500_000_000n;
98109
99 // funding parachain sovereing account on Statemine(t).110 // funding parachain sovereing account on Statemine(t).
100 // The sovereign account should be created before any action111 // The sovereign account should be created before any action
106117
107 await usingPlaygrounds(async (helper) => {118 await usingPlaygrounds(async (helper) => {
108 const location = {119 const location = {
109 V2: {
110 parents: 1,120 parents: 1,
111 interior: {X3: [121 interior: {X3: [
112 {122 {
119 GeneralIndex: USDT_ASSET_ID,129 GeneralIndex: USDT_ASSET_ID,
120 },130 },
121 ]},131 ]},
122 },
123 };132 };
124133
134 if(await helper.foreignAssets.foreignCollectionId(location) == null) {
125 const metadata =135 const tokenPrefix = USDT_ASSET_METADATA_NAME;
126 {
127 name: USDT_ASSET_ID,
128 symbol: USDT_ASSET_METADATA_NAME,
129 decimals: USDT_ASSET_METADATA_DECIMALS,
130 minimalBalance: USDT_ASSET_METADATA_MINIMAL_BALANCE,
131 };
132 await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata);136 await helper.getSudo().foreignAssets.register(alice, location, USDT_ASSET_METADATA_NAME, tokenPrefix, {Fungible: USDT_ASSET_METADATA_DECIMALS});
137 } else {
138 console.log('Foreign collection is already registered on Quartz');
139 }
140
133 balanceQuartzBefore = await helper.balance.getSubstrate(alice.address);141 balanceQuartzBefore = await helper.balance.getSubstrate(alice.address);
142 usdtCollectionId = await helper.foreignAssets.foreignCollectionId(location);
134 });143 });
135144
136145
248 // ensure that asset has been delivered257 // ensure that asset has been delivered
249 await helper.wait.newBlocks(3);258 await helper.wait.newBlocks(3);
250259
251 // expext collection id will be with id 1
252 const free = await helper.ft.getBalance(1, {Substrate: alice.address});260 const free = await helper.ft.getBalance(usdtCollectionId, {Substrate: alice.address});
253261
254 balanceQuartzAfter = await helper.balance.getSubstrate(alice.address);262 balanceQuartzAfter = await helper.balance.getSubstrate(alice.address);
255263
288 const relayFee = 400_000_000_000_000n;296 const relayFee = 400_000_000_000_000n;
289 const currencies: [any, bigint][] = [297 const currencies: [any, bigint][] = [
290 [298 [
291 {
292 ForeignAssetId: 0,
293 },299 usdtCollectionId,
294 TRANSFER_AMOUNT,300 TRANSFER_AMOUNT,
295 ],301 ],
296 [302 [
297 {
298 NativeAssetId: 'Parent',
299 },303 relayCollectionId,
300 relayFee,304 relayFee,
301 ],305 ],
302 ];306 ];
321325
322 itSub('Should connect and send Relay token to Quartz', async ({helper}) => {326 itSub('Should connect and send Relay token to Quartz', async ({helper}) => {
323 balanceBobBefore = await helper.balance.getSubstrate(bob.address);327 balanceBobBefore = await helper.balance.getSubstrate(bob.address);
324 balanceBobRelayTokenBefore = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});328 balanceBobRelayTokenBefore = await helper.ft.getBalance(relayCollectionId, {Substrate: bob.address});
325329
326 await usingRelayPlaygrounds(relayUrl, async (helper) => {330 await usingRelayPlaygrounds(relayUrl, async (helper) => {
327 const destination = {331 const destination = {
369 await helper.wait.newBlocks(3);373 await helper.wait.newBlocks(3);
370374
371 balanceBobAfter = await helper.balance.getSubstrate(bob.address);375 balanceBobAfter = await helper.balance.getSubstrate(bob.address);
372 balanceBobRelayTokenAfter = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});376 balanceBobRelayTokenAfter = await helper.ft.getBalance(relayCollectionId, {Substrate: bob.address});
373377
374 const wndFeeOnQuartz = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore;378 const wndFeeOnQuartz = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore;
375 const wndDiffOnQuartz = balanceBobRelayTokenAfter - balanceBobRelayTokenBefore;379 const wndDiffOnQuartz = balanceBobRelayTokenAfter - balanceBobRelayTokenBefore;
409413
410 const currencies: any = [414 const currencies: any = [
411 [415 [
412 {
413 NativeAssetId: 'Parent',
414 },416 relayCollectionId,
415 TRANSFER_AMOUNT_RELAY,417 TRANSFER_AMOUNT_RELAY,
416 ],418 ],
417 ];419 ];
modifiedjs-packages/tests/xcm/xcmUnique.test.tsdiffbeforeafterboth
20import {Event} from '@unique/playgrounds/unique.dev.js';20import {Event} from '@unique/playgrounds/unique.dev.js';
21import {hexToString, nToBigInt} from '@polkadot/util';21import {hexToString, nToBigInt} from '@polkadot/util';
22import {ACALA_CHAIN, ASTAR_CHAIN, MOONBEAM_CHAIN, POLKADEX_CHAIN, SAFE_XCM_VERSION, STATEMINT_CHAIN, UNIQUE_CHAIN, expectFailedToTransact, expectUntrustedReserveLocationFail, uniqueAssetId, uniqueVersionedMultilocation} from './xcm.types.js';22import {ACALA_CHAIN, ASTAR_CHAIN, MOONBEAM_CHAIN, POLKADEX_CHAIN, SAFE_XCM_VERSION, STATEMINT_CHAIN, UNIQUE_CHAIN, expectFailedToTransact, expectUntrustedReserveLocationFail, uniqueAssetId, uniqueVersionedMultilocation} from './xcm.types.js';
2323import {XcmTestHelper} from './xcm.types';
2424
25const STATEMINT_PALLET_INSTANCE = 50;25const STATEMINT_PALLET_INSTANCE = 50;
2626
50const USDT_ASSET_METADATA_MINIMAL_BALANCE = 1n;50const USDT_ASSET_METADATA_MINIMAL_BALANCE = 1n;
51const USDT_ASSET_AMOUNT = 10_000_000_000_000_000_000_000_000n;51const USDT_ASSET_AMOUNT = 10_000_000_000_000_000_000_000_000n;
52
53const testHelper = new XcmTestHelper('unique');
5254
53describeXCM('[XCM] Integration test: Exchanging USDT with Statemint', () => {55describeXCM('[XCM] Integration test: Exchanging USDT with Statemint', () => {
54 let alice: IKeyringPair;56 let alice: IKeyringPair;
68 let balanceBobRelayTokenBefore: bigint;70 let balanceBobRelayTokenBefore: bigint;
69 let balanceBobRelayTokenAfter: bigint;71 let balanceBobRelayTokenAfter: bigint;
7072
73 let usdtCollectionId: number;
74 let relayCollectionId: number;
7175
72 before(async () => {76 before(async () => {
73 await usingPlaygrounds(async (helper, privateKey) => {77 await usingPlaygrounds(async (helper, privateKey) => {
77 // Set the default version to wrap the first message to other chains.81 // Set the default version to wrap the first message to other chains.
78 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);82 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);
83
84 relayCollectionId = await testHelper.registerRelayNativeTokenOnUnique(alice);
79 });85 });
8086
81 await usingRelayPlaygrounds(relayUrl, async (helper) => {87 await usingRelayPlaygrounds(relayUrl, async (helper) => {
85 });91 });
8692
87 await usingStatemintPlaygrounds(statemintUrl, async (helper) => {93 await usingStatemintPlaygrounds(statemintUrl, async (helper) => {
88 const sovereignFundingAmount = 3_500_000_000n;94 const assetInfo = await helper.assets.assetInfo(USDT_ASSET_ID);
8995 if(assetInfo == null) {
90 await helper.assets.create(96 await helper.assets.create(
91 alice,97 alice,
92 USDT_ASSET_ID,98 USDT_ASSET_ID,
100 USDT_ASSET_METADATA_DESCRIPTION,106 USDT_ASSET_METADATA_DESCRIPTION,
101 USDT_ASSET_METADATA_DECIMALS,107 USDT_ASSET_METADATA_DECIMALS,
102 );108 );
109 } else {
110 console.log('The USDT asset is already registered on AssetHub');
111 }
112
103 await helper.assets.mint(113 await helper.assets.mint(
104 alice,114 alice,
107 USDT_ASSET_AMOUNT,117 USDT_ASSET_AMOUNT,
108 );118 );
119
120 const sovereignFundingAmount = 3_500_000_000n;
109121
110 // funding parachain sovereing account on Statemint.122 // funding parachain sovereing account on Statemint.
111 // The sovereign account should be created before any action123 // The sovereign account should be created before any action
117129
118 await usingPlaygrounds(async (helper) => {130 await usingPlaygrounds(async (helper) => {
119 const location = {131 const location = {
120 V2: {
121 parents: 1,132 parents: 1,
122 interior: {X3: [133 interior: {X3: [
123 {134 {
130 GeneralIndex: USDT_ASSET_ID,141 GeneralIndex: USDT_ASSET_ID,
131 },142 },
132 ]},143 ]},
133 },
134 };144 };
135145
146 if(await helper.foreignAssets.foreignCollectionId(location) == null) {
136 const metadata =147 const tokenPrefix = USDT_ASSET_METADATA_NAME;
137 {
138 name: USDT_ASSET_ID,
139 symbol: USDT_ASSET_METADATA_NAME,
140 decimals: USDT_ASSET_METADATA_DECIMALS,
141 minimalBalance: USDT_ASSET_METADATA_MINIMAL_BALANCE,
142 };
143 await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata);148 await helper.getSudo().foreignAssets.register(alice, location, USDT_ASSET_METADATA_NAME, tokenPrefix, {Fungible: USDT_ASSET_METADATA_DECIMALS});
149 } else {
150 console.log('Foreign collection is already registered on Unique');
151 }
152
144 balanceUniqueBefore = await helper.balance.getSubstrate(alice.address);153 balanceUniqueBefore = await helper.balance.getSubstrate(alice.address);
154 usdtCollectionId = await helper.foreignAssets.foreignCollectionId(location);
145 });155 });
146156
147157
259 // ensure that asset has been delivered269 // ensure that asset has been delivered
260 await helper.wait.newBlocks(3);270 await helper.wait.newBlocks(3);
261271
262 // expext collection id will be with id 1
263 const free = await helper.ft.getBalance(1, {Substrate: alice.address});272 const free = await helper.ft.getBalance(usdtCollectionId, {Substrate: alice.address});
264273
265 balanceUniqueAfter = await helper.balance.getSubstrate(alice.address);274 balanceUniqueAfter = await helper.balance.getSubstrate(alice.address);
266275
299 const relayFee = 400_000_000_000_000n;308 const relayFee = 400_000_000_000_000n;
300 const currencies: [any, bigint][] = [309 const currencies: [any, bigint][] = [
301 [310 [
302 {
303 ForeignAssetId: 0,
304 },311 usdtCollectionId,
305 TRANSFER_AMOUNT,312 TRANSFER_AMOUNT,
306 ],313 ],
307 [314 [
308 {
309 NativeAssetId: 'Parent',
310 },315 relayCollectionId,
311 relayFee,316 relayFee,
312 ],317 ],
313 ];318 ];
332337
333 itSub('Should connect and send Relay token to Unique', async ({helper}) => {338 itSub('Should connect and send Relay token to Unique', async ({helper}) => {
334 balanceBobBefore = await helper.balance.getSubstrate(bob.address);339 balanceBobBefore = await helper.balance.getSubstrate(bob.address);
335 balanceBobRelayTokenBefore = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});340 balanceBobRelayTokenBefore = await helper.ft.getBalance(relayCollectionId, {Substrate: bob.address});
336341
337 await usingRelayPlaygrounds(relayUrl, async (helper) => {342 await usingRelayPlaygrounds(relayUrl, async (helper) => {
338 const destination = {343 const destination = {
380 await helper.wait.newBlocks(3);385 await helper.wait.newBlocks(3);
381386
382 balanceBobAfter = await helper.balance.getSubstrate(bob.address);387 balanceBobAfter = await helper.balance.getSubstrate(bob.address);
383 balanceBobRelayTokenAfter = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});388 balanceBobRelayTokenAfter = await helper.ft.getBalance(relayCollectionId, {Substrate: bob.address});
384389
385 const wndFeeOnUnique = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore;390 const wndFeeOnUnique = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore;
386 const wndDiffOnUnique = balanceBobRelayTokenAfter - balanceBobRelayTokenBefore;391 const wndDiffOnUnique = balanceBobRelayTokenAfter - balanceBobRelayTokenBefore;
420425
421 const currencies: any = [426 const currencies: any = [
422 [427 [
423 {
424 NativeAssetId: 'Parent',
425 },428 relayCollectionId,
426 TRANSFER_AMOUNT_RELAY,429 TRANSFER_AMOUNT_RELAY,
427 ],430 ],
428 ];431 ];