difftreelog
fix XCM tests
in: master
6 files changed
js-packages/playgrounds/types.xcm.tsdiffbeforeafterboth--- a/js-packages/playgrounds/types.xcm.ts
+++ b/js-packages/playgrounds/types.xcm.ts
@@ -27,10 +27,3 @@
conviction: number,
},
}
-
-export interface IForeignAssetMetadata {
- name?: number | Uint8Array,
- symbol?: string,
- decimals?: number,
- minimalBalance?: bigint,
-}
\ No newline at end of file
js-packages/playgrounds/unique.xcm.tsdiffbeforeafterboth--- a/js-packages/playgrounds/unique.xcm.ts
+++ b/js-packages/playgrounds/unique.xcm.ts
@@ -2,7 +2,7 @@
import type {IKeyringPair} from '@polkadot/types/types';
import {ChainHelperBase, EthereumBalanceGroup, HelperGroup, SubstrateBalanceGroup, UniqueHelper} from './unique.js';
import type {ILogger, TSigner, TSubstrateAccount} from './types.js';
-import type {AcalaAssetMetadata, DemocracyStandardAccountVote, IForeignAssetMetadata, MoonbeamAssetInfo} from './types.xcm.js';
+import type {AcalaAssetMetadata, DemocracyStandardAccountVote, MoonbeamAssetInfo} from './types.xcm.js';
export class XcmChainHelper extends ChainHelperBase {
@@ -104,22 +104,17 @@
}
export class ForeignAssetsGroup extends HelperGroup<UniqueHelper> {
- 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 +251,10 @@
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])
js-packages/tests/xcm/xcm.types.tsdiffbeforeafterboth--- a/js-packages/tests/xcm/xcm.types.ts
+++ b/js-packages/tests/xcm/xcm.types.ts
@@ -505,4 +505,26 @@
await expectFailedToTransact(helper, messageSent);
});
}
+
+ 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;
+ }
+ });
+ }
}
js-packages/tests/xcm/xcmOpal.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import type {IKeyringPair} from '@polkadot/types/types';18import config from '../config.js';19import {itSub, expect, describeXCM, usingPlaygrounds, usingWestmintPlaygrounds, usingRelayPlaygrounds} from '../util/index.js';2021const STATEMINE_CHAIN = +(process.env.RELAY_WESTMINT_ID || 1000);22const UNIQUE_CHAIN = +(process.env.RELAY_OPAL_ID || 2095);2324const relayUrl = config.relayUrl;25const westmintUrl = config.westmintUrl;2627const STATEMINE_PALLET_INSTANCE = 50;28const ASSET_ID = 100;29const ASSET_METADATA_DECIMALS = 18;30const ASSET_METADATA_NAME = 'USDT';31const ASSET_METADATA_DESCRIPTION = 'USDT';32const ASSET_METADATA_MINIMAL_BALANCE = 1n;3334const RELAY_DECIMALS = 12;35const WESTMINT_DECIMALS = 12;3637const TRANSFER_AMOUNT = 1_000_000_000_000_000_000n;3839// 10,000.00 (ten thousands) USDT40const ASSET_AMOUNT = 1_000_000_000_000_000_000_000n;4142describeXCM('[XCM] Integration test: Exchanging USDT with Westmint', () => {43 let alice: IKeyringPair;44 let bob: IKeyringPair;4546 let balanceStmnBefore: bigint;47 let balanceStmnAfter: bigint;4849 let balanceOpalBefore: bigint;50 let balanceOpalAfter: bigint;51 let balanceOpalFinal: bigint;5253 let balanceBobBefore: bigint;54 let balanceBobAfter: bigint;55 let balanceBobFinal: bigint;5657 let balanceBobRelayTokenBefore: bigint;58 let balanceBobRelayTokenAfter: bigint;596061 before(async () => {62 await usingPlaygrounds(async (_helper, privateKey) => {63 alice = await privateKey('//Alice');64 bob = await privateKey('//Bob'); // funds donor65 });6667 await usingWestmintPlaygrounds(westmintUrl, async (helper) => {68 // 350.00 (three hundred fifty) DOT69 const fundingAmount = 3_500_000_000_000n;7071 await helper.assets.create(alice, ASSET_ID, alice.address, ASSET_METADATA_MINIMAL_BALANCE);72 await helper.assets.setMetadata(alice, ASSET_ID, ASSET_METADATA_NAME, ASSET_METADATA_DESCRIPTION, ASSET_METADATA_DECIMALS);73 await helper.assets.mint(alice, ASSET_ID, alice.address, ASSET_AMOUNT);7475 // funding parachain sovereing account (Parachain: 2095)76 const parachainSovereingAccount = helper.address.paraSiblingSovereignAccount(UNIQUE_CHAIN);77 await helper.balance.transferToSubstrate(bob, parachainSovereingAccount, fundingAmount);78 });798081 await usingPlaygrounds(async (helper) => {82 const location = {83 V2: {84 parents: 1,85 interior: {X3: [86 {87 Parachain: STATEMINE_CHAIN,88 },89 {90 PalletInstance: STATEMINE_PALLET_INSTANCE,91 },92 {93 GeneralIndex: ASSET_ID,94 },95 ]},96 },97 };9899 const metadata =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);107 balanceOpalBefore = await helper.balance.getSubstrate(alice.address);108 });109110111 // Providing the relay currency to the unique sender account112 await usingRelayPlaygrounds(relayUrl, async (helper) => {113 const destination = {114 V2: {115 parents: 0,116 interior: {X1: {117 Parachain: UNIQUE_CHAIN,118 },119 },120 }};121122 const beneficiary = {123 V2: {124 parents: 0,125 interior: {X1: {126 AccountId32: {127 network: 'Any',128 id: alice.addressRaw,129 },130 }},131 },132 };133134 const assets = {135 V2: [136 {137 id: {138 Concrete: {139 parents: 0,140 interior: 'Here',141 },142 },143 fun: {144 Fungible: 50_000_000_000_000_000n,145 },146 },147 ],148 };149150 const feeAssetItem = 0;151152 await helper.xcm.limitedReserveTransferAssets(alice, destination, beneficiary, assets, feeAssetItem, 'Unlimited');153 });154155 });156157 itSub('Should connect and send USDT from Westmint to Opal', async ({helper}) => {158 await usingWestmintPlaygrounds(westmintUrl, async (helper) => {159 const dest = {160 V2: {161 parents: 1,162 interior: {X1: {163 Parachain: UNIQUE_CHAIN,164 },165 },166 }};167168 const beneficiary = {169 V2: {170 parents: 0,171 interior: {X1: {172 AccountId32: {173 network: 'Any',174 id: alice.addressRaw,175 },176 }},177 },178 };179180 const assets = {181 V2: [182 {183 id: {184 Concrete: {185 parents: 0,186 interior: {187 X2: [188 {189 PalletInstance: STATEMINE_PALLET_INSTANCE,190 },191 {192 GeneralIndex: ASSET_ID,193 },194 ]},195 },196 },197 fun: {198 Fungible: TRANSFER_AMOUNT,199 },200 },201 ],202 };203204 const feeAssetItem = 0;205206 balanceStmnBefore = await helper.balance.getSubstrate(alice.address);207 await helper.xcm.limitedReserveTransferAssets(alice, dest, beneficiary, assets, feeAssetItem, 'Unlimited');208209 balanceStmnAfter = await helper.balance.getSubstrate(alice.address);210211 // common good parachain take commission in it native token212 console.log(213 '[Westmint -> Opal] transaction fees on Westmint: %s WND',214 helper.util.bigIntToDecimals(balanceStmnBefore - balanceStmnAfter, WESTMINT_DECIMALS),215 );216 expect(balanceStmnBefore > balanceStmnAfter).to.be.true;217218 });219220221 // ensure that asset has been delivered222 await helper.wait.newBlocks(3);223224 // expext collection id will be with id 1225 const free = await helper.ft.getBalance(1, {Substrate: alice.address});226227 balanceOpalAfter = await helper.balance.getSubstrate(alice.address);228229 console.log(230 '[Westmint -> Opal] transaction fees on Opal: %s USDT',231 helper.util.bigIntToDecimals(TRANSFER_AMOUNT - free, ASSET_METADATA_DECIMALS),232 );233 console.log(234 '[Westmint -> Opal] transaction fees on Opal: %s OPL',235 helper.util.bigIntToDecimals(balanceOpalAfter - balanceOpalBefore),236 );237238 // commission has not paid in USDT token239 expect(free == TRANSFER_AMOUNT).to.be.true;240 // ... and parachain native token241 expect(balanceOpalAfter == balanceOpalBefore).to.be.true;242 });243244 itSub('Should connect and send USDT from Unique to Statemine back', async ({helper}) => {245 const destination = {246 V2: {247 parents: 1,248 interior: {X2: [249 {250 Parachain: STATEMINE_CHAIN,251 },252 {253 AccountId32: {254 network: 'Any',255 id: alice.addressRaw,256 },257 },258 ]},259 },260 };261262 const currencies: [any, bigint][] = [263 [264 {265 ForeignAssetId: 0,266 },267 //10_000_000_000_000_000n,268 TRANSFER_AMOUNT,269 ],270 [271 {272 NativeAssetId: 'Parent',273 },274 400_000_000_000_000n,275 ],276 ];277278 const feeItem = 1;279280 await helper.xTokens.transferMulticurrencies(alice, currencies, feeItem, destination, 'Unlimited');281282 // the commission has been paid in parachain native token283 balanceOpalFinal = await helper.balance.getSubstrate(alice.address);284 expect(balanceOpalAfter > balanceOpalFinal).to.be.true;285286 await usingWestmintPlaygrounds(westmintUrl, async (helper) => {287 await helper.wait.newBlocks(3);288289 // The USDT token never paid fees. Its amount not changed from begin value.290 // Also check that xcm transfer has been succeeded291 expect((await helper.assets.account(ASSET_ID, alice.address))! == ASSET_AMOUNT).to.be.true;292 });293 });294295 itSub('Should connect and send Relay token to Unique', async ({helper}) => {296 const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;297298 balanceBobBefore = await helper.balance.getSubstrate(bob.address);299 balanceBobRelayTokenBefore = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});300301 // Providing the relay currency to the unique sender account302 await usingRelayPlaygrounds(relayUrl, async (helper) => {303 const destination = {304 V2: {305 parents: 0,306 interior: {X1: {307 Parachain: UNIQUE_CHAIN,308 },309 },310 }};311312 const beneficiary = {313 V2: {314 parents: 0,315 interior: {X1: {316 AccountId32: {317 network: 'Any',318 id: bob.addressRaw,319 },320 }},321 },322 };323324 const assets = {325 V2: [326 {327 id: {328 Concrete: {329 parents: 0,330 interior: 'Here',331 },332 },333 fun: {334 Fungible: TRANSFER_AMOUNT_RELAY,335 },336 },337 ],338 };339340 const feeAssetItem = 0;341342 await helper.xcm.limitedReserveTransferAssets(bob, destination, beneficiary, assets, feeAssetItem, 'Unlimited');343 });344345 await helper.wait.newBlocks(3);346347 balanceBobAfter = await helper.balance.getSubstrate(bob.address);348 balanceBobRelayTokenAfter = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});349350 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore;351 console.log(352 'Relay (Westend) to Opal transaction fees: %s OPL',353 helper.util.bigIntToDecimals(balanceBobAfter - balanceBobBefore),354 );355 console.log(356 'Relay (Westend) to Opal transaction fees: %s WND',357 helper.util.bigIntToDecimals(wndFee, WESTMINT_DECIMALS),358 );359 expect(balanceBobBefore == balanceBobAfter).to.be.true;360 expect(balanceBobRelayTokenBefore < balanceBobRelayTokenAfter).to.be.true;361 });362363 itSub('Should connect and send Relay token back', async ({helper}) => {364 let relayTokenBalanceBefore: bigint;365 let relayTokenBalanceAfter: bigint;366 await usingRelayPlaygrounds(relayUrl, async (helper) => {367 relayTokenBalanceBefore = await helper.balance.getSubstrate(bob.address);368 });369370 const destination = {371 V2: {372 parents: 1,373 interior: {374 X1:{375 AccountId32: {376 network: 'Any',377 id: bob.addressRaw,378 },379 },380 },381 },382 };383384 const currencies: any = [385 [386 {387 NativeAssetId: 'Parent',388 },389 50_000_000_000_000_000n,390 ],391 ];392393 const feeItem = 0;394395 await helper.xTokens.transferMulticurrencies(bob, currencies, feeItem, destination, 'Unlimited');396397 balanceBobFinal = await helper.balance.getSubstrate(bob.address);398 console.log('[Opal -> Relay (Westend)] transaction fees: %s OPL', helper.util.bigIntToDecimals(balanceBobAfter - balanceBobFinal));399400 await usingRelayPlaygrounds(relayUrl, async (helper) => {401 await helper.wait.newBlocks(10);402 relayTokenBalanceAfter = await helper.balance.getSubstrate(bob.address);403404 const diff = relayTokenBalanceAfter - relayTokenBalanceBefore;405 console.log('[Opal -> Relay (Westend)] actually delivered: %s WND', helper.util.bigIntToDecimals(diff, RELAY_DECIMALS));406 expect(diff > 0, 'Relay tokens was not delivered back').to.be.true;407 });408 });409});js-packages/tests/xcm/xcmQuartz.test.tsdiffbeforeafterboth--- a/js-packages/tests/xcm/xcmQuartz.test.ts
+++ b/js-packages/tests/xcm/xcmQuartz.test.ts
@@ -19,9 +19,8 @@
import {DevUniqueHelper, Event} from '@unique/playgrounds/unique.dev.js';
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.js';
import {hexToString} from '@polkadot/util';
-
+import {XcmTestHelper} from './xcm.types';
-
const STATEMINE_PALLET_INSTANCE = 50;
const TRANSFER_AMOUNT = 2000000000000000000000000n;
@@ -39,6 +38,8 @@
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 @@
let balanceBobRelayTokenBefore: bigint;
let balanceBobRelayTokenAfter: bigint;
+ let usdtCollectionId: number;
+ let relayCollectionId: number;
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
@@ -65,6 +68,8 @@
// 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 @@
});
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 @@
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 @@
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 @@
// 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 @@
const relayFee = 400_000_000_000_000n;
const currencies: [any, bigint][] = [
[
- {
- ForeignAssetId: 0,
- },
+ usdtCollectionId,
TRANSFER_AMOUNT,
],
[
- {
- NativeAssetId: 'Parent',
- },
+ relayCollectionId,
relayFee,
],
];
@@ -321,7 +325,7 @@
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 @@
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 @@
const currencies: any = [
[
- {
- NativeAssetId: 'Parent',
- },
+ relayCollectionId,
TRANSFER_AMOUNT_RELAY,
],
];
js-packages/tests/xcm/xcmUnique.test.tsdiffbeforeafterboth--- a/js-packages/tests/xcm/xcmUnique.test.ts
+++ b/js-packages/tests/xcm/xcmUnique.test.ts
@@ -20,7 +20,7 @@
import {Event} from '@unique/playgrounds/unique.dev.js';
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.js';
-
+import {XcmTestHelper} from './xcm.types';
const STATEMINT_PALLET_INSTANCE = 50;
@@ -50,6 +50,8 @@
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 @@
let balanceBobRelayTokenBefore: bigint;
let balanceBobRelayTokenAfter: bigint;
+ let usdtCollectionId: number;
+ let relayCollectionId: number;
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
@@ -76,6 +80,8 @@
// 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 @@
});
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 @@
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 @@
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 @@
// 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 @@
const relayFee = 400_000_000_000_000n;
const currencies: [any, bigint][] = [
[
- {
- ForeignAssetId: 0,
- },
+ usdtCollectionId,
TRANSFER_AMOUNT,
],
[
- {
- NativeAssetId: 'Parent',
- },
+ relayCollectionId,
relayFee,
],
];
@@ -332,7 +337,7 @@
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 @@
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 @@
const currencies: any = [
[
- {
- NativeAssetId: 'Parent',
- },
+ relayCollectionId,
TRANSFER_AMOUNT_RELAY,
],
];