From 299194463ad39e393e8868126d26a736ab2cf097 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Fri, 02 Sep 2022 13:30:00 +0000 Subject: [PATCH] fix: tx fees check in MB tests, run XCM tests only when env var set --- --- a/tests/package.json +++ b/tests/package.json @@ -74,11 +74,11 @@ "testInflation": "mocha --timeout 9999999 -r ts-node/register ./**/inflation.test.ts", "testScheduler": "mocha --timeout 9999999 -r ts-node/register ./**/scheduler.test.ts", "testSchedulingEVM": "mocha --timeout 9999999 -r ts-node/register ./**/eth/scheduling.test.ts", - "testXcmUnique": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmUnique.test.ts", + "testXcmUnique": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmUnique.test.ts", "testXcmOpal": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmOpal.test.ts", "testXcmTransferAcala": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferAcala.test.ts acalaId=2000 uniqueId=5000", "testXcmTransferStatemine": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferStatemine.test.ts statemineId=1000 uniqueId=5000", - "testXcmTransferMoonbeam": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferMoonbeam.test.ts moonbeamId=2000 uniqueId=5000", + "testXcmTransferMoonbeam": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferMoonbeam.test.ts", "testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts", "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts", "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts", --- a/tests/src/util/helpers.ts +++ b/tests/src/util/helpers.ts @@ -1746,6 +1746,12 @@ return (await api.rpc.unique.collectionById(collectionId)).unwrap(); } +export const describe_xcm = ( + process.env.RUN_XCM_TESTS + ? describe + : describe.skip +); + export async function waitNewBlocks(blocksCount = 1): Promise { await usingApi(async (api) => { const promise = new Promise(async (resolve) => { @@ -1762,6 +1768,35 @@ }); } +export async function waitEvent( + api: ApiPromise, + maxBlocksToWait: number, + eventSection: string, + eventMethod: string, +): Promise { + + const promise = new Promise(async (resolve) => { + const unsubscribe = await api.query.system.events(eventRecords => { + const neededEvent = eventRecords.find(r => { + return r.event.section == eventSection && r.event.method == eventMethod; + }); + + if (neededEvent) { + unsubscribe(); + resolve(neededEvent); + } + + if (maxBlocksToWait > 0) { + maxBlocksToWait--; + } else { + unsubscribe(); + resolve(null); + } + }); + }); + return promise; +} + export async function repartitionRFT( api: ApiPromise, collectionId: number, --- a/tests/src/xcm/xcmUnique.test.ts +++ b/tests/src/xcm/xcmUnique.test.ts @@ -21,7 +21,7 @@ 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 {getGenericResult, generateKeyringPair, waitEvent, describe_xcm} from '../util/helpers'; import {MultiLocation} from '@polkadot/types/interfaces'; import {blake2AsHex} from '@polkadot/util-crypto'; import waitNewBlocks from '../substrate/wait-new-blocks'; @@ -53,7 +53,7 @@ return parachainApiOptions(MOONBEAM_PORT); } -describe('Integration test: Exchanging UNQ with Acala', () => { +describe_xcm('Integration test: Exchanging tokens with Acala', () => { let alice: IKeyringPair; let randomAccount: IKeyringPair; @@ -181,7 +181,7 @@ [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccount.address]); - const unqFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle + TRANSFER_AMOUNT; + const unqFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT; console.log('[Unique -> Acala] transaction fees on Unique: %s UNQ', unqFees); expect(unqFees > 0n).to.be.true; }); @@ -273,9 +273,53 @@ expect(unqFees == 0n).to.be.true; }); }); + + it('Unique rejects ACA tokens from Acala', async () => { + // This test is relevant only when the foreign asset pallet is disabled + + await usingApi(async (api) => { + const destination = { + V1: { + parents: 1, + interior: { + X2: [ + {Parachain: UNIQUE_CHAIN}, + { + AccountId32: { + network: 'Any', + id: randomAccount.addressRaw, + }, + }, + ], + }, + }, + }; + + const id = { + Token: 'ACA', + }; + + const destWeight = 50000000; + + const tx = api.tx.xTokens.transfer(id, 100_000_000_000, destination, destWeight); + const events = await submitTransactionAsync(alice, tx); + const result = getGenericResult(events); + expect(result.success).to.be.true; + }, acalaOptions()); + + await usingApi(async api => { + const maxWaitBlocks = 3; + const xcmpQueueFailEvent = await waitEvent(api, maxWaitBlocks, 'xcmpQueue', 'Fail'); + + expect( + xcmpQueueFailEvent != null, + 'Only native token is supported when the Foreign-Assets pallet is not connected', + ).to.be.true; + }); + }); }); -describe('Integration test: Exchanging UNQ with Moonbeam', () => { +describe_xcm('Integration test: Exchanging UNQ with Moonbeam', () => { // Unique constants let uniqueAlice: IKeyringPair; @@ -536,7 +580,7 @@ [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccountUnique.address]); expect(balanceUniqueTokenMiddle < balanceUniqueTokenInit).to.be.true; - const transactionFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle + TRANSFER_AMOUNT; + const transactionFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT; console.log('[Unique -> Moonbeam] transaction fees on Unique: %s UNQ', transactionFees); expect(transactionFees > 0).to.be.true; }); -- gitstuff