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.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.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,
],
];