From 4377c66b23474c6ea34e404f7654cc932767fb33 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Mon, 23 Oct 2023 19:46:29 +0200 Subject: [PATCH] fix: XCM tests --- tests/src/util/playgrounds/types.xcm.ts | 7 -- tests/src/util/playgrounds/unique.xcm.ts | 24 ++--- tests/src/xcm/xcm.types.ts | 22 ++++ tests/src/xcm/xcmOpal.test.ts | 123 +++++++++++++---------- tests/src/xcm/xcmQuartz.test.ts | 104 +++++++++---------- tests/src/xcm/xcmUnique.test.ts | 103 ++++++++++--------- 6 files changed, 209 insertions(+), 174 deletions(-) diff --git a/tests/src/util/playgrounds/types.xcm.ts b/tests/src/util/playgrounds/types.xcm.ts index 161bc78e61..c46a39ec27 100644 --- a/tests/src/util/playgrounds/types.xcm.ts +++ b/tests/src/util/playgrounds/types.xcm.ts @@ -27,10 +27,3 @@ export interface DemocracyStandardAccountVote { conviction: number, }, } - -export interface IForeignAssetMetadata { - name?: number | Uint8Array, - symbol?: string, - decimals?: number, - minimalBalance?: bigint, -} \ No newline at end of file diff --git a/tests/src/util/playgrounds/unique.xcm.ts b/tests/src/util/playgrounds/unique.xcm.ts index c9704ac7f2..2c9c0683a3 100644 --- a/tests/src/util/playgrounds/unique.xcm.ts +++ b/tests/src/util/playgrounds/unique.xcm.ts @@ -1,8 +1,9 @@ import {ApiPromise, WsProvider} from '@polkadot/api'; import {IKeyringPair} from '@polkadot/types/types'; import {ChainHelperBase, EthereumBalanceGroup, HelperGroup, SubstrateBalanceGroup, UniqueHelper} from './unique'; -import {ILogger, TSigner, TSubstrateAccount} from './types'; -import {AcalaAssetMetadata, DemocracyStandardAccountVote, IForeignAssetMetadata, MoonbeamAssetInfo} from './types.xcm'; +import {ILogger, TSigner} from './types'; +import {AcalaAssetMetadata, DemocracyStandardAccountVote, MoonbeamAssetInfo} from './types.xcm'; +import {CollectionMode} from '../../eth/util/playgrounds/types'; export class XcmChainHelper extends ChainHelperBase { @@ -104,22 +105,17 @@ class PolkadexXcmHelperGroup extends HelperGroup { } export class ForeignAssetsGroup extends HelperGroup { - async register(signer: TSigner, ownerAddress: TSubstrateAccount, location: any, metadata: IForeignAssetMetadata) { + async register(signer: TSigner, location: any, name: string, tokenPrefix: string, mode: 'NFT' | { Fungible: number }) { await this.helper.executeExtrinsic( signer, - 'api.tx.foreignAssets.registerForeignAsset', - [ownerAddress, location, metadata], + 'api.tx.foreignAssets.forceRegisterForeignAsset', + [location, this.helper.util.str2vec(name), tokenPrefix, mode], true, ); } - async update(signer: TSigner, foreignAssetId: number, location: any, metadata: IForeignAssetMetadata) { - await this.helper.executeExtrinsic( - signer, - 'api.tx.foreignAssets.updateForeignAsset', - [foreignAssetId, location, metadata], - true, - ); + async foreignCollectionId(location: any) { + return (await this.helper.callRpc('api.query.foreignAssets.foreignReserveLocationToCollection', [location])).toJSON(); } } @@ -256,6 +252,10 @@ export class AssetsGroup extends HelperGroup { await this.helper.executeExtrinsic(signer, 'api.tx.assets.mint', [assetId, beneficiary, amount], true); } + async assetInfo(assetId: number | bigint) { + return (await this.helper.callRpc('api.query.assets.asset', [assetId])).toJSON(); + } + async account(assetId: string | number | bigint, address: string) { const accountAsset = ( await this.helper.callRpc('api.query.assets.account', [assetId, address]) diff --git a/tests/src/xcm/xcm.types.ts b/tests/src/xcm/xcm.types.ts index ae596fd4c9..db0f390807 100644 --- a/tests/src/xcm/xcm.types.ts +++ b/tests/src/xcm/xcm.types.ts @@ -618,4 +618,26 @@ export class XcmTestHelper { expect(await helper.balance.getSubstrate(emptyAccount)).to.be.equal(0n); }); } + + async registerRelayNativeTokenOnUnique(alice: IKeyringPair) { + return await usingPlaygrounds(async (helper) => { + const relayLocation = { + parents: 1, + interior: 'Here', + }; + + const relayCollectionId = await helper.foreignAssets.foreignCollectionId(relayLocation); + if(relayCollectionId == null) { + const name = 'Relay Tokens'; + const tokenPrefix = 'xDOT'; + const decimals = 10; + await helper.getSudo().foreignAssets.register(alice, relayLocation, name, tokenPrefix, {Fungible: decimals}); + + return await helper.foreignAssets.foreignCollectionId(relayLocation); + } else { + console.log('Relay foreign collection is already registered'); + return relayCollectionId; + } + }); + } } diff --git a/tests/src/xcm/xcmOpal.test.ts b/tests/src/xcm/xcmOpal.test.ts index a411f3075b..8120842597 100644 --- a/tests/src/xcm/xcmOpal.test.ts +++ b/tests/src/xcm/xcmOpal.test.ts @@ -17,6 +17,7 @@ import {IKeyringPair} from '@polkadot/types/types'; import config from '../config'; import {itSub, expect, describeXCM, usingPlaygrounds, usingWestmintPlaygrounds, usingRelayPlaygrounds} from '../util'; +import {XcmTestHelper} from './xcm.types'; const STATEMINE_CHAIN = +(process.env.RELAY_WESTMINT_ID || 1000); const UNIQUE_CHAIN = +(process.env.RELAY_OPAL_ID || 2095); @@ -25,11 +26,11 @@ const relayUrl = config.relayUrl; const westmintUrl = config.westmintUrl; const STATEMINE_PALLET_INSTANCE = 50; -const ASSET_ID = 100; -const ASSET_METADATA_DECIMALS = 18; -const ASSET_METADATA_NAME = 'USDT'; -const ASSET_METADATA_DESCRIPTION = 'USDT'; -const ASSET_METADATA_MINIMAL_BALANCE = 1n; +const USDT_ASSET_ID = 100; +const USDT_ASSET_METADATA_DECIMALS = 18; +const USDT_ASSET_METADATA_NAME = 'USDT'; +const USDT_ASSET_METADATA_DESCRIPTION = 'USDT'; +const USDT_ASSET_METADATA_MINIMAL_BALANCE = 1n; const RELAY_DECIMALS = 12; const WESTMINT_DECIMALS = 12; @@ -37,7 +38,9 @@ const WESTMINT_DECIMALS = 12; const TRANSFER_AMOUNT = 1_000_000_000_000_000_000n; // 10,000.00 (ten thousands) USDT -const ASSET_AMOUNT = 1_000_000_000_000_000_000_000n; +const USDT_ASSET_AMOUNT = 1_000_000_000_000_000_000_000n; + +const testHelper = new XcmTestHelper('opal'); describeXCM('[XCM] Integration test: Exchanging USDT with Westmint', () => { let alice: IKeyringPair; @@ -57,57 +60,78 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Westmint', () => { let balanceBobRelayTokenBefore: bigint; let balanceBobRelayTokenAfter: bigint; + let usdtCollectionId: number; + let relayCollectionId: number; before(async () => { await usingPlaygrounds(async (_helper, privateKey) => { alice = await privateKey('//Alice'); bob = await privateKey('//Bob'); // funds donor + + relayCollectionId = await testHelper.registerRelayNativeTokenOnUnique(alice); }); await usingWestmintPlaygrounds(westmintUrl, async (helper) => { - // 350.00 (three hundred fifty) DOT - const fundingAmount = 3_500_000_000_000n; + const assetInfo = await helper.assets.assetInfo(USDT_ASSET_ID); + if(assetInfo == null) { + await helper.assets.create( + alice, + USDT_ASSET_ID, + alice.address, + USDT_ASSET_METADATA_MINIMAL_BALANCE, + ); + await helper.assets.setMetadata( + alice, + USDT_ASSET_ID, + USDT_ASSET_METADATA_NAME, + USDT_ASSET_METADATA_DESCRIPTION, + USDT_ASSET_METADATA_DECIMALS, + ); + } else { + console.log('The USDT asset is already registered on AssetHub'); + } + + await helper.assets.mint( + alice, + USDT_ASSET_ID, + alice.address, + USDT_ASSET_AMOUNT, + ); - await helper.assets.create(alice, ASSET_ID, alice.address, ASSET_METADATA_MINIMAL_BALANCE); - await helper.assets.setMetadata(alice, ASSET_ID, ASSET_METADATA_NAME, ASSET_METADATA_DESCRIPTION, ASSET_METADATA_DECIMALS); - await helper.assets.mint(alice, ASSET_ID, alice.address, ASSET_AMOUNT); + const sovereignFundingAmount = 3_500_000_000n; // funding parachain sovereing account (Parachain: 2095) const parachainSovereingAccount = helper.address.paraSiblingSovereignAccount(UNIQUE_CHAIN); - await helper.balance.transferToSubstrate(bob, parachainSovereingAccount, fundingAmount); + await helper.balance.transferToSubstrate(bob, parachainSovereingAccount, sovereignFundingAmount); }); - await usingPlaygrounds(async (helper) => { const location = { - V2: { - parents: 1, - interior: {X3: [ - { - Parachain: STATEMINE_CHAIN, - }, - { - PalletInstance: STATEMINE_PALLET_INSTANCE, - }, - { - GeneralIndex: ASSET_ID, - }, - ]}, - }, + parents: 1, + interior: {X3: [ + { + Parachain: STATEMINE_CHAIN, + }, + { + PalletInstance: STATEMINE_PALLET_INSTANCE, + }, + { + GeneralIndex: USDT_ASSET_ID, + }, + ]}, }; - const metadata = - { - name: ASSET_ID, - symbol: ASSET_METADATA_NAME, - decimals: ASSET_METADATA_DECIMALS, - minimalBalance: ASSET_METADATA_MINIMAL_BALANCE, - }; - await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata); + if(await helper.foreignAssets.foreignCollectionId(location) == null) { + const tokenPrefix = USDT_ASSET_METADATA_NAME; + await helper.getSudo().foreignAssets.register(alice, location, USDT_ASSET_METADATA_NAME, tokenPrefix, {Fungible: USDT_ASSET_METADATA_DECIMALS}); + } else { + console.log('Foreign collection is already registered on Opal'); + } + balanceOpalBefore = await helper.balance.getSubstrate(alice.address); + usdtCollectionId = await helper.foreignAssets.foreignCollectionId(location); }); - // Providing the relay currency to the unique sender account await usingRelayPlaygrounds(relayUrl, async (helper) => { const destination = { @@ -189,7 +213,7 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Westmint', () => { PalletInstance: STATEMINE_PALLET_INSTANCE, }, { - GeneralIndex: ASSET_ID, + GeneralIndex: USDT_ASSET_ID, }, ]}, }, @@ -217,18 +241,16 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Westmint', () => { }); - // ensure that asset has been delivered await helper.wait.newBlocks(3); - // expext collection id will be with id 1 - const free = await helper.ft.getBalance(1, {Substrate: alice.address}); + const free = await helper.ft.getBalance(usdtCollectionId, {Substrate: alice.address}); balanceOpalAfter = await helper.balance.getSubstrate(alice.address); console.log( '[Westmint -> Opal] transaction fees on Opal: %s USDT', - helper.util.bigIntToDecimals(TRANSFER_AMOUNT - free, ASSET_METADATA_DECIMALS), + helper.util.bigIntToDecimals(TRANSFER_AMOUNT - free, USDT_ASSET_METADATA_DECIMALS), ); console.log( '[Westmint -> Opal] transaction fees on Opal: %s OPL', @@ -261,16 +283,11 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Westmint', () => { const currencies: [any, bigint][] = [ [ - { - ForeignAssetId: 0, - }, - //10_000_000_000_000_000n, + usdtCollectionId, TRANSFER_AMOUNT, ], [ - { - NativeAssetId: 'Parent', - }, + relayCollectionId, 400_000_000_000_000n, ], ]; @@ -288,7 +305,7 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Westmint', () => { // The USDT token never paid fees. Its amount not changed from begin value. // Also check that xcm transfer has been succeeded - expect((await helper.assets.account(ASSET_ID, alice.address))! == ASSET_AMOUNT).to.be.true; + expect((await helper.assets.account(USDT_ASSET_ID, alice.address))! == USDT_ASSET_AMOUNT).to.be.true; }); }); @@ -296,7 +313,7 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Westmint', () => { const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n; balanceBobBefore = await helper.balance.getSubstrate(bob.address); - balanceBobRelayTokenBefore = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'}); + balanceBobRelayTokenBefore = await helper.ft.getBalance(relayCollectionId, {Substrate: bob.address}); // Providing the relay currency to the unique sender account await usingRelayPlaygrounds(relayUrl, async (helper) => { @@ -345,7 +362,7 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Westmint', () => { await helper.wait.newBlocks(3); balanceBobAfter = await helper.balance.getSubstrate(bob.address); - balanceBobRelayTokenAfter = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'}); + balanceBobRelayTokenAfter = await helper.ft.getBalance(relayCollectionId, {Substrate: bob.address}); const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore; console.log( @@ -383,9 +400,7 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Westmint', () => { const currencies: any = [ [ - { - NativeAssetId: 'Parent', - }, + relayCollectionId, 50_000_000_000_000_000n, ], ]; diff --git a/tests/src/xcm/xcmQuartz.test.ts b/tests/src/xcm/xcmQuartz.test.ts index 49b9f84bb2..3e3fe14366 100644 --- a/tests/src/xcm/xcmQuartz.test.ts +++ b/tests/src/xcm/xcmQuartz.test.ts @@ -19,8 +19,7 @@ import {itSub, expect, describeXCM, usingPlaygrounds, usingKaruraPlaygrounds, us import {DevUniqueHelper, Event} from '../util/playgrounds/unique.dev'; import {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'; import {hexToString} from '@polkadot/util'; - - +import {XcmTestHelper} from './xcm.types'; const STATEMINE_PALLET_INSTANCE = 50; @@ -39,6 +38,8 @@ const USDT_ASSET_AMOUNT = 10_000_000_000_000_000_000_000_000n; const SAFE_XCM_VERSION = 2; +const testHelper = new XcmTestHelper('quartz'); + describeXCM('[XCM] Integration test: Exchanging USDT with Statemine', () => { let alice: IKeyringPair; let bob: IKeyringPair; @@ -57,6 +58,8 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemine', () => { let balanceBobRelayTokenBefore: bigint; let balanceBobRelayTokenAfter: bigint; + let usdtCollectionId: number; + let relayCollectionId: number; before(async () => { await usingPlaygrounds(async (helper, privateKey) => { @@ -65,6 +68,8 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemine', () => { // Set the default version to wrap the first message to other chains. await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION); + + relayCollectionId = await testHelper.registerRelayNativeTokenOnUnique(alice); }); await usingRelayPlaygrounds(relayUrl, async (helper) => { @@ -74,21 +79,25 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemine', () => { }); await usingStateminePlaygrounds(statemineUrl, async (helper) => { - const sovereignFundingAmount = 3_500_000_000n; + const assetInfo = await helper.assets.assetInfo(USDT_ASSET_ID); + if(assetInfo == null) { + await helper.assets.create( + alice, + USDT_ASSET_ID, + alice.address, + USDT_ASSET_METADATA_MINIMAL_BALANCE, + ); + await helper.assets.setMetadata( + alice, + USDT_ASSET_ID, + USDT_ASSET_METADATA_NAME, + USDT_ASSET_METADATA_DESCRIPTION, + USDT_ASSET_METADATA_DECIMALS, + ); + } else { + console.log('The USDT asset is already registered on AssetHub'); + } - await helper.assets.create( - alice, - USDT_ASSET_ID, - alice.address, - USDT_ASSET_METADATA_MINIMAL_BALANCE, - ); - await helper.assets.setMetadata( - alice, - USDT_ASSET_ID, - USDT_ASSET_METADATA_NAME, - USDT_ASSET_METADATA_DESCRIPTION, - USDT_ASSET_METADATA_DECIMALS, - ); await helper.assets.mint( alice, USDT_ASSET_ID, @@ -96,6 +105,8 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemine', () => { USDT_ASSET_AMOUNT, ); + const sovereignFundingAmount = 3_500_000_000n; + // funding parachain sovereing account on Statemine(t). // The sovereign account should be created before any action // (the assets pallet on Statemine(t) check if the sovereign account exists) @@ -106,31 +117,29 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemine', () => { await usingPlaygrounds(async (helper) => { const location = { - V2: { - parents: 1, - interior: {X3: [ - { - Parachain: STATEMINE_CHAIN, - }, - { - PalletInstance: STATEMINE_PALLET_INSTANCE, - }, - { - GeneralIndex: USDT_ASSET_ID, - }, - ]}, - }, + parents: 1, + interior: {X3: [ + { + Parachain: STATEMINE_CHAIN, + }, + { + PalletInstance: STATEMINE_PALLET_INSTANCE, + }, + { + GeneralIndex: USDT_ASSET_ID, + }, + ]}, }; - const metadata = - { - name: USDT_ASSET_ID, - symbol: USDT_ASSET_METADATA_NAME, - decimals: USDT_ASSET_METADATA_DECIMALS, - minimalBalance: USDT_ASSET_METADATA_MINIMAL_BALANCE, - }; - await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata); + if(await helper.foreignAssets.foreignCollectionId(location) == null) { + const tokenPrefix = USDT_ASSET_METADATA_NAME; + await helper.getSudo().foreignAssets.register(alice, location, USDT_ASSET_METADATA_NAME, tokenPrefix, {Fungible: USDT_ASSET_METADATA_DECIMALS}); + } else { + console.log('Foreign collection is already registered on Quartz'); + } + balanceQuartzBefore = await helper.balance.getSubstrate(alice.address); + usdtCollectionId = await helper.foreignAssets.foreignCollectionId(location); }); @@ -248,8 +257,7 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemine', () => { // ensure that asset has been delivered await helper.wait.newBlocks(3); - // expext collection id will be with id 1 - const free = await helper.ft.getBalance(1, {Substrate: alice.address}); + const free = await helper.ft.getBalance(usdtCollectionId, {Substrate: alice.address}); balanceQuartzAfter = await helper.balance.getSubstrate(alice.address); @@ -288,15 +296,11 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemine', () => { const relayFee = 400_000_000_000_000n; const currencies: [any, bigint][] = [ [ - { - ForeignAssetId: 0, - }, + usdtCollectionId, TRANSFER_AMOUNT, ], [ - { - NativeAssetId: 'Parent', - }, + relayCollectionId, relayFee, ], ]; @@ -321,7 +325,7 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemine', () => { itSub('Should connect and send Relay token to Quartz', async ({helper}) => { balanceBobBefore = await helper.balance.getSubstrate(bob.address); - balanceBobRelayTokenBefore = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'}); + balanceBobRelayTokenBefore = await helper.ft.getBalance(relayCollectionId, {Substrate: bob.address}); await usingRelayPlaygrounds(relayUrl, async (helper) => { const destination = { @@ -369,7 +373,7 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemine', () => { await helper.wait.newBlocks(3); balanceBobAfter = await helper.balance.getSubstrate(bob.address); - balanceBobRelayTokenAfter = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'}); + balanceBobRelayTokenAfter = await helper.ft.getBalance(relayCollectionId, {Substrate: bob.address}); const wndFeeOnQuartz = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore; const wndDiffOnQuartz = balanceBobRelayTokenAfter - balanceBobRelayTokenBefore; @@ -409,9 +413,7 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemine', () => { const currencies: any = [ [ - { - NativeAssetId: 'Parent', - }, + relayCollectionId, TRANSFER_AMOUNT_RELAY, ], ]; diff --git a/tests/src/xcm/xcmUnique.test.ts b/tests/src/xcm/xcmUnique.test.ts index 76f7693bb8..2f738c3dcc 100644 --- a/tests/src/xcm/xcmUnique.test.ts +++ b/tests/src/xcm/xcmUnique.test.ts @@ -20,7 +20,7 @@ import {itSub, expect, describeXCM, usingPlaygrounds, usingAcalaPlaygrounds, usi import {Event} from '../util/playgrounds/unique.dev'; import {hexToString, nToBigInt} from '@polkadot/util'; import {ACALA_CHAIN, ASTAR_CHAIN, MOONBEAM_CHAIN, POLKADEX_CHAIN, SAFE_XCM_VERSION, STATEMINT_CHAIN, UNIQUE_CHAIN, expectFailedToTransact, expectUntrustedReserveLocationFail, uniqueAssetId, uniqueVersionedMultilocation} from './xcm.types'; - +import {XcmTestHelper} from './xcm.types'; const STATEMINT_PALLET_INSTANCE = 50; @@ -50,6 +50,8 @@ const USDT_ASSET_METADATA_DESCRIPTION = 'USDT'; const USDT_ASSET_METADATA_MINIMAL_BALANCE = 1n; const USDT_ASSET_AMOUNT = 10_000_000_000_000_000_000_000_000n; +const testHelper = new XcmTestHelper('unique'); + describeXCM('[XCM] Integration test: Exchanging USDT with Statemint', () => { let alice: IKeyringPair; let bob: IKeyringPair; @@ -68,6 +70,8 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemint', () => { let balanceBobRelayTokenBefore: bigint; let balanceBobRelayTokenAfter: bigint; + let usdtCollectionId: number; + let relayCollectionId: number; before(async () => { await usingPlaygrounds(async (helper, privateKey) => { @@ -76,6 +80,8 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemint', () => { // Set the default version to wrap the first message to other chains. await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION); + + relayCollectionId = await testHelper.registerRelayNativeTokenOnUnique(alice); }); await usingRelayPlaygrounds(relayUrl, async (helper) => { @@ -85,21 +91,25 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemint', () => { }); await usingStatemintPlaygrounds(statemintUrl, async (helper) => { - const sovereignFundingAmount = 3_500_000_000n; + const assetInfo = await helper.assets.assetInfo(USDT_ASSET_ID); + if(assetInfo == null) { + await helper.assets.create( + alice, + USDT_ASSET_ID, + alice.address, + USDT_ASSET_METADATA_MINIMAL_BALANCE, + ); + await helper.assets.setMetadata( + alice, + USDT_ASSET_ID, + USDT_ASSET_METADATA_NAME, + USDT_ASSET_METADATA_DESCRIPTION, + USDT_ASSET_METADATA_DECIMALS, + ); + } else { + console.log('The USDT asset is already registered on AssetHub'); + } - await helper.assets.create( - alice, - USDT_ASSET_ID, - alice.address, - USDT_ASSET_METADATA_MINIMAL_BALANCE, - ); - await helper.assets.setMetadata( - alice, - USDT_ASSET_ID, - USDT_ASSET_METADATA_NAME, - USDT_ASSET_METADATA_DESCRIPTION, - USDT_ASSET_METADATA_DECIMALS, - ); await helper.assets.mint( alice, USDT_ASSET_ID, @@ -107,6 +117,8 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemint', () => { USDT_ASSET_AMOUNT, ); + const sovereignFundingAmount = 3_500_000_000n; + // funding parachain sovereing account on Statemint. // The sovereign account should be created before any action // (the assets pallet on Statemint check if the sovereign account exists) @@ -117,31 +129,29 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemint', () => { await usingPlaygrounds(async (helper) => { const location = { - V2: { - parents: 1, - interior: {X3: [ - { - Parachain: STATEMINT_CHAIN, - }, - { - PalletInstance: STATEMINT_PALLET_INSTANCE, - }, - { - GeneralIndex: USDT_ASSET_ID, - }, - ]}, - }, + parents: 1, + interior: {X3: [ + { + Parachain: STATEMINT_CHAIN, + }, + { + PalletInstance: STATEMINT_PALLET_INSTANCE, + }, + { + GeneralIndex: USDT_ASSET_ID, + }, + ]}, }; - const metadata = - { - name: USDT_ASSET_ID, - symbol: USDT_ASSET_METADATA_NAME, - decimals: USDT_ASSET_METADATA_DECIMALS, - minimalBalance: USDT_ASSET_METADATA_MINIMAL_BALANCE, - }; - await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata); + if(await helper.foreignAssets.foreignCollectionId(location) == null) { + const tokenPrefix = USDT_ASSET_METADATA_NAME; + await helper.getSudo().foreignAssets.register(alice, location, USDT_ASSET_METADATA_NAME, tokenPrefix, {Fungible: USDT_ASSET_METADATA_DECIMALS}); + } else { + console.log('Foreign collection is already registered on Unique'); + } + balanceUniqueBefore = await helper.balance.getSubstrate(alice.address); + usdtCollectionId = await helper.foreignAssets.foreignCollectionId(location); }); @@ -259,8 +269,7 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemint', () => { // ensure that asset has been delivered await helper.wait.newBlocks(3); - // expext collection id will be with id 1 - const free = await helper.ft.getBalance(1, {Substrate: alice.address}); + const free = await helper.ft.getBalance(usdtCollectionId, {Substrate: alice.address}); balanceUniqueAfter = await helper.balance.getSubstrate(alice.address); @@ -299,15 +308,11 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemint', () => { const relayFee = 400_000_000_000_000n; const currencies: [any, bigint][] = [ [ - { - ForeignAssetId: 0, - }, + usdtCollectionId, TRANSFER_AMOUNT, ], [ - { - NativeAssetId: 'Parent', - }, + relayCollectionId, relayFee, ], ]; @@ -332,7 +337,7 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemint', () => { itSub('Should connect and send Relay token to Unique', async ({helper}) => { balanceBobBefore = await helper.balance.getSubstrate(bob.address); - balanceBobRelayTokenBefore = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'}); + balanceBobRelayTokenBefore = await helper.ft.getBalance(relayCollectionId, {Substrate: bob.address}); await usingRelayPlaygrounds(relayUrl, async (helper) => { const destination = { @@ -380,7 +385,7 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemint', () => { await helper.wait.newBlocks(3); balanceBobAfter = await helper.balance.getSubstrate(bob.address); - balanceBobRelayTokenAfter = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'}); + balanceBobRelayTokenAfter = await helper.ft.getBalance(relayCollectionId, {Substrate: bob.address}); const wndFeeOnUnique = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore; const wndDiffOnUnique = balanceBobRelayTokenAfter - balanceBobRelayTokenBefore; @@ -420,9 +425,7 @@ describeXCM('[XCM] Integration test: Exchanging USDT with Statemint', () => { const currencies: any = [ [ - { - NativeAssetId: 'Parent', - }, + relayCollectionId, TRANSFER_AMOUNT_RELAY, ], ];