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
--- 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,
modifiedtests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth
--- 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;
     });