git.delta.rocks / unique-network / refs/commits / b6fea42a7f33

difftreelog

Tests

Dev2022-08-30parent: #9b72a3a.patch.diff
in: master

4 files changed

modifiedtests/src/xcmTransferAcala.test.tsdiffbeforeafterboth
--- a/tests/src/xcmTransferAcala.test.ts
+++ b/tests/src/xcmTransferAcala.test.ts
@@ -37,20 +37,15 @@
   let alice: IKeyringPair;
   let randomAccount: IKeyringPair;
 
-  let actuallySent1: bigint;
-  let actuallySent2: bigint;
-
-  let balanceUnique1: bigint;
-  let balanceUnique2: bigint;
-  let balanceUnique3: bigint;
-  
-  let balanceAcalaUnq1: bigint;
-  let balanceAcalaUnq2: bigint;
-  let balanceAcalaUnq3: bigint;
-
-  let balanceAcalaAca1: bigint;
-  let balanceAcalaAca2: bigint;
-  let balanceAcalaAca3: bigint;
+  let balanceUniqueTokenBefore: bigint;
+  let balanceUniqueTokenAfter: bigint;
+  let balanceUniqueTokenFinal: bigint;
+  let balanceAcalaTokenBefore: bigint;
+  let balanceAcalaTokenAfter: bigint;
+  let balanceAcalaTokenFinal: bigint;
+  let balanceUniqueForeignTokenAfter: bigint;
+  let balanceUniqueForeignTokenBefore: bigint;
+  let balanceUniqueForeignTokenFinal: bigint;
 
   before(async () => {
     await usingApi(async (api, privateKeyWrapper) => {
@@ -93,10 +88,10 @@
         const result1 = getGenericResult(events1);
         expect(result1.success).to.be.true;
 
-        [balanceAcalaAca1] = await getBalance(api, [randomAccount.address]);
+        [balanceAcalaTokenBefore] = await getBalance(api, [randomAccount.address]);
         {
           const {free} = (await api.query.tokens.accounts(alice.addressRaw, {ForeignAsset: 0})).toJSON() as any;
-          balanceAcalaUnq1 = BigInt(free);
+          balanceUniqueForeignTokenBefore = BigInt(free);
         }
       },
       acalaApiOptions,
@@ -108,7 +103,7 @@
       const result0 = getGenericResult(events0);
       expect(result0.success).to.be.true;
 
-      [balanceUnique1] = await getBalance(api, [randomAccount.address]);
+      [balanceUniqueTokenBefore] = await getBalance(api, [randomAccount.address]);
     });
   });
 
@@ -165,12 +160,9 @@
       const result = getGenericResult(events);
       expect(result.success).to.be.true;
 
-      [balanceUnique2] = await getBalance(api, [randomAccount.address]);
+      [balanceUniqueTokenAfter] = await getBalance(api, [randomAccount.address]);
 
-      const transactionFees = balanceUnique1 - balanceUnique2 - TRANSFER_AMOUNT;
-      actuallySent1 = TRANSFER_AMOUNT;  // Why not TRANSFER_AMOUNT - transactionFees ???
-      console.log('Unique to Acala transaction fees on Unique: %s UNQ', transactionFees);
-      expect(transactionFees > 0).to.be.true;
+      expect((balanceUniqueTokenBefore - balanceUniqueTokenAfter) > 0n).to.be.true;
     });
 
     await usingApi(
@@ -178,13 +170,11 @@
         // todo do something about instant sealing, where there might not be any new blocks
         await waitNewBlocks(api, 3);
         const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
-        balanceAcalaUnq2 = BigInt(free);
-        expect(balanceAcalaUnq2 > balanceAcalaUnq1).to.be.true;
-
-        [balanceAcalaAca2] = await getBalance(api, [randomAccount.address]);
+        balanceUniqueForeignTokenAfter = BigInt(free);
 
-        const acaFees = balanceAcalaAca1 - balanceAcalaAca2;
-        const unqFees = actuallySent1 - balanceAcalaUnq2 + balanceAcalaUnq1;
+        [balanceAcalaTokenAfter] = await getBalance(api, [randomAccount.address]);
+        const acaFees = balanceAcalaTokenBefore - balanceAcalaTokenAfter;
+        const unqFees = balanceUniqueForeignTokenBefore - balanceUniqueForeignTokenAfter;
         console.log('Unique to Acala transaction fees on Acala: %s ACA', acaFees);
         console.log('Unique to Acala transaction fees on Acala: %s UNQ', unqFees);
         expect(acaFees == 0n).to.be.true;
@@ -227,15 +217,14 @@
         const result = getGenericResult(events);
         expect(result.success).to.be.true;
 
-        [balanceAcalaAca3] = await getBalance(api, [randomAccount.address]);
+        [balanceAcalaTokenFinal] = await getBalance(api, [randomAccount.address]);
         {
           const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
-          balanceAcalaUnq3 = BigInt(free);
+          balanceUniqueForeignTokenFinal = BigInt(free);
         }
 
-        const acaFees = balanceAcalaAca2 - balanceAcalaAca3;
-        const unqFees = balanceAcalaUnq2 - balanceAcalaUnq3 - amount;
-        actuallySent2 = amount;  // Why not amount - UNQFees ???
+        const acaFees = balanceAcalaTokenFinal - balanceAcalaTokenAfter;
+        const unqFees = balanceUniqueForeignTokenFinal - balanceUniqueForeignTokenAfter;
         console.log('Acala to Unique transaction fees on Acala: %s ACA', acaFees);
         console.log('Acala to Unique transaction fees on Acala: %s UNQ', unqFees);
         expect(acaFees > 0).to.be.true;
@@ -248,11 +237,11 @@
       // todo do something about instant sealing, where there might not be any new blocks
       await waitNewBlocks(api, 3);
 
-      [balanceUnique3] = await getBalance(api, [randomAccount.address]);
-      const actuallyDelivered = balanceUnique3 - balanceUnique2;
+      [balanceUniqueTokenFinal] = await getBalance(api, [randomAccount.address]);
+      const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenAfter;
       expect(actuallyDelivered > 0).to.be.true;
 
-      const unqFees = actuallySent2 - actuallyDelivered;
+      const unqFees = TRANSFER_AMOUNT - actuallyDelivered;
       console.log('Acala to Unique transaction fees on Unique: %s UNQ', unqFees);
       expect(unqFees > 0).to.be.true;
     });
deletedtests/src/xcmTransferKarura.test.tsdiffbeforeafterboth
--- a/tests/src/xcmTransferKarura.test.ts
+++ /dev/null
@@ -1,260 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// 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, {submitTransactionAsync} from './substrate/substrate-api';
-import {getGenericResult, generateKeyringPair} from './util/helpers';
-import waitNewBlocks from './substrate/wait-new-blocks';
-import getBalance from './substrate/get-balance';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-
-const UNIQUE_CHAIN = 5000;
-const KARURA_CHAIN = 2000;
-const KARURA_PORT = '9946';
-const TRANSFER_AMOUNT = 2000000000000000000000000n;
-
-describe('Integration test: Exchanging QTZ with Karura', () => {
-  let alice: IKeyringPair;
-  let randomAccount: IKeyringPair;
-
-  let actuallySent1: bigint;
-  let actuallySent2: bigint;
-
-  let balanceQuartz1: bigint;
-  let balanceQuartz2: bigint;
-  let balanceQuartz3: bigint;
-
-  let balanceKaruraQtz1: bigint;
-  let balanceKaruraQtz2: bigint;
-  let balanceKaruraQtz3: bigint;
-
-  let balanceKaruraKar1: bigint;
-  let balanceKaruraKar2: bigint;
-  let balanceKaruraKar3: bigint;
-
-  before(async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
-      alice = privateKeyWrapper('//Alice');
-      randomAccount = generateKeyringPair();
-    });
-
-    const karuraApiOptions: ApiOptions = {
-      provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT),
-    };
-
-    await usingApi(
-      async (api) => {
-        const destination = {
-          V0: {
-            X2: [
-              'Parent',
-              {
-                Parachain: UNIQUE_CHAIN,
-              },
-            ],
-          },
-        };
-
-        const metadata = {
-          name: 'QTZ',
-          symbol: 'QTZ',
-          decimals: 18,
-          minimalBalance: 1,
-        };
-
-        const tx = api.tx.assetRegistry.registerForeignAsset(destination, metadata);
-        const sudoTx = api.tx.sudo.sudo(tx as any);
-        const events = await submitTransactionAsync(alice, sudoTx);
-        const result = getGenericResult(events);
-        expect(result.success).to.be.true;
-
-        const tx1 = api.tx.balances.transfer(randomAccount.address, 10000000000000n);
-        const events1 = await submitTransactionAsync(alice, tx1);
-        const result1 = getGenericResult(events1);
-        expect(result1.success).to.be.true;
-
-        [balanceKaruraKar1] = await getBalance(api, [randomAccount.address]);
-        {
-          const {free} = (await api.query.tokens.accounts(alice.addressRaw, {ForeignAsset: 0})).toJSON() as any;
-          balanceKaruraQtz1 = BigInt(free);
-        }
-      },
-      karuraApiOptions,
-    );
-
-    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;
-
-      [balanceQuartz1] = await getBalance(api, [randomAccount.address]);
-    });
-  });
-
-  it('Should connect and send QTZ to Karura', async () => {
-
-    await usingApi(async (api) => {
-
-      const destination = {
-        V0: {
-          X2: [
-            'Parent',
-            {
-              Parachain: KARURA_CHAIN,
-            },
-          ],
-        },
-      };
-
-      const beneficiary = {
-        V0: {
-          X1: {
-            AccountId32: {
-              network: 'Any',
-              id: randomAccount.addressRaw,
-            },
-          },
-        },
-      };
-
-      const assets = {
-        V1: [
-          {
-            id: {
-              Concrete: {
-                parents: 0,
-                interior: 'Here',
-              },
-            },
-            fun: {
-              Fungible: TRANSFER_AMOUNT,
-            },
-          },
-        ],
-      };
-
-      const feeAssetItem = 0;
-
-      const weightLimit = {
-        Limited: 5000000000,
-      };
-
-      const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
-      const events = await submitTransactionAsync(randomAccount, tx);
-      const result = getGenericResult(events);
-      expect(result.success).to.be.true;
-
-      [balanceQuartz2] = await getBalance(api, [randomAccount.address]);
-
-      const transactionFees = balanceQuartz1 - balanceQuartz2 - TRANSFER_AMOUNT;
-      actuallySent1 = TRANSFER_AMOUNT;  // Why not TRANSFER_AMOUNT - transactionFees ???
-      console.log('Quartz to Karura transaction fees on Quartz: %s QTZ', transactionFees);
-      expect(transactionFees > 0).to.be.true;
-    });
-
-    await usingApi(
-      async (api) => {
-        // todo do something about instant sealing, where there might not be any new blocks
-        await waitNewBlocks(api, 3);
-        const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
-        balanceKaruraQtz2 = BigInt(free);
-        expect(balanceKaruraQtz2 > balanceKaruraQtz1).to.be.true;
-
-        [balanceKaruraKar2] = await getBalance(api, [randomAccount.address]);
-
-        const karFees = balanceKaruraKar1 - balanceKaruraKar2;
-        const qtzFees = actuallySent1 - balanceKaruraQtz2 + balanceKaruraQtz1;
-        console.log('Quartz to Karura transaction fees on Karura: %s KAR', karFees);
-        console.log('Quartz to Karura transaction fees on Karura: %s QTZ', qtzFees);
-        expect(karFees == 0n).to.be.true;
-        expect(qtzFees == 0n).to.be.true;
-      },
-      {provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT)},
-    );
-  });
-
-  it('Should connect to Karura and send QTZ back', async () => {
-
-    await usingApi(
-      async (api) => {
-        const destination = {
-          V1: {
-            parents: 1,
-            interior: {
-              X2: [
-                {Parachain: UNIQUE_CHAIN},
-                {
-                  AccountId32: {
-                    network: 'Any',
-                    id: randomAccount.addressRaw,
-                  },
-                },
-              ],
-            },
-          },
-        };
-
-        const id = {
-          ForeignAsset: 0,
-        };
-
-        const amount = TRANSFER_AMOUNT;
-        const destWeight = 50000000;
-
-        const tx = api.tx.xTokens.transfer(id, amount, destination, destWeight);
-        const events = await submitTransactionAsync(randomAccount, tx);
-        const result = getGenericResult(events);
-        expect(result.success).to.be.true;
-
-        [balanceKaruraKar3] = await getBalance(api, [randomAccount.address]);
-        {
-          const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
-          balanceKaruraQtz3 = BigInt(free);
-        }
-
-        const karFees = balanceKaruraKar2 - balanceKaruraKar3;
-        const qtzFees = balanceKaruraQtz2 - balanceKaruraQtz3 - amount;
-        actuallySent2 = amount;  // Why not amount - qtzFees ???
-        console.log('Karura to Quartz transaction fees on Karura: %s KAR', karFees);
-        console.log('Karura to Quartz transaction fees on Karura: %s QTZ', qtzFees);
-        expect(karFees > 0).to.be.true;
-        expect(qtzFees == 0n).to.be.true;
-      },
-      {provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT)},
-    );
-
-    await usingApi(async (api) => {
-      // todo do something about instant sealing, where there might not be any new blocks
-      await waitNewBlocks(api, 3);
-
-      [balanceQuartz3] = await getBalance(api, [randomAccount.address]);
-      const actuallyDelivered = balanceQuartz3 - balanceQuartz2;
-      expect(actuallyDelivered > 0).to.be.true;
-
-      const qtzFees = actuallySent2 - actuallyDelivered;
-      console.log('Karura to Quartz transaction fees on Quartz: %s QTZ', qtzFees);
-      expect(qtzFees > 0).to.be.true;
-    });
-  });
-});
\ No newline at end of file
modifiedtests/src/xcmTransferMoonbeam.test.tsdiffbeforeafterboth
before · tests/src/xcmTransferMoonbeam.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';1920import {Keyring, WsProvider} from '@polkadot/api';21import {ApiOptions} from '@polkadot/api/types';22import {IKeyringPair} from '@polkadot/types/types';23import usingApi, {submitTransactionAsync} from './substrate/substrate-api';24import {getGenericResult, generateKeyringPair} from './util/helpers';25import {MultiLocation} from '@polkadot/types/interfaces';26import {blake2AsHex} from '@polkadot/util-crypto';27import getBalance from './substrate/get-balance';28import waitNewBlocks from './substrate/wait-new-blocks';2930chai.use(chaiAsPromised);31const expect = chai.expect;3233const UNIQUE_CHAIN = 5000;34const MOONBEAM_CHAIN = 1000;35const UNIQUE_PORT = '9944';36const MOONBEAM_PORT = '9946';37const TRANSFER_AMOUNT = 2000000000000000000000000n;3839describe('Integration test: Exchanging UNQ with Moonbeam', () => {4041  // Unique constants42  let uniqueAlice: IKeyringPair;43  let uniqueAssetLocation;4445  let randomAccountUnique: IKeyringPair;46  let randomAccountMoonbeam: IKeyringPair;4748  // Moonbeam constants49  let assetId: Uint8Array;5051  const moonbeamKeyring = new Keyring({type: 'ethereum'});52  const alithPrivateKey = '0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133';53  const baltatharPrivateKey = '0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b';54  const dorothyPrivateKey = '0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68';5556  const alithAccount = moonbeamKeyring.addFromUri(alithPrivateKey, undefined, 'ethereum');57  const baltatharAccount = moonbeamKeyring.addFromUri(baltatharPrivateKey, undefined, 'ethereum');58  const dorothyAccount = moonbeamKeyring.addFromUri(dorothyPrivateKey, undefined, 'ethereum');5960  const councilVotingThreshold = 2;61  const technicalCommitteeThreshold = 2;62  const votingPeriod = 3;63  const delayPeriod = 0;6465  const uniqueAssetMetadata = {66    name: 'xcUnique',67    symbol: 'xcUNQ',68    decimals: 18,69    isFrozen: false,70    minimalBalance: 1,71  };7273  let actuallySent1: bigint;74  let actuallySent2: bigint;7576  let balanceUnique1: bigint;77  let balanceUnique2: bigint;78  let balanceUnique3: bigint;79  80  let balanceMoonbeamGlmr1: bigint;81  let balanceMoonbeamGlmr2: bigint;82  let balanceMoonbeamGlmr3: bigint;8384  before(async () => {85    await usingApi(async (api, privateKeyWrapper) => {86      uniqueAlice = privateKeyWrapper('//Alice');87      randomAccountUnique = generateKeyringPair();88      randomAccountMoonbeam = generateKeyringPair('ethereum');89    });9091    const moonbeamApiOptions: ApiOptions = {92      provider: new WsProvider('ws://127.0.0.1:' + MOONBEAM_PORT),93    };9495    await usingApi(96      async (api) => {9798        // >>> Sponsoring Dorothy >>>99        const tx0 = api.tx.balances.transfer(dorothyAccount.address, 11_000_000_000_000_000_000n);100        const events0 = await submitTransactionAsync(alithAccount, tx0);101        const result0 = getGenericResult(events0);102        expect(result0.success).to.be.true;103        // <<< Sponsoring Dorothy <<<104105        const sourceLocation: MultiLocation = api.createType(106          'MultiLocation',107          {108            parents: 1,109            interior: {X1: {Parachain: UNIQUE_CHAIN}},110          },111        );112113        assetId = api.registry.hash(sourceLocation.toU8a()).slice(0, 16).reverse();114        console.log('Internal asset ID is %s', assetId);115        uniqueAssetLocation = {XCM: sourceLocation};116        const existentialDeposit = 1;117        const isSufficient = true;118        const unitsPerSecond = '1';119        const numAssetsWeightHint = 0;120121        const registerTx = api.tx.assetManager.registerForeignAsset(122          uniqueAssetLocation,123          uniqueAssetMetadata,124          existentialDeposit,125          isSufficient,126        );127        console.log('Encoded proposal for registerAsset is %s', registerTx.method.toHex() || '');128129        const setUnitsTx = api.tx.assetManager.setAssetUnitsPerSecond(130          uniqueAssetLocation,131          unitsPerSecond,132          numAssetsWeightHint,133        );134        console.log('Encoded proposal for setAssetUnitsPerSecond is %s', setUnitsTx.method.toHex() || '');135136        const batchCall = api.tx.utility.batchAll([registerTx, setUnitsTx]);137        console.log('Encoded proposal for batchCall is %s', batchCall.method.toHex() || '');138139        // >>> Note motion preimage >>>140        const encodedProposal = batchCall?.method.toHex() || '';141        const proposalHash = blake2AsHex(encodedProposal);142        console.log('Encoded proposal for batch utility after schedule is %s', encodedProposal);143        console.log('Encoded proposal hash for batch utility after schedule is %s', proposalHash);144        console.log('Encoded length %d', encodedProposal.length);145146        const tx1 = api.tx.democracy.notePreimage(encodedProposal);147        const events1 = await submitTransactionAsync(baltatharAccount, tx1);148        const result1 = getGenericResult(events1);149        expect(result1.success).to.be.true;150        // <<< Note motion preimage <<<151152        // >>> Propose external motion through council >>>153        const externalMotion = api.tx.democracy.externalProposeMajority(proposalHash);154        const tx2 = api.tx.councilCollective.propose(155          councilVotingThreshold,156          externalMotion,157          externalMotion.encodedLength,158        );159        const events2 = await submitTransactionAsync(baltatharAccount, tx2);160        const result2 = getGenericResult(events2);161        expect(result2.success).to.be.true;162163        const encodedMotion = externalMotion?.method.toHex() || '';164        const motionHash = blake2AsHex(encodedMotion);165        console.log('Motion hash is %s', motionHash);166167        const tx3 = api.tx.councilCollective.vote(motionHash, 0, true);168        {169          const events3 = await submitTransactionAsync(dorothyAccount, tx3);170          const result3 = getGenericResult(events3);171          expect(result3.success).to.be.true;172        }173        {174          const events3 = await submitTransactionAsync(baltatharAccount, tx3);175          const result3 = getGenericResult(events3);176          expect(result3.success).to.be.true;177        }178179        const tx4 = api.tx.councilCollective.close(motionHash, 0, 1_000_000_000, externalMotion.encodedLength);180        const events4 = await submitTransactionAsync(dorothyAccount, tx4);181        const result4 = getGenericResult(events4);182        expect(result4.success).to.be.true;183        // <<< Propose external motion through council <<<184185        // >>> Fast track proposal through technical committee >>>186        const fastTrack = api.tx.democracy.fastTrack(proposalHash, votingPeriod, delayPeriod);187        const tx5 = api.tx.techCommitteeCollective.propose(188          technicalCommitteeThreshold,189          fastTrack,190          fastTrack.encodedLength,191        );192        const events5 = await submitTransactionAsync(alithAccount, tx5);193        const result5 = getGenericResult(events5);194        expect(result5.success).to.be.true;195196        const encodedFastTrack = fastTrack?.method.toHex() || '';197        const fastTrackHash = blake2AsHex(encodedFastTrack);198        console.log('FastTrack hash is %s', fastTrackHash);199200        const proposalIdx = Number(await api.query.techCommitteeCollective.proposalCount()) - 1;201        const tx6 = api.tx.techCommitteeCollective.vote(fastTrackHash, proposalIdx, true);202        {203          const events6 = await submitTransactionAsync(baltatharAccount, tx6);204          const result6 = getGenericResult(events6);205          expect(result6.success).to.be.true;206        }207        {208          const events6 = await submitTransactionAsync(alithAccount, tx6);209          const result6 = getGenericResult(events6);210          expect(result6.success).to.be.true;211        }212213        const tx7 = api.tx.techCommitteeCollective214          .close(fastTrackHash, proposalIdx, 1_000_000_000, fastTrack.encodedLength);215        const events7 = await submitTransactionAsync(baltatharAccount, tx7);216        const result7 = getGenericResult(events7);217        expect(result7.success).to.be.true;218        // <<< Fast track proposal through technical committee <<<219220        // >>> Referendum voting >>>221        const tx8 = api.tx.democracy.vote(222          0,223          {Standard: {balance: 10_000_000_000_000_000_000n, vote: {aye: true, conviction: 1}}},224        );225        const events8 = await submitTransactionAsync(dorothyAccount, tx8);226        const result8 = getGenericResult(events8);227        expect(result8.success).to.be.true;228        // <<< Referendum voting <<<229230        // >>> Sponsoring random Account >>>231        const tx9 = api.tx.balances.transfer(randomAccountMoonbeam.address, 11_000_000_000_000_000_000n);232        const events9 = await submitTransactionAsync(baltatharAccount, tx9);233        const result9 = getGenericResult(events9);234        expect(result9.success).to.be.true;235        // <<< Sponsoring random Account <<<236237        [balanceMoonbeamGlmr1] = await getBalance(api, [randomAccountMoonbeam.address]);238      },239      moonbeamApiOptions,240    );241242    await usingApi(async (api) => {243      const tx0 = api.tx.balances.transfer(randomAccountUnique.address, 10n * TRANSFER_AMOUNT);244      const events0 = await submitTransactionAsync(uniqueAlice, tx0);245      const result0 = getGenericResult(events0);246      expect(result0.success).to.be.true;247248      [balanceUnique1] = await getBalance(api, [randomAccountUnique.address]);249    });250  });251252  it('Should connect and send UNQ to Moonbeam', async () => {253    await usingApi(async (api) => {254      const currencyId = {255        NativeAssetId: 'Here',256      };257      const dest = {258        V1: {259          parents: 1,260          interior: {261            X2: [262              {Parachain: MOONBEAM_CHAIN},263              {AccountKey20: {network: 'Any', key: randomAccountMoonbeam.address}},264            ],265          },266        },267      };268      const amount = TRANSFER_AMOUNT;269      const destWeight = 50000000;270271      const tx = api.tx.xTokens.transfer(currencyId, amount, dest, destWeight);272      const events = await submitTransactionAsync(uniqueAlice, tx);273      const result = getGenericResult(events);274      expect(result.success).to.be.true;275276      [balanceUnique2] = await getBalance(api, [randomAccountUnique.address]);277      expect(balanceUnique2 < balanceUnique1).to.be.true;278279      const transactionFees = balanceUnique1 - balanceUnique2 - TRANSFER_AMOUNT;280      actuallySent1 = TRANSFER_AMOUNT;  // Why not TRANSFER_AMOUNT - transactionFees ???281      console.log('Unique to Moonbeam transaction fees on Unique: %s UNQ', transactionFees);282      expect(transactionFees > 0).to.be.true;283    });284285    await usingApi(286      async (api) => {287        // todo do something about instant sealing, where there might not be any new blocks288        await waitNewBlocks(api, 3);289290        [balanceMoonbeamGlmr2] = await getBalance(api, [randomAccountMoonbeam.address]);291292        const glmrFees = balanceMoonbeamGlmr1 - balanceMoonbeamGlmr2;293        console.log('Unique to Moonbeam transaction fees on Moonbeam: %s GLMR', glmrFees);294        expect(glmrFees == 0n).to.be.true;295      },296      {provider: new WsProvider('ws://127.0.0.1:' + MOONBEAM_PORT)},297    );298  });299300  it('Should connect to Moonbeam and send UNQ back', async () => {301    await usingApi(302      async (api) => {303        const amount = TRANSFER_AMOUNT / 2n;304        const asset = {305          V1: {306            id: {307              Concrete: {308                parents: 1,309                interior: {310                  X1: {Parachain: UNIQUE_CHAIN},311                },312              },313            },314            fun: {315              Fungible: amount,316            },317          },318        };319        const destination = {320          V1: {321            parents: 1,322            interior: {323              X2: [324                {Parachain: UNIQUE_CHAIN},325                {AccountId32: {network: 'Any', id: randomAccountUnique.addressRaw}},326              ],327            },328          },329        };330        const destWeight = 50000000;331332        const tx = api.tx.xTokens.transferMultiasset(asset, destination, destWeight);333        const events = await submitTransactionAsync(randomAccountMoonbeam, tx);334        const result = getGenericResult(events);335        expect(result.success).to.be.true;336337        [balanceMoonbeamGlmr3] = await getBalance(api, [randomAccountMoonbeam.address]);338339        const glmrFees = balanceMoonbeamGlmr2 - balanceMoonbeamGlmr3;340        actuallySent2 = amount;341        console.log('Moonbeam to Unique transaction fees on Moonbeam: %s GLMR', glmrFees);342        expect(glmrFees > 0).to.be.true;343      },344      {provider: new WsProvider('ws://127.0.0.1:' + MOONBEAM_PORT)},345    );346347    await usingApi(async (api) => {348      // todo do something about instant sealing, where there might not be any new blocks349      await waitNewBlocks(api, 3);350351      [balanceUnique3] = await getBalance(api, [randomAccountUnique.address]);352      const actuallyDelivered = balanceUnique3 - balanceUnique2;353      expect(actuallyDelivered > 0).to.be.true;354355      const unqFees = actuallySent2 - actuallyDelivered;356      console.log('Moonbeam to Unique transaction fees on Unique: %s UNQ', unqFees);357      expect(unqFees > 0).to.be.true;358    });359  });360});
after · tests/src/xcmTransferMoonbeam.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';1920import {Keyring, WsProvider} from '@polkadot/api';21import {ApiOptions} from '@polkadot/api/types';22import {IKeyringPair} from '@polkadot/types/types';23import usingApi, {submitTransactionAsync} from './substrate/substrate-api';24import {getGenericResult, generateKeyringPair} from './util/helpers';25import {MultiLocation} from '@polkadot/types/interfaces';26import {blake2AsHex} from '@polkadot/util-crypto';27import getBalance from './substrate/get-balance';28import waitNewBlocks from './substrate/wait-new-blocks';2930chai.use(chaiAsPromised);31const expect = chai.expect;3233const UNIQUE_CHAIN = 5000;34const MOONBEAM_CHAIN = 1000;35const UNIQUE_PORT = '9944';36const MOONBEAM_PORT = '9946';37const TRANSFER_AMOUNT = 2000000000000000000000000n;3839describe('Integration test: Exchanging UNQ with Moonbeam', () => {4041  // Unique constants42  let uniqueAlice: IKeyringPair;43  let uniqueAssetLocation;4445  let randomAccountUnique: IKeyringPair;46  let randomAccountMoonbeam: IKeyringPair;4748  // Moonbeam constants49  let assetId: Uint8Array;5051  const moonbeamKeyring = new Keyring({type: 'ethereum'});52  const alithPrivateKey = '0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133';53  const baltatharPrivateKey = '0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b';54  const dorothyPrivateKey = '0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68';5556  const alithAccount = moonbeamKeyring.addFromUri(alithPrivateKey, undefined, 'ethereum');57  const baltatharAccount = moonbeamKeyring.addFromUri(baltatharPrivateKey, undefined, 'ethereum');58  const dorothyAccount = moonbeamKeyring.addFromUri(dorothyPrivateKey, undefined, 'ethereum');5960  const councilVotingThreshold = 2;61  const technicalCommitteeThreshold = 2;62  const votingPeriod = 3;63  const delayPeriod = 0;6465  const uniqueAssetMetadata = {66    name: 'xcUnique',67    symbol: 'xcUNQ',68    decimals: 18,69    isFrozen: false,70    minimalBalance: 1,71  };7273  // let actuallySent1: bigint;74  // let actuallySent2: bigint;7576  // let balanceUnique1: bigint;77  // let balanceUnique2: bigint;78  // let balanceUnique3: bigint;79  80  // let balanceMoonbeamGlmr1: bigint;81  // let balanceMoonbeamGlmr2: bigint;82  // let balanceMoonbeamGlmr3: bigint;8384  let balanceUniqueTokenBefore: bigint;85  let balanceUniqueTokenAfter: bigint;86  let balanceUniqueTokenFinal: bigint;87  let balanceGlmrTokenBefore: bigint;88  let balanceGlmrTokenAfter: bigint;89  let balanceGlmrTokenFinal: bigint;9091  before(async () => {92    await usingApi(async (api, privateKeyWrapper) => {93      uniqueAlice = privateKeyWrapper('//Alice');94      randomAccountUnique = generateKeyringPair();95      randomAccountMoonbeam = generateKeyringPair('ethereum');96    });9798    const moonbeamApiOptions: ApiOptions = {99      provider: new WsProvider('ws://127.0.0.1:' + MOONBEAM_PORT),100    };101102    await usingApi(103      async (api) => {104105        // >>> Sponsoring Dorothy >>>106        const tx0 = api.tx.balances.transfer(dorothyAccount.address, 11_000_000_000_000_000_000n);107        const events0 = await submitTransactionAsync(alithAccount, tx0);108        const result0 = getGenericResult(events0);109        expect(result0.success).to.be.true;110        // <<< Sponsoring Dorothy <<<111112        const sourceLocation: MultiLocation = api.createType(113          'MultiLocation',114          {115            parents: 1,116            interior: {X1: {Parachain: UNIQUE_CHAIN}},117          },118        );119120        assetId = api.registry.hash(sourceLocation.toU8a()).slice(0, 16).reverse();121        console.log('Internal asset ID is %s', assetId);122        uniqueAssetLocation = {XCM: sourceLocation};123        const existentialDeposit = 1;124        const isSufficient = true;125        const unitsPerSecond = '1';126        const numAssetsWeightHint = 0;127128        const registerTx = api.tx.assetManager.registerForeignAsset(129          uniqueAssetLocation,130          uniqueAssetMetadata,131          existentialDeposit,132          isSufficient,133        );134        console.log('Encoded proposal for registerAsset is %s', registerTx.method.toHex() || '');135136        const setUnitsTx = api.tx.assetManager.setAssetUnitsPerSecond(137          uniqueAssetLocation,138          unitsPerSecond,139          numAssetsWeightHint,140        );141        console.log('Encoded proposal for setAssetUnitsPerSecond is %s', setUnitsTx.method.toHex() || '');142143        const batchCall = api.tx.utility.batchAll([registerTx, setUnitsTx]);144        console.log('Encoded proposal for batchCall is %s', batchCall.method.toHex() || '');145146        // >>> Note motion preimage >>>147        const encodedProposal = batchCall?.method.toHex() || '';148        const proposalHash = blake2AsHex(encodedProposal);149        console.log('Encoded proposal for batch utility after schedule is %s', encodedProposal);150        console.log('Encoded proposal hash for batch utility after schedule is %s', proposalHash);151        console.log('Encoded length %d', encodedProposal.length);152153        const tx1 = api.tx.democracy.notePreimage(encodedProposal);154        const events1 = await submitTransactionAsync(baltatharAccount, tx1);155        const result1 = getGenericResult(events1);156        expect(result1.success).to.be.true;157        // <<< Note motion preimage <<<158159        // >>> Propose external motion through council >>>160        const externalMotion = api.tx.democracy.externalProposeMajority(proposalHash);161        const tx2 = api.tx.councilCollective.propose(162          councilVotingThreshold,163          externalMotion,164          externalMotion.encodedLength,165        );166        const events2 = await submitTransactionAsync(baltatharAccount, tx2);167        const result2 = getGenericResult(events2);168        expect(result2.success).to.be.true;169170        const encodedMotion = externalMotion?.method.toHex() || '';171        const motionHash = blake2AsHex(encodedMotion);172        console.log('Motion hash is %s', motionHash);173174        const tx3 = api.tx.councilCollective.vote(motionHash, 0, true);175        {176          const events3 = await submitTransactionAsync(dorothyAccount, tx3);177          const result3 = getGenericResult(events3);178          expect(result3.success).to.be.true;179        }180        {181          const events3 = await submitTransactionAsync(baltatharAccount, tx3);182          const result3 = getGenericResult(events3);183          expect(result3.success).to.be.true;184        }185186        const tx4 = api.tx.councilCollective.close(motionHash, 0, 1_000_000_000, externalMotion.encodedLength);187        const events4 = await submitTransactionAsync(dorothyAccount, tx4);188        const result4 = getGenericResult(events4);189        expect(result4.success).to.be.true;190        // <<< Propose external motion through council <<<191192        // >>> Fast track proposal through technical committee >>>193        const fastTrack = api.tx.democracy.fastTrack(proposalHash, votingPeriod, delayPeriod);194        const tx5 = api.tx.techCommitteeCollective.propose(195          technicalCommitteeThreshold,196          fastTrack,197          fastTrack.encodedLength,198        );199        const events5 = await submitTransactionAsync(alithAccount, tx5);200        const result5 = getGenericResult(events5);201        expect(result5.success).to.be.true;202203        const encodedFastTrack = fastTrack?.method.toHex() || '';204        const fastTrackHash = blake2AsHex(encodedFastTrack);205        console.log('FastTrack hash is %s', fastTrackHash);206207        const proposalIdx = Number(await api.query.techCommitteeCollective.proposalCount()) - 1;208        const tx6 = api.tx.techCommitteeCollective.vote(fastTrackHash, proposalIdx, true);209        {210          const events6 = await submitTransactionAsync(baltatharAccount, tx6);211          const result6 = getGenericResult(events6);212          expect(result6.success).to.be.true;213        }214        {215          const events6 = await submitTransactionAsync(alithAccount, tx6);216          const result6 = getGenericResult(events6);217          expect(result6.success).to.be.true;218        }219220        const tx7 = api.tx.techCommitteeCollective221          .close(fastTrackHash, proposalIdx, 1_000_000_000, fastTrack.encodedLength);222        const events7 = await submitTransactionAsync(baltatharAccount, tx7);223        const result7 = getGenericResult(events7);224        expect(result7.success).to.be.true;225        // <<< Fast track proposal through technical committee <<<226227        // >>> Referendum voting >>>228        const tx8 = api.tx.democracy.vote(229          0,230          {Standard: {balance: 10_000_000_000_000_000_000n, vote: {aye: true, conviction: 1}}},231        );232        const events8 = await submitTransactionAsync(dorothyAccount, tx8);233        const result8 = getGenericResult(events8);234        expect(result8.success).to.be.true;235        // <<< Referendum voting <<<236237        // >>> Sponsoring random Account >>>238        const tx9 = api.tx.balances.transfer(randomAccountMoonbeam.address, 11_000_000_000_000_000_000n);239        const events9 = await submitTransactionAsync(baltatharAccount, tx9);240        const result9 = getGenericResult(events9);241        expect(result9.success).to.be.true;242        // <<< Sponsoring random Account <<<243244        [balanceGlmrTokenBefore] = await getBalance(api, [randomAccountMoonbeam.address]);245      },246      moonbeamApiOptions,247    );248249    await usingApi(async (api) => {250      const tx0 = api.tx.balances.transfer(randomAccountUnique.address, 10n * TRANSFER_AMOUNT);251      const events0 = await submitTransactionAsync(uniqueAlice, tx0);252      const result0 = getGenericResult(events0);253      expect(result0.success).to.be.true;254255      [balanceUniqueTokenBefore] = await getBalance(api, [randomAccountUnique.address]);256    });257  });258259  it('Should connect and send UNQ to Moonbeam', async () => {260    await usingApi(async (api) => {261      const currencyId = {262        NativeAssetId: 'Here',263      };264      const dest = {265        V1: {266          parents: 1,267          interior: {268            X2: [269              {Parachain: MOONBEAM_CHAIN},270              {AccountKey20: {network: 'Any', key: randomAccountMoonbeam.address}},271            ],272          },273        },274      };275      const amount = TRANSFER_AMOUNT;276      const destWeight = 50000000;277278      const tx = api.tx.xTokens.transfer(currencyId, amount, dest, destWeight);279      const events = await submitTransactionAsync(uniqueAlice, tx);280      const result = getGenericResult(events);281      expect(result.success).to.be.true;282283      [balanceUniqueTokenAfter] = await getBalance(api, [randomAccountUnique.address]);284      expect(balanceUniqueTokenAfter < balanceUniqueTokenBefore).to.be.true;285286      const transactionFees = balanceUniqueTokenBefore - balanceUniqueTokenAfter - TRANSFER_AMOUNT;287      console.log('Unique to Moonbeam transaction fees on Unique: %s UNQ', transactionFees);288      expect(transactionFees > 0).to.be.true;289    });290291    await usingApi(292      async (api) => {293        // todo do something about instant sealing, where there might not be any new blocks294        await waitNewBlocks(api, 3);295296        [balanceGlmrTokenAfter] = await getBalance(api, [randomAccountMoonbeam.address]);297298        const glmrFees = balanceGlmrTokenBefore - balanceGlmrTokenAfter;299        console.log('Unique to Moonbeam transaction fees on Moonbeam: %s GLMR', glmrFees);300        expect(glmrFees == 0n).to.be.true;301      },302      {provider: new WsProvider('ws://127.0.0.1:' + MOONBEAM_PORT)},303    );304  });305306  it('Should connect to Moonbeam and send UNQ back', async () => {307    await usingApi(308      async (api) => {309        const amount = TRANSFER_AMOUNT / 2n;310        const asset = {311          V1: {312            id: {313              Concrete: {314                parents: 1,315                interior: {316                  X1: {Parachain: UNIQUE_CHAIN},317                },318              },319            },320            fun: {321              Fungible: amount,322            },323          },324        };325        const destination = {326          V1: {327            parents: 1,328            interior: {329              X2: [330                {Parachain: UNIQUE_CHAIN},331                {AccountId32: {network: 'Any', id: randomAccountUnique.addressRaw}},332              ],333            },334          },335        };336        const destWeight = 50000000;337338        const tx = api.tx.xTokens.transferMultiasset(asset, destination, destWeight);339        const events = await submitTransactionAsync(randomAccountMoonbeam, tx);340        const result = getGenericResult(events);341        expect(result.success).to.be.true;342343        [balanceGlmrTokenFinal] = await getBalance(api, [randomAccountMoonbeam.address]);344345        const glmrFees = balanceGlmrTokenAfter - balanceGlmrTokenFinal;346        console.log('Moonbeam to Unique transaction fees on Moonbeam: %s GLMR', glmrFees);347        expect(glmrFees > 0).to.be.true;348      },349      {provider: new WsProvider('ws://127.0.0.1:' + MOONBEAM_PORT)},350    );351352    await usingApi(async (api) => {353      // todo do something about instant sealing, where there might not be any new blocks354      await waitNewBlocks(api, 3);355356      [balanceUniqueTokenFinal] = await getBalance(api, [randomAccountUnique.address]);357      const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenAfter;358      expect(actuallyDelivered > 0).to.be.true;359360      const unqFees = TRANSFER_AMOUNT - actuallyDelivered;361      console.log('Moonbeam to Unique transaction fees on Unique: %s UNQ', unqFees);362      expect(unqFees > 0).to.be.true;363    });364  });365});
deletedtests/src/xcmTransferMoonriver.test.tsdiffbeforeafterboth
--- a/tests/src/xcmTransferMoonriver.test.ts
+++ /dev/null
@@ -1,360 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// 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 {Keyring, WsProvider} from '@polkadot/api';
-import {ApiOptions} from '@polkadot/api/types';
-import {IKeyringPair} from '@polkadot/types/types';
-import usingApi, {submitTransactionAsync} from './substrate/substrate-api';
-import {getGenericResult, generateKeyringPair} from './util/helpers';
-import {MultiLocation} from '@polkadot/types/interfaces';
-import {blake2AsHex} from '@polkadot/util-crypto';
-import getBalance from './substrate/get-balance';
-import waitNewBlocks from './substrate/wait-new-blocks';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-
-const QUARTZ_CHAIN = 5000;
-const MOONRIVER_CHAIN = 1000;
-const QUARTZ_PORT = '9944';
-const MOONRIVER_PORT = '9946';
-const TRANSFER_AMOUNT = 2000000000000000000000000n;
-
-describe('Integration test: Exchanging QTZ with Moonriver', () => {
-
-  // Unique constants
-  let quartzAlice: IKeyringPair;
-  let quartzAssetLocation;
-
-  let randomAccountQuartz: IKeyringPair;
-  let randomAccountMoonriver: IKeyringPair;
-
-  // Moonriver constants
-  let assetId: Uint8Array;
-
-  const moonriverKeyring = new Keyring({type: 'ethereum'});
-  const alithPrivateKey = '0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133';
-  const baltatharPrivateKey = '0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b';
-  const dorothyPrivateKey = '0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68';
-
-  const alithAccount = moonriverKeyring.addFromUri(alithPrivateKey, undefined, 'ethereum');
-  const baltatharAccount = moonriverKeyring.addFromUri(baltatharPrivateKey, undefined, 'ethereum');
-  const dorothyAccount = moonriverKeyring.addFromUri(dorothyPrivateKey, undefined, 'ethereum');
-
-  const councilVotingThreshold = 2;
-  const technicalCommitteeThreshold = 2;
-  const votingPeriod = 3;
-  const delayPeriod = 0;
-
-  const uniqueAssetMetadata = {
-    name: 'xcQuartz',
-    symbol: 'xcQTZ',
-    decimals: 18,
-    isFrozen: false,
-    minimalBalance: 1,
-  };
-
-  let actuallySent1: bigint;
-  let actuallySent2: bigint;
-
-  let balanceQuartz1: bigint;
-  let balanceQuartz2: bigint;
-  let balanceQuartz3: bigint;
-  
-  let balanceMoonriverMovr1: bigint;
-  let balanceMoonriverMovr2: bigint;
-  let balanceMoonriverMovr3: bigint;
-
-  before(async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
-      quartzAlice = privateKeyWrapper('//Alice');
-      randomAccountQuartz = generateKeyringPair();
-      randomAccountMoonriver = generateKeyringPair('ethereum');
-    });
-
-    const moonriverApiOptions: ApiOptions = {
-      provider: new WsProvider('ws://127.0.0.1:' + MOONRIVER_PORT),
-    };
-
-    await usingApi(
-      async (api) => {
-
-        // >>> 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;
-        // <<< Sponsoring Dorothy <<<
-
-        const sourceLocation: MultiLocation = api.createType(
-          'MultiLocation',
-          {
-            parents: 1,
-            interior: {X1: {Parachain: QUARTZ_CHAIN}},
-          },
-        );
-
-        assetId = api.registry.hash(sourceLocation.toU8a()).slice(0, 16).reverse();
-        console.log('Internal asset ID is %s', assetId);
-        quartzAssetLocation = {XCM: sourceLocation};
-        const existentialDeposit = 1;
-        const isSufficient = true;
-        const unitsPerSecond = '1';
-        const numAssetsWeightHint = 0;
-
-        const registerTx = api.tx.assetManager.registerForeignAsset(
-          quartzAssetLocation,
-          uniqueAssetMetadata,
-          existentialDeposit,
-          isSufficient,
-        );
-        console.log('Encoded proposal for registerAsset is %s', registerTx.method.toHex() || '');
-
-        const setUnitsTx = api.tx.assetManager.setAssetUnitsPerSecond(
-          quartzAssetLocation,
-          unitsPerSecond,
-          numAssetsWeightHint,
-        );
-        console.log('Encoded proposal for setAssetUnitsPerSecond is %s', setUnitsTx.method.toHex() || '');
-
-        const batchCall = api.tx.utility.batchAll([registerTx, setUnitsTx]);
-        console.log('Encoded proposal for batchCall is %s', batchCall.method.toHex() || '');
-
-        // >>> 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 tx1 = api.tx.democracy.notePreimage(encodedProposal);
-        const events1 = await submitTransactionAsync(baltatharAccount, tx1);
-        const result1 = getGenericResult(events1);
-        expect(result1.success).to.be.true;
-        // <<< Note motion preimage <<<
-
-        // >>> 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 encodedMotion = externalMotion?.method.toHex() || '';
-        const motionHash = blake2AsHex(encodedMotion);
-        console.log('Motion hash is %s', motionHash);
-
-        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 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;
-        // <<< Propose external motion through council <<<
-
-        // >>> 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 encodedFastTrack = fastTrack?.method.toHex() || '';
-        const fastTrackHash = blake2AsHex(encodedFastTrack);
-        console.log('FastTrack hash is %s', fastTrackHash);
-
-        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 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;
-        // <<< Fast track proposal through technical committee <<<
-
-        // >>> 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;
-        // <<< Referendum voting <<<
-
-        // >>> Sponsoring random Account >>>
-        const tx9 = api.tx.balances.transfer(randomAccountMoonriver.address, 11_000_000_000_000_000_000n);
-        const events9 = await submitTransactionAsync(baltatharAccount, tx9);
-        const result9 = getGenericResult(events9);
-        expect(result9.success).to.be.true;
-        // <<< Sponsoring random Account <<<
-
-        [balanceMoonriverMovr1] = await getBalance(api, [randomAccountMoonriver.address]);
-      },
-      moonriverApiOptions,
-    );
-
-    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;
-
-      [balanceQuartz1] = await getBalance(api, [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}},
-            ],
-          },
-        },
-      };
-      const amount = TRANSFER_AMOUNT;
-      const destWeight = 50000000;
-
-      const tx = api.tx.xTokens.transfer(currencyId, amount, dest, destWeight);
-      const events = await submitTransactionAsync(quartzAlice, tx);
-      const result = getGenericResult(events);
-      expect(result.success).to.be.true;
-
-      [balanceQuartz2] = await getBalance(api, [randomAccountQuartz.address]);
-      expect(balanceQuartz2 < balanceQuartz1).to.be.true;
-
-      const transactionFees = balanceQuartz1 - balanceQuartz2 - TRANSFER_AMOUNT;
-      actuallySent1 = TRANSFER_AMOUNT;  // Why not TRANSFER_AMOUNT - transactionFees ???
-      console.log('Quartz to Moonriver transaction fees on Quartz: %s QTZ', transactionFees);
-      expect(transactionFees > 0).to.be.true;
-    });
-
-    await usingApi(
-      async (api) => {
-        // todo do something about instant sealing, where there might not be any new blocks
-        await waitNewBlocks(api, 3);
-
-        [balanceMoonriverMovr2] = await getBalance(api, [randomAccountMoonriver.address]);
-
-        const movrFees = balanceMoonriverMovr1 - balanceMoonriverMovr2;
-        console.log('Quartz to Moonriver transaction fees on Moonriver: %s MOVR', movrFees);
-        expect(movrFees == 0n).to.be.true;
-      },
-      {provider: new WsProvider('ws://127.0.0.1:' + MOONRIVER_PORT)},
-    );
-  });
-
-  it('Should connect to Moonriver and send QTZ back', async () => {
-    await usingApi(
-      async (api) => {
-        const amount = TRANSFER_AMOUNT / 2n;
-        const asset = {
-          V1: {
-            id: {
-              Concrete: {
-                parents: 1,
-                interior: {
-                  X1: {Parachain: QUARTZ_CHAIN},
-                },
-              },
-            },
-            fun: {
-              Fungible: amount,
-            },
-          },
-        };
-        const destination = {
-          V1: {
-            parents: 1,
-            interior: {
-              X2: [
-                {Parachain: QUARTZ_CHAIN},
-                {AccountId32: {network: 'Any', id: randomAccountQuartz.addressRaw}},
-              ],
-            },
-          },
-        };
-        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;
-
-        [balanceMoonriverMovr3] = await getBalance(api, [randomAccountMoonriver.address]);
-
-        const movrFees = balanceMoonriverMovr2 - balanceMoonriverMovr3;
-        actuallySent2 = amount;
-        console.log('Moonriver to Quartz transaction fees on Moonriver: %s MOVR', movrFees);
-        expect(movrFees > 0).to.be.true;
-      },
-      {provider: new WsProvider('ws://127.0.0.1:' + MOONRIVER_PORT)},
-    );
-
-    await usingApi(async (api) => {
-      // todo do something about instant sealing, where there might not be any new blocks
-      await waitNewBlocks(api, 3);
-
-      [balanceQuartz3] = await getBalance(api, [randomAccountQuartz.address]);
-      const actuallyDelivered = balanceQuartz3 - balanceQuartz2;
-      expect(actuallyDelivered > 0).to.be.true;
-
-      const qtzFees = actuallySent2 - actuallyDelivered;
-      console.log('Moonriver to Quartz transaction fees on Quartz: %s QTZ', qtzFees);
-      expect(qtzFees > 0).to.be.true;
-    });
-  });
-});