git.delta.rocks / unique-network / refs/commits / 622f2e6d27f9

difftreelog

fix remove outdated xcm tests

Daniel Shiposha2022-09-07parent: #4e863a2.patch.diff
in: master

4 files changed

deletedtests/src/xcm/xcmTransfer.test.tsdiffbeforeafterboth
--- a/tests/src/xcm/xcmTransfer.test.ts
+++ /dev/null
@@ -1,186 +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} 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 = 1000;
-const KARURA_CHAIN = 2000;
-const KARURA_PORT = '9946';
-const TRANSFER_AMOUNT = 2000000000000000000000000n;
-
-describe.skip('Integration test: Exchanging QTZ with Karura', () => {
-  let alice: IKeyringPair;
-
-  before(async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
-      alice = privateKeyWrapper('//Alice');
-    });
-
-    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;
-    }, karuraApiOptions);
-  });
-
-  it('Should connect and send QTZ to Karura', async () => {
-    let balanceOnKaruraBefore: bigint;
-
-    await usingApi(async (api) => {
-      const {free} = (await api.query.tokens.accounts(alice.addressRaw, {ForeignAsset: 0})).toJSON() as any;
-      balanceOnKaruraBefore = free;
-    }, {provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT)});
-
-    await usingApi(async (api) => {
-      const destination = {
-        V0: {
-          X2: [
-            'Parent',
-            {
-              Parachain: KARURA_CHAIN,
-            },
-          ],
-        },
-      };
-
-      const beneficiary = {
-        V0: {
-          X1: {
-            AccountId32: {
-              network: 'Any',
-              id: alice.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(alice, tx);
-      const result = getGenericResult(events);
-      expect(result.success).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(alice.addressRaw, {ForeignAsset: 0})).toJSON() as any;
-      expect(free > balanceOnKaruraBefore).to.be.true;
-    }, {provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT)});
-  });
-
-  it('Should connect to Karura and send QTZ back', async () => {
-    let balanceBefore: bigint;
-
-    await usingApi(async (api) => {
-      [balanceBefore] = await getBalance(api, [alice.address]);
-    });
-
-    await usingApi(async (api) => {
-      const destination = {
-        V1: {
-          parents: 1,
-          interior: {
-            X2: [
-              {Parachain: UNIQUE_CHAIN},
-              {AccountId32: {
-                network: 'Any',
-                id: alice.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(alice, tx);
-      const result = getGenericResult(events);
-      expect(result.success).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);
-      const [balanceAfter] = await getBalance(api, [alice.address]);
-      expect(balanceAfter > balanceBefore).to.be.true;
-    });
-  });
-});
deletedtests/src/xcm/xcmTransferAcala.test.tsdiffbeforeafterboth
--- a/tests/src/xcm/xcmTransferAcala.test.ts
+++ /dev/null
@@ -1,265 +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;
-
-let UNIQUE_CHAIN = 0;
-let ACALA_CHAIN = 0;
-
-// parse parachain id numbers
-process.argv.forEach((val) => {
-
-  const ai = val.indexOf('acalaId=');
-  const ui = val.indexOf('uniqueId=');
-  if (ai != -1)
-  {
-    ACALA_CHAIN = Number(val.substring('acalaId='.length));
-  }
-  if (ui != -1)
-  {
-    UNIQUE_CHAIN = Number(val.substring('uniqueId='.length));
-  }
-});
-
-const ACALA_PORT = '9946';
-const TRANSFER_AMOUNT = 2000000000000000000000000n;
-
-describe('Integration test: Exchanging UNQ with Acala', () => {
-  let alice: IKeyringPair;
-  let randomAccount: IKeyringPair;
-
-  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) => {
-      alice = privateKeyWrapper('//Alice');
-      randomAccount = generateKeyringPair();
-    });
-
-    const acalaApiOptions: ApiOptions = {
-      provider: new WsProvider('ws://127.0.0.1:' + ACALA_PORT),
-    };
-
-    await usingApi(
-      async (api) => {
-        const destination = {
-          V0: {
-            X2: [
-              'Parent',
-              {
-                Parachain: UNIQUE_CHAIN,
-              },
-            ],
-          },
-        };
-
-        const metadata = {
-          name: 'UNQ',
-          symbol: 'UNQ',
-          decimals: 18,
-          minimalBalance: 1,
-        };
-
-        const tx = api.tx.assetRegistry.registerForeignAsset(destination, metadata);
-        const sudoTx = api.tx.sudo.sudo(tx as any);
-        const events = await submitTransactionAsync(alice, sudoTx);
-        const result = getGenericResult(events);
-        expect(result.success).to.be.true;
-
-        const tx1 = api.tx.balances.transfer(randomAccount.address, 10000000000000n);
-        const events1 = await submitTransactionAsync(alice, tx1);
-        const result1 = getGenericResult(events1);
-        expect(result1.success).to.be.true;
-
-        [balanceAcalaTokenBefore] = await getBalance(api, [randomAccount.address]);
-        {
-          const {free} = (await api.query.tokens.accounts(alice.addressRaw, {ForeignAsset: 0})).toJSON() as any;
-          balanceUniqueForeignTokenBefore = BigInt(free);
-        }
-      },
-      acalaApiOptions,
-    );
-
-    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;
-
-      [balanceUniqueTokenBefore] = await getBalance(api, [randomAccount.address]);
-    });
-  });
-
-  it('Should connect and send UNQ to Acala', async () => {
-
-    await usingApi(async (api) => {
-
-      const destination = {
-        V0: {
-          X2: [
-            'Parent',
-            {
-              Parachain: ACALA_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;
-
-      [balanceUniqueTokenAfter] = await getBalance(api, [randomAccount.address]);
-
-      expect((balanceUniqueTokenBefore - balanceUniqueTokenAfter) > 0n).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;
-        balanceUniqueForeignTokenAfter = BigInt(free);
-
-        [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;
-        expect(unqFees == 0n).to.be.true;
-      },
-      {provider: new WsProvider('ws://127.0.0.1:' + ACALA_PORT)},
-    );
-  });
-
-  it('Should connect to Acala and send UNQ 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;
-
-        [balanceAcalaTokenFinal] = await getBalance(api, [randomAccount.address]);
-        {
-          const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
-          balanceUniqueForeignTokenFinal = BigInt(free);
-        }
-
-        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;
-        expect(unqFees == 0n).to.be.true;
-      },
-      {provider: new WsProvider('ws://127.0.0.1:' + ACALA_PORT)},
-    );
-
-    await usingApi(async (api) => {
-      // todo do something about instant sealing, where there might not be any new blocks
-      await waitNewBlocks(api, 3);
-
-      [balanceUniqueTokenFinal] = await getBalance(api, [randomAccount.address]);
-      const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenAfter;
-      expect(actuallyDelivered > 0).to.be.true;
-
-      const unqFees = TRANSFER_AMOUNT - actuallyDelivered;
-      console.log('Acala to Unique transaction fees on Unique: %s UNQ', unqFees);
-      expect(unqFees > 0).to.be.true;
-    });
-  });
-});
\ No newline at end of file
deletedtests/src/xcm/xcmTransferMoonbeam.test.tsdiffbeforeafterboth
--- a/tests/src/xcm/xcmTransferMoonbeam.test.ts
+++ /dev/null
@@ -1,382 +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;
-
-
-let UNIQUE_CHAIN = 0;
-let MOONBEAM_CHAIN = 0;
-
-// parse parachain id numbers
-process.argv.forEach((val) => {
-
-  const ai = val.indexOf('moonbeamId=');
-  const ui = val.indexOf('uniqueId=');
-  if (ai != -1)
-  {
-    MOONBEAM_CHAIN = Number(val.substring('moonbeamId='.length));
-  }
-  if (ui != -1)
-  {
-    UNIQUE_CHAIN = Number(val.substring('uniqueId='.length));
-  }
-});
-
-const UNIQUE_PORT = '9944';
-const MOONBEAM_PORT = '9947';
-const TRANSFER_AMOUNT = 2000000000000000000000000n;
-
-describe('Integration test: Exchanging UNQ with Moonbeam', () => {
-
-  // Unique constants
-  let uniqueAlice: IKeyringPair;
-  let uniqueAssetLocation;
-
-  let randomAccountUnique: IKeyringPair;
-  let randomAccountMoonbeam: IKeyringPair;
-
-  // Moonbeam constants
-  let assetId: Uint8Array;
-
-  const moonbeamKeyring = new Keyring({type: 'ethereum'});
-  const alithPrivateKey = '0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133';
-  const baltatharPrivateKey = '0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b';
-  const dorothyPrivateKey = '0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68';
-
-  const alithAccount = moonbeamKeyring.addFromUri(alithPrivateKey, undefined, 'ethereum');
-  const baltatharAccount = moonbeamKeyring.addFromUri(baltatharPrivateKey, undefined, 'ethereum');
-  const dorothyAccount = moonbeamKeyring.addFromUri(dorothyPrivateKey, undefined, 'ethereum');
-
-  const councilVotingThreshold = 2;
-  const technicalCommitteeThreshold = 2;
-  const votingPeriod = 3;
-  const delayPeriod = 0;
-
-  const uniqueAssetMetadata = {
-    name: 'xcUnique',
-    symbol: 'xcUNQ',
-    decimals: 18,
-    isFrozen: false,
-    minimalBalance: 1,
-  };
-
-  // let actuallySent1: bigint;
-  // let actuallySent2: bigint;
-
-  // let balanceUnique1: bigint;
-  // let balanceUnique2: bigint;
-  // let balanceUnique3: 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) => {
-      uniqueAlice = privateKeyWrapper('//Alice');
-      randomAccountUnique = generateKeyringPair();
-      randomAccountMoonbeam = generateKeyringPair('ethereum');
-    });
-
-    const moonbeamApiOptions: ApiOptions = {
-      provider: new WsProvider('ws://127.0.0.1:' + MOONBEAM_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: UNIQUE_CHAIN}},
-          },
-        );
-
-        assetId = api.registry.hash(sourceLocation.toU8a()).slice(0, 16).reverse();
-        console.log('Internal asset ID is %s', assetId);
-        uniqueAssetLocation = {XCM: sourceLocation};
-        const existentialDeposit = 1;
-        const isSufficient = true;
-        const unitsPerSecond = '1';
-        const numAssetsWeightHint = 0;
-
-        const registerTx = api.tx.assetManager.registerForeignAsset(
-          uniqueAssetLocation,
-          uniqueAssetMetadata,
-          existentialDeposit,
-          isSufficient,
-        );
-        console.log('Encoded proposal for registerAsset is %s', registerTx.method.toHex() || '');
-
-        const setUnitsTx = api.tx.assetManager.setAssetUnitsPerSecond(
-          uniqueAssetLocation,
-          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(randomAccountMoonbeam.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 <<<
-
-        [balanceGlmrTokenBefore] = await getBalance(api, [randomAccountMoonbeam.address]);
-      },
-      moonbeamApiOptions,
-    );
-
-    await usingApi(async (api) => {
-      const tx0 = api.tx.balances.transfer(randomAccountUnique.address, 10n * TRANSFER_AMOUNT);
-      const events0 = await submitTransactionAsync(uniqueAlice, tx0);
-      const result0 = getGenericResult(events0);
-      expect(result0.success).to.be.true;
-
-      [balanceUniqueTokenBefore] = await getBalance(api, [randomAccountUnique.address]);
-    });
-  });
-
-  it('Should connect and send UNQ to Moonbeam', async () => {
-    await usingApi(async (api) => {
-      const currencyId = {
-        NativeAssetId: 'Here',
-      };
-      const dest = {
-        V1: {
-          parents: 1,
-          interior: {
-            X2: [
-              {Parachain: MOONBEAM_CHAIN},
-              {AccountKey20: {network: 'Any', key: randomAccountMoonbeam.address}},
-            ],
-          },
-        },
-      };
-      const amount = TRANSFER_AMOUNT;
-      const destWeight = 50000000;
-
-      const tx = api.tx.xTokens.transfer(currencyId, amount, dest, destWeight);
-      const events = await submitTransactionAsync(uniqueAlice, tx);
-      const result = getGenericResult(events);
-      expect(result.success).to.be.true;
-
-      [balanceUniqueTokenAfter] = await getBalance(api, [randomAccountUnique.address]);
-      expect(balanceUniqueTokenAfter < balanceUniqueTokenBefore).to.be.true;
-
-      const transactionFees = balanceUniqueTokenBefore - balanceUniqueTokenAfter - TRANSFER_AMOUNT;
-      console.log('Unique to Moonbeam transaction fees on Unique: %s UNQ', 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);
-
-        [balanceGlmrTokenAfter] = await getBalance(api, [randomAccountMoonbeam.address]);
-
-        const glmrFees = balanceGlmrTokenBefore - balanceGlmrTokenAfter;
-        console.log('Unique to Moonbeam transaction fees on Moonbeam: %s GLMR', glmrFees);
-        expect(glmrFees == 0n).to.be.true;
-      },
-      {provider: new WsProvider('ws://127.0.0.1:' + MOONBEAM_PORT)},
-    );
-  });
-
-  it('Should connect to Moonbeam and send UNQ back', async () => {
-    await usingApi(
-      async (api) => {
-        const amount = TRANSFER_AMOUNT / 2n;
-        const asset = {
-          V1: {
-            id: {
-              Concrete: {
-                parents: 1,
-                interior: {
-                  X1: {Parachain: UNIQUE_CHAIN},
-                },
-              },
-            },
-            fun: {
-              Fungible: amount,
-            },
-          },
-        };
-        const destination = {
-          V1: {
-            parents: 1,
-            interior: {
-              X2: [
-                {Parachain: UNIQUE_CHAIN},
-                {AccountId32: {network: 'Any', id: randomAccountUnique.addressRaw}},
-              ],
-            },
-          },
-        };
-        const destWeight = 50000000;
-
-        const tx = api.tx.xTokens.transferMultiasset(asset, destination, destWeight);
-        const events = await submitTransactionAsync(randomAccountMoonbeam, tx);
-        const result = getGenericResult(events);
-        expect(result.success).to.be.true;
-
-        [balanceGlmrTokenFinal] = await getBalance(api, [randomAccountMoonbeam.address]);
-
-        const glmrFees = balanceGlmrTokenAfter - balanceGlmrTokenFinal;
-        console.log('Moonbeam to Unique transaction fees on Moonbeam: %s GLMR', glmrFees);
-        expect(glmrFees > 0).to.be.true;
-      },
-      {provider: new WsProvider('ws://127.0.0.1:' + MOONBEAM_PORT)},
-    );
-
-    await usingApi(async (api) => {
-      // todo do something about instant sealing, where there might not be any new blocks
-      await waitNewBlocks(api, 3);
-
-      [balanceUniqueTokenFinal] = await getBalance(api, [randomAccountUnique.address]);
-      const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenAfter;
-      expect(actuallyDelivered > 0).to.be.true;
-
-      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/xcm/xcmTransferStatemine.test.tsdiffbeforeafterboth
before · tests/src/xcm/xcmTransferStatemine.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';1920import {WsProvider} from '@polkadot/api';21import {ApiOptions} from '@polkadot/api/types';22import {IKeyringPair} from '@polkadot/types/types';23import usingApi, {submitTransactionAsync} from './substrate/substrate-api';24import {getGenericResult} from './util/helpers';25import waitNewBlocks from './substrate/wait-new-blocks';26import {normalizeAccountId} from './util/helpers';27import getBalance from './substrate/get-balance';282930chai.use(chaiAsPromised);31const expect = chai.expect;3233// const STATEMINE_CHAIN = 1000;34// const UNIQUE_CHAIN = 2037;3536let UNIQUE_CHAIN = 0;37let STATEMINE_CHAIN = 0;3839// parse parachain id numbers40process.argv.forEach((val) => {4142  const ai = val.indexOf('statemineId=');43  const ui = val.indexOf('uniqueId=');44  if (ai != -1)45  {46    STATEMINE_CHAIN = Number(val.substring('statemineId='.length));47  }48  if (ui != -1)49  {50    UNIQUE_CHAIN = Number(val.substring('uniqueId='.length));51  }52});5354const RELAY_PORT = '9844';55const UNIQUE_PORT = '9944';56const STATEMINE_PORT = '9948';57const STATEMINE_PALLET_INSTANCE = 50;58const ASSET_ID = 100;59const ASSET_METADATA_DECIMALS = 18;60const ASSET_METADATA_NAME = 'USDT';61const ASSET_METADATA_DESCRIPTION = 'USDT';62const ASSET_METADATA_MINIMAL_BALANCE = 1;6364const TRANSFER_AMOUNT = 1_000_000_000_000_000_000n;65const TRANSFER_AMOUNT2 = 10_000_000_000_000_000n;6667describe('Integration test: Exchanging USDT with Statemine', () => {68  let alice: IKeyringPair;69  let bob: IKeyringPair;70  71  let balanceStmnBefore: bigint;72  let balanceStmnAfter: bigint;73  let balanceStmnFinal: bigint;7475  before(async () => {76    await usingApi(async (api, privateKeyWrapper) => {77      alice = privateKeyWrapper('//Alice');78      bob = privateKeyWrapper('//Bob'); // funds donor79    });8081    const statemineApiOptions: ApiOptions = {82      provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),83    };8485    const uniqueApiOptions: ApiOptions = {86      provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),87    };8889    const relayApiOptions: ApiOptions = {90      provider: new WsProvider('ws://127.0.0.1:' + RELAY_PORT),91    };9293    await usingApi(async (api) => {9495      // 10,000.00 (ten thousands) USDT96      const assetAmount = 1_000_000_000_000_000_000_000n; 97      // 350.00 (three hundred fifty) DOT98      const fundingAmount = 3_500_000_000_000; 99100      const tx = api.tx.assets.create(ASSET_ID, alice.addressRaw, ASSET_METADATA_MINIMAL_BALANCE);101      const events = await submitTransactionAsync(alice, tx);102      const result = getGenericResult(events);103      expect(result.success).to.be.true;104105      // set metadata106      const tx2 = api.tx.assets.setMetadata(ASSET_ID, ASSET_METADATA_NAME, ASSET_METADATA_DESCRIPTION, ASSET_METADATA_DECIMALS);107      const events2 = await submitTransactionAsync(alice, tx2);108      const result2 = getGenericResult(events2);109      expect(result2.success).to.be.true;110111      // mint some amount of asset112      const tx3 = api.tx.assets.mint(ASSET_ID, alice.addressRaw, assetAmount);113      const events3 = await submitTransactionAsync(alice, tx3);114      const result3 = getGenericResult(events3);115      expect(result3.success).to.be.true;116117      // funding parachain sovereing account (Parachain: 2037)118      //const parachainSovereingAccount = '0x70617261f5070000000000000000000000000000000000000000000000000000';119      const parachainSovereingAccount = '0x7369626cf5070000000000000000000000000000000000000000000000000000';120      const tx4 = api.tx.balances.transfer(parachainSovereingAccount, fundingAmount);121      const events4 = await submitTransactionAsync(bob, tx4);122      const result4 = getGenericResult(events4);123      expect(result4.success).to.be.true;124125    }, statemineApiOptions);126127128    await usingApi(async (api) => {129130      const location = {131        V1: {132          parents: 1,133          interior: {X3: [134            {135              Parachain: STATEMINE_CHAIN,136            },137            {138              PalletInstance: STATEMINE_PALLET_INSTANCE,139            },140            {141              GeneralIndex: ASSET_ID,142            },143          ]},144        },145      };146147      const metadata =148      {149        name: ASSET_ID,150        symbol: ASSET_METADATA_NAME,151        decimals: ASSET_METADATA_DECIMALS,152        minimalBalance: ASSET_METADATA_MINIMAL_BALANCE,153      };154      //registerForeignAsset(owner, location, metadata)155      const tx = api.tx.foreingAssets.registerForeignAsset(alice.addressRaw, location, metadata);156      const sudoTx = api.tx.sudo.sudo(tx as any);157      const events = await submitTransactionAsync(alice, sudoTx);158      const result = getGenericResult(events);159      expect(result.success).to.be.true;160161    }, uniqueApiOptions);162163164    // Providing the relay currency to the unique sender account165    await usingApi(async (api) => {166      const destination = {167        V1: {168          parents: 0,169          interior: {X1: {170            Parachain: UNIQUE_CHAIN,171          },172          },173        }};174175      const beneficiary = {176        V1: {177          parents: 0,178          interior: {X1: {179            AccountId32: {180              network: 'Any',181              id: alice.addressRaw,182            },183          }},184        },185      };186187      const assets = {188        V1: [189          {190            id: {191              Concrete: {192                parents: 0,193                interior: 'Here',194              },195            },196            fun: {197              Fungible: 50_000_000_000_000_000n,198            },199          },200        ],201      };202203      const feeAssetItem = 0;204205      const weightLimit = {206        Limited: 5_000_000_000,207      };208209      const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);210      const events = await submitTransactionAsync(alice, tx);211      const result = getGenericResult(events);212      expect(result.success).to.be.true;213    }, relayApiOptions);214  215  });216217  it('Should connect and send USDT from Statemine to Unique', async () => {218    219    const statemineApiOptions: ApiOptions = {220      provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),221    };222223    const uniqueApiOptions: ApiOptions = {224      provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),225    };226227    await usingApi(async (api) => {228229      const dest = {230        V1: {231          parents: 1,232          interior: {X1: {233            Parachain: UNIQUE_CHAIN,234          },235          },236        }};237238      const beneficiary = {239        V1: {240          parents: 0,241          interior: {X1: {242            AccountId32: {243              network: 'Any',244              id: alice.addressRaw,245            },246          }},247        },248      };249250      const assets = {251        V1: [252          {253            id: {254              Concrete: {255                parents: 0,256                interior: {257                  X2: [258                    {259                      PalletInstance: STATEMINE_PALLET_INSTANCE,260                    },261                    {262                      GeneralIndex: ASSET_ID,263                    }, 264                  ]},265              },266            },267            fun: {268              Fungible: TRANSFER_AMOUNT,269            },270          },271        ],272      };273274      const feeAssetItem = 0;275276      const weightLimit = {277        Limited: 5000000000,278      };279280      [balanceStmnBefore] = await getBalance(api, [alice.address]);281282      const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(dest, beneficiary, assets, feeAssetItem, weightLimit);283      const events = await submitTransactionAsync(alice, tx);284      const result = getGenericResult(events);285      expect(result.success).to.be.true;286287      [balanceStmnAfter] = await getBalance(api, [alice.address]);288      expect(balanceStmnBefore > balanceStmnAfter).to.be.true;289290    }, statemineApiOptions);291292293    // ensure that asset has been delivered294    await usingApi(async (api) => {295      await waitNewBlocks(api, 3);296      // expext collection id will be with id 1297      const free = (await api.query.fungible.balance(1, normalizeAccountId(alice.address))).toBigInt();298      expect(free == TRANSFER_AMOUNT).to.be.true;299300    }, uniqueApiOptions);301  });302303  it('Should connect and send USDT from Unique to Statemine back', async () => {304    let balanceBefore: bigint;305    const uniqueApiOptions: ApiOptions = {306      provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),307    };308309    await usingApi(async (api) => {310      balanceBefore = (await api.query.fungible.balance(1, normalizeAccountId(alice.address))).toBigInt();311312      const destination = {313        V1: {314          parents: 1,315          interior: {X2: [316            {317              Parachain: STATEMINE_CHAIN,318            },319            {320              AccountId32: {321                network: 'Any',322                id: alice.addressRaw,323              },324            },325          ]},326        },327      };328329      const currencies = [[330        {331          ForeignAssetId: 0,332        },333        10_000_000_000_000_000n,334      ], 335      [336        {337          NativeAssetId: 'Parent',338        },339        400_000_000_000_000n,340      ]];341342      const feeItem = 1;343      const destWeight = 500000000000;344345      const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);346      const events = await submitTransactionAsync(alice, tx);347      const result = getGenericResult(events);348      expect(result.success).to.be.true;349350      351      [balanceStmnFinal] = await getBalance(api, [alice.address]);352      expect(balanceStmnFinal > balanceStmnBefore).to.be.true;353354      // todo do something about instant sealing, where there might not be any new blocks355      await waitNewBlocks(api, 3);356      const balanceAfter = (await api.query.fungible.balance(1, normalizeAccountId(alice.address))).toBigInt();357      expect(balanceAfter < balanceBefore).to.be.true;358    }, uniqueApiOptions);359  });360});