git.delta.rocks / unique-network / refs/commits / 299194463ad3

difftreelog

fix tx fees check in MB tests, run XCM tests only when env var set

Daniel Shiposha2022-09-02parent: #c9cd747.patch.diff
in: master

3 files changed

modifiedtests/package.jsondiffbeforeafterboth
74 "testInflation": "mocha --timeout 9999999 -r ts-node/register ./**/inflation.test.ts",74 "testInflation": "mocha --timeout 9999999 -r ts-node/register ./**/inflation.test.ts",
75 "testScheduler": "mocha --timeout 9999999 -r ts-node/register ./**/scheduler.test.ts",75 "testScheduler": "mocha --timeout 9999999 -r ts-node/register ./**/scheduler.test.ts",
76 "testSchedulingEVM": "mocha --timeout 9999999 -r ts-node/register ./**/eth/scheduling.test.ts",76 "testSchedulingEVM": "mocha --timeout 9999999 -r ts-node/register ./**/eth/scheduling.test.ts",
77 "testXcmUnique": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmUnique.test.ts",77 "testXcmUnique": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmUnique.test.ts",
78 "testXcmOpal": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmOpal.test.ts",78 "testXcmOpal": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmOpal.test.ts",
79 "testXcmTransferAcala": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferAcala.test.ts acalaId=2000 uniqueId=5000",79 "testXcmTransferAcala": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferAcala.test.ts acalaId=2000 uniqueId=5000",
80 "testXcmTransferStatemine": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferStatemine.test.ts statemineId=1000 uniqueId=5000",80 "testXcmTransferStatemine": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferStatemine.test.ts statemineId=1000 uniqueId=5000",
81 "testXcmTransferMoonbeam": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferMoonbeam.test.ts moonbeamId=2000 uniqueId=5000",81 "testXcmTransferMoonbeam": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferMoonbeam.test.ts",
82 "testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",82 "testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",
83 "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",83 "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",
84 "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",84 "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
1746 return (await api.rpc.unique.collectionById(collectionId)).unwrap();1746 return (await api.rpc.unique.collectionById(collectionId)).unwrap();
1747}1747}
1748
1749export const describe_xcm = (
1750 process.env.RUN_XCM_TESTS
1751 ? describe
1752 : describe.skip
1753);
17481754
1749export async function waitNewBlocks(blocksCount = 1): Promise<void> {1755export async function waitNewBlocks(blocksCount = 1): Promise<void> {
1750 await usingApi(async (api) => {1756 await usingApi(async (api) => {
1762 });1768 });
1763}1769}
1770
1771export async function waitEvent(
1772 api: ApiPromise,
1773 maxBlocksToWait: number,
1774 eventSection: string,
1775 eventMethod: string,
1776): Promise<EventRecord | null> {
1777
1778 const promise = new Promise<EventRecord | null>(async (resolve) => {
1779 const unsubscribe = await api.query.system.events(eventRecords => {
1780 const neededEvent = eventRecords.find(r => {
1781 return r.event.section == eventSection && r.event.method == eventMethod;
1782 });
1783
1784 if (neededEvent) {
1785 unsubscribe();
1786 resolve(neededEvent);
1787 }
1788
1789 if (maxBlocksToWait > 0) {
1790 maxBlocksToWait--;
1791 } else {
1792 unsubscribe();
1793 resolve(null);
1794 }
1795 });
1796 });
1797 return promise;
1798}
17641799
1765export async function repartitionRFT(1800export async function repartitionRFT(
1766 api: ApiPromise,1801 api: ApiPromise,
modifiedtests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth
21import {ApiOptions} from '@polkadot/api/types';21import {ApiOptions} from '@polkadot/api/types';
22import {IKeyringPair} from '@polkadot/types/types';22import {IKeyringPair} from '@polkadot/types/types';
23import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';23import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
24import {getGenericResult, generateKeyringPair} from '../util/helpers';24import {getGenericResult, generateKeyringPair, waitEvent, describe_xcm} from '../util/helpers';
25import {MultiLocation} from '@polkadot/types/interfaces';25import {MultiLocation} from '@polkadot/types/interfaces';
26import {blake2AsHex} from '@polkadot/util-crypto';26import {blake2AsHex} from '@polkadot/util-crypto';
27import waitNewBlocks from '../substrate/wait-new-blocks';27import waitNewBlocks from '../substrate/wait-new-blocks';
53 return parachainApiOptions(MOONBEAM_PORT);53 return parachainApiOptions(MOONBEAM_PORT);
54}54}
5555
56describe('Integration test: Exchanging UNQ with Acala', () => {56describe_xcm('Integration test: Exchanging tokens with Acala', () => {
57 let alice: IKeyringPair;57 let alice: IKeyringPair;
58 let randomAccount: IKeyringPair;58 let randomAccount: IKeyringPair;
59 59
181 181
182 [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccount.address]);182 [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccount.address]);
183 183
184 const unqFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle + TRANSFER_AMOUNT;184 const unqFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;
185 console.log('[Unique -> Acala] transaction fees on Unique: %s UNQ', unqFees);185 console.log('[Unique -> Acala] transaction fees on Unique: %s UNQ', unqFees);
186 expect(unqFees > 0n).to.be.true;186 expect(unqFees > 0n).to.be.true;
187 });187 });
274 });274 });
275 });275 });
276
277 it('Unique rejects ACA tokens from Acala', async () => {
278 // This test is relevant only when the foreign asset pallet is disabled
279
280 await usingApi(async (api) => {
281 const destination = {
282 V1: {
283 parents: 1,
284 interior: {
285 X2: [
286 {Parachain: UNIQUE_CHAIN},
287 {
288 AccountId32: {
289 network: 'Any',
290 id: randomAccount.addressRaw,
291 },
292 },
293 ],
294 },
295 },
296 };
297
298 const id = {
299 Token: 'ACA',
300 };
301
302 const destWeight = 50000000;
303
304 const tx = api.tx.xTokens.transfer(id, 100_000_000_000, destination, destWeight);
305 const events = await submitTransactionAsync(alice, tx);
306 const result = getGenericResult(events);
307 expect(result.success).to.be.true;
308 }, acalaOptions());
309
310 await usingApi(async api => {
311 const maxWaitBlocks = 3;
312 const xcmpQueueFailEvent = await waitEvent(api, maxWaitBlocks, 'xcmpQueue', 'Fail');
313
314 expect(
315 xcmpQueueFailEvent != null,
316 'Only native token is supported when the Foreign-Assets pallet is not connected',
317 ).to.be.true;
318 });
319 });
276});320});
277321
278describe('Integration test: Exchanging UNQ with Moonbeam', () => {322describe_xcm('Integration test: Exchanging UNQ with Moonbeam', () => {
279323
280 // Unique constants324 // Unique constants
281 let uniqueAlice: IKeyringPair;325 let uniqueAlice: IKeyringPair;
536 [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccountUnique.address]);580 [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccountUnique.address]);
537 expect(balanceUniqueTokenMiddle < balanceUniqueTokenInit).to.be.true;581 expect(balanceUniqueTokenMiddle < balanceUniqueTokenInit).to.be.true;
538582
539 const transactionFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle + TRANSFER_AMOUNT;583 const transactionFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;
540 console.log('[Unique -> Moonbeam] transaction fees on Unique: %s UNQ', transactionFees);584 console.log('[Unique -> Moonbeam] transaction fees on Unique: %s UNQ', transactionFees);
541 expect(transactionFees > 0).to.be.true;585 expect(transactionFees > 0).to.be.true;
542 });586 });