git.delta.rocks / unique-network / refs/commits / b544464f4ffd

difftreelog

feat tests requirePallets

Daniel Shiposha2022-08-03parent: #fe18d26.patch.diff
in: master

21 files changed

modifiedtests/src/rmrk/acceptNft.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/acceptNft.test.ts
+++ b/tests/src/rmrk/acceptNft.test.ts
@@ -8,13 +8,13 @@
 } from './util/tx';
 import {NftIdTuple} from './util/fetch';
 import {isNftChildOfAnother, expectTxFailure} from './util/helpers';
-import { getModuleNames, Pallets } from '../util/helpers';
+import { requirePallets, Pallets } from '../util/helpers';
 
 describe('integration test: accept NFT', () => {
   let api: any;
   before(async function() {
     api = await getApiConnection();
-    if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();
+    requirePallets(this, api, [Pallets.RmrkCore]);
   });
   
   
modifiedtests/src/rmrk/addResource.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/addResource.test.ts
+++ b/tests/src/rmrk/addResource.test.ts
@@ -12,7 +12,7 @@
   addNftComposableResource,
 } from './util/tx';
 import {RmrkTraitsResourceResourceInfo as ResourceInfo} from '@polkadot/types/lookup';
-import { getModuleNames, Pallets } from '../util/helpers';
+import { requirePallets, Pallets } from '../util/helpers';
 
 describe('integration test: add NFT resource', () => {
   const Alice = '//Alice';
@@ -27,7 +27,7 @@
   let api: any;
   before(async function() {
     api = await getApiConnection();
-    if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();
+    requirePallets(this, api, [Pallets.RmrkCore]);
   });
 
   it('add resource', async () => {
modifiedtests/src/rmrk/addTheme.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/addTheme.test.ts
+++ b/tests/src/rmrk/addTheme.test.ts
@@ -3,13 +3,13 @@
 import {createBase, addTheme} from './util/tx';
 import {expectTxFailure} from './util/helpers';
 import {getThemeNames} from './util/fetch';
-import { getModuleNames, Pallets } from '../util/helpers';
+import { requirePallets, Pallets } from '../util/helpers';
 
 describe('integration test: add Theme to Base', () => {
   let api: any;
   before(async function() {
     api = await getApiConnection();
-    if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();
+    requirePallets(this, api, [Pallets.RmrkEquip]);
   });
 
   const alice = '//Alice';
modifiedtests/src/rmrk/burnNft.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/burnNft.test.ts
+++ b/tests/src/rmrk/burnNft.test.ts
@@ -5,7 +5,7 @@
 
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
-import { getModuleNames, Pallets } from '../util/helpers';
+import { requirePallets, Pallets } from '../util/helpers';
 
 chai.use(chaiAsPromised);
 const expect = chai.expect;
@@ -17,7 +17,7 @@
   let api: any;
   before(async function() {
     api = await getApiConnection();
-    if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();
+    requirePallets(this, api, [Pallets.RmrkCore]);
   });
 
 
modifiedtests/src/rmrk/changeCollectionIssuer.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/changeCollectionIssuer.test.ts
+++ b/tests/src/rmrk/changeCollectionIssuer.test.ts
@@ -1,5 +1,5 @@
 import {getApiConnection} from '../substrate/substrate-api';
-import { getModuleNames, Pallets } from '../util/helpers';
+import { requirePallets, Pallets } from '../util/helpers';
 import {expectTxFailure} from './util/helpers';
 import {
   changeIssuer,
@@ -13,7 +13,7 @@
   let api: any;
   before(async function() {
     api = await getApiConnection();
-    if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();
+    requirePallets(this, api, [Pallets.RmrkCore]);
   });
 
 
modifiedtests/src/rmrk/createBase.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/createBase.test.ts
+++ b/tests/src/rmrk/createBase.test.ts
@@ -1,12 +1,12 @@
 import {getApiConnection} from '../substrate/substrate-api';
-import { getModuleNames, Pallets } from '../util/helpers';
+import { requirePallets, Pallets } from '../util/helpers';
 import {createCollection, createBase} from './util/tx';
 
 describe('integration test: create new Base', () => {
   let api: any;
   before(async function() {
     api = await getApiConnection();
-    if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();
+    requirePallets(this, api, [Pallets.RmrkCore, Pallets.RmrkEquip]);
   });
 
   const alice = '//Alice';
modifiedtests/src/rmrk/createCollection.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/createCollection.test.ts
+++ b/tests/src/rmrk/createCollection.test.ts
@@ -1,12 +1,12 @@
 import {getApiConnection} from '../substrate/substrate-api';
-import {getModuleNames, Pallets} from '../util/helpers';
+import {requirePallets, Pallets} from '../util/helpers';
 import {createCollection} from './util/tx';
 
 describe('Integration test: create new collection', () => {
   let api: any;
   before(async function () {
     api = await getApiConnection();
-    if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();
+    requirePallets(this, api, [Pallets.RmrkCore]);
   });
 
 
modifiedtests/src/rmrk/deleteCollection.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/deleteCollection.test.ts
+++ b/tests/src/rmrk/deleteCollection.test.ts
@@ -1,5 +1,5 @@
 import {getApiConnection} from '../substrate/substrate-api';
-import { getModuleNames, Pallets } from '../util/helpers';
+import { requirePallets, Pallets } from '../util/helpers';
 import {expectTxFailure} from './util/helpers';
 import {createCollection, deleteCollection} from './util/tx';
 
@@ -7,7 +7,7 @@
   let api: any;
   before(async function () {
     api = await getApiConnection();
-    if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();
+    requirePallets(this, api, [Pallets.RmrkCore]);
   });
 
   const Alice = '//Alice';
modifiedtests/src/rmrk/equipNft.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/equipNft.test.ts
+++ b/tests/src/rmrk/equipNft.test.ts
@@ -1,7 +1,7 @@
 import {ApiPromise} from '@polkadot/api';
 import {expect} from 'chai';
 import {getApiConnection} from '../substrate/substrate-api';
-import {getModuleNames, Pallets} from '../util/helpers';
+import {requirePallets, Pallets} from '../util/helpers';
 import {getNft, getParts, NftIdTuple} from './util/fetch';
 import {expectTxFailure} from './util/helpers';
 import {
@@ -126,7 +126,7 @@
   
   before(async function () {
     api = await getApiConnection();
-    if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();
+    requirePallets(this, api, [Pallets.RmrkCore, Pallets.RmrkEquip]);
   });
 
   it('equip nft', async () => {
modifiedtests/src/rmrk/getOwnedNfts.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/getOwnedNfts.test.ts
+++ b/tests/src/rmrk/getOwnedNfts.test.ts
@@ -1,6 +1,6 @@
 import {expect} from 'chai';
 import {getApiConnection} from '../substrate/substrate-api';
-import { getModuleNames, Pallets } from '../util/helpers';
+import { requirePallets, Pallets } from '../util/helpers';
 import {getOwnedNfts} from './util/fetch';
 import {mintNft, createCollection} from './util/tx';
 
@@ -9,7 +9,7 @@
   
   before(async function () {
     api = await getApiConnection();
-    if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();
+    requirePallets(this, api, [Pallets.RmrkCore]);
   });
 
 
modifiedtests/src/rmrk/lockCollection.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/lockCollection.test.ts
+++ b/tests/src/rmrk/lockCollection.test.ts
@@ -1,5 +1,5 @@
 import {getApiConnection} from '../substrate/substrate-api';
-import { getModuleNames, Pallets } from '../util/helpers';
+import { requirePallets, Pallets } from '../util/helpers';
 import {expectTxFailure} from './util/helpers';
 import {createCollection, lockCollection, mintNft} from './util/tx';
 
@@ -11,7 +11,7 @@
   let api: any;
   before(async function () {
     api = await getApiConnection();
-    if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();
+    requirePallets(this, api, [Pallets.RmrkCore]);
   });
 
   it('lock collection', async () => {
modifiedtests/src/rmrk/mintNft.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/mintNft.test.ts
+++ b/tests/src/rmrk/mintNft.test.ts
@@ -1,6 +1,6 @@
 import {expect} from 'chai';
 import {getApiConnection} from '../substrate/substrate-api';
-import { getModuleNames, Pallets } from '../util/helpers';
+import { requirePallets, Pallets } from '../util/helpers';
 import {getNft} from './util/fetch';
 import {expectTxFailure} from './util/helpers';
 import {createCollection, mintNft} from './util/tx';
@@ -10,7 +10,7 @@
  
   before(async function () {
     api = await getApiConnection();
-    if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();
+    requirePallets(this, api, [Pallets.RmrkCore]);
   });
 
 
modifiedtests/src/rmrk/rejectNft.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/rejectNft.test.ts
+++ b/tests/src/rmrk/rejectNft.test.ts
@@ -8,13 +8,13 @@
 } from './util/tx';
 import {getChildren, NftIdTuple} from './util/fetch';
 import {isNftChildOfAnother, expectTxFailure} from './util/helpers';
-import { getModuleNames, Pallets } from '../util/helpers';
+import { requirePallets, Pallets } from '../util/helpers';
 
 describe('integration test: reject NFT', () => {
   let api: any;
   before(async function () {
     api = await getApiConnection();
-    if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();
+    requirePallets(this, api, [Pallets.RmrkCore]);
   });
 
 
modifiedtests/src/rmrk/removeResource.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/removeResource.test.ts
+++ b/tests/src/rmrk/removeResource.test.ts
@@ -1,7 +1,7 @@
 import {expect} from 'chai';
 import privateKey from '../substrate/privateKey';
 import {executeTransaction, getApiConnection} from '../substrate/substrate-api';
-import { getModuleNames, Pallets } from '../util/helpers';
+import { requirePallets, Pallets } from '../util/helpers';
 import {getNft, NftIdTuple} from './util/fetch';
 import {expectTxFailure} from './util/helpers';
 import {
@@ -20,7 +20,7 @@
   before(async function() {
     api = await getApiConnection();
     ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;
-    if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();
+    requirePallets(this, api, [Pallets.RmrkCore]);
   });
 
   const Alice = '//Alice';
modifiedtests/src/rmrk/rmrkIsolation.test.tsdiffbeforeafterboth
before · tests/src/rmrk/rmrkIsolation.test.ts
1import {expect} from 'chai';2import usingApi, {executeTransaction} from '../substrate/substrate-api';3import {4  createCollectionExpectSuccess,5  createItemExpectSuccess,6  getCreateCollectionResult,7  getDetailedCollectionInfo,8  getGenericResult,9  getModuleNames,10  normalizeAccountId,11  Pallets,12} from '../util/helpers';13import {IKeyringPair} from '@polkadot/types/types';14import {ApiPromise} from '@polkadot/api';15import {it} from 'mocha';1617let alice: IKeyringPair;18let bob: IKeyringPair;1920async function createRmrkCollection(api: ApiPromise, sender: IKeyringPair): Promise<{uniqueId: number, rmrkId: number}> {21  const tx = api.tx.rmrkCore.createCollection('metadata', null, 'symbol');22  const events = await executeTransaction(api, sender, tx);2324  const uniqueResult = getCreateCollectionResult(events);25  const rmrkResult = getGenericResult(events, 'rmrkCore', 'CollectionCreated', (data) => {26    return parseInt(data[1].toString(), 10);27  });2829  return {30    uniqueId: uniqueResult.collectionId,31    rmrkId: rmrkResult.data!,32  };33}3435async function createRmrkNft(api: ApiPromise, sender: IKeyringPair, collectionId: number): Promise<number> {36  const tx = api.tx.rmrkCore.mintNft(37    sender.address,38    collectionId,39    sender.address,40    null,41    'nft-metadata',42    true,43    null,44  );45  const events = await executeTransaction(api, sender, tx);46  const result = getGenericResult(events, 'rmrkCore', 'NftMinted', (data) => {47    return parseInt(data[2].toString(), 10);48  });4950  return result.data!;51}5253async function isUnique(): Promise<boolean> {54  return usingApi(async api => {55    const chain = await api.rpc.system.chain();5657    return chain.eq('UNIQUE');58  });59}6061describe('RMRK External Integration Test', async () => {62  const it_rmrk = (await isUnique() ? it : it.skip);6364  before(async function() {65    await usingApi(async (api, privateKeyWrapper) => {66      alice = privateKeyWrapper('//Alice');67      if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();68    });69  });7071  it_rmrk('Creates a new RMRK collection that is mapped to a different ID and is tagged as external', async () => {72    await usingApi(async api => {73      // throwaway collection to bump last Unique collection ID to test ID mapping74      await createCollectionExpectSuccess();7576      const collectionIds = await createRmrkCollection(api, alice);7778      expect(collectionIds.rmrkId).to.be.lessThan(collectionIds.uniqueId, 'collection ID mapping');7980      const collection = (await getDetailedCollectionInfo(api, collectionIds.uniqueId))!;81      expect(collection.readOnly.toHuman(), 'tagged external').to.be.true;82    });83  });84});8586describe('Negative Integration Test: External Collections, Internal Ops', async () => {87  let uniqueCollectionId: number;88  let rmrkCollectionId: number;89  let rmrkNftId: number;9091  const it_rmrk = (await isUnique() ? it : it.skip);9293  before(async () => {94    await usingApi(async (api, privateKeyWrapper) => {95      alice = privateKeyWrapper('//Alice');96      bob = privateKeyWrapper('//Bob');9798      const collectionIds = await createRmrkCollection(api, alice);99      uniqueCollectionId = collectionIds.uniqueId;100      rmrkCollectionId = collectionIds.rmrkId;101102      rmrkNftId = await createRmrkNft(api, alice, rmrkCollectionId);103    });104  });105106  it_rmrk('[Negative] Forbids Unique operations with an external collection, handled by dispatch_call', async () => {107    await usingApi(async api => {108      // Collection item creation109110      const txCreateItem = api.tx.unique.createItem(uniqueCollectionId, normalizeAccountId(alice), 'NFT');111      await expect(executeTransaction(api, alice, txCreateItem), 'creating item')112        .to.be.rejectedWith(/common\.CollectionIsExternal/);113114      const txCreateMultipleItems = api.tx.unique.createMultipleItems(uniqueCollectionId, normalizeAccountId(alice), [{NFT: {}}, {NFT: {}}]);115      await expect(executeTransaction(api, alice, txCreateMultipleItems), 'creating multiple')116        .to.be.rejectedWith(/common\.CollectionIsExternal/);117118      const txCreateMultipleItemsEx = api.tx.unique.createMultipleItemsEx(uniqueCollectionId, {NFT: [{}]});119      await expect(executeTransaction(api, alice, txCreateMultipleItemsEx), 'creating multiple ex')120        .to.be.rejectedWith(/common\.CollectionIsExternal/);121122      // Collection properties123124      const txSetCollectionProperties = api.tx.unique.setCollectionProperties(uniqueCollectionId, [{key: 'a', value: '1'}, {key: 'b'}]);125      await expect(executeTransaction(api, alice, txSetCollectionProperties), 'setting collection properties')126        .to.be.rejectedWith(/common\.CollectionIsExternal/);127128      const txDeleteCollectionProperties = api.tx.unique.deleteCollectionProperties(uniqueCollectionId, ['a']);129      await expect(executeTransaction(api, alice, txDeleteCollectionProperties), 'deleting collection properties')130        .to.be.rejectedWith(/common\.CollectionIsExternal/);131132      const txsetTokenPropertyPermissions = api.tx.unique.setTokenPropertyPermissions(uniqueCollectionId, [{key: 'a', permission: {mutable: true}}]);133      await expect(executeTransaction(api, alice, txsetTokenPropertyPermissions), 'setting property permissions')134        .to.be.rejectedWith(/common\.CollectionIsExternal/);135136      // NFT137138      const txBurn = api.tx.unique.burnItem(uniqueCollectionId, rmrkNftId, 1);139      await expect(executeTransaction(api, alice, txBurn), 'burning').to.be.rejectedWith(/common\.CollectionIsExternal/);140141      const txBurnFrom = api.tx.unique.burnFrom(uniqueCollectionId, normalizeAccountId(alice), rmrkNftId, 1);142      await expect(executeTransaction(api, alice, txBurnFrom), 'burning-from').to.be.rejectedWith(/common\.CollectionIsExternal/);143144      const txTransfer = api.tx.unique.transfer(normalizeAccountId(bob), uniqueCollectionId, rmrkNftId, 1);145      await expect(executeTransaction(api, alice, txTransfer), 'transferring').to.be.rejectedWith(/common\.CollectionIsExternal/);146147      const txApprove = api.tx.unique.approve(normalizeAccountId(bob), uniqueCollectionId, rmrkNftId, 1);148      await expect(executeTransaction(api, alice, txApprove), 'approving').to.be.rejectedWith(/common\.CollectionIsExternal/);149150      const txTransferFrom = api.tx.unique.transferFrom(normalizeAccountId(alice), normalizeAccountId(bob), uniqueCollectionId, rmrkNftId, 1);151      await expect(executeTransaction(api, alice, txTransferFrom), 'transferring-from').to.be.rejectedWith(/common\.CollectionIsExternal/);152153      // NFT properties154155      const txSetTokenProperties = api.tx.unique.setTokenProperties(uniqueCollectionId, rmrkNftId, [{key: 'a', value: '2'}]);156      await expect(executeTransaction(api, alice, txSetTokenProperties), 'setting token properties')157        .to.be.rejectedWith(/common\.CollectionIsExternal/);158159      const txDeleteTokenProperties = api.tx.unique.deleteTokenProperties(uniqueCollectionId, rmrkNftId, ['a']);160      await expect(executeTransaction(api, alice, txDeleteTokenProperties), 'deleting token properties')161        .to.be.rejectedWith(/common\.CollectionIsExternal/);162    });163  });164165  it_rmrk('[Negative] Forbids Unique collection operations with an external collection', async () => {166    await usingApi(async api => {167      const txDestroyCollection = api.tx.unique.destroyCollection(uniqueCollectionId);168      await expect(executeTransaction(api, alice, txDestroyCollection), 'destroying collection')169        .to.be.rejectedWith(/common\.CollectionIsExternal/);170171      // Allow list172173      const txAddAllowList = api.tx.unique.addToAllowList(uniqueCollectionId, normalizeAccountId(bob));174      await expect(executeTransaction(api, alice, txAddAllowList), 'adding to allow list')175        .to.be.rejectedWith(/common\.CollectionIsExternal/);176177      const txRemoveAllowList = api.tx.unique.removeFromAllowList(uniqueCollectionId, normalizeAccountId(bob));178      await expect(executeTransaction(api, alice, txRemoveAllowList), 'removing from allowlist')179        .to.be.rejectedWith(/common\.CollectionIsExternal/);180181      // Owner / Admin / Sponsor182183      const txChangeOwner = api.tx.unique.changeCollectionOwner(uniqueCollectionId, bob.address);184      await expect(executeTransaction(api, alice, txChangeOwner), 'changing owner')185        .to.be.rejectedWith(/common\.CollectionIsExternal/);186187      const txAddAdmin = api.tx.unique.addCollectionAdmin(uniqueCollectionId, normalizeAccountId(bob));188      await expect(executeTransaction(api, alice, txAddAdmin), 'adding admin')189        .to.be.rejectedWith(/common\.CollectionIsExternal/);190191      const txRemoveAdmin = api.tx.unique.removeCollectionAdmin(uniqueCollectionId, normalizeAccountId(bob));192      await expect(executeTransaction(api, alice, txRemoveAdmin), 'removing admin')193        .to.be.rejectedWith(/common\.CollectionIsExternal/);194195      const txAddCollectionSponsor = api.tx.unique.setCollectionSponsor(uniqueCollectionId, bob.address);196      await expect(executeTransaction(api, alice, txAddCollectionSponsor), 'setting sponsor')197        .to.be.rejectedWith(/common\.CollectionIsExternal/);198199      const txConfirmCollectionSponsor = api.tx.unique.confirmSponsorship(uniqueCollectionId);200      await expect(executeTransaction(api, alice, txConfirmCollectionSponsor), 'confirming sponsor')201        .to.be.rejectedWith(/common\.CollectionIsExternal/);202203      const txRemoveCollectionSponsor = api.tx.unique.removeCollectionSponsor(uniqueCollectionId);204      await expect(executeTransaction(api, alice, txRemoveCollectionSponsor), 'removing sponsor')205        .to.be.rejectedWith(/common\.CollectionIsExternal/);206      207      // Limits / permissions / transfers208209      const txSetTransfers = api.tx.unique.setTransfersEnabledFlag(uniqueCollectionId, true);210      await expect(executeTransaction(api, alice, txSetTransfers), 'setting transfers enabled flag')211        .to.be.rejectedWith(/common\.CollectionIsExternal/);212213      const txSetLimits = api.tx.unique.setCollectionLimits(uniqueCollectionId, {transfersEnabled: false});214      await expect(executeTransaction(api, alice, txSetLimits), 'setting collection limits')215        .to.be.rejectedWith(/common\.CollectionIsExternal/);216217      const txSetPermissions = api.tx.unique.setCollectionPermissions(uniqueCollectionId, {access: 'AllowList'});218      await expect(executeTransaction(api, alice, txSetPermissions), 'setting collection permissions')219        .to.be.rejectedWith(/common\.CollectionIsExternal/);220    });221  });222});223224describe('Negative Integration Test: Internal Collections, External Ops', async () => {225  let collectionId: number;226  let nftId: number;227228  const it_rmrk = (await isUnique() ? it : it.skip);229230  before(async () => {231    await usingApi(async (api, privateKeyWrapper) => {232      alice = privateKeyWrapper('//Alice');233      bob = privateKeyWrapper('//Bob');234235      collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});236      nftId = await createItemExpectSuccess(alice, collectionId, 'NFT');237    });238  });239240  it_rmrk('[Negative] Forbids RMRK operations with the internal collection and NFT (due to the lack of mapping)', async () => {241    await usingApi(async api => {242      const txChangeOwner = api.tx.rmrkCore.changeCollectionIssuer(collectionId, bob.address);243      await expect(executeTransaction(api, alice, txChangeOwner), 'changing collection issuer')244        .to.be.rejectedWith(/rmrkCore\.CollectionUnknown/);245246      const maxBurns = 10;247      const txBurnItem = api.tx.rmrkCore.burnNft(collectionId, nftId, maxBurns);248      await expect(executeTransaction(api, alice, txBurnItem), 'burning NFT').to.be.rejectedWith(/rmrkCore\.CollectionUnknown/);249    });250  });251});
after · tests/src/rmrk/rmrkIsolation.test.ts
1import {expect} from 'chai';2import usingApi, {executeTransaction} from '../substrate/substrate-api';3import {4  createCollectionExpectSuccess,5  createItemExpectSuccess,6  getCreateCollectionResult,7  getDetailedCollectionInfo,8  getGenericResult,9  requirePallets,10  normalizeAccountId,11  Pallets,12} from '../util/helpers';13import {IKeyringPair} from '@polkadot/types/types';14import {ApiPromise} from '@polkadot/api';15import {it} from 'mocha';1617let alice: IKeyringPair;18let bob: IKeyringPair;1920async function createRmrkCollection(api: ApiPromise, sender: IKeyringPair): Promise<{uniqueId: number, rmrkId: number}> {21  const tx = api.tx.rmrkCore.createCollection('metadata', null, 'symbol');22  const events = await executeTransaction(api, sender, tx);2324  const uniqueResult = getCreateCollectionResult(events);25  const rmrkResult = getGenericResult(events, 'rmrkCore', 'CollectionCreated', (data) => {26    return parseInt(data[1].toString(), 10);27  });2829  return {30    uniqueId: uniqueResult.collectionId,31    rmrkId: rmrkResult.data!,32  };33}3435async function createRmrkNft(api: ApiPromise, sender: IKeyringPair, collectionId: number): Promise<number> {36  const tx = api.tx.rmrkCore.mintNft(37    sender.address,38    collectionId,39    sender.address,40    null,41    'nft-metadata',42    true,43    null,44  );45  const events = await executeTransaction(api, sender, tx);46  const result = getGenericResult(events, 'rmrkCore', 'NftMinted', (data) => {47    return parseInt(data[2].toString(), 10);48  });4950  return result.data!;51}5253async function isUnique(): Promise<boolean> {54  return usingApi(async api => {55    const chain = await api.rpc.system.chain();5657    return chain.eq('UNIQUE');58  });59}6061describe('RMRK External Integration Test', async () => {62  const it_rmrk = (await isUnique() ? it : it.skip);6364  before(async function() {65    await usingApi(async (api, privateKeyWrapper) => {66      alice = privateKeyWrapper('//Alice');67      requirePallets(this, api, [Pallets.RmrkCore]);68    });69  });7071  it_rmrk('Creates a new RMRK collection that is mapped to a different ID and is tagged as external', async () => {72    await usingApi(async api => {73      // throwaway collection to bump last Unique collection ID to test ID mapping74      await createCollectionExpectSuccess();7576      const collectionIds = await createRmrkCollection(api, alice);7778      expect(collectionIds.rmrkId).to.be.lessThan(collectionIds.uniqueId, 'collection ID mapping');7980      const collection = (await getDetailedCollectionInfo(api, collectionIds.uniqueId))!;81      expect(collection.readOnly.toHuman(), 'tagged external').to.be.true;82    });83  });84});8586describe('Negative Integration Test: External Collections, Internal Ops', async () => {87  let uniqueCollectionId: number;88  let rmrkCollectionId: number;89  let rmrkNftId: number;9091  const it_rmrk = (await isUnique() ? it : it.skip);9293  before(async () => {94    await usingApi(async (api, privateKeyWrapper) => {95      alice = privateKeyWrapper('//Alice');96      bob = privateKeyWrapper('//Bob');9798      const collectionIds = await createRmrkCollection(api, alice);99      uniqueCollectionId = collectionIds.uniqueId;100      rmrkCollectionId = collectionIds.rmrkId;101102      rmrkNftId = await createRmrkNft(api, alice, rmrkCollectionId);103    });104  });105106  it_rmrk('[Negative] Forbids Unique operations with an external collection, handled by dispatch_call', async () => {107    await usingApi(async api => {108      // Collection item creation109110      const txCreateItem = api.tx.unique.createItem(uniqueCollectionId, normalizeAccountId(alice), 'NFT');111      await expect(executeTransaction(api, alice, txCreateItem), 'creating item')112        .to.be.rejectedWith(/common\.CollectionIsExternal/);113114      const txCreateMultipleItems = api.tx.unique.createMultipleItems(uniqueCollectionId, normalizeAccountId(alice), [{NFT: {}}, {NFT: {}}]);115      await expect(executeTransaction(api, alice, txCreateMultipleItems), 'creating multiple')116        .to.be.rejectedWith(/common\.CollectionIsExternal/);117118      const txCreateMultipleItemsEx = api.tx.unique.createMultipleItemsEx(uniqueCollectionId, {NFT: [{}]});119      await expect(executeTransaction(api, alice, txCreateMultipleItemsEx), 'creating multiple ex')120        .to.be.rejectedWith(/common\.CollectionIsExternal/);121122      // Collection properties123124      const txSetCollectionProperties = api.tx.unique.setCollectionProperties(uniqueCollectionId, [{key: 'a', value: '1'}, {key: 'b'}]);125      await expect(executeTransaction(api, alice, txSetCollectionProperties), 'setting collection properties')126        .to.be.rejectedWith(/common\.CollectionIsExternal/);127128      const txDeleteCollectionProperties = api.tx.unique.deleteCollectionProperties(uniqueCollectionId, ['a']);129      await expect(executeTransaction(api, alice, txDeleteCollectionProperties), 'deleting collection properties')130        .to.be.rejectedWith(/common\.CollectionIsExternal/);131132      const txsetTokenPropertyPermissions = api.tx.unique.setTokenPropertyPermissions(uniqueCollectionId, [{key: 'a', permission: {mutable: true}}]);133      await expect(executeTransaction(api, alice, txsetTokenPropertyPermissions), 'setting property permissions')134        .to.be.rejectedWith(/common\.CollectionIsExternal/);135136      // NFT137138      const txBurn = api.tx.unique.burnItem(uniqueCollectionId, rmrkNftId, 1);139      await expect(executeTransaction(api, alice, txBurn), 'burning').to.be.rejectedWith(/common\.CollectionIsExternal/);140141      const txBurnFrom = api.tx.unique.burnFrom(uniqueCollectionId, normalizeAccountId(alice), rmrkNftId, 1);142      await expect(executeTransaction(api, alice, txBurnFrom), 'burning-from').to.be.rejectedWith(/common\.CollectionIsExternal/);143144      const txTransfer = api.tx.unique.transfer(normalizeAccountId(bob), uniqueCollectionId, rmrkNftId, 1);145      await expect(executeTransaction(api, alice, txTransfer), 'transferring').to.be.rejectedWith(/common\.CollectionIsExternal/);146147      const txApprove = api.tx.unique.approve(normalizeAccountId(bob), uniqueCollectionId, rmrkNftId, 1);148      await expect(executeTransaction(api, alice, txApprove), 'approving').to.be.rejectedWith(/common\.CollectionIsExternal/);149150      const txTransferFrom = api.tx.unique.transferFrom(normalizeAccountId(alice), normalizeAccountId(bob), uniqueCollectionId, rmrkNftId, 1);151      await expect(executeTransaction(api, alice, txTransferFrom), 'transferring-from').to.be.rejectedWith(/common\.CollectionIsExternal/);152153      // NFT properties154155      const txSetTokenProperties = api.tx.unique.setTokenProperties(uniqueCollectionId, rmrkNftId, [{key: 'a', value: '2'}]);156      await expect(executeTransaction(api, alice, txSetTokenProperties), 'setting token properties')157        .to.be.rejectedWith(/common\.CollectionIsExternal/);158159      const txDeleteTokenProperties = api.tx.unique.deleteTokenProperties(uniqueCollectionId, rmrkNftId, ['a']);160      await expect(executeTransaction(api, alice, txDeleteTokenProperties), 'deleting token properties')161        .to.be.rejectedWith(/common\.CollectionIsExternal/);162    });163  });164165  it_rmrk('[Negative] Forbids Unique collection operations with an external collection', async () => {166    await usingApi(async api => {167      const txDestroyCollection = api.tx.unique.destroyCollection(uniqueCollectionId);168      await expect(executeTransaction(api, alice, txDestroyCollection), 'destroying collection')169        .to.be.rejectedWith(/common\.CollectionIsExternal/);170171      // Allow list172173      const txAddAllowList = api.tx.unique.addToAllowList(uniqueCollectionId, normalizeAccountId(bob));174      await expect(executeTransaction(api, alice, txAddAllowList), 'adding to allow list')175        .to.be.rejectedWith(/common\.CollectionIsExternal/);176177      const txRemoveAllowList = api.tx.unique.removeFromAllowList(uniqueCollectionId, normalizeAccountId(bob));178      await expect(executeTransaction(api, alice, txRemoveAllowList), 'removing from allowlist')179        .to.be.rejectedWith(/common\.CollectionIsExternal/);180181      // Owner / Admin / Sponsor182183      const txChangeOwner = api.tx.unique.changeCollectionOwner(uniqueCollectionId, bob.address);184      await expect(executeTransaction(api, alice, txChangeOwner), 'changing owner')185        .to.be.rejectedWith(/common\.CollectionIsExternal/);186187      const txAddAdmin = api.tx.unique.addCollectionAdmin(uniqueCollectionId, normalizeAccountId(bob));188      await expect(executeTransaction(api, alice, txAddAdmin), 'adding admin')189        .to.be.rejectedWith(/common\.CollectionIsExternal/);190191      const txRemoveAdmin = api.tx.unique.removeCollectionAdmin(uniqueCollectionId, normalizeAccountId(bob));192      await expect(executeTransaction(api, alice, txRemoveAdmin), 'removing admin')193        .to.be.rejectedWith(/common\.CollectionIsExternal/);194195      const txAddCollectionSponsor = api.tx.unique.setCollectionSponsor(uniqueCollectionId, bob.address);196      await expect(executeTransaction(api, alice, txAddCollectionSponsor), 'setting sponsor')197        .to.be.rejectedWith(/common\.CollectionIsExternal/);198199      const txConfirmCollectionSponsor = api.tx.unique.confirmSponsorship(uniqueCollectionId);200      await expect(executeTransaction(api, alice, txConfirmCollectionSponsor), 'confirming sponsor')201        .to.be.rejectedWith(/common\.CollectionIsExternal/);202203      const txRemoveCollectionSponsor = api.tx.unique.removeCollectionSponsor(uniqueCollectionId);204      await expect(executeTransaction(api, alice, txRemoveCollectionSponsor), 'removing sponsor')205        .to.be.rejectedWith(/common\.CollectionIsExternal/);206      207      // Limits / permissions / transfers208209      const txSetTransfers = api.tx.unique.setTransfersEnabledFlag(uniqueCollectionId, true);210      await expect(executeTransaction(api, alice, txSetTransfers), 'setting transfers enabled flag')211        .to.be.rejectedWith(/common\.CollectionIsExternal/);212213      const txSetLimits = api.tx.unique.setCollectionLimits(uniqueCollectionId, {transfersEnabled: false});214      await expect(executeTransaction(api, alice, txSetLimits), 'setting collection limits')215        .to.be.rejectedWith(/common\.CollectionIsExternal/);216217      const txSetPermissions = api.tx.unique.setCollectionPermissions(uniqueCollectionId, {access: 'AllowList'});218      await expect(executeTransaction(api, alice, txSetPermissions), 'setting collection permissions')219        .to.be.rejectedWith(/common\.CollectionIsExternal/);220    });221  });222});223224describe('Negative Integration Test: Internal Collections, External Ops', async () => {225  let collectionId: number;226  let nftId: number;227228  const it_rmrk = (await isUnique() ? it : it.skip);229230  before(async () => {231    await usingApi(async (api, privateKeyWrapper) => {232      alice = privateKeyWrapper('//Alice');233      bob = privateKeyWrapper('//Bob');234235      collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});236      nftId = await createItemExpectSuccess(alice, collectionId, 'NFT');237    });238  });239240  it_rmrk('[Negative] Forbids RMRK operations with the internal collection and NFT (due to the lack of mapping)', async () => {241    await usingApi(async api => {242      const txChangeOwner = api.tx.rmrkCore.changeCollectionIssuer(collectionId, bob.address);243      await expect(executeTransaction(api, alice, txChangeOwner), 'changing collection issuer')244        .to.be.rejectedWith(/rmrkCore\.CollectionUnknown/);245246      const maxBurns = 10;247      const txBurnItem = api.tx.rmrkCore.burnNft(collectionId, nftId, maxBurns);248      await expect(executeTransaction(api, alice, txBurnItem), 'burning NFT').to.be.rejectedWith(/rmrkCore\.CollectionUnknown/);249    });250  });251});
modifiedtests/src/rmrk/sendNft.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/sendNft.test.ts
+++ b/tests/src/rmrk/sendNft.test.ts
@@ -3,13 +3,13 @@
 import {createCollection, mintNft, sendNft} from './util/tx';
 import {NftIdTuple} from './util/fetch';
 import {isNftChildOfAnother, expectTxFailure} from './util/helpers';
-import { getModuleNames, Pallets } from '../util/helpers';
+import { requirePallets, Pallets } from '../util/helpers';
 
 describe('integration test: send NFT', () => {
   let api: any;
   before(async function () {
     api = await getApiConnection();
-    if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();
+    requirePallets(this, api, [Pallets.RmrkCore]);
   });
 
   const maxNftId = 0xFFFFFFFF;
modifiedtests/src/rmrk/setCollectionProperty.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/setCollectionProperty.test.ts
+++ b/tests/src/rmrk/setCollectionProperty.test.ts
@@ -1,5 +1,5 @@
 import {getApiConnection} from '../substrate/substrate-api';
-import { getModuleNames, Pallets } from '../util/helpers';
+import { requirePallets, Pallets } from '../util/helpers';
 import {expectTxFailure} from './util/helpers';
 import {createCollection, setPropertyCollection} from './util/tx';
 
@@ -10,7 +10,7 @@
   let api: any;
   before(async function () {
     api = await getApiConnection();
-    if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();
+    requirePallets(this, api, [Pallets.RmrkCore]);
   });
 
   it('set collection property', async () => {
modifiedtests/src/rmrk/setEquippableList.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/setEquippableList.test.ts
+++ b/tests/src/rmrk/setEquippableList.test.ts
@@ -1,5 +1,5 @@
 import {getApiConnection} from '../substrate/substrate-api';
-import { getModuleNames, Pallets } from '../util/helpers';
+import { requirePallets, Pallets } from '../util/helpers';
 import {expectTxFailure} from './util/helpers';
 import {createCollection, createBase, setEquippableList} from './util/tx';
 
@@ -7,7 +7,7 @@
   let api: any;
   before(async function () {
     api = await getApiConnection();
-    if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();
+    requirePallets(this, api, [Pallets.RmrkCore]);
   });
 
   const alice = '//Alice';
modifiedtests/src/rmrk/setNftProperty.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/setNftProperty.test.ts
+++ b/tests/src/rmrk/setNftProperty.test.ts
@@ -1,5 +1,5 @@
 import {getApiConnection} from '../substrate/substrate-api';
-import { getModuleNames, Pallets } from '../util/helpers';
+import { requirePallets, Pallets } from '../util/helpers';
 import {NftIdTuple} from './util/fetch';
 import {expectTxFailure} from './util/helpers';
 import {createCollection, mintNft, sendNft, setNftProperty} from './util/tx';
@@ -8,7 +8,7 @@
   let api: any;
   before(async function () {
     api = await getApiConnection();
-    if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();
+    requirePallets(this, api, [Pallets.RmrkCore]);
   });
 
   const alice = '//Alice';
modifiedtests/src/rmrk/setResourcePriorities.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/setResourcePriorities.test.ts
+++ b/tests/src/rmrk/setResourcePriorities.test.ts
@@ -1,5 +1,5 @@
 import {getApiConnection} from '../substrate/substrate-api';
-import { getModuleNames, Pallets } from '../util/helpers';
+import { requirePallets, Pallets } from '../util/helpers';
 import {expectTxFailure} from './util/helpers';
 import {mintNft, createCollection, setResourcePriorities} from './util/tx';
 
@@ -7,7 +7,7 @@
   let api: any;
   before(async function () {
     api = await getApiConnection();
-    if (!getModuleNames(api).includes(Pallets.RmrkCore)) this.skip();
+    requirePallets(this, api, [Pallets.RmrkCore]);
   });
 
   const alice = '//Alice';
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -28,6 +28,7 @@
 import {hexToStr, strToUTF16, utf16ToStr} from './util';
 import {UpDataStructsRpcCollection, UpDataStructsCreateItemData, UpDataStructsProperty} from '@polkadot/types/lookup';
 import {UpDataStructsTokenChild} from '../interfaces';
+import { Context } from 'mocha';
 
 chai.use(chaiAsPromised);
 const expect = chai.expect;
@@ -42,6 +43,7 @@
 export enum Pallets {
   Inflation = 'inflation',
   RmrkCore = 'rmrkcore',
+  RmrkEquip = 'rmrkequip',
   ReFungible = 'refungible',
   Fungible = 'fungible',
   NFT = 'nonfungible',
@@ -70,6 +72,16 @@
   return modulesNames;
 }
 
+export function requirePallets(mocha: Context, api: ApiPromise, requiredPallets: string[]) {
+  const pallets = getModuleNames(api);
+
+  const isAllPalletsPresent = requiredPallets.every(p => pallets.includes(p));
+
+  if (!isAllPalletsPresent) {
+    mocha.skip();
+  }
+}
+
 export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {
   if (typeof input === 'string') {
     if (input.length >= 47) {