git.delta.rocks / unique-network / refs/commits / 3ed96161dde6

difftreelog

approve and transferFrom test scenarios

kpozdnikin2021-01-15parent: #c980d88.patch.diff
in: master

6 files changed

modifiedtests/package.jsondiffbeforeafterboth
--- a/tests/package.json
+++ b/tests/package.json
@@ -21,7 +21,10 @@
     "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",
     "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",
     "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",
-    "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts"
+    "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",
+    "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",
+    "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",
+    "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts"
   },
   "author": "",
   "license": "Apache 2.0",
modifiedtests/src/approve.test.tsdiffbeforeafterboth
--- a/tests/src/approve.test.ts
+++ b/tests/src/approve.test.ts
@@ -8,53 +8,151 @@
 import chaiAsPromised from 'chai-as-promised';
 import privateKey from './substrate/privateKey';
 import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
-import {createCollectionExpectSuccess, destroyCollectionExpectSuccess} from './util/helpers';
+import {
+  approveExpectFail,
+  approveExpectSuccess,
+  createCollectionExpectSuccess,
+  createItemExpectSuccess,
+  destroyCollectionExpectSuccess,
+} from './util/helpers';
 
 chai.use(chaiAsPromised);
 const expect = chai.expect;
 
-interface ITokenDataType {
-  Owner: number[];
-  ConstData: number[];
-  VariableData: number[];
-}
-
 describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {
   it('Execute the extrinsic and check approvedList', async () => {
     await usingApi(async (api: ApiPromise) => {
+      const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+      const nftCollectionId = await createCollectionExpectSuccess();
+      // nft
+      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);
+      // fungible
+      const fungibleCollectionId = await createCollectionExpectSuccess({mode: 'Fungible'});
+      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
+      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
+      // reFungible
+      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: 'ReFungible'});
+      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
+      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);
 
+      // garbage collection :-D
+      await destroyCollectionExpectSuccess(nftCollectionId);
+      await destroyCollectionExpectSuccess(fungibleCollectionId);
+      await destroyCollectionExpectSuccess(reFungibleCollectionId);
     });
   });
+
+  it('Remove approval by using 0 amount', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+      const nftCollectionId = await createCollectionExpectSuccess();
+      // nft
+      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1);
+      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 0);
+      // fungible
+      const fungibleCollectionId = await createCollectionExpectSuccess({mode: 'Fungible'});
+      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
+      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1);
+      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 0);
+      // reFungible
+      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: 'ReFungible'});
+      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
+      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 1);
+      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 0);
+
+      // garbage collection :-D
+      await destroyCollectionExpectSuccess(nftCollectionId);
+      await destroyCollectionExpectSuccess(fungibleCollectionId);
+      await destroyCollectionExpectSuccess(reFungibleCollectionId);
+    });
+  });
 });
 
 describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {
   it('Approve for a collection that does not exist', async () => {
     await usingApi(async (api: ApiPromise) => {
-
+      const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+      // nft
+      const nftCollectionId = await createCollectionExpectSuccess();
+      await approveExpectFail(nftCollectionId + 1, 1, Alice, Bob);
+      // fungible
+      const fungibleCollectionId = await createCollectionExpectSuccess({mode: 'Fungible'});
+      await approveExpectFail(fungibleCollectionId + 1, 1, Alice, Bob);
+      // reFungible
+      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: 'ReFungible'});
+      await approveExpectFail(reFungibleCollectionId + 1, 1, Alice, Bob);
+      // garbage collection :-D
+      await destroyCollectionExpectSuccess(nftCollectionId);
+      await destroyCollectionExpectSuccess(fungibleCollectionId);
+      await destroyCollectionExpectSuccess(reFungibleCollectionId);
     });
   });
 
   it('Approve for a collection that was destroyed', async () => {
     await usingApi(async (api: ApiPromise) => {
-
+      const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+      // nft
+      const nftCollectionId = await createCollectionExpectSuccess();
+      await destroyCollectionExpectSuccess(nftCollectionId);
+      await approveExpectFail(nftCollectionId, 1, Alice, Bob);
+      // fungible
+      const fungibleCollectionId = await createCollectionExpectSuccess({mode: 'Fungible'});
+      await destroyCollectionExpectSuccess(fungibleCollectionId);
+      await approveExpectFail(fungibleCollectionId, 1, Alice, Bob);
+      // reFungible
+      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: 'ReFungible'});
+      await destroyCollectionExpectSuccess(reFungibleCollectionId);
+      await approveExpectFail(reFungibleCollectionId, 1, Alice, Bob);
     });
   });
 
   it('Approve transfer of a token that does not exist', async () => {
     await usingApi(async (api: ApiPromise) => {
-
+      const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+      // nft
+      const nftCollectionId = await createCollectionExpectSuccess();
+      await approveExpectFail(nftCollectionId, 2, Alice, Bob);
+      // fungible
+      const fungibleCollectionId = await createCollectionExpectSuccess({mode: 'Fungible'});
+      await approveExpectFail(fungibleCollectionId, 2, Alice, Bob);
+      // reFungible
+      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: 'ReFungible'});
+      await approveExpectFail(reFungibleCollectionId, 2, Alice, Bob);
+      // garbage collection :-D
+      await destroyCollectionExpectSuccess(nftCollectionId);
+      await destroyCollectionExpectSuccess(fungibleCollectionId);
+      await destroyCollectionExpectSuccess(reFungibleCollectionId);
     });
   });
 
   it('Approve using the address that does not own the approved token', async () => {
     await usingApi(async (api: ApiPromise) => {
+      const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+      const nftCollectionId = await createCollectionExpectSuccess();
+      // nft
+      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+      await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice);
+      // fungible
+      const fungibleCollectionId = await createCollectionExpectSuccess({mode: 'Fungible'});
+      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
+      await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice);
+      // reFungible
+      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: 'ReFungible'});
+      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
+      await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice);
 
-    });
-  });
-
-  it('Remove approval by using 0 amount', async () => {
-    await usingApi(async (api: ApiPromise) => {
-
+      // garbage collection :-D
+      await destroyCollectionExpectSuccess(nftCollectionId);
+      await destroyCollectionExpectSuccess(fungibleCollectionId);
+      await destroyCollectionExpectSuccess(reFungibleCollectionId);
     });
   });
 });
modifiedtests/src/createCollection.test.tsdiffbeforeafterboth
--- a/tests/src/createCollection.test.ts
+++ b/tests/src/createCollection.test.ts
@@ -5,15 +5,15 @@
 
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
-import { default as usingApi } from "./substrate/substrate-api";
-import { createCollectionExpectSuccess, createCollectionExpectFailure, CollectionMode } from "./util/helpers";
+import { default as usingApi } from './substrate/substrate-api';
+import { createCollectionExpectFailure, createCollectionExpectSuccess } from './util/helpers';
 
 chai.use(chaiAsPromised);
 const expect = chai.expect;
 
 describe('integration test: ext. createCollection():', () => {
   it('Create new NFT collection', async () => {
-    await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});
+    await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
   });
   it('Create new NFT collection whith collection_name of maximum length (64 bytes)', async () => {
     await createCollectionExpectSuccess({name: 'A'.repeat(64)});
@@ -25,34 +25,33 @@
     await createCollectionExpectSuccess({tokenPrefix: 'A'.repeat(16)});
   });
   it('Create new Fungible collection', async () => {
-    await createCollectionExpectSuccess({mode: 'Fungible'});
+    await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
   });
   it('Create new ReFungible collection', async () => {
-    await createCollectionExpectSuccess({mode: 'ReFungible'});
+    await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
   });
 });
 
 describe('(!negative test!) integration test: ext. createCollection():', () => {
   it('(!negative test!) create new NFT collection whith incorrect data (mode)', async () => {
     await usingApi(async (api) => {
-      const AcollectionCount = parseInt((await api.query.nft.collectionCount()).toString());
+      const AcollectionCount = parseInt((await api.query.nft.collectionCount()).toString(), 10);
 
-      const badTransaction = async function () { 
-        await createCollectionExpectSuccess({mode: 'BadMode' as CollectionMode});
-      };
+      const badTransaction = async () => await createCollectionExpectSuccess({mode: {type: 'Invalid'}});
+      // tslint:disable-next-line:no-unused-expression
       expect(badTransaction()).to.be.rejected;
 
-      const BcollectionCount = parseInt((await api.query.nft.collectionCount()).toString());
+      const BcollectionCount = parseInt((await api.query.nft.collectionCount()).toString(), 10);
       expect(BcollectionCount).to.be.equal(AcollectionCount, 'Error: Incorrect collection created.');
     });
   });
   it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {
-    await createCollectionExpectFailure({name: 'A'.repeat(65)});
+    await createCollectionExpectFailure({ name: 'A'.repeat(65), mode: {type: 'NFT'}});
   });
   it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => {
-    await createCollectionExpectFailure({description: 'A'.repeat(257)});
+    await createCollectionExpectFailure({ description: 'A'.repeat(257), mode: { type: 'NFT' }});
   });
   it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => {
-    await createCollectionExpectFailure({tokenPrefix: 'A'.repeat(17)});
+    await createCollectionExpectFailure({tokenPrefix: 'A'.repeat(17), mode: {type: 'NFT'}});
   });
 });
modifiedtests/src/substrate/substrate-api.tsdiffbeforeafterboth
--- a/tests/src/substrate/substrate-api.ts
+++ b/tests/src/substrate/substrate-api.ts
@@ -90,7 +90,6 @@
         res(rec);
         console.error = consoleError;
         console.log = consoleLog;
-        
       });
     };
     const reject = (errror: any) => {
@@ -104,6 +103,8 @@
       await transaction.signAndSend(sender, ({ events = [], status }) => {
         const transactionStatus = getTransactionStatus(events, status);
 
+        console.log('transactionStatus', transactionStatus, 'events', events);
+
         if (transactionStatus == TransactionStatus.Success) {
           resolve(events);
         } else if (transactionStatus == TransactionStatus.Fail) {
@@ -114,4 +115,4 @@
       reject(e);
     }
   });
-}
\ No newline at end of file
+}
modifiedtests/src/transferFrom.test.tsdiffbeforeafterboth
--- a/tests/src/transferFrom.test.ts
+++ b/tests/src/transferFrom.test.ts
@@ -8,21 +8,47 @@
 import chaiAsPromised from 'chai-as-promised';
 import privateKey from './substrate/privateKey';
 import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
-import {createCollectionExpectSuccess, destroyCollectionExpectSuccess} from './util/helpers';
+import {
+  approveExpectSuccess,
+  createCollectionExpectSuccess,
+  createItemExpectSuccess,
+  destroyCollectionExpectSuccess,
+  transferFromExpectSuccess,
+} from './util/helpers';
+import {IKeyringPair} from "@polkadot/types/types";
 
 chai.use(chaiAsPromised);
 const expect = chai.expect;
 
-interface ITokenDataType {
-  Owner: number[];
-  ConstData: number[];
-  VariableData: number[];
-}
-
 describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {
-  it('Execute the extrinsic and check nftItemList - owner of toren', async () => {
+  it('Execute the extrinsic and check nftItemList - owner of token', async () => {
     await usingApi(async (api: ApiPromise) => {
+      const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+      const Charlie = privateKey('//CHARLIE');
+      const nftCollectionId = await createCollectionExpectSuccess();
+      console.log('nftCollectionId', nftCollectionId);
+      const collectionInfo = await api.query.nft.collection(nftCollectionId);
+      console.log('collectionInfo', collectionInfo);
+      // nft
+      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);
 
+      await transferFromExpectSuccess(nftCollectionId, newNftTokenId, Alice, Charlie, 1, 'NFT');
+
+      // fungible
+      /*const fungibleCollectionId = await createCollectionExpectSuccess({mode: 'Fungible'});
+      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
+      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
+      // reFungible
+      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: 'ReFungible'});
+      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
+      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);*/
+
+      // garbage collection :-D
+      await destroyCollectionExpectSuccess(nftCollectionId);
+      // await destroyCollectionExpectSuccess(fungibleCollectionId);
+      // await destroyCollectionExpectSuccess(reFungibleCollectionId);
     });
   });
 });
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
before · tests/src/util/helpers.ts
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import type { AccountId, EventRecord } from '@polkadot/types/interfaces';9import { ApiPromise, Keyring } from "@polkadot/api";10import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from "../substrate/substrate-api";11import privateKey from '../substrate/privateKey';12import { alicesPublicKey, nullPublicKey } from "../accounts";13import { strToUTF16, utf16ToStr, hexToStr } from './util';14import { IKeyringPair } from '@polkadot/types/types';15import { BigNumber } from 'bignumber.js';16import { Struct, Enum } from '@polkadot/types/codec';17import { u128 } from '@polkadot/types/primitive';18import { ICollectionInterface } from '../types';19import BN from "bn.js";2021chai.use(chaiAsPromised);22const expect = chai.expect;2324type GenericResult = {25  success: boolean,26};2728type CreateCollectionResult = {29  success: boolean,30  collectionId: number31};3233type CreateItemResult = {34  success: boolean,35  collectionId: number,36  itemId: number37};3839export function getGenericResult(events: EventRecord[]): GenericResult {40  let result: GenericResult = {41    success: false42  }43  events.forEach(({ phase, event: { data, method, section } }) => {44    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);45    if (method == 'ExtrinsicSuccess') {46      result.success = true;47    }48  });49  return result;50}5152export function getCreateCollectionResult(events: EventRecord[]): CreateCollectionResult {53  let success = false;54  let collectionId: number = 0;55  events.forEach(({ phase, event: { data, method, section } }) => {56    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);57    if (method == 'ExtrinsicSuccess') {58      success = true;59    } else if ((section == 'nft') && (method == 'Created')) {60      collectionId = parseInt(data[0].toString());61    }62  });63  let result: CreateCollectionResult = {64    success,65    collectionId66  }67  return result;68}6970export function getCreateItemResult(events: EventRecord[]): CreateItemResult {71  let success = false;72  let collectionId: number = 0;73  let itemId: number = 0;74  events.forEach(({ phase, event: { data, method, section } }) => {75    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);76    if (method == 'ExtrinsicSuccess') {77      success = true;78    } else if ((section == 'nft') && (method == 'ItemCreated')) {79      collectionId = parseInt(data[0].toString());80      itemId = parseInt(data[1].toString());81    }82  });83  let result: CreateItemResult = {84    success,85    collectionId,86    itemId87  }88  return result;89}9091export type CollectionMode = 'NFT' | 'Fungible' | 'ReFungible';92export type CreateCollectionParams = {93  mode: CollectionMode,94  name: string,95  description: string,96  tokenPrefix: string97};9899const defaultCreateCollectionParams: CreateCollectionParams = {100  name: 'name',101  description: 'description',102  mode: 'NFT',103  tokenPrefix: 'prefix'104}105106export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {107  const {name, description, mode, tokenPrefix } = {...defaultCreateCollectionParams, ...params};108109  let collectionId: number = 0;110  await usingApi(async (api) => {111    // Get number of collections before the transaction112    const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());113114    // Run the CreateCollection transaction115    const alicePrivateKey = privateKey('//Alice');116    const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), mode);117    const events = await submitTransactionAsync(alicePrivateKey, tx);118    const result = getCreateCollectionResult(events);119120    // Get number of collections after the transaction121    const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());122123    // Get the collection 124    const collection: any = (await api.query.nft.collection(result.collectionId)).toJSON();125126    // What to expect127    expect(result.success).to.be.true;128    expect(result.collectionId).to.be.equal(BcollectionCount);129    expect(collection).to.be.not.null;130    expect(BcollectionCount).to.be.equal(AcollectionCount+1, 'Error: NFT collection NOT created.');131    expect(collection.Owner).to.be.equal(alicesPublicKey);132    expect(utf16ToStr(collection.Name)).to.be.equal(name);133    expect(utf16ToStr(collection.Description)).to.be.equal(description);134    expect(hexToStr(collection.TokenPrefix)).to.be.equal(tokenPrefix);135136    collectionId = result.collectionId;137  });138139  return collectionId;140}141  142export async function createCollectionExpectFailure(params: Partial<CreateCollectionParams> = {}) {143  const {name, description, mode, tokenPrefix } = {...defaultCreateCollectionParams, ...params};144145  await usingApi(async (api) => {146    // Get number of collections before the transaction147    const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());148149    // Run the CreateCollection transaction150    const alicePrivateKey = privateKey('//Alice');151    const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), mode);152    const events = await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;153    const result = getCreateCollectionResult(events);154155    // Get number of collections after the transaction156    const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());157158    // What to expect159    expect(result.success).to.be.false;160    expect(BcollectionCount).to.be.equal(AcollectionCount, 'Error: Collection with incorrect data created.');161  });162}163  164export async function findUnusedAddress(api: ApiPromise): Promise<IKeyringPair> {165  let bal = new BigNumber(0);166  let unused;167  do {168    const randomSeed = 'seed' +  Math.floor(Math.random() * Math.floor(10000));169    const keyring = new Keyring({ type: 'sr25519' });170    unused = keyring.addFromUri(`//${randomSeed}`);171    bal = new BigNumber((await api.query.system.account(unused.address)).data.free.toString());172  } while (bal.toFixed() != '0');173  return unused; 174}175176function getDestroyResult(events: EventRecord[]): boolean {177  let success: boolean = false;178  events.forEach(({ phase, event: { data, method, section } }) => {179    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);180    if (method == 'ExtrinsicSuccess') {181      success = true;182    }183  });184  return success;185}186187export async function destroyCollectionExpectFailure(collectionId: number, senderSeed: string = '//Alice') {188  await usingApi(async (api) => {189    // Run the DestroyCollection transaction190    const alicePrivateKey = privateKey(senderSeed);191    const tx = api.tx.nft.destroyCollection(collectionId);192    await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;193  });194}195196export async function destroyCollectionExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {197  await usingApi(async (api) => {198    // Run the DestroyCollection transaction199    const alicePrivateKey = privateKey(senderSeed);200    const tx = api.tx.nft.destroyCollection(collectionId);201    const events = await submitTransactionAsync(alicePrivateKey, tx);202    const result = getDestroyResult(events);203204    // Get the collection 205    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();206207    // What to expect208    expect(result).to.be.true;209    expect(collection).to.be.not.null;210    expect(collection.Owner).to.be.equal(nullPublicKey);211  });212}213214export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string) {215  await usingApi(async (api) => {216217    // Run the transaction218    const alicePrivateKey = privateKey('//Alice');219    const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);220    const events = await submitTransactionAsync(alicePrivateKey, tx);221    const result = getGenericResult(events);222223    // Get the collection 224    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();225226    // What to expect227    expect(result.success).to.be.true;228    expect(collection.Sponsor.toString()).to.be.equal(sponsor.toString());229    expect(collection.SponsorConfirmed).to.be.false;230  });231}232233export async function removeCollectionSponsorExpectSuccess(collectionId: number) {234  await usingApi(async (api) => {235236    // Run the transaction237    const alicePrivateKey = privateKey('//Alice');238    const tx = api.tx.nft.removeCollectionSponsor(collectionId);239    const events = await submitTransactionAsync(alicePrivateKey, tx);240    const result = getGenericResult(events);241242    // Get the collection 243    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();244245    // What to expect246    expect(result.success).to.be.true;247    expect(collection.Sponsor).to.be.equal(nullPublicKey);248    expect(collection.SponsorConfirmed).to.be.false;249  });250}251252export async function removeCollectionSponsorExpectFailure(collectionId: number) {253  await usingApi(async (api) => {254255    // Run the transaction256    const alicePrivateKey = privateKey('//Alice');257    const tx = api.tx.nft.removeCollectionSponsor(collectionId);258    await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;259  });260}261262export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string, senderSeed: string = '//Alice') {263  await usingApi(async (api) => {264265    // Run the transaction266    const alicePrivateKey = privateKey(senderSeed);267    const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);268    await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;269  });270}271272export async function confirmSponsorshipExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {273  await usingApi(async (api) => {274275    // Run the transaction276    const sender = privateKey(senderSeed);277    const tx = api.tx.nft.confirmSponsorship(collectionId);278    const events = await submitTransactionAsync(sender, tx);279    const result = getGenericResult(events);280281    // Get the collection 282    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();283284    // What to expect285    expect(result.success).to.be.true;286    expect(collection.Sponsor).to.be.equal(sender.address);287    expect(collection.SponsorConfirmed).to.be.true;288  });289}290291export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed: string = '//Alice') {292  await usingApi(async (api) => {293294    // Run the transaction295    const sender = privateKey(senderSeed);296    const tx = api.tx.nft.confirmSponsorship(collectionId);297    await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;298  });299}300301export interface CreateFungibleData extends Struct {302  readonly value: u128;303};304305export interface CreateReFungibleData extends Struct {};306export interface CreateNftData extends Struct {};307308export interface CreateItemData extends Enum {309  NFT: CreateNftData,310  Fungible: CreateFungibleData,311  ReFungible: CreateReFungibleData312};313314export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: string = '') {315  let newItemId: number = 0;316  await usingApi(async (api) => {317    const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString());318    const Aitem: any = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON();    319    const AItemBalance = new BigNumber(Aitem.Value);320321    if (owner === '') owner = sender.address;322323    let tx;324    if (createMode == 'Fungible') {325      let createData = {fungible: {value: 10}};326      tx = api.tx.nft.createItem(collectionId, owner, createData);327    }328    else {329      tx = api.tx.nft.createItem(collectionId, owner, createMode);330    }331    const events = await submitTransactionAsync(sender, tx);332    const result = getCreateItemResult(events);333334    const BItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString());335    const Bitem: any = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON();    336    const BItemBalance = new BigNumber(Bitem.Value);337338    // What to expect339    expect(result.success).to.be.true;340    if (createMode == 'Fungible') {341      expect(BItemBalance.minus(AItemBalance).toNumber()).to.be.equal(10);342    }343    else {344      expect(BItemCount).to.be.equal(AItemCount+1);345    }346    expect(collectionId).to.be.equal(result.collectionId);347    expect(BItemCount).to.be.equal(result.itemId);348    newItemId = result.itemId;349  });350  return newItemId;351}352353export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {354  await usingApi(async (api) => {355356    // Run the transaction357    const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');358    const events = await submitTransactionAsync(sender, tx);359    const result = getGenericResult(events);360361    // Get the collection 362    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();363364    // What to expect365    expect(result.success).to.be.true;366    expect(collection.Access).to.be.equal('WhiteList');367  });368}369370export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {371  await usingApi(async (api) => {372373    // Run the transaction374    const tx = api.tx.nft.setMintPermission(collectionId, true);375    const events = await submitTransactionAsync(sender, tx);376    const result = getGenericResult(events);377378    // Get the collection 379    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();380381    // What to expect382    expect(result.success).to.be.true;383    expect(collection.MintMode).to.be.equal(true);384  });385}386387export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {388  await usingApi(async (api) => {389390    // Run the transaction391    const tx = api.tx.nft.addToWhiteList(collectionId, address);392    const events = await submitTransactionAsync(sender, tx);393    const result = getGenericResult(events);394395    // Get the collection 396    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();397398    // What to expect399    expect(result.success).to.be.true;400    expect(collection.MintMode).to.be.equal(true);401  });402}403404export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)405  : Promise<ICollectionInterface | null> => {406  return await api.query.nft.collection(collectionId) as unknown as ICollectionInterface;407};408409export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {410  // set global object - collectionsCount411  return (await api.query.nft.createdCollectionCount() as unknown as BN).toNumber();412};
after · tests/src/util/helpers.ts
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import { ApiPromise, Keyring } from '@polkadot/api';7import { Enum, Struct } from '@polkadot/types/codec';8import type { AccountId, EventRecord } from '@polkadot/types/interfaces';9import { u128 } from '@polkadot/types/primitive';10import { IKeyringPair } from '@polkadot/types/types';11import { BigNumber } from 'bignumber.js';12import BN from 'bn.js';13import chai from 'chai';14import chaiAsPromised from 'chai-as-promised';15import { alicesPublicKey, nullPublicKey } from '../accounts';16import privateKey from '../substrate/privateKey';17import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from '../substrate/substrate-api';18import { ICollectionInterface } from '../types';19import { hexToStr, strToUTF16, utf16ToStr } from './util';2021chai.use(chaiAsPromised);22const expect = chai.expect;2324type GenericResult = {25  success: boolean,26};2728interface CreateCollectionResult {29  success: boolean;30  collectionId: number;31}3233interface CreateItemResult {34  success: boolean;35  collectionId: number;36  itemId: number;37}3839interface ITokenDataType {40  Owner: number[];41  ConstData: number[];42  VariableData: number[];43}4445export function getGenericResult(events: EventRecord[]): GenericResult {46  const result: GenericResult = {47    success: false,48  };49  events.forEach(({ phase, event: { data, method, section } }) => {50    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);51    if (method === 'ExtrinsicSuccess') {52      result.success = true;53    }54  });55  return result;56}5758export function getCreateCollectionResult(events: EventRecord[]): CreateCollectionResult {59  let success = false;60  let collectionId: number = 0;61  events.forEach(({ phase, event: { data, method, section } }) => {62    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);63    if (method == 'ExtrinsicSuccess') {64      success = true;65    } else if ((section == 'nft') && (method == 'Created')) {66      collectionId = parseInt(data[0].toString());67    }68  });69  const result: CreateCollectionResult = {70    success,71    collectionId,72  };73  return result;74}7576export function getCreateItemResult(events: EventRecord[]): CreateItemResult {77  let success = false;78  let collectionId: number = 0;79  let itemId: number = 0;80  events.forEach(({ phase, event: { data, method, section } }) => {81    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);82    if (method == 'ExtrinsicSuccess') {83      success = true;84    } else if ((section == 'nft') && (method == 'ItemCreated')) {85      collectionId = parseInt(data[0].toString());86      itemId = parseInt(data[1].toString());87    }88  });89  const result: CreateItemResult = {90    success,91    collectionId,92    itemId,93  };94  return result;95}9697interface Invalid {98  type: 'Invalid';99}100101interface Nft {102  type: 'NFT';103}104105interface Fungible {106  type: 'Fungible';107  decimalPoints: number;108}109110interface ReFungible {111  type: 'ReFungible';112  decimalPoints: number;113}114115type CollectionMode = Nft | Fungible | ReFungible | Invalid;116117export type CreateCollectionParams = {118  mode: CollectionMode,119  name: string,120  description: string,121  tokenPrefix: string,122};123124const defaultCreateCollectionParams: CreateCollectionParams = {125  description: 'description',126  mode: { type: 'NFT' },127  name: 'name',128  tokenPrefix: 'prefix',129}130131export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {132  const {name, description, mode, tokenPrefix } = {...defaultCreateCollectionParams, ...params};133134  let collectionId: number = 0;135  await usingApi(async (api) => {136    // Get number of collections before the transaction137    const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);138139    // Run the CreateCollection transaction140    const alicePrivateKey = privateKey('//Alice');141142    let modeprm = {};143    if (mode.type === 'NFT') {144      modeprm = {nft: null};145    } else if (mode.type === 'Fungible') {146      modeprm = {fungible: mode.decimalPoints};147    } else if (mode.type === 'ReFungible') {148      modeprm = {refungible: mode.decimalPoints};149    } else if (mode.type === 'Invalid') {150      modeprm = {invalid: null};151    }152153    const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);154    const events = await submitTransactionAsync(alicePrivateKey, tx);155    const result = getCreateCollectionResult(events);156157    // Get number of collections after the transaction158    const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);159160    // Get the collection161    const collection: any = (await api.query.nft.collection(result.collectionId)).toJSON();162163    // What to expect164    // tslint:disable-next-line:no-unused-expression165    expect(result.success).to.be.true;166    expect(result.collectionId).to.be.equal(BcollectionCount);167    // tslint:disable-next-line:no-unused-expression168    expect(collection).to.be.not.null;169    expect(BcollectionCount).to.be.equal(AcollectionCount + 1, 'Error: NFT collection NOT created.');170    expect(collection.Owner).to.be.equal(alicesPublicKey);171    expect(utf16ToStr(collection.Name)).to.be.equal(name);172    expect(utf16ToStr(collection.Description)).to.be.equal(description);173    expect(hexToStr(collection.TokenPrefix)).to.be.equal(tokenPrefix);174175    collectionId = result.collectionId;176  });177178  return collectionId;179}180181export async function createCollectionExpectFailure(params: Partial<CreateCollectionParams> = {}) {182  const {name, description, mode, tokenPrefix } = {...defaultCreateCollectionParams, ...params};183184  let modeprm = {};185  if (mode.type === 'NFT') {186    modeprm = {nft: null};187  } else if (mode.type === 'Fungible') {188    modeprm = {fungible: mode.decimalPoints};189  } else if (mode.type === 'ReFungible') {190    modeprm = {refungible: mode.decimalPoints};191  } else if (mode.type === 'Invalid') {192    modeprm = {invalid: null};193  }194195  await usingApi(async (api) => {196    // Get number of collections before the transaction197    const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());198199    // Run the CreateCollection transaction200    const alicePrivateKey = privateKey('//Alice');201    const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);202    const events = await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;203    const result = getCreateCollectionResult(events);204205    // Get number of collections after the transaction206    const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());207208    // What to expect209    // tslint:disable-next-line:no-unused-expression210    expect(result.success).to.be.false;211    expect(BcollectionCount).to.be.equal(AcollectionCount, 'Error: Collection with incorrect data created.');212  });213}214215export async function findUnusedAddress(api: ApiPromise): Promise<IKeyringPair> {216  let bal = new BigNumber(0);217  let unused;218  do {219    const randomSeed = 'seed' +  Math.floor(Math.random() * Math.floor(10000));220    const keyring = new Keyring({ type: 'sr25519' });221    unused = keyring.addFromUri(`//${randomSeed}`);222    bal = new BigNumber((await api.query.system.account(unused.address)).data.free.toString());223  } while (bal.toFixed() != '0');224  return unused;225}226227function getDestroyResult(events: EventRecord[]): boolean {228  let success: boolean = false;229  events.forEach(({ phase, event: { data, method, section } }) => {230    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);231    if (method == 'ExtrinsicSuccess') {232      success = true;233    }234  });235  return success;236}237238export async function destroyCollectionExpectFailure(collectionId: number, senderSeed: string = '//Alice') {239  await usingApi(async (api) => {240    // Run the DestroyCollection transaction241    const alicePrivateKey = privateKey(senderSeed);242    const tx = api.tx.nft.destroyCollection(collectionId);243    await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;244  });245}246247export async function destroyCollectionExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {248  await usingApi(async (api) => {249    // Run the DestroyCollection transaction250    const alicePrivateKey = privateKey(senderSeed);251    const tx = api.tx.nft.destroyCollection(collectionId);252    const events = await submitTransactionAsync(alicePrivateKey, tx);253    const result = getDestroyResult(events);254255    // Get the collection256    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();257258    // What to expect259    expect(result).to.be.true;260    expect(collection).to.be.not.null;261    expect(collection.Owner).to.be.equal(nullPublicKey);262  });263}264265export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string) {266  await usingApi(async (api) => {267268    // Run the transaction269    const alicePrivateKey = privateKey('//Alice');270    const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);271    const events = await submitTransactionAsync(alicePrivateKey, tx);272    const result = getGenericResult(events);273274    // Get the collection275    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();276277    // What to expect278    expect(result.success).to.be.true;279    expect(collection.Sponsor.toString()).to.be.equal(sponsor.toString());280    expect(collection.SponsorConfirmed).to.be.false;281  });282}283284export async function removeCollectionSponsorExpectSuccess(collectionId: number) {285  await usingApi(async (api) => {286287    // Run the transaction288    const alicePrivateKey = privateKey('//Alice');289    const tx = api.tx.nft.removeCollectionSponsor(collectionId);290    const events = await submitTransactionAsync(alicePrivateKey, tx);291    const result = getGenericResult(events);292293    // Get the collection294    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();295296    // What to expect297    expect(result.success).to.be.true;298    expect(collection.Sponsor).to.be.equal(nullPublicKey);299    expect(collection.SponsorConfirmed).to.be.false;300  });301}302303export async function removeCollectionSponsorExpectFailure(collectionId: number) {304  await usingApi(async (api) => {305306    // Run the transaction307    const alicePrivateKey = privateKey('//Alice');308    const tx = api.tx.nft.removeCollectionSponsor(collectionId);309    await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;310  });311}312313export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string, senderSeed: string = '//Alice') {314  await usingApi(async (api) => {315316    // Run the transaction317    const alicePrivateKey = privateKey(senderSeed);318    const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);319    await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;320  });321}322323export async function confirmSponsorshipExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {324  await usingApi(async (api) => {325326    // Run the transaction327    const sender = privateKey(senderSeed);328    const tx = api.tx.nft.confirmSponsorship(collectionId);329    const events = await submitTransactionAsync(sender, tx);330    const result = getGenericResult(events);331332    // Get the collection333    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();334335    // What to expect336    expect(result.success).to.be.true;337    expect(collection.Sponsor).to.be.equal(sender.address);338    expect(collection.SponsorConfirmed).to.be.true;339  });340}341342export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed: string = '//Alice') {343  await usingApi(async (api) => {344345    // Run the transaction346    const sender = privateKey(senderSeed);347    const tx = api.tx.nft.confirmSponsorship(collectionId);348    await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;349  });350}351352export interface CreateFungibleData extends Struct {353  readonly value: u128;354}355356export interface CreateReFungibleData extends Struct {}357export interface CreateNftData extends Struct {}358359export interface CreateItemData extends Enum {360  NFT: CreateNftData;361  Fungible: CreateFungibleData;362  ReFungible: CreateReFungibleData;363}364365export async function366approveExpectSuccess(collectionId: number,367                     tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {368  await usingApi(async (api: ApiPromise) => {369    const allowanceBefore =370      await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;371    const approveNftTx = await api.tx.nft.approve(approved.address, collectionId, tokenId, amount);372    const events = await submitTransactionAsync(owner, approveNftTx);373    const result = getCreateItemResult(events);374    // tslint:disable-next-line:no-unused-expression375    expect(result.success).to.be.true;376    const allowanceAfter =377      await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;378    expect(allowanceAfter.toNumber() - allowanceBefore.toNumber()).to.be.equal(amount);379  });380}381382export async function383transferFromExpectSuccess(collectionId: number, tokenId: number, accountFrom: IKeyringPair,384                          accountTo: IKeyringPair, value: number = 1, type: string = 'NFT') {385  await usingApi(async (api: ApiPromise) => {386    const transferFromTx = await api.tx.nft.transferFrom(387      accountFrom.address, accountTo.address, collectionId, tokenId, value);388    const events = await submitTransactionAsync(accountFrom, transferFromTx);389    const result = getCreateItemResult(events);390    // tslint:disable-next-line:no-unused-expression391    expect(result.success).to.be.true;392    if (type === 'NFT') {393      const nftItemData = api.query.nft.nftItemList(collectionId, tokenId) as unknown as ITokenDataType;394      console.log('NFT data', nftItemData);395    }396    if (type === 'Fungible') {397      const nftItemData = api.query.nft.fungibleItemList(collectionId, tokenId) as unknown as ITokenDataType;398      console.log('Fungible data', nftItemData);399    }400    if (type === 'ReFungible') {401      const nftItemData = api.query.nft.reFungibleItemList(collectionId, tokenId) as unknown as ITokenDataType;402      console.log('reFungibleItemList data', nftItemData);403    }404  });405}406407export async function408approveExpectFail(collectionId: number,409                  tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {410  await usingApi(async (api: ApiPromise) => {411    const approveNftTx = await api.tx.nft.approve(approved.address, collectionId, tokenId, amount);412    const events = await expect(submitTransactionExpectFailAsync(owner, approveNftTx)).to.be.rejected;413    const result = getCreateCollectionResult(events);414    // tslint:disable-next-line:no-unused-expression415    expect(result.success).to.be.false;416  });417}418419export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: string = '') {420  let newItemId: number = 0;421  await usingApi(async (api) => {422    const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);423    const Aitem: any = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON();424    const AItemBalance = new BigNumber(Aitem.Value);425426    if (owner === '') {427      owner = sender.address;428    }429430    let tx;431    if (createMode === 'Fungible') {432      const createData = {fungible: {value: 10}};433      tx = api.tx.nft.createItem(collectionId, owner, createData);434    } else {435      tx = api.tx.nft.createItem(collectionId, owner, createMode);436    }437    const events = await submitTransactionAsync(sender, tx);438    const result = getCreateItemResult(events);439440    const BItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);441    const Bitem: any = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON();442    const BItemBalance = new BigNumber(Bitem.Value);443444    // What to expect445    // tslint:disable-next-line:no-unused-expression446    expect(result.success).to.be.true;447    if (createMode === 'Fungible') {448      expect(BItemBalance.minus(AItemBalance).toNumber()).to.be.equal(10);449    } else {450      expect(BItemCount).to.be.equal(AItemCount + 1);451    }452    expect(collectionId).to.be.equal(result.collectionId);453    expect(BItemCount).to.be.equal(result.itemId);454    newItemId = result.itemId;455  });456  return newItemId;457}458459export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {460  await usingApi(async (api) => {461462    // Run the transaction463    const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');464    const events = await submitTransactionAsync(sender, tx);465    const result = getGenericResult(events);466467    // Get the collection468    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();469470    // What to expect471    expect(result.success).to.be.true;472    expect(collection.Access).to.be.equal('WhiteList');473  });474}475476export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {477  await usingApi(async (api) => {478479    // Run the transaction480    const tx = api.tx.nft.setMintPermission(collectionId, true);481    const events = await submitTransactionAsync(sender, tx);482    const result = getGenericResult(events);483484    // Get the collection485    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();486487    // What to expect488    expect(result.success).to.be.true;489    expect(collection.MintMode).to.be.equal(true);490  });491}492493export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {494  await usingApi(async (api) => {495496    // Run the transaction497    const tx = api.tx.nft.addToWhiteList(collectionId, address);498    const events = await submitTransactionAsync(sender, tx);499    const result = getGenericResult(events);500501    // Get the collection502    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();503504    // What to expect505    expect(result.success).to.be.true;506    expect(collection.MintMode).to.be.equal(true);507  });508}509510export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)511  : Promise<ICollectionInterface | null> => {512  return await api.query.nft.collection(collectionId) as unknown as ICollectionInterface;513};514515export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {516  // set global object - collectionsCount517  return (await api.query.nft.createdCollectionCount() as unknown as BN).toNumber();518};