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
--- 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",
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
--- 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;
     });