git.delta.rocks / unique-network / refs/commits / 5ea65b7821a4

difftreelog

refactor draft move xcm tests to playgrounds

Daniel Shiposha2022-10-06parent: #f2ade55.patch.diff
in: master

3 files changed

modifiedtests/src/xcm/xcmOpal.test.tsdiffbeforeafterboth
--- a/tests/src/xcm/xcmOpal.test.ts
+++ b/tests/src/xcm/xcmOpal.test.ts
@@ -14,33 +14,27 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-
-import {WsProvider} from '@polkadot/api';
-import {ApiOptions} from '@polkadot/api/types';
 import {IKeyringPair} from '@polkadot/types/types';
-import usingApi, {executeTransaction} from './../substrate/substrate-api';
-import {bigIntToDecimals, describe_xcm, getGenericResult, paraSiblingSovereignAccount, normalizeAccountId} from './../deprecated-helpers/helpers';
-import waitNewBlocks from './../substrate/wait-new-blocks';
+import {executeTransaction} from './../substrate/substrate-api';
+import {bigIntToDecimals, getGenericResult, paraSiblingSovereignAccount} from './../deprecated-helpers/helpers';
 import getBalance from './../substrate/get-balance';
-
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
+import {itSub, expect, describeXcm, usingPlaygrounds} from '../util/playgrounds';
 
 const STATEMINE_CHAIN = 1000;
 const UNIQUE_CHAIN = 2095;
 
 const RELAY_PORT = '9844';
-const UNIQUE_PORT = '9944';
 const STATEMINE_PORT = '9948';
+
+const relayUrl = 'ws://127.0.0.1:' + RELAY_PORT;
+const statemineUrl = 'ws://127.0.0.1:' + STATEMINE_PORT;
+
 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 = 1;
+const ASSET_METADATA_MINIMAL_BALANCE = 1n;
 
 const WESTMINT_DECIMALS = 12;
 
@@ -49,7 +43,7 @@
 // 10,000.00 (ten thousands) USDT
 const ASSET_AMOUNT = 1_000_000_000_000_000_000_000n; 
 
-describe_xcm('[XCM] Integration test: Exchanging USDT with Westmint', () => {
+describeXcm('[XCM] Integration test: Exchanging USDT with Westmint', () => {
   let alice: IKeyringPair;
   let bob: IKeyringPair;
   
@@ -69,24 +63,13 @@
 
 
   before(async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
-      alice = privateKeyWrapper('//Alice');
-      bob = privateKeyWrapper('//Bob'); // funds donor
+    await usingPlaygrounds(async (_helper, privateKey) => {
+      alice = privateKey('//Alice');
+      bob = privateKey('//Bob'); // funds donor
     });
-
-    const statemineApiOptions: ApiOptions = {
-      provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),
-    };
 
-    const uniqueApiOptions: ApiOptions = {
-      provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),
-    };
-
-    const relayApiOptions: ApiOptions = {
-      provider: new WsProvider('ws://127.0.0.1:' + RELAY_PORT),
-    };
-
-    await usingApi(async (api) => {
+    await usingPlaygrounds.atUrl(statemineUrl, async (helper) => {
+      const api = helper.getApi();
 
       // 350.00 (three hundred fifty) DOT
       const fundingAmount = 3_500_000_000_000; 
@@ -115,11 +98,10 @@
       const result4 = getGenericResult(events4);
       expect(result4.success).to.be.true;
 
-    }, statemineApiOptions);
+    });
 
 
-    await usingApi(async (api) => {
-
+    await usingPlaygrounds(async (helper) => {
       const location = {
         V1: {
           parents: 1,
@@ -144,20 +126,23 @@
         decimals: ASSET_METADATA_DECIMALS,
         minimalBalance: ASSET_METADATA_MINIMAL_BALANCE,
       };
-      //registerForeignAsset(owner, location, metadata)
-      const tx = api.tx.foreignAssets.registerForeignAsset(alice.addressRaw, location, metadata);
-      const sudoTx = api.tx.sudo.sudo(tx as any);
-      const events = await executeTransaction(api, alice, sudoTx);
-      const result = getGenericResult(events);
-      expect(result.success).to.be.true;
+      await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata);
+      // const tx = api.tx.foreignAssets.registerForeignAsset(alice.addressRaw, location, metadata);
+      // const sudoTx = api.tx.sudo.sudo(tx as any);
+      // const events = await executeTransaction(api, alice, sudoTx);
+      // const result = getGenericResult(events);
+      // expect(result.success).to.be.true;
 
-      [balanceOpalBefore] = await getBalance(api, [alice.address]);
+      // [balanceOpalBefore] = await getBalance(api, [alice.address]);
+      balanceOpalBefore = await helper.balance.getSubstrate(alice.address);
 
-    }, uniqueApiOptions);
+    });
 
 
     // Providing the relay currency to the unique sender account
-    await usingApi(async (api) => {
+    await usingPlaygrounds.atUrl(relayUrl, async (helper) => {
+      const api = helper.getApi();
+
       const destination = {
         V1: {
           parents: 0,
@@ -205,22 +190,14 @@
       const events = await executeTransaction(api, alice, tx);
       const result = getGenericResult(events);
       expect(result.success).to.be.true;
-    }, relayApiOptions);
+    });
   
   });
 
-  it('Should connect and send USDT from Westmint to Opal', async () => {
-    
-    const statemineApiOptions: ApiOptions = {
-      provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),
-    };
-
-    const uniqueApiOptions: ApiOptions = {
-      provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),
-    };
+  itSub('Should connect and send USDT from Westmint to Opal', async ({helper}) => {
+    await usingPlaygrounds.atUrl(statemineUrl, async (helper) => {
+      const api = helper.getApi();
 
-    await usingApi(async (api) => {
-
       const dest = {
         V1: {
           parents: 1,
@@ -288,125 +265,109 @@
       );
       expect(balanceStmnBefore > balanceStmnAfter).to.be.true;
 
-    }, statemineApiOptions);
+    });
 
 
     // ensure that asset has been delivered
-    await usingApi(async (api) => {
-      await waitNewBlocks(api, 3);
-      // expext collection id will be with id 1
-      const free = (await api.query.fungible.balance(1, normalizeAccountId(alice.address))).toBigInt();
+    // await waitNewBlocks(api, 3);
+    await helper.wait.newBlocks(3);
 
-      [balanceOpalAfter] = await getBalance(api, [alice.address]);
+    // expext collection id will be with id 1
+    // const free = (await api.query.fungible.balance(1, normalizeAccountId(alice.address))).toBigInt();
+    const free = await helper.ft.getBalance(1, {Substrate: alice.address});
 
-      // commission has not paid in USDT token
-      expect(free == TRANSFER_AMOUNT).to.be.true;
-      console.log(
-        'Opal to Westmint transaction fees on Opal: %s USDT',
-        bigIntToDecimals(TRANSFER_AMOUNT - free),
-      );
-      // ... and parachain native token
-      expect(balanceOpalAfter == balanceOpalBefore).to.be.true;
-      console.log(
-        'Opal to Westmint transaction fees on Opal: %s WND',
-        bigIntToDecimals(balanceOpalAfter - balanceOpalBefore, WESTMINT_DECIMALS),
-      );
+    // [balanceOpalAfter] = await getBalance(api, [alice.address]);
+    balanceOpalAfter = await helper.balance.getSubstrate(alice.address);
 
-    }, uniqueApiOptions);
-    
+    // commission has not paid in USDT token
+    expect(free == TRANSFER_AMOUNT).to.be.true;
+    console.log(
+      'Opal to Westmint transaction fees on Opal: %s USDT',
+      bigIntToDecimals(TRANSFER_AMOUNT - free),
+    );
+    // ... and parachain native token
+    expect(balanceOpalAfter == balanceOpalBefore).to.be.true;
+    console.log(
+      'Opal to Westmint transaction fees on Opal: %s WND',
+      bigIntToDecimals(balanceOpalAfter - balanceOpalBefore, WESTMINT_DECIMALS),
+    );    
   });
 
-  it('Should connect and send USDT from Unique to Statemine back', async () => {
+  itSub('Should connect and send USDT from Unique to Statemine back', async ({helper}) => {
+    const api = helper.getApi();
 
-    const uniqueApiOptions: ApiOptions = {
-      provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),
-    };
-
-    const statemineApiOptions: ApiOptions = {
-      provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),
+    const destination = {
+      V1: {
+        parents: 1,
+        interior: {X2: [
+          {
+            Parachain: STATEMINE_CHAIN,
+          },
+          {
+            AccountId32: {
+              network: 'Any',
+              id: alice.addressRaw,
+            },
+          },
+        ]},
+      },
     };
 
-    await usingApi(async (api) => {
-      const destination = {
-        V1: {
-          parents: 1,
-          interior: {X2: [
-            {
-              Parachain: STATEMINE_CHAIN,
-            },
-            {
-              AccountId32: {
-                network: 'Any',
-                id: alice.addressRaw,
-              },
-            },
-          ]},
+    const currencies: [any, bigint][] = [
+      [
+        {
+          ForeignAssetId: 0,
+        },
+        //10_000_000_000_000_000n,
+        TRANSFER_AMOUNT,
+      ], 
+      [
+        {
+          NativeAssetId: 'Parent',
         },
-      };
+        400_000_000_000_000n,
+      ],
+    ];
 
-      const currencies: [any, bigint][] = [
-        [
-          {
-            ForeignAssetId: 0,
-          },
-          //10_000_000_000_000_000n,
-          TRANSFER_AMOUNT,
-        ], 
-        [
-          {
-            NativeAssetId: 'Parent',
-          },
-          400_000_000_000_000n,
-        ],
-      ];
+    const feeItem = 1;
+    const destWeight = 500000000000;
 
-      const feeItem = 1;
-      const destWeight = 500000000000;
+    const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);
+    const events = await executeTransaction(api, alice, tx);
+    const result = getGenericResult(events);
+    expect(result.success).to.be.true;
+    
+    // the commission has been paid in parachain native token
+    [balanceOpalFinal] = await getBalance(api, [alice.address]);
+    expect(balanceOpalAfter > balanceOpalFinal).to.be.true;
 
-      const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);
-      const events = await executeTransaction(api, alice, tx);
-      const result = getGenericResult(events);
-      expect(result.success).to.be.true;
-      
-      // the commission has been paid in parachain native token
-      [balanceOpalFinal] = await getBalance(api, [alice.address]);
-      expect(balanceOpalAfter > balanceOpalFinal).to.be.true;
-    }, uniqueApiOptions);
+    await usingPlaygrounds.atUrl(statemineUrl, async (helper) => {
+      // await waitNewBlocks(api, 3);
+      await helper.wait.newBlocks(3);
 
-    await usingApi(async (api) => {
-      await waitNewBlocks(api, 3);
+      const api = helper.getApi();
       
       // The USDT token never paid fees. Its amount not changed from begin value.
       // Also check that xcm transfer has been succeeded 
       const free = ((await api.query.assets.account(100, alice.address)).toHuman()) as any;
       expect(BigInt(free.balance.replace(/,/g, '')) == ASSET_AMOUNT).to.be.true;
-    }, statemineApiOptions);
+    });
   });
-
-  it('Should connect and send Relay token to Unique', async () => {
 
-    const uniqueApiOptions: ApiOptions = {
-      provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),
-    };
-
-    const uniqueApiOptions2: ApiOptions = {
-      provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),
-    };
-
-    const relayApiOptions: ApiOptions = {
-      provider: new WsProvider('ws://127.0.0.1:' + RELAY_PORT),
-    };
-
+  itSub('Should connect and send Relay token to Unique', async ({helper}) => {
     const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;
 
-    await usingApi(async (api) => {
-      [balanceBobBefore] = await getBalance(api, [bob.address]);
-      balanceBobRelayTokenBefore = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);
+    // [balanceBobBefore] = await getBalance(api, [bob.address]);
+    // balanceBobRelayTokenBefore = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);
+    balanceBobBefore = await helper.balance.getSubstrate(bob.address);
 
-    }, uniqueApiOptions);
+    // TODO
+    balanceBobRelayTokenBefore = BigInt(((await helper.getApi().query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);
 
     // Providing the relay currency to the unique sender account
-    await usingApi(async (api) => {
+    await usingPlaygrounds.atUrl(relayUrl, async (helper) => {
+      const api = helper.getApi();
+
       const destination = {
         V1: {
           parents: 0,
@@ -454,73 +415,72 @@
       const events = await executeTransaction(api, bob, tx);
       const result = getGenericResult(events);
       expect(result.success).to.be.true;
-    }, relayApiOptions);
+    });
   
 
-    await usingApi(async (api) => {
-      await waitNewBlocks(api, 3);
+    // await waitNewBlocks(api, 3);
+    await helper.wait.newBlocks(3);
 
-      [balanceBobAfter] = await getBalance(api, [bob.address]);
-      balanceBobRelayTokenAfter = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);
-      const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore; 
-      console.log(
-        'Relay (Westend) to Opal transaction fees: %s OPL',
-        bigIntToDecimals(balanceBobAfter - balanceBobBefore),
-      );
-      console.log(
-        'Relay (Westend) to Opal transaction fees: %s WND',
-        bigIntToDecimals(wndFee, WESTMINT_DECIMALS),
-      );
-      expect(balanceBobBefore == balanceBobAfter).to.be.true;
-      expect(balanceBobRelayTokenBefore < balanceBobRelayTokenAfter).to.be.true;
-    }, uniqueApiOptions2);
+    // [balanceBobAfter] = await getBalance(api, [bob.address]);
+    // balanceBobRelayTokenAfter = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);
+    balanceBobAfter = await helper.balance.getSubstrate(bob.address);
+    
+    // TODO
+    balanceBobRelayTokenAfter = BigInt(((await helper.getApi().query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);
 
+    const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore; 
+    console.log(
+      'Relay (Westend) to Opal transaction fees: %s OPL',
+      bigIntToDecimals(balanceBobAfter - balanceBobBefore),
+    );
+    console.log(
+      'Relay (Westend) to Opal transaction fees: %s WND',
+      bigIntToDecimals(wndFee, WESTMINT_DECIMALS),
+    );
+    expect(balanceBobBefore == balanceBobAfter).to.be.true;
+    expect(balanceBobRelayTokenBefore < balanceBobRelayTokenAfter).to.be.true;
   });
 
-  it('Should connect and send Relay token back', async () => {
-    const uniqueApiOptions: ApiOptions = {
-      provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),
+  itSub('Should connect and send Relay token back', async ({helper}) => {
+    const destination = {
+      V1: {
+        parents: 1,
+        interior: {X2: [
+          {
+            Parachain: STATEMINE_CHAIN,
+          },
+          {
+            AccountId32: {
+              network: 'Any',
+              id: bob.addressRaw,
+            },
+          },
+        ]},
+      },
     };
 
-    await usingApi(async (api) => {
-      const destination = {
-        V1: {
-          parents: 1,
-          interior: {X2: [
-            {
-              Parachain: STATEMINE_CHAIN,
-            },
-            {
-              AccountId32: {
-                network: 'Any',
-                id: bob.addressRaw,
-              },
-            },
-          ]},
+    const currencies: any = [
+      [
+        {
+          NativeAssetId: 'Parent',
         },
-      };
-
-      const currencies: any = [
-        [
-          {
-            NativeAssetId: 'Parent',
-          },
-          50_000_000_000_000_000n,
-        ],
-      ];
-
-      const feeItem = 0;
-      const destWeight = 500000000000;
+        50_000_000_000_000_000n,
+      ],
+    ];
 
-      const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);
-      const events = await executeTransaction(api, bob, tx);
-      const result = getGenericResult(events);
-      expect(result.success).to.be.true;
+    const feeItem = 0;
+    const destWeight = 500000000000;
 
-      [balanceBobFinal] = await getBalance(api, [bob.address]);
-      console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobFinal);
+    // TODO
+    const api = helper.getApi();
+    const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);
+    const events = await executeTransaction(api, bob, tx);
+    const result = getGenericResult(events);
+    expect(result.success).to.be.true;
 
-    }, uniqueApiOptions);
+    // [balanceBobFinal] = await getBalance(api, [bob.address]);
+    balanceBobFinal = await helper.balance.getSubstrate(bob.address);
+    console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobFinal);
   });
 
 });
modifiedtests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth
--- a/tests/src/xcm/xcmQuartz.test.ts
+++ b/tests/src/xcm/xcmQuartz.test.ts
@@ -14,23 +14,16 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-
-import {WsProvider, Keyring} from '@polkadot/api';
-import {ApiOptions} from '@polkadot/api/types';
+import {Keyring} from '@polkadot/api';
 import {IKeyringPair} from '@polkadot/types/types';
-import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
-import {getGenericResult, generateKeyringPair, waitEvent, describe_xcm, bigIntToDecimals} from '../deprecated-helpers/helpers';
+import {submitTransactionAsync} from '../substrate/substrate-api';
+import {getGenericResult, generateKeyringPair, waitEvent, bigIntToDecimals} from '../deprecated-helpers/helpers';
 import {MultiLocation} from '@polkadot/types/interfaces';
 import {blake2AsHex} from '@polkadot/util-crypto';
-import waitNewBlocks from '../substrate/wait-new-blocks';
 import getBalance from '../substrate/get-balance';
 import {XcmV2TraitsOutcome, XcmV2TraitsError} from '../interfaces';
+import {itSub, expect, describeXcm, usingPlaygrounds} from '../util/playgrounds';
 
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-
 const QUARTZ_CHAIN = 2095;
 const KARURA_CHAIN = 2000;
 const MOONRIVER_CHAIN = 2023;
@@ -39,29 +32,15 @@
 const KARURA_PORT = 9946;
 const MOONRIVER_PORT = 9947;
 
+const relayUrl = 'ws://127.0.0.1:' + RELAY_PORT;
+const karuraUrl = 'ws://127.0.0.1:' + KARURA_PORT;
+const moonriverUrl = 'ws://127.0.0.1:' + MOONRIVER_PORT;
+
 const KARURA_DECIMALS = 12;
 
 const TRANSFER_AMOUNT = 2000000000000000000000000n;
 
-function parachainApiOptions(port: number): ApiOptions {
-  return {
-    provider: new WsProvider('ws://127.0.0.1:' + port.toString()),
-  };
-}
-
-function karuraOptions(): ApiOptions {
-  return parachainApiOptions(KARURA_PORT);
-}
-
-function moonriverOptions(): ApiOptions {
-  return parachainApiOptions(MOONRIVER_PORT);
-}
-
-function relayOptions(): ApiOptions {
-  return parachainApiOptions(RELAY_PORT);
-}
-
-describe_xcm('[XCM] Integration test: Exchanging tokens with Karura', () => {
+describeXcm('[XCM] Integration test: Exchanging tokens with Karura', () => {
   let alice: IKeyringPair;
   let randomAccount: IKeyringPair;
 
@@ -76,233 +55,234 @@
   let balanceQuartzForeignTokenFinal: bigint;
 
   before(async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
+    await usingPlaygrounds(async (helper, privateKey) => {
       const keyringSr25519 = new Keyring({type: 'sr25519'});
 
-      alice = privateKeyWrapper('//Alice');
+      alice = privateKey('//Alice');
       randomAccount = generateKeyringPair(keyringSr25519);
     });
 
     // Karura side
-    await usingApi(
-      async (api) => {
-        const destination = {
-          V0: {
-            X2: [
-              'Parent',
-              {
-                Parachain: QUARTZ_CHAIN,
-              },
-            ],
-          },
-        };
+    await usingPlaygrounds.atUrl(karuraUrl, async (helper) => {
+      const api = helper.getApi();
+
+      const destination = {
+        V0: {
+          X2: [
+            'Parent',
+            {
+              Parachain: QUARTZ_CHAIN,
+            },
+          ],
+        },
+      };
 
-        const metadata = {
-          name: 'QTZ',
-          symbol: 'QTZ',
-          decimals: 18,
-          minimalBalance: 1,
-        };
+      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 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;
+      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;
-          balanceQuartzForeignTokenInit = BigInt(free);
-        }
-      },
-      karuraOptions(),
-    );
+      [balanceKaruraTokenInit] = await getBalance(api, [randomAccount.address]);
+      {
+        const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
+        balanceQuartzForeignTokenInit = BigInt(free);
+      }
+    });
 
     // 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;
+    await usingPlaygrounds(async (helper) => {
+      // 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;
+      await helper.balance.transferToSubstrate(alice, randomAccount.address, 10n * TRANSFER_AMOUNT);
 
-      [balanceQuartzTokenInit] = await getBalance(api, [randomAccount.address]);
+      // [balanceQuartzTokenInit] = await getBalance(api, [randomAccount.address]);
+      balanceQuartzTokenInit = await helper.balance.getSubstrate(randomAccount.address);
     });
   });
 
-  it('Should connect and send QTZ to Karura', async () => {
+  itSub('Should connect and send QTZ to Karura', async ({helper}) => {
 
     // Quartz side
-    await usingApi(async (api) => {
+    const destination = {
+      V0: {
+        X2: [
+          'Parent',
+          {
+            Parachain: KARURA_CHAIN,
+          },
+        ],
+      },
+    };
 
-      const destination = {
-        V0: {
-          X2: [
-            'Parent',
-            {
-              Parachain: KARURA_CHAIN,
-            },
-          ],
+    const beneficiary = {
+      V0: {
+        X1: {
+          AccountId32: {
+            network: 'Any',
+            id: randomAccount.addressRaw,
+          },
         },
-      };
+      },
+    };
 
-      const beneficiary = {
-        V0: {
-          X1: {
-            AccountId32: {
-              network: 'Any',
-              id: randomAccount.addressRaw,
+    const assets = {
+      V1: [
+        {
+          id: {
+            Concrete: {
+              parents: 0,
+              interior: 'Here',
             },
           },
+          fun: {
+            Fungible: TRANSFER_AMOUNT,
+          },
         },
-      };
+      ],
+    };
 
-      const assets = {
-        V1: [
-          {
-            id: {
-              Concrete: {
-                parents: 0,
-                interior: 'Here',
-              },
-            },
-            fun: {
-              Fungible: TRANSFER_AMOUNT,
-            },
-          },
-        ],
-      };
+    const feeAssetItem = 0;
 
-      const feeAssetItem = 0;
-
-      const weightLimit = {
-        Limited: 5000000000,
-      };
+    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;
+    // TODO
+    const tx = helper.getApi().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]);
+    // [balanceQuartzTokenMiddle] = await getBalance(api, [randomAccount.address]);
+    balanceQuartzTokenMiddle = await helper.balance.getSubstrate(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;
-    });
+    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;
-        balanceQuartzForeignTokenMiddle = BigInt(free);
+    await usingPlaygrounds.atUrl(karuraUrl, async (helper) => {
+      // await waitNewBlocks(api, 3);
+      await helper.wait.newBlocks(3);
+
+      // TODO
+      const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
+      balanceQuartzForeignTokenMiddle = BigInt(free);
 
-        [balanceKaruraTokenMiddle] = await getBalance(api, [randomAccount.address]);
+      // [balanceKaruraTokenMiddle] = await getBalance(api, [randomAccount.address]);
+      balanceKaruraTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);
 
-        const karFees = balanceKaruraTokenInit - balanceKaruraTokenMiddle;
-        const qtzIncomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenInit;
+      const karFees = balanceKaruraTokenInit - balanceKaruraTokenMiddle;
+      const qtzIncomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenInit;
 
-        console.log(
-          '[Quartz -> Karura] transaction fees on Karura: %s KAR',
-          bigIntToDecimals(karFees, KARURA_DECIMALS),
-        );
-        console.log('[Quartz -> Karura] income %s QTZ', bigIntToDecimals(qtzIncomeTransfer));
-        expect(karFees == 0n).to.be.true;
-        expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
-      },
-      karuraOptions(),
-    );
+      console.log(
+        '[Quartz -> Karura] transaction fees on Karura: %s KAR',
+        bigIntToDecimals(karFees, KARURA_DECIMALS),
+      );
+      console.log('[Quartz -> Karura] income %s QTZ', bigIntToDecimals(qtzIncomeTransfer));
+      expect(karFees == 0n).to.be.true;
+      expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
+    });
   });
 
-  it('Should connect to Karura and send QTZ back', async () => {
+  itSub('Should connect to Karura and send QTZ back', async ({helper}) => {
 
     // Karura side
-    await usingApi(
-      async (api) => {
-        const destination = {
-          V1: {
-            parents: 1,
-            interior: {
-              X2: [
-                {Parachain: QUARTZ_CHAIN},
-                {
-                  AccountId32: {
-                    network: 'Any',
-                    id: randomAccount.addressRaw,
-                  },
+    await usingPlaygrounds.atUrl(karuraUrl, async (helper) => {
+      const destination = {
+        V1: {
+          parents: 1,
+          interior: {
+            X2: [
+              {Parachain: QUARTZ_CHAIN},
+              {
+                AccountId32: {
+                  network: 'Any',
+                  id: randomAccount.addressRaw,
                 },
-              ],
-            },
+              },
+            ],
           },
-        };
+        },
+      };
 
-        const id = {
-          ForeignAsset: 0,
-        };
+      const id = {
+        ForeignAsset: 0,
+      };
 
-        const destWeight = 50000000;
+      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;
+      // TODO
+      const tx = helper.getApi().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, id)).toJSON() as any;
-          balanceQuartzForeignTokenFinal = BigInt(free);
-        }
+      // [balanceKaruraTokenFinal] = await getBalance(api, [randomAccount.address]);
+      balanceKaruraTokenFinal = await helper.balance.getSubstrate(randomAccount.address);
+      {
+        // TODO
+        const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, id)).toJSON() as any;
+        balanceQuartzForeignTokenFinal = BigInt(free);
+      }
 
-        const karFees = balanceKaruraTokenMiddle - balanceKaruraTokenFinal;
-        const qtzOutcomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenFinal;
+      const karFees = balanceKaruraTokenMiddle - balanceKaruraTokenFinal;
+      const qtzOutcomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenFinal;
 
-        console.log(
-          '[Karura -> Quartz] transaction fees on Karura: %s KAR',
-          bigIntToDecimals(karFees, KARURA_DECIMALS),
-        );
-        console.log('[Karura -> Quartz] outcome %s QTZ', bigIntToDecimals(qtzOutcomeTransfer));
+      console.log(
+        '[Karura -> Quartz] transaction fees on Karura: %s KAR',
+        bigIntToDecimals(karFees, KARURA_DECIMALS),
+      );
+      console.log('[Karura -> Quartz] outcome %s QTZ', bigIntToDecimals(qtzOutcomeTransfer));
 
-        expect(karFees > 0).to.be.true;
-        expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
-      },
-      karuraOptions(),
-    );
+      expect(karFees > 0).to.be.true;
+      expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
+    });
 
     // Quartz side
-    await usingApi(async (api) => {
-      await waitNewBlocks(api, 3);
+    // await waitNewBlocks(api, 3);
+    await helper.wait.newBlocks(3);
 
-      [balanceQuartzTokenFinal] = await getBalance(api, [randomAccount.address]);
-      const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;
-      expect(actuallyDelivered > 0).to.be.true;
+    // [balanceQuartzTokenFinal] = await getBalance(api, [randomAccount.address]);
+    balanceQuartzTokenFinal = await helper.balance.getSubstrate(randomAccount.address);
+    const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;
+    expect(actuallyDelivered > 0).to.be.true;
 
-      console.log('[Karura -> Quartz] actually delivered %s QTZ', bigIntToDecimals(actuallyDelivered));
+    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;
-    });
+    const qtzFees = TRANSFER_AMOUNT - actuallyDelivered;
+    console.log('[Karura -> Quartz] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));
+    expect(qtzFees == 0n).to.be.true;
   });
 });
 
 // These tests are relevant only when the foreign asset pallet is disabled
-describe_xcm('[XCM] Integration test: Quartz rejects non-native tokens', () => {
+describeXcm('[XCM] Integration test: Quartz rejects non-native tokens', () => {
   let alice: IKeyringPair;
 
   before(async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
-      alice = privateKeyWrapper('//Alice');
+    await usingPlaygrounds(async (_helper, privateKey) => {
+      alice = privateKey('//Alice');
     });
   });
 
-  it('Quartz rejects tokens from the Relay', async () => {
-    await usingApi(async (api) => {
+  itSub('Quartz rejects tokens from the Relay', async ({helper}) => {
+    await usingPlaygrounds.atUrl(relayUrl, async (helper) => {
       const destination = {
         V1: {
           parents: 0,
@@ -346,44 +326,45 @@
         Limited: 5_000_000_000,
       };
 
-      const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
+      // TODO
+      const tx = helper.getApi().tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
       const events = await submitTransactionAsync(alice, tx);
       const result = getGenericResult(events);
       expect(result.success).to.be.true;
-    }, relayOptions());
+    });
 
-    await usingApi(async api => {
-      const maxWaitBlocks = 3;
-      const dmpQueueExecutedDownward = await waitEvent(
-        api,
-        maxWaitBlocks,
-        'dmpQueue',
-        'ExecutedDownward',
-      );
+    const maxWaitBlocks = 3;
 
-      expect(
-        dmpQueueExecutedDownward != null,
-        '[Relay] dmpQueue.ExecutedDownward event is expected',
-      ).to.be.true;
+    // TODO
+    const dmpQueueExecutedDownward = await waitEvent(
+      helper.getApi(),
+      maxWaitBlocks,
+      'dmpQueue',
+      'ExecutedDownward',
+    );
 
-      const event = dmpQueueExecutedDownward!.event;
-      const outcome = event.data[1] as XcmV2TraitsOutcome;
+    expect(
+      dmpQueueExecutedDownward != null,
+      '[Relay] dmpQueue.ExecutedDownward event is expected',
+    ).to.be.true;
 
-      expect(
-        outcome.isIncomplete,
-        '[Relay] The outcome of the XCM should be `Incomplete`',
-      ).to.be.true;
+    const event = dmpQueueExecutedDownward!.event;
+    const outcome = event.data[1] as XcmV2TraitsOutcome;
+
+    expect(
+      outcome.isIncomplete,
+      '[Relay] The outcome of the XCM should be `Incomplete`',
+    ).to.be.true;
 
-      const incomplete = outcome.asIncomplete;
-      expect(
-        incomplete[1].toString() == 'AssetNotFound',
-        '[Relay] The XCM error should be `AssetNotFound`',
-      ).to.be.true;
-    });
+    const incomplete = outcome.asIncomplete;
+    expect(
+      incomplete[1].toString() == 'AssetNotFound',
+      '[Relay] The XCM error should be `AssetNotFound`',
+    ).to.be.true;
   });
 
-  it('Quartz rejects KAR tokens from Karura', async () => {
-    await usingApi(async (api) => {
+  itSub('Quartz rejects KAR tokens from Karura', async ({helper}) => {
+    await usingPlaygrounds.atUrl(karuraUrl, async (helper) => {
       const destination = {
         V1: {
           parents: 1,
@@ -407,33 +388,34 @@
 
       const destWeight = 50000000;
 
-      const tx = api.tx.xTokens.transfer(id as any, 100_000_000_000, destination, destWeight);
+      // TODO
+      const tx = helper.getApi().tx.xTokens.transfer(id as any, 100_000_000_000, destination, destWeight);
       const events = await submitTransactionAsync(alice, tx);
       const result = getGenericResult(events);
       expect(result.success).to.be.true;
-    }, karuraOptions());
+    });
 
-    await usingApi(async api => {
-      const maxWaitBlocks = 3;
-      const xcmpQueueFailEvent = await waitEvent(api, maxWaitBlocks, 'xcmpQueue', 'Fail');
+    const maxWaitBlocks = 3;
 
-      expect(
-        xcmpQueueFailEvent != null,
-        '[Karura] xcmpQueue.FailEvent event is expected',
-      ).to.be.true;
+    // TODO
+    const xcmpQueueFailEvent = await waitEvent(helper.getApi(), maxWaitBlocks, 'xcmpQueue', 'Fail');
 
-      const event = xcmpQueueFailEvent!.event;
-      const outcome = event.data[1] as XcmV2TraitsError;
+    expect(
+      xcmpQueueFailEvent != null,
+      '[Karura] xcmpQueue.FailEvent event is expected',
+    ).to.be.true;
 
-      expect(
-        outcome.isUntrustedReserveLocation,
-        '[Karura] The XCM error should be `UntrustedReserveLocation`',
-      ).to.be.true;
-    });
+    const event = xcmpQueueFailEvent!.event;
+    const outcome = event.data[1] as XcmV2TraitsError;
+
+    expect(
+      outcome.isUntrustedReserveLocation,
+      '[Karura] The XCM error should be `UntrustedReserveLocation`',
+    ).to.be.true;
   });
 });
 
-describe_xcm('[XCM] Integration test: Exchanging QTZ with Moonriver', () => {
+describeXcm('[XCM] Integration test: Exchanging QTZ with Moonriver', () => {
 
   // Quartz constants
   let quartzAlice: IKeyringPair;
@@ -478,322 +460,327 @@
   let balanceMovrTokenFinal: bigint;
 
   before(async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
+    await usingPlaygrounds(async (_helper, privateKey) => {
       const keyringEth = new Keyring({type: 'ethereum'});
       const keyringSr25519 = new Keyring({type: 'sr25519'});
 
-      quartzAlice = privateKeyWrapper('//Alice');
+      quartzAlice = privateKey('//Alice');
       randomAccountQuartz = generateKeyringPair(keyringSr25519);
       randomAccountMoonriver = generateKeyringPair(keyringEth);
 
       balanceForeignQtzTokenInit = 0n;
     });
 
-    await usingApi(
-      async (api) => {
+    await usingPlaygrounds.atUrl(moonriverUrl, async (helper) => {
+      // TODO
 
-        // >>> Sponsoring Dorothy >>>
-        console.log('Sponsoring Dorothy.......');
-        const tx0 = api.tx.balances.transfer(dorothyAccount.address, 11_000_000_000_000_000_000n);
-        const events0 = await submitTransactionAsync(alithAccount, tx0);
-        const result0 = getGenericResult(events0);
-        expect(result0.success).to.be.true;
-        console.log('Sponsoring Dorothy.......DONE');
-        // <<< Sponsoring Dorothy <<<
+      const api = helper.getApi();
 
-        const sourceLocation: MultiLocation = api.createType(
-          'MultiLocation',
-          {
-            parents: 1,
-            interior: {X1: {Parachain: QUARTZ_CHAIN}},
-          },
-        );
+      // >>> Sponsoring Dorothy >>>
+      console.log('Sponsoring Dorothy.......');
+      // const tx0 = api.tx.balances.transfer(dorothyAccount.address, 11_000_000_000_000_000_000n);
+      // const events0 = await submitTransactionAsync(alithAccount, tx0);
+      // const result0 = getGenericResult(events0);
+      // expect(result0.success).to.be.true;
+      await helper.balance.transferToSubstrate(alithAccount, dorothyAccount.address, 11_000_000_000_000_000_000n);
+      console.log('Sponsoring Dorothy.......DONE');
+      // <<< Sponsoring Dorothy <<<
 
-        quartzAssetLocation = {XCM: sourceLocation};
-        const existentialDeposit = 1;
-        const isSufficient = true;
-        const unitsPerSecond = '1';
-        const numAssetsWeightHint = 0;
+      const sourceLocation: MultiLocation = api.createType(
+        'MultiLocation',
+        {
+          parents: 1,
+          interior: {X1: {Parachain: QUARTZ_CHAIN}},
+        },
+      );
 
-        const registerTx = api.tx.assetManager.registerForeignAsset(
-          quartzAssetLocation,
-          quartzAssetMetadata,
-          existentialDeposit,
-          isSufficient,
-        );
-        console.log('Encoded proposal for registerAsset is %s', registerTx.method.toHex() || '');
+      quartzAssetLocation = {XCM: sourceLocation};
+      const existentialDeposit = 1;
+      const isSufficient = true;
+      const unitsPerSecond = '1';
+      const numAssetsWeightHint = 0;
 
-        const setUnitsTx = api.tx.assetManager.setAssetUnitsPerSecond(
-          quartzAssetLocation,
-          unitsPerSecond,
-          numAssetsWeightHint,
-        );
-        console.log('Encoded proposal for setAssetUnitsPerSecond is %s', setUnitsTx.method.toHex() || '');
+      const registerTx = api.tx.assetManager.registerForeignAsset(
+        quartzAssetLocation,
+        quartzAssetMetadata,
+        existentialDeposit,
+        isSufficient,
+      );
+      console.log('Encoded proposal for registerAsset is %s', registerTx.method.toHex() || '');
 
-        const batchCall = api.tx.utility.batchAll([registerTx, setUnitsTx]);
-        console.log('Encoded proposal for batchCall is %s', batchCall.method.toHex() || '');
+      const setUnitsTx = api.tx.assetManager.setAssetUnitsPerSecond(
+        quartzAssetLocation,
+        unitsPerSecond,
+        numAssetsWeightHint,
+      );
+      console.log('Encoded proposal for setAssetUnitsPerSecond is %s', setUnitsTx.method.toHex() || '');
 
-        // >>> Note motion preimage >>>
-        console.log('Note motion preimage.......');
-        const encodedProposal = batchCall?.method.toHex() || '';
-        const proposalHash = blake2AsHex(encodedProposal);
-        console.log('Encoded proposal for batch utility after schedule is %s', encodedProposal);
-        console.log('Encoded proposal hash for batch utility after schedule is %s', proposalHash);
-        console.log('Encoded length %d', encodedProposal.length);
+      const batchCall = api.tx.utility.batchAll([registerTx, setUnitsTx]);
+      console.log('Encoded proposal for batchCall is %s', batchCall.method.toHex() || '');
 
-        const tx1 = api.tx.democracy.notePreimage(encodedProposal);
-        const events1 = await submitTransactionAsync(baltatharAccount, tx1);
-        const result1 = getGenericResult(events1);
-        expect(result1.success).to.be.true;
-        console.log('Note motion preimage.......DONE');
-        // <<< Note motion preimage <<<
+      // >>> Note motion preimage >>>
+      console.log('Note motion preimage.......');
+      const encodedProposal = batchCall?.method.toHex() || '';
+      const proposalHash = blake2AsHex(encodedProposal);
+      console.log('Encoded proposal for batch utility after schedule is %s', encodedProposal);
+      console.log('Encoded proposal hash for batch utility after schedule is %s', proposalHash);
+      console.log('Encoded length %d', encodedProposal.length);
 
-        // >>> Propose external motion through council >>>
-        console.log('Propose external motion through council.......');
-        const externalMotion = api.tx.democracy.externalProposeMajority(proposalHash);
-        const tx2 = api.tx.councilCollective.propose(
-          councilVotingThreshold,
-          externalMotion,
-          externalMotion.encodedLength,
-        );
-        const events2 = await submitTransactionAsync(baltatharAccount, tx2);
-        const result2 = getGenericResult(events2);
-        expect(result2.success).to.be.true;
+      const tx1 = api.tx.democracy.notePreimage(encodedProposal);
+      const events1 = await submitTransactionAsync(baltatharAccount, tx1);
+      const result1 = getGenericResult(events1);
+      expect(result1.success).to.be.true;
+      console.log('Note motion preimage.......DONE');
+      // <<< Note motion preimage <<<
 
-        const encodedMotion = externalMotion?.method.toHex() || '';
-        const motionHash = blake2AsHex(encodedMotion);
-        console.log('Motion hash is %s', motionHash);
+      // >>> Propose external motion through council >>>
+      console.log('Propose external motion through council.......');
+      const externalMotion = api.tx.democracy.externalProposeMajority(proposalHash);
+      const tx2 = api.tx.councilCollective.propose(
+        councilVotingThreshold,
+        externalMotion,
+        externalMotion.encodedLength,
+      );
+      const events2 = await submitTransactionAsync(baltatharAccount, tx2);
+      const result2 = getGenericResult(events2);
+      expect(result2.success).to.be.true;
 
-        const tx3 = api.tx.councilCollective.vote(motionHash, 0, true);
-        {
-          const events3 = await submitTransactionAsync(dorothyAccount, tx3);
-          const result3 = getGenericResult(events3);
-          expect(result3.success).to.be.true;
-        }
-        {
-          const events3 = await submitTransactionAsync(baltatharAccount, tx3);
-          const result3 = getGenericResult(events3);
-          expect(result3.success).to.be.true;
-        }
+      const encodedMotion = externalMotion?.method.toHex() || '';
+      const motionHash = blake2AsHex(encodedMotion);
+      console.log('Motion hash is %s', motionHash);
 
-        const tx4 = api.tx.councilCollective.close(motionHash, 0, 1_000_000_000, externalMotion.encodedLength);
-        const events4 = await submitTransactionAsync(dorothyAccount, tx4);
-        const result4 = getGenericResult(events4);
-        expect(result4.success).to.be.true;
-        console.log('Propose external motion through council.......DONE');
-        // <<< Propose external motion through council <<<
+      const tx3 = api.tx.councilCollective.vote(motionHash, 0, true);
+      {
+        const events3 = await submitTransactionAsync(dorothyAccount, tx3);
+        const result3 = getGenericResult(events3);
+        expect(result3.success).to.be.true;
+      }
+      {
+        const events3 = await submitTransactionAsync(baltatharAccount, tx3);
+        const result3 = getGenericResult(events3);
+        expect(result3.success).to.be.true;
+      }
 
-        // >>> Fast track proposal through technical committee >>>
-        console.log('Fast track proposal through technical committee.......');
-        const fastTrack = api.tx.democracy.fastTrack(proposalHash, votingPeriod, delayPeriod);
-        const tx5 = api.tx.techCommitteeCollective.propose(
-          technicalCommitteeThreshold,
-          fastTrack,
-          fastTrack.encodedLength,
-        );
-        const events5 = await submitTransactionAsync(alithAccount, tx5);
-        const result5 = getGenericResult(events5);
-        expect(result5.success).to.be.true;
+      const tx4 = api.tx.councilCollective.close(motionHash, 0, 1_000_000_000, externalMotion.encodedLength);
+      const events4 = await submitTransactionAsync(dorothyAccount, tx4);
+      const result4 = getGenericResult(events4);
+      expect(result4.success).to.be.true;
+      console.log('Propose external motion through council.......DONE');
+      // <<< Propose external motion through council <<<
 
-        const encodedFastTrack = fastTrack?.method.toHex() || '';
-        const fastTrackHash = blake2AsHex(encodedFastTrack);
-        console.log('FastTrack hash is %s', fastTrackHash);
+      // >>> Fast track proposal through technical committee >>>
+      console.log('Fast track proposal through technical committee.......');
+      const fastTrack = api.tx.democracy.fastTrack(proposalHash, votingPeriod, delayPeriod);
+      const tx5 = api.tx.techCommitteeCollective.propose(
+        technicalCommitteeThreshold,
+        fastTrack,
+        fastTrack.encodedLength,
+      );
+      const events5 = await submitTransactionAsync(alithAccount, tx5);
+      const result5 = getGenericResult(events5);
+      expect(result5.success).to.be.true;
 
-        const proposalIdx = Number(await api.query.techCommitteeCollective.proposalCount()) - 1;
-        const tx6 = api.tx.techCommitteeCollective.vote(fastTrackHash, proposalIdx, true);
-        {
-          const events6 = await submitTransactionAsync(baltatharAccount, tx6);
-          const result6 = getGenericResult(events6);
-          expect(result6.success).to.be.true;
-        }
-        {
-          const events6 = await submitTransactionAsync(alithAccount, tx6);
-          const result6 = getGenericResult(events6);
-          expect(result6.success).to.be.true;
-        }
+      const encodedFastTrack = fastTrack?.method.toHex() || '';
+      const fastTrackHash = blake2AsHex(encodedFastTrack);
+      console.log('FastTrack hash is %s', fastTrackHash);
 
-        const tx7 = api.tx.techCommitteeCollective
-          .close(fastTrackHash, proposalIdx, 1_000_000_000, fastTrack.encodedLength);
-        const events7 = await submitTransactionAsync(baltatharAccount, tx7);
-        const result7 = getGenericResult(events7);
-        expect(result7.success).to.be.true;
-        console.log('Fast track proposal through technical committee.......DONE');
-        // <<< Fast track proposal through technical committee <<<
+      const proposalIdx = Number(await api.query.techCommitteeCollective.proposalCount()) - 1;
+      const tx6 = api.tx.techCommitteeCollective.vote(fastTrackHash, proposalIdx, true);
+      {
+        const events6 = await submitTransactionAsync(baltatharAccount, tx6);
+        const result6 = getGenericResult(events6);
+        expect(result6.success).to.be.true;
+      }
+      {
+        const events6 = await submitTransactionAsync(alithAccount, tx6);
+        const result6 = getGenericResult(events6);
+        expect(result6.success).to.be.true;
+      }
 
-        // >>> Referendum voting >>>
-        console.log('Referendum voting.......');
-        const tx8 = api.tx.democracy.vote(
-          0,
-          {Standard: {balance: 10_000_000_000_000_000_000n, vote: {aye: true, conviction: 1}}},
-        );
-        const events8 = await submitTransactionAsync(dorothyAccount, tx8);
-        const result8 = getGenericResult(events8);
-        expect(result8.success).to.be.true;
-        console.log('Referendum voting.......DONE');
-        // <<< Referendum voting <<<
+      const tx7 = api.tx.techCommitteeCollective
+        .close(fastTrackHash, proposalIdx, 1_000_000_000, fastTrack.encodedLength);
+      const events7 = await submitTransactionAsync(baltatharAccount, tx7);
+      const result7 = getGenericResult(events7);
+      expect(result7.success).to.be.true;
+      console.log('Fast track proposal through technical committee.......DONE');
+      // <<< Fast track proposal through technical committee <<<
 
-        // >>> Acquire Quartz AssetId Info on Moonriver >>>
-        console.log('Acquire Quartz AssetId Info on Moonriver.......');
+      // >>> Referendum voting >>>
+      console.log('Referendum voting.......');
+      const tx8 = api.tx.democracy.vote(
+        0,
+        {Standard: {balance: 10_000_000_000_000_000_000n, vote: {aye: true, conviction: 1}}},
+      );
+      const events8 = await submitTransactionAsync(dorothyAccount, tx8);
+      const result8 = getGenericResult(events8);
+      expect(result8.success).to.be.true;
+      console.log('Referendum voting.......DONE');
+      // <<< Referendum voting <<<
 
-        // Wait for the democracy execute
-        await waitNewBlocks(api, 5);
+      // >>> Acquire Quartz AssetId Info on Moonriver >>>
+      console.log('Acquire Quartz AssetId Info on Moonriver.......');
 
-        assetId = (await api.query.assetManager.assetTypeId({
-          XCM: sourceLocation,
-        })).toString();
+      // Wait for the democracy execute
+      // await waitNewBlocks(api, 5);
+      await helper.wait.newBlocks(5);
 
-        console.log('QTZ asset ID is %s', assetId);
-        console.log('Acquire Quartz AssetId Info on Moonriver.......DONE');
-        // >>> Acquire Quartz AssetId Info on Moonriver >>>
+      assetId = (await api.query.assetManager.assetTypeId({
+        XCM: sourceLocation,
+      })).toString();
 
-        // >>> Sponsoring random Account >>>
-        console.log('Sponsoring random Account.......');
-        const tx10 = api.tx.balances.transfer(randomAccountMoonriver.address, 11_000_000_000_000_000_000n);
-        const events10 = await submitTransactionAsync(baltatharAccount, tx10);
-        const result10 = getGenericResult(events10);
-        expect(result10.success).to.be.true;
-        console.log('Sponsoring random Account.......DONE');
-        // <<< Sponsoring random Account <<<
+      console.log('QTZ asset ID is %s', assetId);
+      console.log('Acquire Quartz AssetId Info on Moonriver.......DONE');
+      // >>> Acquire Quartz AssetId Info on Moonriver >>>
 
-        [balanceMovrTokenInit] = await getBalance(api, [randomAccountMoonriver.address]);
-      },
-      moonriverOptions(),
-    );
+      // >>> Sponsoring random Account >>>
+      console.log('Sponsoring random Account.......');
+      // const tx10 = api.tx.balances.transfer(randomAccountMoonriver.address, 11_000_000_000_000_000_000n);
+      // const events10 = await submitTransactionAsync(baltatharAccount, tx10);
+      // const result10 = getGenericResult(events10);
+      // expect(result10.success).to.be.true;
+      await helper.balance.transferToSubstrate(baltatharAccount, randomAccountMoonriver.address, 11_000_000_000_000_000_000n);
+      console.log('Sponsoring random Account.......DONE');
+      // <<< Sponsoring random Account <<<
 
-    await usingApi(async (api) => {
-      const tx0 = api.tx.balances.transfer(randomAccountQuartz.address, 10n * TRANSFER_AMOUNT);
-      const events0 = await submitTransactionAsync(quartzAlice, tx0);
-      const result0 = getGenericResult(events0);
-      expect(result0.success).to.be.true;
+      // [balanceMovrTokenInit] = await getBalance(api, [randomAccountMoonriver.address]);
+      balanceMovrTokenInit = await helper.balance.getSubstrate(randomAccountMoonriver.address);
+    });
 
-      [balanceQuartzTokenInit] = await getBalance(api, [randomAccountQuartz.address]);
+    await usingPlaygrounds(async (helper) => {
+      // const tx0 = api.tx.balances.transfer(randomAccountQuartz.address, 10n * TRANSFER_AMOUNT);
+      // const events0 = await submitTransactionAsync(quartzAlice, tx0);
+      // const result0 = getGenericResult(events0);
+      // expect(result0.success).to.be.true;
+      await helper.balance.transferToSubstrate(quartzAlice, randomAccountQuartz.address, 10n * TRANSFER_AMOUNT);
+
+      // [balanceQuartzTokenInit] = await getBalance(api, [randomAccountQuartz.address]);
+      balanceQuartzTokenInit = await helper.balance.getSubstrate(randomAccountQuartz.address);
     });
   });
 
-  it('Should connect and send QTZ to Moonriver', async () => {
-    await usingApi(async (api) => {
-      const currencyId = {
-        NativeAssetId: 'Here',
-      };
-      const dest = {
-        V1: {
-          parents: 1,
-          interior: {
-            X2: [
-              {Parachain: MOONRIVER_CHAIN},
-              {AccountKey20: {network: 'Any', key: randomAccountMoonriver.address}},
-            ],
-          },
+  itSub('Should connect and send QTZ to Moonriver', async ({helper}) => {
+    const currencyId = {
+      NativeAssetId: 'Here',
+    };
+    const dest = {
+      V1: {
+        parents: 1,
+        interior: {
+          X2: [
+            {Parachain: MOONRIVER_CHAIN},
+            {AccountKey20: {network: 'Any', key: randomAccountMoonriver.address}},
+          ],
         },
-      };
-      const amount = TRANSFER_AMOUNT;
-      const destWeight = 850000000;
+      },
+    };
+    const amount = TRANSFER_AMOUNT;
+    const destWeight = 850000000;
 
-      const tx = api.tx.xTokens.transfer(currencyId, amount, dest, destWeight);
-      const events = await submitTransactionAsync(randomAccountQuartz, tx);
-      const result = getGenericResult(events);
-      expect(result.success).to.be.true;
+    // TODO
+    const tx = helper.getApi().tx.xTokens.transfer(currencyId, amount, dest, destWeight);
+    const events = await submitTransactionAsync(randomAccountQuartz, tx);
+    const result = getGenericResult(events);
+    expect(result.success).to.be.true;
 
-      [balanceQuartzTokenMiddle] = await getBalance(api, [randomAccountQuartz.address]);
-      expect(balanceQuartzTokenMiddle < balanceQuartzTokenInit).to.be.true;
+    // [balanceQuartzTokenMiddle] = await getBalance(api, [randomAccountQuartz.address]);
+    balanceQuartzTokenMiddle = await helper.balance.getSubstrate(randomAccountQuartz.address);
+    expect(balanceQuartzTokenMiddle < balanceQuartzTokenInit).to.be.true;
 
-      const transactionFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;
-      console.log('[Quartz -> Moonriver] transaction fees on Quartz: %s QTZ', bigIntToDecimals(transactionFees));
-      expect(transactionFees > 0).to.be.true;
-    });
+    const transactionFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;
+    console.log('[Quartz -> Moonriver] transaction fees on Quartz: %s QTZ', bigIntToDecimals(transactionFees));
+    expect(transactionFees > 0).to.be.true;
 
-    await usingApi(
-      async (api) => {
-        await waitNewBlocks(api, 3);
+    await usingPlaygrounds.atUrl(moonriverUrl, async (helper) => {
+      // await waitNewBlocks(api, 3);
+      await helper.wait.newBlocks(3);
 
-        [balanceMovrTokenMiddle] = await getBalance(api, [randomAccountMoonriver.address]);
+      // [balanceMovrTokenMiddle] = await getBalance(api, [randomAccountMoonriver.address]);
+      balanceMovrTokenMiddle = await helper.balance.getSubstrate(randomAccountMoonriver.address);
 
-        const movrFees = balanceMovrTokenInit - balanceMovrTokenMiddle;
-        console.log('[Quartz -> Moonriver] transaction fees on Moonriver: %s MOVR',bigIntToDecimals(movrFees));
-        expect(movrFees == 0n).to.be.true;
+      const movrFees = balanceMovrTokenInit - balanceMovrTokenMiddle;
+      console.log('[Quartz -> Moonriver] transaction fees on Moonriver: %s MOVR',bigIntToDecimals(movrFees));
+      expect(movrFees == 0n).to.be.true;
 
-        const qtzRandomAccountAsset = (
-          await api.query.assets.account(assetId, randomAccountMoonriver.address)
-        ).toJSON()! as any;
+      // TODO
+      const qtzRandomAccountAsset = (
+        await helper.getApi().query.assets.account(assetId, randomAccountMoonriver.address)
+      ).toJSON()! as any;
 
-        balanceForeignQtzTokenMiddle = BigInt(qtzRandomAccountAsset['balance']);
-        const qtzIncomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenInit;
-        console.log('[Quartz -> Moonriver] income %s QTZ', bigIntToDecimals(qtzIncomeTransfer));
-        expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
-      },
-      moonriverOptions(),
-    );
+      balanceForeignQtzTokenMiddle = BigInt(qtzRandomAccountAsset['balance']);
+      const qtzIncomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenInit;
+      console.log('[Quartz -> Moonriver] income %s QTZ', bigIntToDecimals(qtzIncomeTransfer));
+      expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
+    });
   });
 
-  it('Should connect to Moonriver and send QTZ back', async () => {
-    await usingApi(
-      async (api) => {
-        const asset = {
-          V1: {
-            id: {
-              Concrete: {
-                parents: 1,
-                interior: {
-                  X1: {Parachain: QUARTZ_CHAIN},
-                },
+  itSub('Should connect to Moonriver and send QTZ back', async ({helper}) => {
+    await usingPlaygrounds.atUrl(moonriverUrl, async (helper) => {
+      const asset = {
+        V1: {
+          id: {
+            Concrete: {
+              parents: 1,
+              interior: {
+                X1: {Parachain: QUARTZ_CHAIN},
               },
             },
-            fun: {
-              Fungible: TRANSFER_AMOUNT,
-            },
           },
-        };
-        const destination = {
-          V1: {
-            parents: 1,
-            interior: {
-              X2: [
-                {Parachain: QUARTZ_CHAIN},
-                {AccountId32: {network: 'Any', id: randomAccountQuartz.addressRaw}},
-              ],
-            },
+          fun: {
+            Fungible: TRANSFER_AMOUNT,
+          },
+        },
+      };
+      const destination = {
+        V1: {
+          parents: 1,
+          interior: {
+            X2: [
+              {Parachain: QUARTZ_CHAIN},
+              {AccountId32: {network: 'Any', id: randomAccountQuartz.addressRaw}},
+            ],
           },
-        };
-        const destWeight = 50000000;
+        },
+      };
+      const destWeight = 50000000;
 
-        const tx = api.tx.xTokens.transferMultiasset(asset, destination, destWeight);
-        const events = await submitTransactionAsync(randomAccountMoonriver, tx);
-        const result = getGenericResult(events);
-        expect(result.success).to.be.true;
+      // TODO
+      const tx = helper.getApi().tx.xTokens.transferMultiasset(asset, destination, destWeight);
+      const events = await submitTransactionAsync(randomAccountMoonriver, tx);
+      const result = getGenericResult(events);
+      expect(result.success).to.be.true;
 
-        [balanceMovrTokenFinal] = await getBalance(api, [randomAccountMoonriver.address]);
+      // [balanceMovrTokenFinal] = await getBalance(api, [randomAccountMoonriver.address]);
+      balanceMovrTokenFinal = await helper.balance.getSubstrate(randomAccountMoonriver.address);
 
-        const movrFees = balanceMovrTokenMiddle - balanceMovrTokenFinal;
-        console.log('[Moonriver -> Quartz] transaction fees on Moonriver: %s MOVR', bigIntToDecimals(movrFees));
-        expect(movrFees > 0).to.be.true;
+      const movrFees = balanceMovrTokenMiddle - balanceMovrTokenFinal;
+      console.log('[Moonriver -> Quartz] transaction fees on Moonriver: %s MOVR', bigIntToDecimals(movrFees));
+      expect(movrFees > 0).to.be.true;
 
-        const qtzRandomAccountAsset = (
-          await api.query.assets.account(assetId, randomAccountMoonriver.address)
-        ).toJSON()! as any;
+      const qtzRandomAccountAsset = (
+        await helper.getApi().query.assets.account(assetId, randomAccountMoonriver.address)
+      ).toJSON()! as any;
 
-        expect(qtzRandomAccountAsset).to.be.null;
+      expect(qtzRandomAccountAsset).to.be.null;
 
-        balanceForeignQtzTokenFinal = 0n;
+      balanceForeignQtzTokenFinal = 0n;
 
-        const qtzOutcomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenFinal;
-        console.log('[Quartz -> Moonriver] outcome %s QTZ', bigIntToDecimals(qtzOutcomeTransfer));
-        expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
-      },
-      moonriverOptions(),
-    );
+      const qtzOutcomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenFinal;
+      console.log('[Quartz -> Moonriver] outcome %s QTZ', bigIntToDecimals(qtzOutcomeTransfer));
+      expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
+    });
 
-    await usingApi(async (api) => {
-      await waitNewBlocks(api, 3);
+    // await waitNewBlocks(api, 3);
+    await helper.wait.newBlocks(3);
 
-      [balanceQuartzTokenFinal] = await getBalance(api, [randomAccountQuartz.address]);
-      const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;
-      expect(actuallyDelivered > 0).to.be.true;
+    // [balanceQuartzTokenFinal] = await getBalance(api, [randomAccountQuartz.address]);
+    balanceQuartzTokenFinal = await helper.balance.getSubstrate(randomAccountQuartz.address);
+    const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;
+    expect(actuallyDelivered > 0).to.be.true;
 
-      console.log('[Moonriver -> Quartz] actually delivered %s QTZ', bigIntToDecimals(actuallyDelivered));
+    console.log('[Moonriver -> Quartz] actually delivered %s QTZ', bigIntToDecimals(actuallyDelivered));
 
-      const qtzFees = TRANSFER_AMOUNT - actuallyDelivered;
-      console.log('[Moonriver -> Quartz] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));
-      expect(qtzFees == 0n).to.be.true;
-    });
+    const qtzFees = TRANSFER_AMOUNT - actuallyDelivered;
+    console.log('[Moonriver -> Quartz] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));
+    expect(qtzFees == 0n).to.be.true;
   });
 });
modifiedtests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth
after · tests/src/xcm/xcmUnique.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 {Keyring} from '@polkadot/api';18import {IKeyringPair} from '@polkadot/types/types';19import {submitTransactionAsync} from '../substrate/substrate-api';20import {getGenericResult, generateKeyringPair, waitEvent, bigIntToDecimals} from '../deprecated-helpers/helpers';21import {MultiLocation} from '@polkadot/types/interfaces';22import {blake2AsHex} from '@polkadot/util-crypto';23import getBalance from '../substrate/get-balance';24import {XcmV2TraitsError, XcmV2TraitsOutcome} from '../interfaces';25import {itSub, expect, describeXcm, usingPlaygrounds} from '../util/playgrounds';2627const UNIQUE_CHAIN = 2037;28const ACALA_CHAIN = 2000;29const MOONBEAM_CHAIN = 2004;3031const RELAY_PORT = 9844;32const ACALA_PORT = 9946;33const MOONBEAM_PORT = 9947;3435const relayUrl = 'ws://127.0.0.1:' + RELAY_PORT;36const acalaUrl = 'ws://127.0.0.1:' + ACALA_PORT;37const moonbeamUrl = 'ws://127.0.0.1:' + MOONBEAM_PORT;3839const ACALA_DECIMALS = 12;4041const TRANSFER_AMOUNT = 2000000000000000000000000n;4243describeXcm('[XCM] Integration test: Exchanging tokens with Acala', () => {44  let alice: IKeyringPair;45  let randomAccount: IKeyringPair;4647  let balanceUniqueTokenInit: bigint;48  let balanceUniqueTokenMiddle: bigint;49  let balanceUniqueTokenFinal: bigint;50  let balanceAcalaTokenInit: bigint;51  let balanceAcalaTokenMiddle: bigint;52  let balanceAcalaTokenFinal: bigint;53  let balanceUniqueForeignTokenInit: bigint;54  let balanceUniqueForeignTokenMiddle: bigint;55  let balanceUniqueForeignTokenFinal: bigint;5657  before(async () => {58    await usingPlaygrounds(async (_helper, privateKey) => {59      const keyringSr25519 = new Keyring({type: 'sr25519'});6061      alice = privateKey('//Alice');62      randomAccount = generateKeyringPair(keyringSr25519);63    });6465    // Acala side66    await usingPlaygrounds.atUrl(acalaUrl, async (helper) => {67      const destination = {68        V0: {69          X2: [70            'Parent',71            {72              Parachain: UNIQUE_CHAIN,73            },74          ],75        },76      };7778      const metadata = {79        name: 'UNQ',80        symbol: 'UNQ',81        decimals: 18,82        minimalBalance: 1,83      };8485      // TODO86      const tx = helper.getApi().tx.assetRegistry.registerForeignAsset(destination, metadata);87      const sudoTx = helper.getApi().tx.sudo.sudo(tx as any);88      const events = await submitTransactionAsync(alice, sudoTx);89      const result = getGenericResult(events);90      expect(result.success).to.be.true;9192      // const tx1 = api.tx.balances.transfer(randomAccount.address, 10000000000000n);93      // const events1 = await submitTransactionAsync(alice, tx1);94      // const result1 = getGenericResult(events1);95      // expect(result1.success).to.be.true;96      await helper.balance.transferToSubstrate(alice, randomAccount.address, 10000000000000n);9798      // [balanceAcalaTokenInit] = await getBalance(api, [randomAccount.address]);99      balanceAcalaTokenInit = await helper.balance.getSubstrate(randomAccount.address);100      {101        // TODO102        const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;103        balanceUniqueForeignTokenInit = BigInt(free);104      }105    });106107    // Unique side108    await usingPlaygrounds(async (helper) => {109      // const tx0 = api.tx.balances.transfer(randomAccount.address, 10n * TRANSFER_AMOUNT);110      // const events0 = await submitTransactionAsync(alice, tx0);111      // const result0 = getGenericResult(events0);112      // expect(result0.success).to.be.true;113      await helper.balance.transferToSubstrate(alice, randomAccount.address, 10n * TRANSFER_AMOUNT);114115      // [balanceUniqueTokenInit] = await getBalance(api, [randomAccount.address]);116      balanceUniqueTokenInit = await helper.balance.getSubstrate(randomAccount.address);117    });118  });119120  itSub('Should connect and send UNQ to Acala', async ({helper}) => {121122    // Unique side123    const destination = {124      V0: {125        X2: [126          'Parent',127          {128            Parachain: ACALA_CHAIN,129          },130        ],131      },132    };133134    const beneficiary = {135      V0: {136        X1: {137          AccountId32: {138            network: 'Any',139            id: randomAccount.addressRaw,140          },141        },142      },143    };144145    const assets = {146      V1: [147        {148          id: {149            Concrete: {150              parents: 0,151              interior: 'Here',152            },153          },154          fun: {155            Fungible: TRANSFER_AMOUNT,156          },157        },158      ],159    };160161    const feeAssetItem = 0;162163    const weightLimit = {164      Limited: 5000000000,165    };166167    // TODO168    const tx = helper.getApi().tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);169    const events = await submitTransactionAsync(randomAccount, tx);170    const result = getGenericResult(events);171    expect(result.success).to.be.true;172173    // [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccount.address]);174    balanceUniqueTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);175176    const unqFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;177    console.log('[Unique -> Acala] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));178    expect(unqFees > 0n).to.be.true;179180    // Acala side181    await usingPlaygrounds.atUrl(acalaUrl, async (helper) => {182      // await waitNewBlocks(api, 3);183      await helper.wait.newBlocks(3);184185      // TODO186      const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;187      balanceUniqueForeignTokenMiddle = BigInt(free);188189      // [balanceAcalaTokenMiddle] = await getBalance(api, [randomAccount.address]);190      balanceAcalaTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);191192      const acaFees = balanceAcalaTokenInit - balanceAcalaTokenMiddle;193      const unqIncomeTransfer = balanceUniqueForeignTokenMiddle - balanceUniqueForeignTokenInit;194195      console.log(196        '[Unique -> Acala] transaction fees on Acala: %s ACA',197        bigIntToDecimals(acaFees, ACALA_DECIMALS),198      );199      console.log('[Unique -> Acala] income %s UNQ', bigIntToDecimals(unqIncomeTransfer));200      expect(acaFees == 0n).to.be.true;201      expect(unqIncomeTransfer == TRANSFER_AMOUNT).to.be.true;202    });203  });204205  itSub('Should connect to Acala and send UNQ back', async ({helper}) => {206207    // Acala side208    await usingPlaygrounds.atUrl(acalaUrl, async (helper) => {209      const destination = {210        V1: {211          parents: 1,212          interior: {213            X2: [214              {Parachain: UNIQUE_CHAIN},215              {216                AccountId32: {217                  network: 'Any',218                  id: randomAccount.addressRaw,219                },220              },221            ],222          },223        },224      };225226      const id = {227        ForeignAsset: 0,228      };229230      const destWeight = 50000000;231232      // TODO233      const tx = helper.getApi().tx.xTokens.transfer(id as any, TRANSFER_AMOUNT, destination, destWeight);234      const events = await submitTransactionAsync(randomAccount, tx);235      const result = getGenericResult(events);236      expect(result.success).to.be.true;237238      // [balanceAcalaTokenFinal] = await getBalance(api, [randomAccount.address]);239      balanceAcalaTokenFinal = await helper.balance.getSubstrate(randomAccount.address);240      {241        // TODO242        const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, id)).toJSON() as any;243        balanceUniqueForeignTokenFinal = BigInt(free);244      }245246      const acaFees = balanceAcalaTokenMiddle - balanceAcalaTokenFinal;247      const unqOutcomeTransfer = balanceUniqueForeignTokenMiddle - balanceUniqueForeignTokenFinal;248249      console.log(250        '[Acala -> Unique] transaction fees on Acala: %s ACA',251        bigIntToDecimals(acaFees, ACALA_DECIMALS),252      );253      console.log('[Acala -> Unique] outcome %s UNQ', bigIntToDecimals(unqOutcomeTransfer));254255      expect(acaFees > 0).to.be.true;256      expect(unqOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;257    });258259    // await waitNewBlocks(api, 3);260    await helper.wait.newBlocks(3);261262    // [balanceUniqueTokenFinal] = await getBalance(api, [randomAccount.address]);263    balanceUniqueTokenFinal = await helper.balance.getSubstrate(randomAccount.address);264    const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenMiddle;265    expect(actuallyDelivered > 0).to.be.true;266267    console.log('[Acala -> Unique] actually delivered %s UNQ', bigIntToDecimals(actuallyDelivered));268269    const unqFees = TRANSFER_AMOUNT - actuallyDelivered;270    console.log('[Acala -> Unique] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));271    expect(unqFees == 0n).to.be.true;272  });273});274275// These tests are relevant only when the foreign asset pallet is disabled276describeXcm('[XCM] Integration test: Unique rejects non-native tokens', () => {277  let alice: IKeyringPair;278279  before(async () => {280    await usingPlaygrounds(async (_helper, privateKey) => {281      alice = privateKey('//Alice');282    });283  });284285  itSub('Unique rejects tokens from the Relay', async ({helper}) => {286    await usingPlaygrounds.atUrl(relayUrl, async (helper) => {287      const destination = {288        V1: {289          parents: 0,290          interior: {X1: {291            Parachain: UNIQUE_CHAIN,292          },293          },294        }};295296      const beneficiary = {297        V1: {298          parents: 0,299          interior: {X1: {300            AccountId32: {301              network: 'Any',302              id: alice.addressRaw,303            },304          }},305        },306      };307308      const assets = {309        V1: [310          {311            id: {312              Concrete: {313                parents: 0,314                interior: 'Here',315              },316            },317            fun: {318              Fungible: 50_000_000_000_000_000n,319            },320          },321        ],322      };323324      const feeAssetItem = 0;325326      const weightLimit = {327        Limited: 5_000_000_000,328      };329330      // TODO331      const tx = helper.getApi().tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);332      const events = await submitTransactionAsync(alice, tx);333      const result = getGenericResult(events);334      expect(result.success).to.be.true;335    });336337    const maxWaitBlocks = 3;338339    // TODO340    const dmpQueueExecutedDownward = await waitEvent(341      helper.getApi(),342      maxWaitBlocks,343      'dmpQueue',344      'ExecutedDownward',345    );346347    expect(348      dmpQueueExecutedDownward != null,349      '[Relay] dmpQueue.ExecutedDownward event is expected',350    ).to.be.true;351352    const event = dmpQueueExecutedDownward!.event;353    const outcome = event.data[1] as XcmV2TraitsOutcome;354355    expect(356      outcome.isIncomplete,357      '[Relay] The outcome of the XCM should be `Incomplete`',358    ).to.be.true;359360    const incomplete = outcome.asIncomplete;361    expect(362      incomplete[1].toString() == 'AssetNotFound',363      '[Relay] The XCM error should be `AssetNotFound`',364    ).to.be.true;365  });366367  itSub('Unique rejects ACA tokens from Acala', async ({helper}) => {368    await usingPlaygrounds.atUrl(acalaUrl, async (helper) => {369      const destination = {370        V1: {371          parents: 1,372          interior: {373            X2: [374              {Parachain: UNIQUE_CHAIN},375              {376                AccountId32: {377                  network: 'Any',378                  id: alice.addressRaw,379                },380              },381            ],382          },383        },384      };385386      const id = {387        Token: 'ACA',388      };389390      const destWeight = 50000000;391392      // TODO393      const tx = helper.getApi().tx.xTokens.transfer(id as any, 100_000_000_000, destination, destWeight);394      const events = await submitTransactionAsync(alice, tx);395      const result = getGenericResult(events);396      expect(result.success).to.be.true;397    });398399    const maxWaitBlocks = 3;400401    // TODO402    const xcmpQueueFailEvent = await waitEvent(helper.getApi(), maxWaitBlocks, 'xcmpQueue', 'Fail');403404    expect(405      xcmpQueueFailEvent != null,406      '[Acala] xcmpQueue.FailEvent event is expected',407    ).to.be.true;408409    const event = xcmpQueueFailEvent!.event;410    const outcome = event.data[1] as XcmV2TraitsError;411412    expect(413      outcome.isUntrustedReserveLocation,414      '[Acala] The XCM error should be `UntrustedReserveLocation`',415    ).to.be.true;416  });417});418419describeXcm('[XCM] Integration test: Exchanging UNQ with Moonbeam', () => {420421  // Unique constants422  let uniqueAlice: IKeyringPair;423  let uniqueAssetLocation;424425  let randomAccountUnique: IKeyringPair;426  let randomAccountMoonbeam: IKeyringPair;427428  // Moonbeam constants429  let assetId: string;430431  const moonbeamKeyring = new Keyring({type: 'ethereum'});432  const alithPrivateKey = '0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133';433  const baltatharPrivateKey = '0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b';434  const dorothyPrivateKey = '0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68';435436  const alithAccount = moonbeamKeyring.addFromUri(alithPrivateKey, undefined, 'ethereum');437  const baltatharAccount = moonbeamKeyring.addFromUri(baltatharPrivateKey, undefined, 'ethereum');438  const dorothyAccount = moonbeamKeyring.addFromUri(dorothyPrivateKey, undefined, 'ethereum');439440  const councilVotingThreshold = 2;441  const technicalCommitteeThreshold = 2;442  const votingPeriod = 3;443  const delayPeriod = 0;444445  const uniqueAssetMetadata = {446    name: 'xcUnique',447    symbol: 'xcUNQ',448    decimals: 18,449    isFrozen: false,450    minimalBalance: 1,451  };452453  let balanceUniqueTokenInit: bigint;454  let balanceUniqueTokenMiddle: bigint;455  let balanceUniqueTokenFinal: bigint;456  let balanceForeignUnqTokenInit: bigint;457  let balanceForeignUnqTokenMiddle: bigint;458  let balanceForeignUnqTokenFinal: bigint;459  let balanceGlmrTokenInit: bigint;460  let balanceGlmrTokenMiddle: bigint;461  let balanceGlmrTokenFinal: bigint;462463  before(async () => {464    await usingPlaygrounds(async (_helper, privateKey) => {465      const keyringEth = new Keyring({type: 'ethereum'});466      const keyringSr25519 = new Keyring({type: 'sr25519'});467468      uniqueAlice = privateKey('//Alice');469      randomAccountUnique = generateKeyringPair(keyringSr25519);470      randomAccountMoonbeam = generateKeyringPair(keyringEth);471472      balanceForeignUnqTokenInit = 0n;473    });474475    await usingPlaygrounds.atUrl(moonbeamUrl, async (helper) => {476      // TODO477478      const api = helper.getApi();479480      // >>> Sponsoring Dorothy >>>481      console.log('Sponsoring Dorothy.......');482      // const tx0 = api.tx.balances.transfer(dorothyAccount.address, 11_000_000_000_000_000_000n);483      // const events0 = await submitTransactionAsync(alithAccount, tx0);484      // const result0 = getGenericResult(events0);485      // expect(result0.success).to.be.true;486      await helper.balance.transferToSubstrate(alithAccount, dorothyAccount.address, 11_000_000_000_000_000_000n);487      console.log('Sponsoring Dorothy.......DONE');488      // <<< Sponsoring Dorothy <<<489490      const sourceLocation: MultiLocation = api.createType(491        'MultiLocation',492        {493          parents: 1,494          interior: {X1: {Parachain: UNIQUE_CHAIN}},495        },496      );497498      uniqueAssetLocation = {XCM: sourceLocation};499      const existentialDeposit = 1;500      const isSufficient = true;501      const unitsPerSecond = '1';502      const numAssetsWeightHint = 0;503504      const registerTx = api.tx.assetManager.registerForeignAsset(505        uniqueAssetLocation,506        uniqueAssetMetadata,507        existentialDeposit,508        isSufficient,509      );510      console.log('Encoded proposal for registerAsset is %s', registerTx.method.toHex() || '');511512      const setUnitsTx = api.tx.assetManager.setAssetUnitsPerSecond(513        uniqueAssetLocation,514        unitsPerSecond,515        numAssetsWeightHint,516      );517      console.log('Encoded proposal for setAssetUnitsPerSecond is %s', setUnitsTx.method.toHex() || '');518519      const batchCall = api.tx.utility.batchAll([registerTx, setUnitsTx]);520      console.log('Encoded proposal for batchCall is %s', batchCall.method.toHex() || '');521522      // >>> Note motion preimage >>>523      console.log('Note motion preimage.......');524      const encodedProposal = batchCall?.method.toHex() || '';525      const proposalHash = blake2AsHex(encodedProposal);526      console.log('Encoded proposal for batch utility after schedule is %s', encodedProposal);527      console.log('Encoded proposal hash for batch utility after schedule is %s', proposalHash);528      console.log('Encoded length %d', encodedProposal.length);529530      const tx1 = api.tx.democracy.notePreimage(encodedProposal);531      const events1 = await submitTransactionAsync(baltatharAccount, tx1);532      const result1 = getGenericResult(events1);533      expect(result1.success).to.be.true;534      console.log('Note motion preimage.......DONE');535      // <<< Note motion preimage <<<536537      // >>> Propose external motion through council >>>538      console.log('Propose external motion through council.......');539      const externalMotion = api.tx.democracy.externalProposeMajority(proposalHash);540      const tx2 = api.tx.councilCollective.propose(541        councilVotingThreshold,542        externalMotion,543        externalMotion.encodedLength,544      );545      const events2 = await submitTransactionAsync(baltatharAccount, tx2);546      const result2 = getGenericResult(events2);547      expect(result2.success).to.be.true;548549      const encodedMotion = externalMotion?.method.toHex() || '';550      const motionHash = blake2AsHex(encodedMotion);551      console.log('Motion hash is %s', motionHash);552553      const tx3 = api.tx.councilCollective.vote(motionHash, 0, true);554      {555        const events3 = await submitTransactionAsync(dorothyAccount, tx3);556        const result3 = getGenericResult(events3);557        expect(result3.success).to.be.true;558      }559      {560        const events3 = await submitTransactionAsync(baltatharAccount, tx3);561        const result3 = getGenericResult(events3);562        expect(result3.success).to.be.true;563      }564565      const tx4 = api.tx.councilCollective.close(motionHash, 0, 1_000_000_000, externalMotion.encodedLength);566      const events4 = await submitTransactionAsync(dorothyAccount, tx4);567      const result4 = getGenericResult(events4);568      expect(result4.success).to.be.true;569      console.log('Propose external motion through council.......DONE');570      // <<< Propose external motion through council <<<571572      // >>> Fast track proposal through technical committee >>>573      console.log('Fast track proposal through technical committee.......');574      const fastTrack = api.tx.democracy.fastTrack(proposalHash, votingPeriod, delayPeriod);575      const tx5 = api.tx.techCommitteeCollective.propose(576        technicalCommitteeThreshold,577        fastTrack,578        fastTrack.encodedLength,579      );580      const events5 = await submitTransactionAsync(alithAccount, tx5);581      const result5 = getGenericResult(events5);582      expect(result5.success).to.be.true;583584      const encodedFastTrack = fastTrack?.method.toHex() || '';585      const fastTrackHash = blake2AsHex(encodedFastTrack);586      console.log('FastTrack hash is %s', fastTrackHash);587588      const proposalIdx = Number(await api.query.techCommitteeCollective.proposalCount()) - 1;589      const tx6 = api.tx.techCommitteeCollective.vote(fastTrackHash, proposalIdx, true);590      {591        const events6 = await submitTransactionAsync(baltatharAccount, tx6);592        const result6 = getGenericResult(events6);593        expect(result6.success).to.be.true;594      }595      {596        const events6 = await submitTransactionAsync(alithAccount, tx6);597        const result6 = getGenericResult(events6);598        expect(result6.success).to.be.true;599      }600601      const tx7 = api.tx.techCommitteeCollective602        .close(fastTrackHash, proposalIdx, 1_000_000_000, fastTrack.encodedLength);603      const events7 = await submitTransactionAsync(baltatharAccount, tx7);604      const result7 = getGenericResult(events7);605      expect(result7.success).to.be.true;606      console.log('Fast track proposal through technical committee.......DONE');607      // <<< Fast track proposal through technical committee <<<608609      // >>> Referendum voting >>>610      console.log('Referendum voting.......');611      const tx8 = api.tx.democracy.vote(612        0,613        {Standard: {balance: 10_000_000_000_000_000_000n, vote: {aye: true, conviction: 1}}},614      );615      const events8 = await submitTransactionAsync(dorothyAccount, tx8);616      const result8 = getGenericResult(events8);617      expect(result8.success).to.be.true;618      console.log('Referendum voting.......DONE');619      // <<< Referendum voting <<<620621      // >>> Acquire Unique AssetId Info on Moonbeam >>>622      console.log('Acquire Unique AssetId Info on Moonbeam.......');623624      // Wait for the democracy execute625      // await waitNewBlocks(api, 5);626      await helper.wait.newBlocks(5);627628      assetId = (await api.query.assetManager.assetTypeId({629        XCM: sourceLocation,630      })).toString();631632      console.log('UNQ asset ID is %s', assetId);633      console.log('Acquire Unique AssetId Info on Moonbeam.......DONE');634      // >>> Acquire Unique AssetId Info on Moonbeam >>>635636      // >>> Sponsoring random Account >>>637      console.log('Sponsoring random Account.......');638      // const tx10 = api.tx.balances.transfer(randomAccountMoonbeam.address, 11_000_000_000_000_000_000n);639      // const events10 = await submitTransactionAsync(baltatharAccount, tx10);640      // const result10 = getGenericResult(events10);641      // expect(result10.success).to.be.true;642      await helper.balance.transferToSubstrate(baltatharAccount, randomAccountMoonbeam.address, 11_000_000_000_000_000_000n);643      console.log('Sponsoring random Account.......DONE');644      // <<< Sponsoring random Account <<<645646      [balanceGlmrTokenInit] = await getBalance(api, [randomAccountMoonbeam.address]);647    });648649    await usingPlaygrounds(async (helper) => {650      // const tx0 = api.tx.balances.transfer(randomAccountUnique.address, 10n * TRANSFER_AMOUNT);651      // const events0 = await submitTransactionAsync(uniqueAlice, tx0);652      // const result0 = getGenericResult(events0);653      // expect(result0.success).to.be.true;654      await helper.balance.transferToSubstrate(uniqueAlice, randomAccountUnique.address, 10n * TRANSFER_AMOUNT);655656      // [balanceUniqueTokenInit] = await getBalance(api, [randomAccountUnique.address]);657      balanceUniqueTokenInit = await helper.balance.getSubstrate(randomAccountUnique.address);658    });659  });660661  itSub('Should connect and send UNQ to Moonbeam', async ({helper}) => {662    const currencyId = {663      NativeAssetId: 'Here',664    };665    const dest = {666      V1: {667        parents: 1,668        interior: {669          X2: [670            {Parachain: MOONBEAM_CHAIN},671            {AccountKey20: {network: 'Any', key: randomAccountMoonbeam.address}},672          ],673        },674      },675    };676    const amount = TRANSFER_AMOUNT;677    const destWeight = 850000000;678679    // TODO680    const tx = helper.getApi().tx.xTokens.transfer(currencyId, amount, dest, destWeight);681    const events = await submitTransactionAsync(randomAccountUnique, tx);682    const result = getGenericResult(events);683    expect(result.success).to.be.true;684685    // [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccountUnique.address]);686    balanceUniqueTokenMiddle = await helper.balance.getSubstrate(randomAccountUnique.address);687    expect(balanceUniqueTokenMiddle < balanceUniqueTokenInit).to.be.true;688689    const transactionFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;690    console.log('[Unique -> Moonbeam] transaction fees on Unique: %s UNQ', bigIntToDecimals(transactionFees));691    expect(transactionFees > 0).to.be.true;692693    await usingPlaygrounds.atUrl(moonbeamUrl, async (helper) => {694      // await waitNewBlocks(api, 3);695      await helper.wait.newBlocks(3);696697      // [balanceGlmrTokenMiddle] = await getBalance(api, [randomAccountMoonbeam.address]);698      balanceGlmrTokenMiddle = await helper.balance.getSubstrate(randomAccountMoonbeam.address);699700      const glmrFees = balanceGlmrTokenInit - balanceGlmrTokenMiddle;701      console.log('[Unique -> Moonbeam] transaction fees on Moonbeam: %s GLMR', bigIntToDecimals(glmrFees));702      expect(glmrFees == 0n).to.be.true;703704      // TODO705      const unqRandomAccountAsset = (706        await helper.getApi().query.assets.account(assetId, randomAccountMoonbeam.address)707      ).toJSON()! as any;708709      balanceForeignUnqTokenMiddle = BigInt(unqRandomAccountAsset['balance']);710      const unqIncomeTransfer = balanceForeignUnqTokenMiddle - balanceForeignUnqTokenInit;711      console.log('[Unique -> Moonbeam] income %s UNQ', bigIntToDecimals(unqIncomeTransfer));712      expect(unqIncomeTransfer == TRANSFER_AMOUNT).to.be.true;713    });714  });715716  itSub('Should connect to Moonbeam and send UNQ back', async ({helper}) => {717    await usingPlaygrounds.atUrl(moonbeamUrl, async (helper) => {718      const asset = {719        V1: {720          id: {721            Concrete: {722              parents: 1,723              interior: {724                X1: {Parachain: UNIQUE_CHAIN},725              },726            },727          },728          fun: {729            Fungible: TRANSFER_AMOUNT,730          },731        },732      };733      const destination = {734        V1: {735          parents: 1,736          interior: {737            X2: [738              {Parachain: UNIQUE_CHAIN},739              {AccountId32: {network: 'Any', id: randomAccountUnique.addressRaw}},740            ],741          },742        },743      };744      const destWeight = 50000000;745746      // TODO747      const tx = helper.getApi().tx.xTokens.transferMultiasset(asset, destination, destWeight);748      const events = await submitTransactionAsync(randomAccountMoonbeam, tx);749      const result = getGenericResult(events);750      expect(result.success).to.be.true;751752      // [balanceGlmrTokenFinal] = await getBalance(api, [randomAccountMoonbeam.address]);753      balanceGlmrTokenFinal = await helper.balance.getSubstrate(randomAccountMoonbeam.address);754755      const glmrFees = balanceGlmrTokenMiddle - balanceGlmrTokenFinal;756      console.log('[Moonbeam -> Unique] transaction fees on Moonbeam: %s GLMR', bigIntToDecimals(glmrFees));757      expect(glmrFees > 0).to.be.true;758759      // TODO760      const unqRandomAccountAsset = (761        await helper.getApi().query.assets.account(assetId, randomAccountMoonbeam.address)762      ).toJSON()! as any;763764      expect(unqRandomAccountAsset).to.be.null;765766      balanceForeignUnqTokenFinal = 0n;767768      const unqOutcomeTransfer = balanceForeignUnqTokenMiddle - balanceForeignUnqTokenFinal;769      console.log('[Unique -> Moonbeam] outcome %s UNQ', bigIntToDecimals(unqOutcomeTransfer));770      expect(unqOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;771    });772773    // await waitNewBlocks(api, 3);774    await helper.wait.newBlocks(3);775776    // [balanceUniqueTokenFinal] = await getBalance(api, [randomAccountUnique.address]);777    balanceUniqueTokenFinal = await helper.balance.getSubstrate(randomAccountUnique.address);778    const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenMiddle;779    expect(actuallyDelivered > 0).to.be.true;780781    console.log('[Moonbeam -> Unique] actually delivered %s UNQ', bigIntToDecimals(actuallyDelivered));782783    const unqFees = TRANSFER_AMOUNT - actuallyDelivered;784    console.log('[Moonbeam -> Unique] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));785    expect(unqFees == 0n).to.be.true;786  });787});