difftreelog
fix XCM tests
in: master
6 files changed
js-packages/playgrounds/types.xcm.tsdiffbeforeafterboth28 },28 },29}29}303031export interface IForeignAssetMetadata {32 name?: number | Uint8Array,33 symbol?: string,34 decimals?: number,35 minimalBalance?: bigint,36}js-packages/playgrounds/unique.xcm.tsdiffbeforeafterboth2import 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';66778export class XcmChainHelper extends ChainHelperBase {8export class XcmChainHelper extends ChainHelperBase {104}104}105105106export 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 }115115116 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 }253254 async assetInfo(assetId: number | bigint) {255 return (await this.helper.callRpc('api.query.assets.asset', [assetId])).toJSON();256 }258257259 async account(assetId: string | number | bigint, address: string) {258 async account(assetId: string | number | bigint, address: string) {260 const accountAsset = (259 const accountAsset = (js-packages/tests/xcm/xcm.types.tsdiffbeforeafterboth506 });506 });507 }507 }508509 async registerRelayNativeTokenOnUnique(alice: IKeyringPair) {510 return await usingPlaygrounds(async (helper) => {511 const relayLocation = {512 parents: 1,513 interior: 'Here',514 };515516 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});522523 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}509531js-packages/tests/xcm/xcmOpal.test.tsdiffbeforeafterboth17import 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';202121const 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;262727const 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;333434const RELAY_DECIMALS = 12;35const RELAY_DECIMALS = 12;35const WESTMINT_DECIMALS = 12;36const WESTMINT_DECIMALS = 12;363737const TRANSFER_AMOUNT = 1_000_000_000_000_000_000n;38const TRANSFER_AMOUNT = 1_000_000_000_000_000_000n;383939// 10,000.00 (ten thousands) USDT40// 10,000.00 (ten thousands) USDT40const ASSET_AMOUNT = 1_000_000_000_000_000_000_000n;41const USDT_ASSET_AMOUNT = 1_000_000_000_000_000_000_000n;4243const testHelper = new XcmTestHelper('opal');414442describeXCM('[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;596263 let usdtCollectionId: number;64 let relayCollectionId: number;606561 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 donor7071 relayCollectionId = await testHelper.registerRelayNativeTokenOnUnique(alice);65 });72 });667367 await usingWestmintPlaygrounds(westmintUrl, async (helper) => {74 await usingWestmintPlaygrounds(westmintUrl, async (helper) => {68 // 350.00 (three hundred fifty) DOT69 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 }9373 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 );100101 const sovereignFundingAmount = 3_500_000_000n;7410275 // 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 });798010781 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 };98123124 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 }130107 balanceOpalBefore = await helper.balance.getSubstrate(alice.address);131 balanceOpalBefore = await helper.balance.getSubstrate(alice.address);132 usdtCollectionId = await helper.foreignAssets.foreignCollectionId(location);108 });133 });109110134189 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 delivered222 await helper.wait.newBlocks(3);245 await helper.wait.newBlocks(3);223246224 // expext collection id will be with id 1225 const free = await helper.ft.getBalance(1, {Substrate: alice.address});247 const free = await helper.ft.getBalance(usdtCollectionId, {Substrate: alice.address});226248227 balanceOpalAfter = await helper.balance.getSubstrate(alice.address);249 balanceOpalAfter = await helper.balance.getSubstrate(alice.address);228250229 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',261283262 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 ];288305289 // 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 succeeded291 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 });294311295 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;297314298 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});300317301 // Providing the relay currency to the unique sender account318 // Providing the relay currency to the unique sender account302 await usingRelayPlaygrounds(relayUrl, async (helper) => {319 await usingRelayPlaygrounds(relayUrl, async (helper) => {345 await helper.wait.newBlocks(3);362 await helper.wait.newBlocks(3);346363347 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});349366350 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore;367 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore;351 console.log(368 console.log(383400384 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 ];js-packages/tests/xcm/xcmQuartz.test.tsdiffbeforeafterboth19import {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';23242325const STATEMINE_PALLET_INSTANCE = 50;24const STATEMINE_PALLET_INSTANCE = 50;393840const SAFE_XCM_VERSION = 2;39const SAFE_XCM_VERSION = 2;4041const testHelper = new XcmTestHelper('quartz');414242describeXCM('[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;596061 let usdtCollectionId: number;62 let relayCollectionId: number;606361 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);7172 relayCollectionId = await testHelper.registerRelayNativeTokenOnUnique(alice);68 });73 });697470 await usingRelayPlaygrounds(relayUrl, async (helper) => {75 await usingRelayPlaygrounds(relayUrl, async (helper) => {74 });79 });758076 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 }10092 await helper.assets.mint(101 await helper.assets.mint(93 alice,102 alice,96 USDT_ASSET_AMOUNT,105 USDT_ASSET_AMOUNT,97 );106 );107108 const sovereignFundingAmount = 3_500_000_000n;9810999 // 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 action106117107 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 };124133134 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 }140133 balanceQuartzBefore = await helper.balance.getSubstrate(alice.address);141 balanceQuartzBefore = await helper.balance.getSubstrate(alice.address);142 usdtCollectionId = await helper.foreignAssets.foreignCollectionId(location);134 });143 });135144136145248 // ensure that asset has been delivered257 // ensure that asset has been delivered249 await helper.wait.newBlocks(3);258 await helper.wait.newBlocks(3);250259251 // expext collection id will be with id 1252 const free = await helper.ft.getBalance(1, {Substrate: alice.address});260 const free = await helper.ft.getBalance(usdtCollectionId, {Substrate: alice.address});253261254 balanceQuartzAfter = await helper.balance.getSubstrate(alice.address);262 balanceQuartzAfter = await helper.balance.getSubstrate(alice.address);255263288 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 ];321325322 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});325329326 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);370374371 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});373377374 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;409413410 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 ];js-packages/tests/xcm/xcmUnique.test.tsdiffbeforeafterboth20import {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';242425const STATEMINT_PALLET_INSTANCE = 50;25const STATEMINT_PALLET_INSTANCE = 50;262650const 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;5253const testHelper = new XcmTestHelper('unique');525453describeXCM('[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;707273 let usdtCollectionId: number;74 let relayCollectionId: number;717572 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);8384 relayCollectionId = await testHelper.registerRelayNativeTokenOnUnique(alice);79 });85 });808681 await usingRelayPlaygrounds(relayUrl, async (helper) => {87 await usingRelayPlaygrounds(relayUrl, async (helper) => {85 });91 });869287 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 }112103 await helper.assets.mint(113 await helper.assets.mint(104 alice,114 alice,107 USDT_ASSET_AMOUNT,117 USDT_ASSET_AMOUNT,108 );118 );119120 const sovereignFundingAmount = 3_500_000_000n;109121110 // 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 action117129118 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 };135145146 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 }152144 balanceUniqueBefore = await helper.balance.getSubstrate(alice.address);153 balanceUniqueBefore = await helper.balance.getSubstrate(alice.address);154 usdtCollectionId = await helper.foreignAssets.foreignCollectionId(location);145 });155 });146156147157259 // ensure that asset has been delivered269 // ensure that asset has been delivered260 await helper.wait.newBlocks(3);270 await helper.wait.newBlocks(3);261271262 // expext collection id will be with id 1263 const free = await helper.ft.getBalance(1, {Substrate: alice.address});272 const free = await helper.ft.getBalance(usdtCollectionId, {Substrate: alice.address});264273265 balanceUniqueAfter = await helper.balance.getSubstrate(alice.address);274 balanceUniqueAfter = await helper.balance.getSubstrate(alice.address);266275299 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 ];332337333 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});336341337 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);381386382 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});384389385 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;420425421 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 ];