difftreelog
fix tx fees check in MB tests, run XCM tests only when env var set
in: master
3 files changed
tests/package.jsondiffbeforeafterboth--- 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",
tests/src/util/helpers.tsdiffbeforeafterboth--- 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<void> {
await usingApi(async (api) => {
const promise = new Promise<void>(async (resolve) => {
@@ -1762,6 +1768,35 @@
});
}
+export async function waitEvent(
+ api: ApiPromise,
+ maxBlocksToWait: number,
+ eventSection: string,
+ eventMethod: string,
+): Promise<EventRecord | null> {
+
+ const promise = new Promise<EventRecord | null>(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,
tests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth21import {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}555556describe('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 });276277 it('Unique rejects ACA tokens from Acala', async () => {278 // This test is relevant only when the foreign asset pallet is disabled279280 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 };297298 const id = {299 Token: 'ACA',300 };301302 const destWeight = 50000000;303304 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());309310 await usingApi(async api => {311 const maxWaitBlocks = 3;312 const xcmpQueueFailEvent = await waitEvent(api, maxWaitBlocks, 'xcmpQueue', 'Fail');313314 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});277321278describe('Integration test: Exchanging UNQ with Moonbeam', () => {322describe_xcm('Integration test: Exchanging UNQ with Moonbeam', () => {279323280 // Unique constants324 // Unique constants281 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;538582539 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 });