git.delta.rocks / unique-network / refs/commits / 698c51fd21a7

difftreelog

fix move RMRK needed parts of deprecated helpers

Daniel Shiposha2022-10-11parent: #681fe40.patch.diff
in: master

20 files changed

modifiedtests/src/rmrk/acceptNft.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/acceptNft.test.ts
+++ b/tests/src/rmrk/acceptNft.test.ts
@@ -7,8 +7,7 @@
   acceptNft,
 } from './util/tx';
 import {NftIdTuple} from './util/fetch';
-import {isNftChildOfAnother, expectTxFailure} from './util/helpers';
-import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
+import {isNftChildOfAnother, expectTxFailure, requirePallets, Pallets} from './util/helpers';
 
 describe('integration test: accept NFT', () => {
   let api: any;
modifiedtests/src/rmrk/addResource.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/addResource.test.ts
+++ b/tests/src/rmrk/addResource.test.ts
@@ -1,7 +1,7 @@
 import {expect} from 'chai';
 import {getApiConnection} from '../substrate/substrate-api';
 import {NftIdTuple} from './util/fetch';
-import {expectTxFailure, getResourceById} from './util/helpers';
+import {expectTxFailure, getResourceById, requirePallets, Pallets} from './util/helpers';
 import {
   addNftBasicResource,
   acceptNftResource,
@@ -12,7 +12,6 @@
   addNftComposableResource,
 } from './util/tx';
 import {RmrkTraitsResourceResourceInfo as ResourceInfo} from '@polkadot/types/lookup';
-import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
 
 describe('integration test: add NFT resource', () => {
   const Alice = '//Alice';
modifiedtests/src/rmrk/addTheme.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/addTheme.test.ts
+++ b/tests/src/rmrk/addTheme.test.ts
@@ -1,9 +1,8 @@
 import {expect} from 'chai';
 import {getApiConnection} from '../substrate/substrate-api';
 import {createBase, addTheme} from './util/tx';
-import {expectTxFailure} from './util/helpers';
+import {expectTxFailure, requirePallets, Pallets} from './util/helpers';
 import {getThemeNames} from './util/fetch';
-import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
 
 describe('integration test: add Theme to Base', () => {
   let api: any;
modifiedtests/src/rmrk/burnNft.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/burnNft.test.ts
+++ b/tests/src/rmrk/burnNft.test.ts
@@ -1,11 +1,10 @@
 import {getApiConnection} from '../substrate/substrate-api';
-import {expectTxFailure} from './util/helpers';
+import {expectTxFailure, requirePallets, Pallets} from './util/helpers';
 import {NftIdTuple, getChildren} from './util/fetch';
 import {burnNft, createCollection, sendNft, mintNft} from './util/tx';
 
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
-import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
 
 chai.use(chaiAsPromised);
 const expect = chai.expect;
modifiedtests/src/rmrk/changeCollectionIssuer.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/changeCollectionIssuer.test.ts
+++ b/tests/src/rmrk/changeCollectionIssuer.test.ts
@@ -1,6 +1,5 @@
 import {getApiConnection} from '../substrate/substrate-api';
-import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
-import {expectTxFailure} from './util/helpers';
+import {expectTxFailure, requirePallets, Pallets} from './util/helpers';
 import {
   changeIssuer,
   createCollection,
modifiedtests/src/rmrk/createBase.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/createBase.test.ts
+++ b/tests/src/rmrk/createBase.test.ts
@@ -1,5 +1,5 @@
 import {getApiConnection} from '../substrate/substrate-api';
-import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
+import {requirePallets, Pallets} from './util/helpers';
 import {createCollection, createBase} from './util/tx';
 
 describe('integration test: create new Base', () => {
modifiedtests/src/rmrk/createCollection.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/createCollection.test.ts
+++ b/tests/src/rmrk/createCollection.test.ts
@@ -1,5 +1,5 @@
 import {getApiConnection} from '../substrate/substrate-api';
-import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
+import {requirePallets, Pallets} from './util/helpers';
 import {createCollection} from './util/tx';
 
 describe('Integration test: create new collection', () => {
modifiedtests/src/rmrk/deleteCollection.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/deleteCollection.test.ts
+++ b/tests/src/rmrk/deleteCollection.test.ts
@@ -1,6 +1,5 @@
 import {getApiConnection} from '../substrate/substrate-api';
-import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
-import {expectTxFailure} from './util/helpers';
+import {expectTxFailure, requirePallets, Pallets} from './util/helpers';
 import {createCollection, deleteCollection} from './util/tx';
 
 describe('integration test: delete collection', () => {
modifiedtests/src/rmrk/equipNft.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/equipNft.test.ts
+++ b/tests/src/rmrk/equipNft.test.ts
@@ -1,9 +1,8 @@
 import {ApiPromise} from '@polkadot/api';
 import {expect} from 'chai';
 import {getApiConnection} from '../substrate/substrate-api';
-import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
 import {getNft, getParts, NftIdTuple} from './util/fetch';
-import {expectTxFailure} from './util/helpers';
+import {expectTxFailure, requirePallets, Pallets} from './util/helpers';
 import {
   addNftComposableResource,
   addNftSlotResource,
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 {requirePallets, Pallets} from '../deprecated-helpers/helpers';
+import {requirePallets, Pallets} from './util/helpers';
 import {getOwnedNfts} from './util/fetch';
 import {mintNft, createCollection} from './util/tx';
 
modifiedtests/src/rmrk/lockCollection.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/lockCollection.test.ts
+++ b/tests/src/rmrk/lockCollection.test.ts
@@ -1,6 +1,5 @@
 import {getApiConnection} from '../substrate/substrate-api';
-import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
-import {expectTxFailure} from './util/helpers';
+import {expectTxFailure, requirePallets, Pallets} from './util/helpers';
 import {createCollection, lockCollection, mintNft} from './util/tx';
 
 describe('integration test: lock collection', () => {
modifiedtests/src/rmrk/mintNft.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/mintNft.test.ts
+++ b/tests/src/rmrk/mintNft.test.ts
@@ -1,8 +1,7 @@
 import {expect} from 'chai';
 import {getApiConnection} from '../substrate/substrate-api';
-import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
 import {getNft} from './util/fetch';
-import {expectTxFailure} from './util/helpers';
+import {expectTxFailure, requirePallets, Pallets} from './util/helpers';
 import {createCollection, mintNft} from './util/tx';
 
 describe('integration test: mint new NFT', () => {
modifiedtests/src/rmrk/rejectNft.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/rejectNft.test.ts
+++ b/tests/src/rmrk/rejectNft.test.ts
@@ -7,8 +7,7 @@
   rejectNft,
 } from './util/tx';
 import {getChildren, NftIdTuple} from './util/fetch';
-import {isNftChildOfAnother, expectTxFailure} from './util/helpers';
-import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
+import {isNftChildOfAnother, expectTxFailure, requirePallets, Pallets} from './util/helpers';
 
 describe('integration test: reject NFT', () => {
   let api: any;
modifiedtests/src/rmrk/removeResource.test.tsdiffbeforeafterboth
after · tests/src/rmrk/removeResource.test.ts
1import {expect} from 'chai';2import privateKey from '../substrate/privateKey';3import {executeTransaction, getApiConnection} from '../substrate/substrate-api';4import {getNft, NftIdTuple} from './util/fetch';5import {expectTxFailure, requirePallets, Pallets} from './util/helpers';6import {7  acceptNft, acceptResourceRemoval, addNftBasicResource,8  createBase,9  createCollection,10  mintNft, removeNftResource, sendNft,11} from './util/tx';1213141516describe('Integration test: remove nft resource', () => {17  let api: any;18  let ss58Format: string;19  before(async function() {20    api = await getApiConnection();21    ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;22    await requirePallets(this, [Pallets.RmrkCore]);23  });2425  const Alice = '//Alice';26  const Bob = '//Bob';27  const src = 'test-basic-src';28  const metadata = 'test-basic-metadata';29  const license = 'test-basic-license';30  const thumb = 'test-basic-thumb';3132  it('deleting a resource directly by the NFT owner', async () => {33    const collectionIdAlice = await createCollection(34      api,35      Alice,36      'test-metadata',37      null,38      'test-symbol',39    );4041    const nftAlice = await mintNft(42      api,43      Alice,44      Alice,45      collectionIdAlice,46      'nft-metadata',47    );4849    const resourceId = await addNftBasicResource(50      api,51      Alice,52      'added',53      collectionIdAlice,54      nftAlice,55      src,56      metadata,57      license,58      thumb,59    );6061    await removeNftResource(api, 'removed', Alice, collectionIdAlice, nftAlice, resourceId);62  });6364  it('deleting resources indirectly by the NFT owner', async () => {65    const collectionIdAlice = await createCollection(66      api,67      Alice,68      'test-metadata',69      null,70      'test-symbol',71    );7273    const parentNftId = await mintNft(api, Alice, Alice, collectionIdAlice, 'parent-nft-metadata');74    const childNftId = await mintNft(api, Alice, Alice, collectionIdAlice, 'child-nft-metadata');7576    const resourceId = await addNftBasicResource(77      api,78      Alice,79      'added',80      collectionIdAlice,81      childNftId,82      src,83      metadata,84      license,85      thumb,86    );8788    const newOwnerNFT: NftIdTuple = [collectionIdAlice, parentNftId];8990    await sendNft(api, 'sent', Alice, collectionIdAlice, childNftId, newOwnerNFT);9192    await removeNftResource(api, 'removed', Alice, collectionIdAlice, childNftId, resourceId);93  });9495  it('deleting a resource by the collection owner', async () => {96    const collectionIdAlice = await createCollection(97      api,98      Alice,99      'test-metadata',100      null,101      'test-symbol',102    );103104    const nftBob = await mintNft(105      api,106      Alice,107      Bob,108      collectionIdAlice,109      'nft-metadata',110    );111112    const resourceId = await addNftBasicResource(113      api,114      Alice,115      'pending',116      collectionIdAlice,117      nftBob,118      src,119      metadata,120      license,121      thumb,122    );123124    await removeNftResource(api, 'pending', Alice, collectionIdAlice, nftBob, resourceId);125    await acceptResourceRemoval(api, Bob, collectionIdAlice, nftBob, resourceId);126  });127128  it('deleting a resource in a nested NFT by the collection owner', async () => {129    const collectionIdAlice = await createCollection(130      api,131      Alice,132      'test-metadata',133      null,134      'test-symbol',135    );136137    const parentNftId = await mintNft(138      api,139      Alice,140      Bob,141      collectionIdAlice,142      'parent-nft-metadata',143    );144    const childNftId = await mintNft(145      api,146      Alice,147      Bob,148      collectionIdAlice,149      'child-nft-metadata',150    );151152    const resourceId = await addNftBasicResource(153      api,154      Alice,155      'pending',156      collectionIdAlice,157      childNftId,158      src,159      metadata,160      license,161      thumb,162    );163164    const newOwnerNFT: NftIdTuple = [collectionIdAlice, parentNftId];165166    await sendNft(api, 'sent', Bob, collectionIdAlice, childNftId, newOwnerNFT);167168    await removeNftResource(api, 'pending', Alice, collectionIdAlice, childNftId, resourceId);169    await acceptResourceRemoval(api, Bob, collectionIdAlice, childNftId, resourceId);170  });171172  it('[negative]: can\'t delete a resource in a non-existing collection', async () => {173    const collectionIdAlice = await createCollection(174      api,175      Alice,176      'test-metadata',177      null,178      'test-symbol',179    );180181    const nftAlice = await mintNft(182      api,183      Alice,184      Alice,185      collectionIdAlice,186      'nft-metadata',187    );188189    const resourceId = await addNftBasicResource(190      api,191      Alice,192      'added',193      collectionIdAlice,194      nftAlice,195      src,196      metadata,197      license,198      thumb,199    );200201    const tx = removeNftResource(api, 'removed', Alice, 0xFFFFFFFF, nftAlice, resourceId);202    await expectTxFailure(/rmrkCore\.CollectionUnknown/, tx); // FIXME: inappropriate error message (NoAvailableNftId)203  });204205  it('[negative]: only collection owner can delete a resource', async () => {206    const collectionIdAlice = await createCollection(207      api,208      Alice,209      'test-metadata',210      null,211      'test-symbol',212    );213214    const nftAlice = await mintNft(215      api,216      Alice,217      Alice,218      collectionIdAlice,219      'nft-metadata',220    );221222    const resourceId = await addNftBasicResource(223      api,224      Alice,225      'added',226      collectionIdAlice,227      nftAlice,228      src,229      metadata,230      license,231      thumb,232    );233234    const tx = removeNftResource(api, 'removed', Bob, collectionIdAlice, nftAlice, resourceId);235    await expectTxFailure(/rmrkCore\.NoPermission/, tx);236  });237238  it('[negative]: cannot delete a resource that does not exist', async () => {239    const collectionIdAlice = await createCollection(240      api,241      Alice,242      'test-metadata',243      null,244      'test-symbol',245    );246247    const nftAlice = await mintNft(248      api,249      Alice,250      Alice,251      collectionIdAlice,252      'nft-metadata',253    );254255    const tx = removeNftResource(api, 'removed', Alice, collectionIdAlice, nftAlice, 127);256    await expectTxFailure(/rmrkCore\.ResourceDoesntExist/, tx);257  });258259  it('[negative]: Cannot accept deleting resource without owner attempt do delete it', async () => {260    const collectionIdAlice = await createCollection(261      api,262      Alice,263      'test-metadata',264      null,265      'test-symbol',266    );267268    const nftBob = await mintNft(269      api,270      Alice,271      Bob,272      collectionIdAlice,273      'nft-metadata',274    );275276    const resourceId = await addNftBasicResource(277      api,278      Alice,279      'pending',280      collectionIdAlice,281      nftBob,282      src,283      metadata,284      license,285      thumb,286    );287288    const tx = acceptResourceRemoval(api, Bob, collectionIdAlice, nftBob, resourceId);289    await expectTxFailure(/rmrkCore\.ResourceNotPending/, tx);290  });291292  it('[negative]: cannot confirm the deletion of a non-existing resource', async () => {293    const collectionIdAlice = await createCollection(294      api,295      Alice,296      'test-metadata',297      null,298      'test-symbol',299    );300301    const nftBob = await mintNft(302      api,303      Alice,304      Bob,305      collectionIdAlice,306      'nft-metadata',307    );308309    const tx = acceptResourceRemoval(api, Bob, collectionIdAlice, nftBob, 127);310    await expectTxFailure(/rmrkCore\.ResourceDoesntExist/, tx);311  });312313  it('[negative]: Non-owner user cannot confirm the deletion of resource', async () => {314    const collectionIdAlice = await createCollection(315      api,316      Alice,317      'test-metadata',318      null,319      'test-symbol',320    );321322    const nftAlice = await mintNft(323      api,324      Alice,325      Alice,326      collectionIdAlice,327      'nft-metadata',328    );329330    const resourceId = await addNftBasicResource(331      api,332      Alice,333      'added',334      collectionIdAlice,335      nftAlice,336      src,337      metadata,338      license,339      thumb,340    );341342    const tx = acceptResourceRemoval(api, Bob, collectionIdAlice, nftAlice, resourceId);343    await expectTxFailure(/rmrkCore\.NoPermission/, tx);344  });345346  after(() => {347    api.disconnect();348  });349});
modifiedtests/src/rmrk/sendNft.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/sendNft.test.ts
+++ b/tests/src/rmrk/sendNft.test.ts
@@ -2,8 +2,7 @@
 import {getApiConnection} from '../substrate/substrate-api';
 import {createCollection, mintNft, sendNft} from './util/tx';
 import {NftIdTuple} from './util/fetch';
-import {isNftChildOfAnother, expectTxFailure} from './util/helpers';
-import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
+import {isNftChildOfAnother, expectTxFailure, requirePallets, Pallets} from './util/helpers';
 
 describe('integration test: send NFT', () => {
   let api: any;
modifiedtests/src/rmrk/setCollectionProperty.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/setCollectionProperty.test.ts
+++ b/tests/src/rmrk/setCollectionProperty.test.ts
@@ -1,6 +1,5 @@
 import {getApiConnection} from '../substrate/substrate-api';
-import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
-import {expectTxFailure} from './util/helpers';
+import {expectTxFailure, requirePallets, Pallets} from './util/helpers';
 import {createCollection, setPropertyCollection} from './util/tx';
 
 describe('integration test: set collection property', () => {
modifiedtests/src/rmrk/setEquippableList.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/setEquippableList.test.ts
+++ b/tests/src/rmrk/setEquippableList.test.ts
@@ -1,6 +1,5 @@
 import {getApiConnection} from '../substrate/substrate-api';
-import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
-import {expectTxFailure} from './util/helpers';
+import {expectTxFailure, requirePallets, Pallets} from './util/helpers';
 import {createCollection, createBase, setEquippableList} from './util/tx';
 
 describe("integration test: set slot's Equippable List", () => {
modifiedtests/src/rmrk/setNftProperty.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/setNftProperty.test.ts
+++ b/tests/src/rmrk/setNftProperty.test.ts
@@ -1,7 +1,6 @@
 import {getApiConnection} from '../substrate/substrate-api';
-import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
 import {NftIdTuple} from './util/fetch';
-import {expectTxFailure} from './util/helpers';
+import {expectTxFailure, requirePallets, Pallets} from './util/helpers';
 import {createCollection, mintNft, sendNft, setNftProperty} from './util/tx';
 
 describe('integration test: set NFT property', () => {
modifiedtests/src/rmrk/setResourcePriorities.test.tsdiffbeforeafterboth
--- a/tests/src/rmrk/setResourcePriorities.test.ts
+++ b/tests/src/rmrk/setResourcePriorities.test.ts
@@ -1,6 +1,5 @@
 import {getApiConnection} from '../substrate/substrate-api';
-import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
-import {expectTxFailure} from './util/helpers';
+import {expectTxFailure, requirePallets, Pallets} from './util/helpers';
 import {mintNft, createCollection, setResourcePriorities} from './util/tx';
 
 describe('integration test: set NFT resource priorities', () => {
modifiedtests/src/rmrk/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/rmrk/util/helpers.ts
+++ b/tests/src/rmrk/util/helpers.ts
@@ -10,6 +10,8 @@
 import {NftIdTuple, getChildren, getOwnedNfts, getCollectionProperties, getNftProperties, getResources} from './fetch';
 import chaiAsPromised from 'chai-as-promised';
 import chai from 'chai';
+import {getApiConnection} from '../../substrate/substrate-api';
+import {Context} from 'mocha';
 
 chai.use(chaiAsPromised);
 const expect = chai.expect;
@@ -19,6 +21,45 @@
     successData: T | null;
 }
 
+export enum Pallets {
+  Inflation = 'inflation',
+  RmrkCore = 'rmrkcore',
+  RmrkEquip = 'rmrkequip',
+  ReFungible = 'refungible',
+  Fungible = 'fungible',
+  NFT = 'nonfungible',
+  Scheduler = 'scheduler',
+  AppPromotion = 'apppromotion',
+}
+
+let modulesNames: any;
+export function getModuleNames(api: ApiPromise): string[] {
+  if (typeof modulesNames === 'undefined')
+    modulesNames = api.runtimeMetadata.asLatest.pallets.map(m => m.name.toString().toLowerCase());
+  return modulesNames;
+}
+
+export async function missingRequiredPallets(requiredPallets: string[]): Promise<string[]> {
+  const api = await getApiConnection();
+  const pallets = getModuleNames(api);
+
+  return requiredPallets.filter(p => !pallets.includes(p));
+}
+
+export async function requirePallets(mocha: Context, requiredPallets: string[]) {
+  const missingPallets = await missingRequiredPallets(requiredPallets);
+
+  if (missingPallets.length > 0) {
+    const skippingTestMsg = `\tSkipping test "${mocha.test?.title}".`;
+    const missingPalletsMsg = `\tThe following pallets are missing:\n\t- ${missingPallets.join('\n\t- ')}`;
+    const skipMsg = `${skippingTestMsg}\n${missingPalletsMsg}`;
+
+    console.error('\x1b[38:5:208m%s\x1b[0m', skipMsg);
+
+    mocha.skip();
+  }
+}
+
 export function makeNftOwner(api: ApiPromise, owner: string | NftIdTuple): NftOwner {
   const isNftSending = (typeof owner !== 'string');