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
--- a/tests/src/xcmTransferMoonbeam.test.ts
+++ b/tests/src/xcmTransferMoonbeam.test.ts
@@ -70,16 +70,23 @@
     minimalBalance: 1,
   };
 
-  let actuallySent1: bigint;
-  let actuallySent2: bigint;
+  // let actuallySent1: bigint;
+  // let actuallySent2: bigint;
 
-  let balanceUnique1: bigint;
-  let balanceUnique2: bigint;
-  let balanceUnique3: bigint;
+  // let balanceUnique1: bigint;
+  // let balanceUnique2: bigint;
+  // let balanceUnique3: bigint;
   
-  let balanceMoonbeamGlmr1: bigint;
-  let balanceMoonbeamGlmr2: bigint;
-  let balanceMoonbeamGlmr3: bigint;
+  // let balanceMoonbeamGlmr1: bigint;
+  // let balanceMoonbeamGlmr2: bigint;
+  // let balanceMoonbeamGlmr3: bigint;
+
+  let balanceUniqueTokenBefore: bigint;
+  let balanceUniqueTokenAfter: bigint;
+  let balanceUniqueTokenFinal: bigint;
+  let balanceGlmrTokenBefore: bigint;
+  let balanceGlmrTokenAfter: bigint;
+  let balanceGlmrTokenFinal: bigint;
 
   before(async () => {
     await usingApi(async (api, privateKeyWrapper) => {
@@ -234,7 +241,7 @@
         expect(result9.success).to.be.true;
         // <<< Sponsoring random Account <<<
 
-        [balanceMoonbeamGlmr1] = await getBalance(api, [randomAccountMoonbeam.address]);
+        [balanceGlmrTokenBefore] = await getBalance(api, [randomAccountMoonbeam.address]);
       },
       moonbeamApiOptions,
     );
@@ -245,7 +252,7 @@
       const result0 = getGenericResult(events0);
       expect(result0.success).to.be.true;
 
-      [balanceUnique1] = await getBalance(api, [randomAccountUnique.address]);
+      [balanceUniqueTokenBefore] = await getBalance(api, [randomAccountUnique.address]);
     });
   });
 
@@ -273,11 +280,10 @@
       const result = getGenericResult(events);
       expect(result.success).to.be.true;
 
-      [balanceUnique2] = await getBalance(api, [randomAccountUnique.address]);
-      expect(balanceUnique2 < balanceUnique1).to.be.true;
+      [balanceUniqueTokenAfter] = await getBalance(api, [randomAccountUnique.address]);
+      expect(balanceUniqueTokenAfter < balanceUniqueTokenBefore).to.be.true;
 
-      const transactionFees = balanceUnique1 - balanceUnique2 - TRANSFER_AMOUNT;
-      actuallySent1 = TRANSFER_AMOUNT;  // Why not TRANSFER_AMOUNT - transactionFees ???
+      const transactionFees = balanceUniqueTokenBefore - balanceUniqueTokenAfter - TRANSFER_AMOUNT;
       console.log('Unique to Moonbeam transaction fees on Unique: %s UNQ', transactionFees);
       expect(transactionFees > 0).to.be.true;
     });
@@ -287,9 +293,9 @@
         // todo do something about instant sealing, where there might not be any new blocks
         await waitNewBlocks(api, 3);
 
-        [balanceMoonbeamGlmr2] = await getBalance(api, [randomAccountMoonbeam.address]);
+        [balanceGlmrTokenAfter] = await getBalance(api, [randomAccountMoonbeam.address]);
 
-        const glmrFees = balanceMoonbeamGlmr1 - balanceMoonbeamGlmr2;
+        const glmrFees = balanceGlmrTokenBefore - balanceGlmrTokenAfter;
         console.log('Unique to Moonbeam transaction fees on Moonbeam: %s GLMR', glmrFees);
         expect(glmrFees == 0n).to.be.true;
       },
@@ -334,10 +340,9 @@
         const result = getGenericResult(events);
         expect(result.success).to.be.true;
 
-        [balanceMoonbeamGlmr3] = await getBalance(api, [randomAccountMoonbeam.address]);
+        [balanceGlmrTokenFinal] = await getBalance(api, [randomAccountMoonbeam.address]);
 
-        const glmrFees = balanceMoonbeamGlmr2 - balanceMoonbeamGlmr3;
-        actuallySent2 = amount;
+        const glmrFees = balanceGlmrTokenAfter - balanceGlmrTokenFinal;
         console.log('Moonbeam to Unique transaction fees on Moonbeam: %s GLMR', glmrFees);
         expect(glmrFees > 0).to.be.true;
       },
@@ -348,11 +353,11 @@
       // todo do something about instant sealing, where there might not be any new blocks
       await waitNewBlocks(api, 3);
 
-      [balanceUnique3] = await getBalance(api, [randomAccountUnique.address]);
-      const actuallyDelivered = balanceUnique3 - balanceUnique2;
+      [balanceUniqueTokenFinal] = await getBalance(api, [randomAccountUnique.address]);
+      const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenAfter;
       expect(actuallyDelivered > 0).to.be.true;
 
-      const unqFees = actuallySent2 - actuallyDelivered;
+      const unqFees = TRANSFER_AMOUNT - actuallyDelivered;
       console.log('Moonbeam to Unique transaction fees on Unique: %s UNQ', unqFees);
       expect(unqFees > 0).to.be.true;
     });
deletedtests/src/xcmTransferMoonriver.test.tsdiffbeforeafterboth

no changes