git.delta.rocks / unique-network / refs/commits / 48c1587fa96f

difftreelog

test fix pallet-tokens field name change

Yaroslav Bolyukin2022-09-16parent: #6ca971a.patch.diff
in: master

4 files changed

modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -63,14 +63,14 @@
 export async function isQuartz(): Promise<boolean> {
   return usingApi(async api => {
     const chain = await api.rpc.system.chain();
-    
+
     return chain.eq('QUARTZ');
   });
 }
 
 let modulesNames: any;
 export function getModuleNames(api: ApiPromise): string[] {
-  if (typeof modulesNames === 'undefined') 
+  if (typeof modulesNames === 'undefined')
     modulesNames = api.runtimeMetadata.asLatest.pallets.map(m => m.name.toString().toLowerCase());
   return modulesNames;
 }
@@ -304,7 +304,7 @@
 
 export function getCreateItemsResult(events: EventRecord[]): CreateItemResult[] {
   const results: CreateItemResult[] = [];
-  
+
   const genericResult = getGenericResult<CreateItemResult[]>(events, 'common', 'ItemCreated', (data) => {
     const collectionId = parseInt(data[0].toString(), 10);
     const itemId = parseInt(data[1].toString(), 10);
@@ -329,15 +329,15 @@
 
 export function getCreateItemResult(events: EventRecord[]): CreateItemResult {
   const genericResult = getGenericResult(events, 'common', 'ItemCreated', (data) => data.map(function(value) { return value.toJSON(); }));
-  
-  if (genericResult.data == null) 
+
+  if (genericResult.data == null)
     return {
       success: genericResult.success,
       collectionId: 0,
       itemId: 0,
       amount: 0,
     };
-  else 
+  else
     return {
       success: genericResult.success,
       collectionId: genericResult.data[0] as number,
@@ -349,7 +349,7 @@
 
 export function getDestroyItemsResult(events: EventRecord[]): DestroyItemResult[] {
   const results: DestroyItemResult[] = [];
-  
+
   const genericResult = getGenericResult<DestroyItemResult[]>(events, 'common', 'ItemDestroyed', (data) => {
     const collectionId = parseInt(data[0].toString(), 10);
     const itemId = parseInt(data[1].toString(), 10);
@@ -1151,9 +1151,9 @@
     expect(blockNumber).to.be.greaterThan(0);
     const scheduleTx = api.tx.scheduler.scheduleNamed( // schedule
       scheduledId,
-      expectedBlockNumber, 
-      repetitions > 1 ? [period, repetitions] : null, 
-      0, 
+      expectedBlockNumber,
+      repetitions > 1 ? [period, repetitions] : null,
+      0,
       {Value: operationTx as any},
     );
 
@@ -1178,13 +1178,13 @@
     expect(blockNumber).to.be.greaterThan(0);
     const scheduleTx = api.tx.scheduler.scheduleNamed( // schedule
       scheduledId,
-      expectedBlockNumber, 
-      repetitions <= 1 ? null : [period, repetitions], 
-      0, 
+      expectedBlockNumber,
+      repetitions <= 1 ? null : [period, repetitions],
+      0,
       {Value: operationTx as any},
     );
 
-    //const events = 
+    //const events =
     await expect(submitTransactionExpectFailAsync(sender, scheduleTx)).to.be.rejected;
     //expect(getGenericResult(events).success).to.be.false;
   });
@@ -1248,7 +1248,7 @@
     const transferTx = api.tx.balances.transfer(recipient.address, amount);
 
     const balanceBefore = await getFreeBalance(recipient);
-    
+
     await scheduleExpectSuccess(transferTx, sender, blockSchedule, scheduledId, period, repetitions);
 
     expect(await getFreeBalance(recipient)).to.be.equal(balanceBefore);
modifiedtests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth
--- a/tests/src/xcm/xcmQuartz.test.ts
+++ b/tests/src/xcm/xcmQuartz.test.ts
@@ -64,7 +64,7 @@
 describe_xcm('[XCM] Integration test: Exchanging tokens with Karura', () => {
   let alice: IKeyringPair;
   let randomAccount: IKeyringPair;
-  
+
   let balanceQuartzTokenInit: bigint;
   let balanceQuartzTokenMiddle: bigint;
   let balanceQuartzTokenFinal: bigint;
@@ -74,7 +74,7 @@
   let balanceQuartzForeignTokenInit: bigint;
   let balanceQuartzForeignTokenMiddle: bigint;
   let balanceQuartzForeignTokenFinal: bigint;
-  
+
   before(async () => {
     await usingApi(async (api, privateKeyWrapper) => {
       const keyringSr25519 = new Keyring({type: 'sr25519'});
@@ -96,50 +96,50 @@
             ],
           },
         };
-  
+
         const metadata = {
           name: 'QTZ',
           symbol: 'QTZ',
           decimals: 18,
           minimalBalance: 1,
         };
-  
+
         const tx = api.tx.assetRegistry.registerForeignAsset(destination, metadata);
         const sudoTx = api.tx.sudo.sudo(tx as any);
         const events = await submitTransactionAsync(alice, sudoTx);
         const result = getGenericResult(events);
         expect(result.success).to.be.true;
-  
+
         const tx1 = api.tx.balances.transfer(randomAccount.address, 10000000000000n);
         const events1 = await submitTransactionAsync(alice, tx1);
         const result1 = getGenericResult(events1);
         expect(result1.success).to.be.true;
-  
+
         [balanceKaruraTokenInit] = await getBalance(api, [randomAccount.address]);
         {
-          const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
+          const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAssetId: 0})).toJSON() as any;
           balanceQuartzForeignTokenInit = BigInt(free);
         }
       },
       karuraOptions(),
     );
-  
+
     // Quartz side
     await usingApi(async (api) => {
       const tx0 = api.tx.balances.transfer(randomAccount.address, 10n * TRANSFER_AMOUNT);
       const events0 = await submitTransactionAsync(alice, tx0);
       const result0 = getGenericResult(events0);
       expect(result0.success).to.be.true;
-  
+
       [balanceQuartzTokenInit] = await getBalance(api, [randomAccount.address]);
     });
   });
-  
+
   it('Should connect and send QTZ to Karura', async () => {
-  
+
     // Quartz side
     await usingApi(async (api) => {
-  
+
       const destination = {
         V0: {
           X2: [
@@ -150,7 +150,7 @@
           ],
         },
       };
-  
+
       const beneficiary = {
         V0: {
           X1: {
@@ -161,7 +161,7 @@
           },
         },
       };
-  
+
       const assets = {
         V1: [
           {
@@ -177,32 +177,32 @@
           },
         ],
       };
-  
+
       const feeAssetItem = 0;
-  
+
       const weightLimit = {
         Limited: 5000000000,
       };
-  
+
       const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
       const events = await submitTransactionAsync(randomAccount, tx);
       const result = getGenericResult(events);
       expect(result.success).to.be.true;
-  
+
       [balanceQuartzTokenMiddle] = await getBalance(api, [randomAccount.address]);
-  
+
       const qtzFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;
       console.log('[Quartz -> Karura] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));
       expect(qtzFees > 0n).to.be.true;
     });
-  
+
     // Karura side
     await usingApi(
       async (api) => {
         await waitNewBlocks(api, 3);
-        const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
+        const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAssetId: 0})).toJSON() as any;
         balanceQuartzForeignTokenMiddle = BigInt(free);
-  
+
         [balanceKaruraTokenMiddle] = await getBalance(api, [randomAccount.address]);
 
         const karFees = balanceKaruraTokenInit - balanceKaruraTokenMiddle;
@@ -219,9 +219,9 @@
       karuraOptions(),
     );
   });
-  
+
   it('Should connect to Karura and send QTZ back', async () => {
-  
+
     // Karura side
     await usingApi(
       async (api) => {
@@ -241,24 +241,24 @@
             },
           },
         };
-  
+
         const id = {
-          ForeignAsset: 0,
+          ForeignAssetId: 0,
         };
 
         const destWeight = 50000000;
-  
+
         const tx = api.tx.xTokens.transfer(id as any, TRANSFER_AMOUNT, destination, destWeight);
         const events = await submitTransactionAsync(randomAccount, tx);
         const result = getGenericResult(events);
         expect(result.success).to.be.true;
-  
+
         [balanceKaruraTokenFinal] = await getBalance(api, [randomAccount.address]);
         {
-          const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
+          const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAssetId: 0})).toJSON() as any;
           balanceQuartzForeignTokenFinal = BigInt(free);
         }
-  
+
         const karFees = balanceKaruraTokenMiddle - balanceKaruraTokenFinal;
         const qtzOutcomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenFinal;
 
@@ -277,13 +277,13 @@
     // Quartz side
     await usingApi(async (api) => {
       await waitNewBlocks(api, 3);
-  
+
       [balanceQuartzTokenFinal] = await getBalance(api, [randomAccount.address]);
       const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;
       expect(actuallyDelivered > 0).to.be.true;
 
       console.log('[Karura -> Quartz] actually delivered %s QTZ', bigIntToDecimals(actuallyDelivered));
-  
+
       const qtzFees = TRANSFER_AMOUNT - actuallyDelivered;
       console.log('[Karura -> Quartz] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));
       expect(qtzFees == 0n).to.be.true;
@@ -300,7 +300,7 @@
       alice = privateKeyWrapper('//Alice');
     });
   });
-  
+
   it('Quartz rejects tokens from the Relay', async () => {
     await usingApi(async (api) => {
       const destination = {
modifiedtests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth
--- a/tests/src/xcm/xcmUnique.test.ts
+++ b/tests/src/xcm/xcmUnique.test.ts
@@ -64,7 +64,7 @@
 describe_xcm('[XCM] Integration test: Exchanging tokens with Acala', () => {
   let alice: IKeyringPair;
   let randomAccount: IKeyringPair;
-  
+
   let balanceUniqueTokenInit: bigint;
   let balanceUniqueTokenMiddle: bigint;
   let balanceUniqueTokenFinal: bigint;
@@ -74,7 +74,7 @@
   let balanceUniqueForeignTokenInit: bigint;
   let balanceUniqueForeignTokenMiddle: bigint;
   let balanceUniqueForeignTokenFinal: bigint;
-  
+
   before(async () => {
     await usingApi(async (api, privateKeyWrapper) => {
       const keyringSr25519 = new Keyring({type: 'sr25519'});
@@ -96,50 +96,50 @@
             ],
           },
         };
-  
+
         const metadata = {
           name: 'UNQ',
           symbol: 'UNQ',
           decimals: 18,
           minimalBalance: 1,
         };
-  
+
         const tx = api.tx.assetRegistry.registerForeignAsset(destination, metadata);
         const sudoTx = api.tx.sudo.sudo(tx as any);
         const events = await submitTransactionAsync(alice, sudoTx);
         const result = getGenericResult(events);
         expect(result.success).to.be.true;
-  
+
         const tx1 = api.tx.balances.transfer(randomAccount.address, 10000000000000n);
         const events1 = await submitTransactionAsync(alice, tx1);
         const result1 = getGenericResult(events1);
         expect(result1.success).to.be.true;
-  
+
         [balanceAcalaTokenInit] = await getBalance(api, [randomAccount.address]);
         {
-          const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
+          const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAssetId: 0})).toJSON() as any;
           balanceUniqueForeignTokenInit = BigInt(free);
         }
       },
       acalaOptions(),
     );
-  
+
     // Unique side
     await usingApi(async (api) => {
       const tx0 = api.tx.balances.transfer(randomAccount.address, 10n * TRANSFER_AMOUNT);
       const events0 = await submitTransactionAsync(alice, tx0);
       const result0 = getGenericResult(events0);
       expect(result0.success).to.be.true;
-  
+
       [balanceUniqueTokenInit] = await getBalance(api, [randomAccount.address]);
     });
   });
-  
+
   it('Should connect and send UNQ to Acala', async () => {
-  
+
     // Unique side
     await usingApi(async (api) => {
-  
+
       const destination = {
         V0: {
           X2: [
@@ -150,7 +150,7 @@
           ],
         },
       };
-  
+
       const beneficiary = {
         V0: {
           X1: {
@@ -161,7 +161,7 @@
           },
         },
       };
-  
+
       const assets = {
         V1: [
           {
@@ -177,32 +177,32 @@
           },
         ],
       };
-  
+
       const feeAssetItem = 0;
-  
+
       const weightLimit = {
         Limited: 5000000000,
       };
-  
+
       const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
       const events = await submitTransactionAsync(randomAccount, tx);
       const result = getGenericResult(events);
       expect(result.success).to.be.true;
-  
+
       [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccount.address]);
-  
+
       const unqFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;
       console.log('[Unique -> Acala] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));
       expect(unqFees > 0n).to.be.true;
     });
-  
+
     // Acala side
     await usingApi(
       async (api) => {
         await waitNewBlocks(api, 3);
-        const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
+        const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAssetId: 0})).toJSON() as any;
         balanceUniqueForeignTokenMiddle = BigInt(free);
-  
+
         [balanceAcalaTokenMiddle] = await getBalance(api, [randomAccount.address]);
 
         const acaFees = balanceAcalaTokenInit - balanceAcalaTokenMiddle;
@@ -219,9 +219,9 @@
       acalaOptions(),
     );
   });
-  
+
   it('Should connect to Acala and send UNQ back', async () => {
-  
+
     // Acala side
     await usingApi(
       async (api) => {
@@ -241,24 +241,24 @@
             },
           },
         };
-  
+
         const id = {
-          ForeignAsset: 0,
+          ForeignAssetId: 0,
         };
 
         const destWeight = 50000000;
-  
+
         const tx = api.tx.xTokens.transfer(id as any, TRANSFER_AMOUNT, destination, destWeight);
         const events = await submitTransactionAsync(randomAccount, tx);
         const result = getGenericResult(events);
         expect(result.success).to.be.true;
-  
+
         [balanceAcalaTokenFinal] = await getBalance(api, [randomAccount.address]);
         {
-          const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
+          const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAssetId: 0})).toJSON() as any;
           balanceUniqueForeignTokenFinal = BigInt(free);
         }
-  
+
         const acaFees = balanceAcalaTokenMiddle - balanceAcalaTokenFinal;
         const unqOutcomeTransfer = balanceUniqueForeignTokenMiddle - balanceUniqueForeignTokenFinal;
 
@@ -277,13 +277,13 @@
     // Unique side
     await usingApi(async (api) => {
       await waitNewBlocks(api, 3);
-  
+
       [balanceUniqueTokenFinal] = await getBalance(api, [randomAccount.address]);
       const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenMiddle;
       expect(actuallyDelivered > 0).to.be.true;
 
       console.log('[Acala -> Unique] actually delivered %s UNQ', bigIntToDecimals(actuallyDelivered));
-  
+
       const unqFees = TRANSFER_AMOUNT - actuallyDelivered;
       console.log('[Acala -> Unique] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));
       expect(unqFees == 0n).to.be.true;
@@ -300,7 +300,7 @@
       alice = privateKeyWrapper('//Alice');
     });
   });
-  
+
   it('Unique rejects tokens from the Relay', async () => {
     await usingApi(async (api) => {
       const destination = {
modifiedtests/src/xcmTransfer.test.tsdiffbeforeafterboth
before · tests/src/xcmTransfer.test.ts
1// 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 chai from 'chai';18import chaiAsPromised from 'chai-as-promised';1920import {WsProvider} from '@polkadot/api';21import {ApiOptions} from '@polkadot/api/types';22import {IKeyringPair} from '@polkadot/types/types';23import usingApi, {submitTransactionAsync} from './substrate/substrate-api';24import {getGenericResult} from './util/helpers';25import waitNewBlocks from './substrate/wait-new-blocks';26import getBalance from './substrate/get-balance';2728chai.use(chaiAsPromised);29const expect = chai.expect;3031const UNIQUE_CHAIN = 1000;32const KARURA_CHAIN = 2000;33const KARURA_PORT = '9946';34const TRANSFER_AMOUNT = 2000000000000000000000000n;3536// todo:playgrounds refit when XCM drops37describe.skip('Integration test: Exchanging QTZ with Karura', () => {38  let alice: IKeyringPair;3940  before(async () => {41    await usingApi(async (api, privateKeyWrapper) => {42      alice = privateKeyWrapper('//Alice');43    });4445    const karuraApiOptions: ApiOptions = {46      provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT),47    };4849    await usingApi(async (api) => {50      const destination = {51        V0: {52          X2: [53            'Parent',54            {55              Parachain: UNIQUE_CHAIN,56            },57          ],58        },59      };6061      const metadata =62      {63        name: 'QTZ',64        symbol: 'QTZ',65        decimals: 18,66        minimalBalance: 1,67      };6869      const tx = api.tx.assetRegistry.registerForeignAsset(destination, metadata);70      const sudoTx = api.tx.sudo.sudo(tx as any);71      const events = await submitTransactionAsync(alice, sudoTx);72      const result = getGenericResult(events);73      expect(result.success).to.be.true;74    }, karuraApiOptions);75  });7677  it('Should connect and send QTZ to Karura', async () => {78    let balanceOnKaruraBefore: bigint;7980    await usingApi(async (api) => {81      const {free} = (await api.query.tokens.accounts(alice.addressRaw, {ForeignAsset: 0})).toJSON() as any;82      balanceOnKaruraBefore = free;83    }, {provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT)});8485    await usingApi(async (api) => {86      const destination = {87        V0: {88          X2: [89            'Parent',90            {91              Parachain: KARURA_CHAIN,92            },93          ],94        },95      };9697      const beneficiary = {98        V0: {99          X1: {100            AccountId32: {101              network: 'Any',102              id: alice.addressRaw,103            },104          },105        },106      };107108      const assets = {109        V1: [110          {111            id: {112              Concrete: {113                parents: 0,114                interior: 'Here',115              },116            },117            fun: {118              Fungible: TRANSFER_AMOUNT,119            },120          },121        ],122      };123124      const feeAssetItem = 0;125126      const weightLimit = {127        Limited: 5000000000,128      };129130      const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);131      const events = await submitTransactionAsync(alice, tx);132      const result = getGenericResult(events);133      expect(result.success).to.be.true;134    });135136    await usingApi(async (api) => {137      // todo do something about instant sealing, where there might not be any new blocks138      await waitNewBlocks(api, 3);139      const {free} = (await api.query.tokens.accounts(alice.addressRaw, {ForeignAsset: 0})).toJSON() as any;140      expect(free > balanceOnKaruraBefore).to.be.true;141    }, {provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT)});142  });143144  it('Should connect to Karura and send QTZ back', async () => {145    let balanceBefore: bigint;146147    await usingApi(async (api) => {148      [balanceBefore] = await getBalance(api, [alice.address]);149    });150151    await usingApi(async (api) => {152      const destination = {153        V1: {154          parents: 1,155          interior: {156            X2: [157              {Parachain: UNIQUE_CHAIN},158              {AccountId32: {159                network: 'Any',160                id: alice.addressRaw,161              }},162            ],163          },164        },165      };166167      const id = {168        ForeignAsset: 0,169      };170171      const amount = TRANSFER_AMOUNT;172      const destWeight = 50000000;173174      const tx = api.tx.xTokens.transfer(id, amount, destination, destWeight);175      const events = await submitTransactionAsync(alice, tx);176      const result = getGenericResult(events);177      expect(result.success).to.be.true;178    }, {provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT)});179180    await usingApi(async (api) => {181      // todo do something about instant sealing, where there might not be any new blocks182      await waitNewBlocks(api, 3);183      const [balanceAfter] = await getBalance(api, [alice.address]);184      expect(balanceAfter > balanceBefore).to.be.true;185    });186  });187});
after · tests/src/xcmTransfer.test.ts
1// 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 chai from 'chai';18import chaiAsPromised from 'chai-as-promised';1920import {WsProvider} from '@polkadot/api';21import {ApiOptions} from '@polkadot/api/types';22import {IKeyringPair} from '@polkadot/types/types';23import usingApi, {submitTransactionAsync} from './substrate/substrate-api';24import {getGenericResult} from './util/helpers';25import waitNewBlocks from './substrate/wait-new-blocks';26import getBalance from './substrate/get-balance';2728chai.use(chaiAsPromised);29const expect = chai.expect;3031const UNIQUE_CHAIN = 1000;32const KARURA_CHAIN = 2000;33const KARURA_PORT = '9946';34const TRANSFER_AMOUNT = 2000000000000000000000000n;3536// todo:playgrounds refit when XCM drops37describe.skip('Integration test: Exchanging QTZ with Karura', () => {38  let alice: IKeyringPair;3940  before(async () => {41    await usingApi(async (api, privateKeyWrapper) => {42      alice = privateKeyWrapper('//Alice');43    });4445    const karuraApiOptions: ApiOptions = {46      provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT),47    };4849    await usingApi(async (api) => {50      const destination = {51        V0: {52          X2: [53            'Parent',54            {55              Parachain: UNIQUE_CHAIN,56            },57          ],58        },59      };6061      const metadata =62      {63        name: 'QTZ',64        symbol: 'QTZ',65        decimals: 18,66        minimalBalance: 1,67      };6869      const tx = api.tx.assetRegistry.registerForeignAsset(destination, metadata);70      const sudoTx = api.tx.sudo.sudo(tx as any);71      const events = await submitTransactionAsync(alice, sudoTx);72      const result = getGenericResult(events);73      expect(result.success).to.be.true;74    }, karuraApiOptions);75  });7677  it('Should connect and send QTZ to Karura', async () => {78    let balanceOnKaruraBefore: bigint;7980    await usingApi(async (api) => {81      const {free} = (await api.query.tokens.accounts(alice.addressRaw, {ForeignAssetId: 0})).toJSON() as any;82      balanceOnKaruraBefore = free;83    }, {provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT)});8485    await usingApi(async (api) => {86      const destination = {87        V0: {88          X2: [89            'Parent',90            {91              Parachain: KARURA_CHAIN,92            },93          ],94        },95      };9697      const beneficiary = {98        V0: {99          X1: {100            AccountId32: {101              network: 'Any',102              id: alice.addressRaw,103            },104          },105        },106      };107108      const assets = {109        V1: [110          {111            id: {112              Concrete: {113                parents: 0,114                interior: 'Here',115              },116            },117            fun: {118              Fungible: TRANSFER_AMOUNT,119            },120          },121        ],122      };123124      const feeAssetItem = 0;125126      const weightLimit = {127        Limited: 5000000000,128      };129130      const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);131      const events = await submitTransactionAsync(alice, tx);132      const result = getGenericResult(events);133      expect(result.success).to.be.true;134    });135136    await usingApi(async (api) => {137      // todo do something about instant sealing, where there might not be any new blocks138      await waitNewBlocks(api, 3);139      const {free} = (await api.query.tokens.accounts(alice.addressRaw, {ForeignAssetId: 0})).toJSON() as any;140      expect(free > balanceOnKaruraBefore).to.be.true;141    }, {provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT)});142  });143144  it('Should connect to Karura and send QTZ back', async () => {145    let balanceBefore: bigint;146147    await usingApi(async (api) => {148      [balanceBefore] = await getBalance(api, [alice.address]);149    });150151    await usingApi(async (api) => {152      const destination = {153        V1: {154          parents: 1,155          interior: {156            X2: [157              {Parachain: UNIQUE_CHAIN},158              {AccountId32: {159                network: 'Any',160                id: alice.addressRaw,161              }},162            ],163          },164        },165      };166167      const id = {168        ForeignAssetId: 0,169      };170171      const amount = TRANSFER_AMOUNT;172      const destWeight = 50000000;173174      const tx = api.tx.xTokens.transfer(id, amount, destination, destWeight);175      const events = await submitTransactionAsync(alice, tx);176      const result = getGenericResult(events);177      expect(result.success).to.be.true;178    }, {provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT)});179180    await usingApi(async (api) => {181      // todo do something about instant sealing, where there might not be any new blocks182      await waitNewBlocks(api, 3);183      const [balanceAfter] = await getBalance(api, [alice.address]);184      expect(balanceAfter > balanceBefore).to.be.true;185    });186  });187});