difftreelog
Tests
in: master
4 files changed
tests/src/xcmTransferAcala.test.tsdiffbeforeafterboth37 let alice: IKeyringPair;37 let alice: IKeyringPair;38 let randomAccount: IKeyringPair;38 let randomAccount: IKeyringPair;393940 let actuallySent1: bigint;40 let balanceUniqueTokenBefore: bigint;41 let actuallySent2: bigint;41 let balanceUniqueTokenAfter: bigint;4243 let balanceUnique1: bigint;42 let balanceUniqueTokenFinal: bigint;44 let balanceUnique2: bigint;43 let balanceAcalaTokenBefore: bigint;45 let balanceUnique3: bigint;44 let balanceAcalaTokenAfter: bigint;46 47 let balanceAcalaUnq1: bigint;45 let balanceAcalaTokenFinal: bigint;48 let balanceAcalaUnq2: bigint;46 let balanceUniqueForeignTokenAfter: bigint;49 let balanceAcalaUnq3: bigint;47 let balanceUniqueForeignTokenBefore: bigint;5051 let balanceAcalaAca1: bigint;48 let balanceUniqueForeignTokenFinal: bigint;52 let balanceAcalaAca2: bigint;53 let balanceAcalaAca3: bigint;544955 before(async () => {50 before(async () => {56 await usingApi(async (api, privateKeyWrapper) => {51 await usingApi(async (api, privateKeyWrapper) => {93 const result1 = getGenericResult(events1);88 const result1 = getGenericResult(events1);94 expect(result1.success).to.be.true;89 expect(result1.success).to.be.true;959096 [balanceAcalaAca1] = await getBalance(api, [randomAccount.address]);91 [balanceAcalaTokenBefore] = await getBalance(api, [randomAccount.address]);97 {92 {98 const {free} = (await api.query.tokens.accounts(alice.addressRaw, {ForeignAsset: 0})).toJSON() as any;93 const {free} = (await api.query.tokens.accounts(alice.addressRaw, {ForeignAsset: 0})).toJSON() as any;99 balanceAcalaUnq1 = BigInt(free);94 balanceUniqueForeignTokenBefore = BigInt(free);100 }95 }101 },96 },102 acalaApiOptions,97 acalaApiOptions,108 const result0 = getGenericResult(events0);103 const result0 = getGenericResult(events0);109 expect(result0.success).to.be.true;104 expect(result0.success).to.be.true;110105111 [balanceUnique1] = await getBalance(api, [randomAccount.address]);106 [balanceUniqueTokenBefore] = await getBalance(api, [randomAccount.address]);112 });107 });113 });108 });114109165 const result = getGenericResult(events);160 const result = getGenericResult(events);166 expect(result.success).to.be.true;161 expect(result.success).to.be.true;167162168 [balanceUnique2] = await getBalance(api, [randomAccount.address]);163 [balanceUniqueTokenAfter] = await getBalance(api, [randomAccount.address]);169164170 const transactionFees = balanceUnique1 - balanceUnique2 - TRANSFER_AMOUNT;171 actuallySent1 = TRANSFER_AMOUNT; // Why not TRANSFER_AMOUNT - transactionFees ???172 console.log('Unique to Acala transaction fees on Unique: %s UNQ', transactionFees);173 expect(transactionFees > 0).to.be.true;165 expect((balanceUniqueTokenBefore - balanceUniqueTokenAfter) > 0n).to.be.true;174 });166 });175167176 await usingApi(168 await usingApi(177 async (api) => {169 async (api) => {178 // todo do something about instant sealing, where there might not be any new blocks170 // todo do something about instant sealing, where there might not be any new blocks179 await waitNewBlocks(api, 3);171 await waitNewBlocks(api, 3);180 const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;172 const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;181 balanceAcalaUnq2 = BigInt(free);173 balanceUniqueForeignTokenAfter = BigInt(free);182 expect(balanceAcalaUnq2 > balanceAcalaUnq1).to.be.true;183174184 [balanceAcalaAca2] = await getBalance(api, [randomAccount.address]);175 [balanceAcalaTokenAfter] = await getBalance(api, [randomAccount.address]);185186 const acaFees = balanceAcalaAca1 - balanceAcalaAca2;176 const acaFees = balanceAcalaTokenBefore - balanceAcalaTokenAfter;187 const unqFees = actuallySent1 - balanceAcalaUnq2 + balanceAcalaUnq1;177 const unqFees = balanceUniqueForeignTokenBefore - balanceUniqueForeignTokenAfter;188 console.log('Unique to Acala transaction fees on Acala: %s ACA', acaFees);178 console.log('Unique to Acala transaction fees on Acala: %s ACA', acaFees);189 console.log('Unique to Acala transaction fees on Acala: %s UNQ', unqFees);179 console.log('Unique to Acala transaction fees on Acala: %s UNQ', unqFees);190 expect(acaFees == 0n).to.be.true;180 expect(acaFees == 0n).to.be.true;227 const result = getGenericResult(events);217 const result = getGenericResult(events);228 expect(result.success).to.be.true;218 expect(result.success).to.be.true;229219230 [balanceAcalaAca3] = await getBalance(api, [randomAccount.address]);220 [balanceAcalaTokenFinal] = await getBalance(api, [randomAccount.address]);231 {221 {232 const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;222 const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;233 balanceAcalaUnq3 = BigInt(free);223 balanceUniqueForeignTokenFinal = BigInt(free);234 }224 }235225236 const acaFees = balanceAcalaAca2 - balanceAcalaAca3;226 const acaFees = balanceAcalaTokenFinal - balanceAcalaTokenAfter;237 const unqFees = balanceAcalaUnq2 - balanceAcalaUnq3 - amount;227 const unqFees = balanceUniqueForeignTokenFinal - balanceUniqueForeignTokenAfter;238 actuallySent2 = amount; // Why not amount - UNQFees ???239 console.log('Acala to Unique transaction fees on Acala: %s ACA', acaFees);228 console.log('Acala to Unique transaction fees on Acala: %s ACA', acaFees);240 console.log('Acala to Unique transaction fees on Acala: %s UNQ', unqFees);229 console.log('Acala to Unique transaction fees on Acala: %s UNQ', unqFees);241 expect(acaFees > 0).to.be.true;230 expect(acaFees > 0).to.be.true;248 // todo do something about instant sealing, where there might not be any new blocks237 // todo do something about instant sealing, where there might not be any new blocks249 await waitNewBlocks(api, 3);238 await waitNewBlocks(api, 3);250239251 [balanceUnique3] = await getBalance(api, [randomAccount.address]);240 [balanceUniqueTokenFinal] = await getBalance(api, [randomAccount.address]);252 const actuallyDelivered = balanceUnique3 - balanceUnique2;241 const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenAfter;253 expect(actuallyDelivered > 0).to.be.true;242 expect(actuallyDelivered > 0).to.be.true;254243255 const unqFees = actuallySent2 - actuallyDelivered;244 const unqFees = TRANSFER_AMOUNT - actuallyDelivered;256 console.log('Acala to Unique transaction fees on Unique: %s UNQ', unqFees);245 console.log('Acala to Unique transaction fees on Unique: %s UNQ', unqFees);257 expect(unqFees > 0).to.be.true;246 expect(unqFees > 0).to.be.true;258 });247 });tests/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
tests/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;
});
tests/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;
- });
- });
-});