difftreelog
tests: find not existing ids
in: master
2 files changed
tests/src/setVariableMetaData.test.tsdiffbeforeafterboth--- a/tests/src/setVariableMetaData.test.ts
+++ b/tests/src/setVariableMetaData.test.ts
@@ -8,6 +8,7 @@
createCollectionExpectSuccess,
createItemExpectSuccess,
destroyCollectionExpectSuccess,
+ findNotExistingCollection,
setVariableMetaDataExpectFailure,
setVariableMetaDataExpectSuccess,
} from './util/helpers';
@@ -62,9 +63,10 @@
});
it('fails on not existing collection id', async () => {
- // Not sure how to implement it
- const nonExistingCollectionId = 200000;
- await setVariableMetaDataExpectFailure(alice, nonExistingCollectionId, 1, data);
+ await usingApi(async api => {
+ let nonExistingCollectionId = await findNotExistingCollection(api);
+ await setVariableMetaDataExpectFailure(alice, nonExistingCollectionId, 1, data);
+ });
});
it('fails on removed collection id', async () => {
const removedCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
@@ -81,7 +83,7 @@
await setVariableMetaDataExpectFailure(alice, removedTokenCollectionId, removedTokenId, data);
});
it('fails on not existing token', async () => {
- const nonExistingTokenId = 200000;
+ const nonExistingTokenId = validTokenId + 1;
await setVariableMetaDataExpectFailure(alice, validCollectionId, nonExistingTokenId, data);
});
tests/src/util/helpers.tsdiffbeforeafterboth1//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 IReFungibleOwner {40 Fraction: BN;41 Owner: number[];42}4344interface ITokenDataType {45 Owner: number[];46 ConstData: number[];47 VariableData: number[];48}4950interface IFungibleTokenDataType {51 Value: BN;52}5354interface IReFungibleTokenDataType {55 Owner: IReFungibleOwner[];56 ConstData: number[];57 VariableData: number[];58}5960export function getGenericResult(events: EventRecord[]): GenericResult {61 const result: GenericResult = {62 success: false,63 };64 events.forEach(({ phase, event: { data, method, section } }) => {65 // console.log(` ${phase}: ${section}.${method}:: ${data}`);66 if (method === 'ExtrinsicSuccess') {67 result.success = true;68 }69 });70 return result;71}7273export function getCreateCollectionResult(events: EventRecord[]): CreateCollectionResult {74 let success = false;75 let collectionId: number = 0;76 events.forEach(({ phase, event: { data, method, section } }) => {77 // console.log(` ${phase}: ${section}.${method}:: ${data}`);78 if (method == 'ExtrinsicSuccess') {79 success = true;80 } else if ((section == 'nft') && (method == 'Created')) {81 collectionId = parseInt(data[0].toString());82 }83 });84 const result: CreateCollectionResult = {85 success,86 collectionId,87 };88 return result;89}9091export function getCreateItemResult(events: EventRecord[]): CreateItemResult {92 let success = false;93 let collectionId: number = 0;94 let itemId: number = 0;95 events.forEach(({ phase, event: { data, method, section } }) => {96 // console.log(` ${phase}: ${section}.${method}:: ${data}`);97 if (method == 'ExtrinsicSuccess') {98 success = true;99 } else if ((section == 'nft') && (method == 'ItemCreated')) {100 collectionId = parseInt(data[0].toString());101 itemId = parseInt(data[1].toString());102 }103 });104 const result: CreateItemResult = {105 success,106 collectionId,107 itemId,108 };109 return result;110}111112interface Invalid {113 type: 'Invalid';114}115116interface Nft {117 type: 'NFT';118}119120interface Fungible {121 type: 'Fungible';122 decimalPoints: number;123}124125interface ReFungible {126 type: 'ReFungible';127 decimalPoints: number;128}129130interface Nft {131 type: 'NFT'132}133134interface Fungible {135 type: 'Fungible',136 decimalPoints: number137}138139interface ReFungible {140 type: 'ReFungible',141 decimalPoints: number142}143144type CollectionMode = Nft | Fungible | ReFungible | Invalid;145146export type CreateCollectionParams = {147 mode: CollectionMode,148 name: string,149 description: string,150 tokenPrefix: string,151};152153const defaultCreateCollectionParams: CreateCollectionParams = {154 description: 'description',155 mode: { type: 'NFT' },156 name: 'name',157 tokenPrefix: 'prefix',158}159160export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {161 const {name, description, mode, tokenPrefix } = {...defaultCreateCollectionParams, ...params};162163 let collectionId: number = 0;164 await usingApi(async (api) => {165 // Get number of collections before the transaction166 const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);167168 // Run the CreateCollection transaction169 const alicePrivateKey = privateKey('//Alice');170171 let modeprm = {};172 if (mode.type === 'NFT') {173 modeprm = {nft: null};174 } else if (mode.type === 'Fungible') {175 modeprm = {fungible: mode.decimalPoints};176 } else if (mode.type === 'ReFungible') {177 modeprm = {refungible: mode.decimalPoints};178 } else if (mode.type === 'Invalid') {179 modeprm = {invalid: null};180 }181182 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);183 const events = await submitTransactionAsync(alicePrivateKey, tx);184 const result = getCreateCollectionResult(events);185186 // Get number of collections after the transaction187 const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);188189 // Get the collection190 const collection: any = (await api.query.nft.collection(result.collectionId)).toJSON();191192 // What to expect193 // tslint:disable-next-line:no-unused-expression194 expect(result.success).to.be.true;195 expect(result.collectionId).to.be.equal(BcollectionCount);196 // tslint:disable-next-line:no-unused-expression197 expect(collection).to.be.not.null;198 expect(BcollectionCount).to.be.equal(AcollectionCount + 1, 'Error: NFT collection NOT created.');199 expect(collection.Owner).to.be.equal(alicesPublicKey);200 expect(utf16ToStr(collection.Name)).to.be.equal(name);201 expect(utf16ToStr(collection.Description)).to.be.equal(description);202 expect(hexToStr(collection.TokenPrefix)).to.be.equal(tokenPrefix);203204 collectionId = result.collectionId;205 });206207 return collectionId;208}209210export async function createCollectionExpectFailure(params: Partial<CreateCollectionParams> = {}) {211 const {name, description, mode, tokenPrefix } = {...defaultCreateCollectionParams, ...params};212213 let modeprm = {};214 if (mode.type === 'NFT') {215 modeprm = {nft: null};216 } else if (mode.type === 'Fungible') {217 modeprm = {fungible: mode.decimalPoints};218 } else if (mode.type === 'ReFungible') {219 modeprm = {refungible: mode.decimalPoints};220 } else if (mode.type === 'Invalid') {221 modeprm = {invalid: null};222 }223224 await usingApi(async (api) => {225 // Get number of collections before the transaction226 const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());227228 // Run the CreateCollection transaction229 const alicePrivateKey = privateKey('//Alice');230 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);231 const events = await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;232 const result = getCreateCollectionResult(events);233234 // Get number of collections after the transaction235 const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());236237 // What to expect238 // tslint:disable-next-line:no-unused-expression239 expect(result.success).to.be.false;240 expect(BcollectionCount).to.be.equal(AcollectionCount, 'Error: Collection with incorrect data created.');241 });242}243244export async function findUnusedAddress(api: ApiPromise): Promise<IKeyringPair> {245 let bal = new BigNumber(0);246 let unused;247 do {248 const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000));249 const keyring = new Keyring({ type: 'sr25519' });250 unused = keyring.addFromUri(`//${randomSeed}`);251 bal = new BigNumber((await api.query.system.account(unused.address)).data.free.toString());252 } while (bal.toFixed() != '0');253 return unused;254}255256function getDestroyResult(events: EventRecord[]): boolean {257 let success: boolean = false;258 events.forEach(({ phase, event: { data, method, section } }) => {259 // console.log(` ${phase}: ${section}.${method}:: ${data}`);260 if (method == 'ExtrinsicSuccess') {261 success = true;262 }263 });264 return success;265}266267export async function destroyCollectionExpectFailure(collectionId: number, senderSeed: string = '//Alice') {268 await usingApi(async (api) => {269 // Run the DestroyCollection transaction270 const alicePrivateKey = privateKey(senderSeed);271 const tx = api.tx.nft.destroyCollection(collectionId);272 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;273 });274}275276export async function destroyCollectionExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {277 await usingApi(async (api) => {278 // Run the DestroyCollection transaction279 const alicePrivateKey = privateKey(senderSeed);280 const tx = api.tx.nft.destroyCollection(collectionId);281 const events = await submitTransactionAsync(alicePrivateKey, tx);282 const result = getDestroyResult(events);283284 // Get the collection285 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();286287 // What to expect288 expect(result).to.be.true;289 expect(collection).to.be.not.null;290 expect(collection.Owner).to.be.equal(nullPublicKey);291 });292}293294export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string) {295 await usingApi(async (api) => {296297 // Run the transaction298 const alicePrivateKey = privateKey('//Alice');299 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);300 const events = await submitTransactionAsync(alicePrivateKey, tx);301 const result = getGenericResult(events);302303 // Get the collection304 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();305306 // What to expect307 expect(result.success).to.be.true;308 expect(collection.Sponsor.toString()).to.be.equal(sponsor.toString());309 expect(collection.SponsorConfirmed).to.be.false;310 });311}312313export async function removeCollectionSponsorExpectSuccess(collectionId: number) {314 await usingApi(async (api) => {315316 // Run the transaction317 const alicePrivateKey = privateKey('//Alice');318 const tx = api.tx.nft.removeCollectionSponsor(collectionId);319 const events = await submitTransactionAsync(alicePrivateKey, tx);320 const result = getGenericResult(events);321322 // Get the collection323 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();324325 // What to expect326 expect(result.success).to.be.true;327 expect(collection.Sponsor).to.be.equal(nullPublicKey);328 expect(collection.SponsorConfirmed).to.be.false;329 });330}331332export async function removeCollectionSponsorExpectFailure(collectionId: number) {333 await usingApi(async (api) => {334335 // Run the transaction336 const alicePrivateKey = privateKey('//Alice');337 const tx = api.tx.nft.removeCollectionSponsor(collectionId);338 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;339 });340}341342export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string, senderSeed: string = '//Alice') {343 await usingApi(async (api) => {344345 // Run the transaction346 const alicePrivateKey = privateKey(senderSeed);347 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);348 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;349 });350}351352export async function confirmSponsorshipExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {353 await usingApi(async (api) => {354355 // Run the transaction356 const sender = privateKey(senderSeed);357 const tx = api.tx.nft.confirmSponsorship(collectionId);358 const events = await submitTransactionAsync(sender, tx);359 const result = getGenericResult(events);360361 // Get the collection362 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();363364 // What to expect365 expect(result.success).to.be.true;366 expect(collection.Sponsor).to.be.equal(sender.address);367 expect(collection.SponsorConfirmed).to.be.true;368 });369}370371export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed: string = '//Alice') {372 await usingApi(async (api) => {373374 // Run the transaction375 const sender = privateKey(senderSeed);376 const tx = api.tx.nft.confirmSponsorship(collectionId);377 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;378 });379}380381export async function setVariableMetaDataExpectSuccess(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) {382 await usingApi(async (api) => {383 const tx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(data).toString('hex'));384 const events = await submitTransactionAsync(sender, tx);385 const result = getGenericResult(events);386387 expect(result.success).to.be.true;388 });389}390391export async function setVariableMetaDataExpectFailure(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) {392 await usingApi(async (api) => {393 const tx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(data).toString('hex'));394 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;395 });396}397398export interface CreateFungibleData extends Struct {399 readonly value: u128;400}401402export interface CreateReFungibleData extends Struct {}403export interface CreateNftData extends Struct {}404405export interface CreateItemData extends Enum {406 NFT: CreateNftData;407 Fungible: CreateFungibleData;408 ReFungible: CreateReFungibleData;409}410411export async function burnItemExpectSuccess(owner: IKeyringPair, collectionId: number, tokenId: number, value = 0) {412 await usingApi(async (api) => {413 const tx = api.tx.nft.burnItem(collectionId, tokenId, value);414 const events = await submitTransactionAsync(owner, tx);415 const result = getGenericResult(events);416 // Get the item417 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();418 // What to expect419 // tslint:disable-next-line:no-unused-expression420 expect(result.success).to.be.true;421 // tslint:disable-next-line:no-unused-expression422 expect(item).to.be.not.null;423 expect(item.Owner).to.be.equal(nullPublicKey);424 });425}426427export async function428approveExpectSuccess(collectionId: number,429 tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {430 await usingApi(async (api: ApiPromise) => {431 const allowanceBefore =432 await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;433 const approveNftTx = await api.tx.nft.approve(approved.address, collectionId, tokenId, amount);434 const events = await submitTransactionAsync(owner, approveNftTx);435 const result = getCreateItemResult(events);436 // tslint:disable-next-line:no-unused-expression437 expect(result.success).to.be.true;438 const allowanceAfter =439 await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;440 expect(allowanceAfter.toNumber() - allowanceBefore.toNumber()).to.be.equal(amount);441 });442}443444export async function445transferFromExpectSuccess(collectionId: number,446 tokenId: number,447 accountApproved: IKeyringPair,448 accountFrom: IKeyringPair,449 accountTo: IKeyringPair,450 value: number = 1,451 type: string = 'NFT') {452 await usingApi(async (api: ApiPromise) => {453 let balanceBefore = new BN(0);454 if (type === 'Fungible') {455 balanceBefore = await api.query.nft.balance(collectionId, accountTo.address) as unknown as BN;456 }457 const transferFromTx = await api.tx.nft.transferFrom(458 accountFrom.address, accountTo.address, collectionId, tokenId, value);459 const events = await submitTransactionAsync(accountFrom, transferFromTx);460 const result = getCreateItemResult(events);461 // tslint:disable-next-line:no-unused-expression462 expect(result.success).to.be.true;463 if (type === 'NFT') {464 const nftItemData = await api.query.nft.nftItemList(collectionId, tokenId) as unknown as ITokenDataType;465 expect(nftItemData.Owner.toString()).to.be.equal(accountTo.address);466 }467 if (type === 'Fungible') {468 const balanceAfter = await api.query.nft.balance(collectionId, accountTo.address) as unknown as BN;469 expect(balanceAfter.sub(balanceBefore).toNumber()).to.be.equal(value);470 }471 if (type === 'ReFungible') {472 const nftItemData =473 await api.query.nft.reFungibleItemList(collectionId, tokenId) as unknown as IReFungibleTokenDataType;474 expect(nftItemData.Owner[0].Owner.toString()).to.be.equal(accountTo.address);475 expect(nftItemData.Owner[0].Fraction.toNumber()).to.be.equal(value);476 }477 });478}479480export async function481transferFromExpectFail(collectionId: number,482 tokenId: number,483 accountApproved: IKeyringPair,484 accountFrom: IKeyringPair,485 accountTo: IKeyringPair,486 value: number = 1) {487 await usingApi(async (api: ApiPromise) => {488 const transferFromTx = await api.tx.nft.transferFrom(489 accountFrom.address, accountTo.address, collectionId, tokenId, value);490 const events = await expect(submitTransactionExpectFailAsync(accountApproved, transferFromTx)).to.be.rejected;491 const result = getCreateCollectionResult(events);492 // tslint:disable-next-line:no-unused-expression493 expect(result.success).to.be.false;494 });495}496497export async function498transferExpectSuccess(collectionId: number,499 tokenId: number,500 sender: IKeyringPair,501 recipient: IKeyringPair,502 value: number = 1,503 type: string = 'NFT') {504 await usingApi(async (api: ApiPromise) => {505 let balanceBefore = new BN(0);506 if (type === 'Fungible') {507 balanceBefore = await api.query.nft.balance(collectionId, recipient.address) as unknown as BN;508 }509 const transferTx = await api.tx.nft.transfer(recipient.address, collectionId, tokenId, value);510 const events = await submitTransactionAsync(sender, transferTx);511 const result = getCreateItemResult(events);512 // tslint:disable-next-line:no-unused-expression513 expect(result.success).to.be.true;514 if (type === 'NFT') {515 const nftItemData = await api.query.nft.nftItemList(collectionId, tokenId) as unknown as ITokenDataType;516 expect(nftItemData.Owner.toString()).to.be.equal(recipient.address);517 }518 if (type === 'Fungible') {519 const balanceAfter = await api.query.nft.balance(collectionId, recipient.address) as unknown as BN;520 expect(balanceAfter.sub(balanceBefore).toNumber()).to.be.equal(value);521 }522 if (type === 'ReFungible') {523 const nftItemData =524 await api.query.nft.reFungibleItemList(collectionId, tokenId) as unknown as IReFungibleTokenDataType;525 expect(nftItemData.Owner[0].Owner.toString()).to.be.equal(recipient.address);526 expect(nftItemData.Owner[0].Fraction.toNumber()).to.be.equal(value);527 }528 });529}530531export async function532transferExpectFail(collectionId: number,533 tokenId: number,534 sender: IKeyringPair,535 recipient: IKeyringPair,536 value: number = 1,537 type: string = 'NFT') {538 await usingApi(async (api: ApiPromise) => {539 const transferTx = await api.tx.nft.transfer(recipient.address, collectionId, tokenId, value);540 const events = await expect(submitTransactionExpectFailAsync(sender, transferTx)).to.be.rejected;541 if (events && Array.isArray(events)) {542 const result = getCreateCollectionResult(events);543 // tslint:disable-next-line:no-unused-expression544 expect(result.success).to.be.false;545 }546 });547}548549export async function550approveExpectFail(collectionId: number,551 tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {552 await usingApi(async (api: ApiPromise) => {553 const approveNftTx = await api.tx.nft.approve(approved.address, collectionId, tokenId, amount);554 const events = await expect(submitTransactionExpectFailAsync(owner, approveNftTx)).to.be.rejected;555 const result = getCreateCollectionResult(events);556 // tslint:disable-next-line:no-unused-expression557 expect(result.success).to.be.false;558 });559}560561export async function createItemExpectSuccess(562 sender: IKeyringPair, collectionId: number, createMode: string, owner: string = '') {563 let newItemId: number = 0;564 await usingApi(async (api) => {565 const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);566 const Aitem: any = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON();567 const AItemBalance = new BigNumber(Aitem.Value);568569 if (owner === '') {570 owner = sender.address;571 }572573 let tx;574 if (createMode === 'Fungible') {575 const createData = {fungible: {value: 10}};576 tx = api.tx.nft.createItem(collectionId, owner, createData);577 } else {578 tx = api.tx.nft.createItem(collectionId, owner, createMode);579 }580 const events = await submitTransactionAsync(sender, tx);581 const result = getCreateItemResult(events);582583 const BItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);584 const Bitem: any = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON();585 const BItemBalance = new BigNumber(Bitem.Value);586587 // What to expect588 // tslint:disable-next-line:no-unused-expression589 expect(result.success).to.be.true;590 if (createMode === 'Fungible') {591 expect(BItemBalance.minus(AItemBalance).toNumber()).to.be.equal(10);592 } else {593 expect(BItemCount).to.be.equal(AItemCount + 1);594 }595 expect(collectionId).to.be.equal(result.collectionId);596 expect(BItemCount).to.be.equal(result.itemId);597 newItemId = result.itemId;598 });599 return newItemId;600}601602export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {603 await usingApi(async (api) => {604605 // Run the transaction606 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');607 const events = await submitTransactionAsync(sender, tx);608 const result = getGenericResult(events);609610 // Get the collection611 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();612613 // What to expect614 // tslint:disable-next-line:no-unused-expression615 expect(result.success).to.be.true;616 expect(collection.Access).to.be.equal('WhiteList');617 });618}619620export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {621 await usingApi(async (api) => {622623 // Run the transaction624 const tx = api.tx.nft.setMintPermission(collectionId, true);625 const events = await submitTransactionAsync(sender, tx);626 const result = getGenericResult(events);627628 // Get the collection629 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();630631 // What to expect632 expect(result.success).to.be.true;633 expect(collection.MintMode).to.be.equal(true);634 });635}636637export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {638 await usingApi(async (api) => {639640 const whiteListedBefore = (await api.query.nft.whiteList(collectionId, address)).toJSON();641642 // Run the transaction643 const tx = api.tx.nft.addToWhiteList(collectionId, address);644 const events = await submitTransactionAsync(sender, tx);645 const result = getGenericResult(events);646647 const whiteListedAfter = (await api.query.nft.whiteList(collectionId, address)).toJSON();648649 // What to expect650 // tslint:disable-next-line:no-unused-expression651 expect(result.success).to.be.true;652 // tslint:disable-next-line: no-unused-expression653 expect(whiteListedBefore).to.be.false;654 // tslint:disable-next-line: no-unused-expression655 expect(whiteListedAfter).to.be.true;656 });657}658659export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)660 : Promise<ICollectionInterface | null> => {661 return await api.query.nft.collection(collectionId) as unknown as ICollectionInterface;662};663664export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {665 // set global object - collectionsCount666 return (await api.query.nft.createdCollectionCount() as unknown as BN).toNumber();667};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 IReFungibleOwner {40 Fraction: BN;41 Owner: number[];42}4344interface ITokenDataType {45 Owner: number[];46 ConstData: number[];47 VariableData: number[];48}4950interface IFungibleTokenDataType {51 Value: BN;52}5354interface IReFungibleTokenDataType {55 Owner: IReFungibleOwner[];56 ConstData: number[];57 VariableData: number[];58}5960export function getGenericResult(events: EventRecord[]): GenericResult {61 const result: GenericResult = {62 success: false,63 };64 events.forEach(({ phase, event: { data, method, section } }) => {65 // console.log(` ${phase}: ${section}.${method}:: ${data}`);66 if (method === 'ExtrinsicSuccess') {67 result.success = true;68 }69 });70 return result;71}7273export function getCreateCollectionResult(events: EventRecord[]): CreateCollectionResult {74 let success = false;75 let collectionId: number = 0;76 events.forEach(({ phase, event: { data, method, section } }) => {77 // console.log(` ${phase}: ${section}.${method}:: ${data}`);78 if (method == 'ExtrinsicSuccess') {79 success = true;80 } else if ((section == 'nft') && (method == 'Created')) {81 collectionId = parseInt(data[0].toString());82 }83 });84 const result: CreateCollectionResult = {85 success,86 collectionId,87 };88 return result;89}9091export function getCreateItemResult(events: EventRecord[]): CreateItemResult {92 let success = false;93 let collectionId: number = 0;94 let itemId: number = 0;95 events.forEach(({ phase, event: { data, method, section } }) => {96 // console.log(` ${phase}: ${section}.${method}:: ${data}`);97 if (method == 'ExtrinsicSuccess') {98 success = true;99 } else if ((section == 'nft') && (method == 'ItemCreated')) {100 collectionId = parseInt(data[0].toString());101 itemId = parseInt(data[1].toString());102 }103 });104 const result: CreateItemResult = {105 success,106 collectionId,107 itemId,108 };109 return result;110}111112interface Invalid {113 type: 'Invalid';114}115116interface Nft {117 type: 'NFT';118}119120interface Fungible {121 type: 'Fungible';122 decimalPoints: number;123}124125interface ReFungible {126 type: 'ReFungible';127 decimalPoints: number;128}129130interface Nft {131 type: 'NFT'132}133134interface Fungible {135 type: 'Fungible',136 decimalPoints: number137}138139interface ReFungible {140 type: 'ReFungible',141 decimalPoints: number142}143144type CollectionMode = Nft | Fungible | ReFungible | Invalid;145146export type CreateCollectionParams = {147 mode: CollectionMode,148 name: string,149 description: string,150 tokenPrefix: string,151};152153const defaultCreateCollectionParams: CreateCollectionParams = {154 description: 'description',155 mode: { type: 'NFT' },156 name: 'name',157 tokenPrefix: 'prefix',158}159160export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {161 const {name, description, mode, tokenPrefix } = {...defaultCreateCollectionParams, ...params};162163 let collectionId: number = 0;164 await usingApi(async (api) => {165 // Get number of collections before the transaction166 const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);167168 // Run the CreateCollection transaction169 const alicePrivateKey = privateKey('//Alice');170171 let modeprm = {};172 if (mode.type === 'NFT') {173 modeprm = {nft: null};174 } else if (mode.type === 'Fungible') {175 modeprm = {fungible: mode.decimalPoints};176 } else if (mode.type === 'ReFungible') {177 modeprm = {refungible: mode.decimalPoints};178 } else if (mode.type === 'Invalid') {179 modeprm = {invalid: null};180 }181182 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);183 const events = await submitTransactionAsync(alicePrivateKey, tx);184 const result = getCreateCollectionResult(events);185186 // Get number of collections after the transaction187 const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);188189 // Get the collection190 const collection: any = (await api.query.nft.collection(result.collectionId)).toJSON();191192 // What to expect193 // tslint:disable-next-line:no-unused-expression194 expect(result.success).to.be.true;195 expect(result.collectionId).to.be.equal(BcollectionCount);196 // tslint:disable-next-line:no-unused-expression197 expect(collection).to.be.not.null;198 expect(BcollectionCount).to.be.equal(AcollectionCount + 1, 'Error: NFT collection NOT created.');199 expect(collection.Owner).to.be.equal(alicesPublicKey);200 expect(utf16ToStr(collection.Name)).to.be.equal(name);201 expect(utf16ToStr(collection.Description)).to.be.equal(description);202 expect(hexToStr(collection.TokenPrefix)).to.be.equal(tokenPrefix);203204 collectionId = result.collectionId;205 });206207 return collectionId;208}209210export async function createCollectionExpectFailure(params: Partial<CreateCollectionParams> = {}) {211 const {name, description, mode, tokenPrefix } = {...defaultCreateCollectionParams, ...params};212213 let modeprm = {};214 if (mode.type === 'NFT') {215 modeprm = {nft: null};216 } else if (mode.type === 'Fungible') {217 modeprm = {fungible: mode.decimalPoints};218 } else if (mode.type === 'ReFungible') {219 modeprm = {refungible: mode.decimalPoints};220 } else if (mode.type === 'Invalid') {221 modeprm = {invalid: null};222 }223224 await usingApi(async (api) => {225 // Get number of collections before the transaction226 const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());227228 // Run the CreateCollection transaction229 const alicePrivateKey = privateKey('//Alice');230 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);231 const events = await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;232 const result = getCreateCollectionResult(events);233234 // Get number of collections after the transaction235 const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());236237 // What to expect238 // tslint:disable-next-line:no-unused-expression239 expect(result.success).to.be.false;240 expect(BcollectionCount).to.be.equal(AcollectionCount, 'Error: Collection with incorrect data created.');241 });242}243244export async function findUnusedAddress(api: ApiPromise): Promise<IKeyringPair> {245 let bal = new BigNumber(0);246 let unused;247 do {248 const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000));249 const keyring = new Keyring({ type: 'sr25519' });250 unused = keyring.addFromUri(`//${randomSeed}`);251 bal = new BigNumber((await api.query.system.account(unused.address)).data.free.toString());252 } while (bal.toFixed() != '0');253 return unused;254}255256export async function findNotExistingCollection(api: ApiPromise): Promise<number> {257 let collection: number = parseInt((await api.query.nft.createdCollectionCount()).toString()) as unknown as number + 1;258 return collection;259}260261function getDestroyResult(events: EventRecord[]): boolean {262 let success: boolean = false;263 events.forEach(({ phase, event: { data, method, section } }) => {264 // console.log(` ${phase}: ${section}.${method}:: ${data}`);265 if (method == 'ExtrinsicSuccess') {266 success = true;267 }268 });269 return success;270}271272export async function destroyCollectionExpectFailure(collectionId: number, senderSeed: string = '//Alice') {273 await usingApi(async (api) => {274 // Run the DestroyCollection transaction275 const alicePrivateKey = privateKey(senderSeed);276 const tx = api.tx.nft.destroyCollection(collectionId);277 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;278 });279}280281export async function destroyCollectionExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {282 await usingApi(async (api) => {283 // Run the DestroyCollection transaction284 const alicePrivateKey = privateKey(senderSeed);285 const tx = api.tx.nft.destroyCollection(collectionId);286 const events = await submitTransactionAsync(alicePrivateKey, tx);287 const result = getDestroyResult(events);288289 // Get the collection290 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();291292 // What to expect293 expect(result).to.be.true;294 expect(collection).to.be.not.null;295 expect(collection.Owner).to.be.equal(nullPublicKey);296 });297}298299export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string) {300 await usingApi(async (api) => {301302 // Run the transaction303 const alicePrivateKey = privateKey('//Alice');304 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);305 const events = await submitTransactionAsync(alicePrivateKey, tx);306 const result = getGenericResult(events);307308 // Get the collection309 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();310311 // What to expect312 expect(result.success).to.be.true;313 expect(collection.Sponsor.toString()).to.be.equal(sponsor.toString());314 expect(collection.SponsorConfirmed).to.be.false;315 });316}317318export async function removeCollectionSponsorExpectSuccess(collectionId: number) {319 await usingApi(async (api) => {320321 // Run the transaction322 const alicePrivateKey = privateKey('//Alice');323 const tx = api.tx.nft.removeCollectionSponsor(collectionId);324 const events = await submitTransactionAsync(alicePrivateKey, tx);325 const result = getGenericResult(events);326327 // Get the collection328 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();329330 // What to expect331 expect(result.success).to.be.true;332 expect(collection.Sponsor).to.be.equal(nullPublicKey);333 expect(collection.SponsorConfirmed).to.be.false;334 });335}336337export async function removeCollectionSponsorExpectFailure(collectionId: number) {338 await usingApi(async (api) => {339340 // Run the transaction341 const alicePrivateKey = privateKey('//Alice');342 const tx = api.tx.nft.removeCollectionSponsor(collectionId);343 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;344 });345}346347export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string, senderSeed: string = '//Alice') {348 await usingApi(async (api) => {349350 // Run the transaction351 const alicePrivateKey = privateKey(senderSeed);352 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);353 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;354 });355}356357export async function confirmSponsorshipExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {358 await usingApi(async (api) => {359360 // Run the transaction361 const sender = privateKey(senderSeed);362 const tx = api.tx.nft.confirmSponsorship(collectionId);363 const events = await submitTransactionAsync(sender, tx);364 const result = getGenericResult(events);365366 // Get the collection367 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();368369 // What to expect370 expect(result.success).to.be.true;371 expect(collection.Sponsor).to.be.equal(sender.address);372 expect(collection.SponsorConfirmed).to.be.true;373 });374}375376export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed: string = '//Alice') {377 await usingApi(async (api) => {378379 // Run the transaction380 const sender = privateKey(senderSeed);381 const tx = api.tx.nft.confirmSponsorship(collectionId);382 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;383 });384}385386export async function setVariableMetaDataExpectSuccess(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) {387 await usingApi(async (api) => {388 const tx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(data).toString('hex'));389 const events = await submitTransactionAsync(sender, tx);390 const result = getGenericResult(events);391392 expect(result.success).to.be.true;393 });394}395396export async function setVariableMetaDataExpectFailure(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) {397 await usingApi(async (api) => {398 const tx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(data).toString('hex'));399 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;400 });401}402403export interface CreateFungibleData extends Struct {404 readonly value: u128;405}406407export interface CreateReFungibleData extends Struct {}408export interface CreateNftData extends Struct {}409410export interface CreateItemData extends Enum {411 NFT: CreateNftData;412 Fungible: CreateFungibleData;413 ReFungible: CreateReFungibleData;414}415416export async function burnItemExpectSuccess(owner: IKeyringPair, collectionId: number, tokenId: number, value = 0) {417 await usingApi(async (api) => {418 const tx = api.tx.nft.burnItem(collectionId, tokenId, value);419 const events = await submitTransactionAsync(owner, tx);420 const result = getGenericResult(events);421 // Get the item422 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();423 // What to expect424 // tslint:disable-next-line:no-unused-expression425 expect(result.success).to.be.true;426 // tslint:disable-next-line:no-unused-expression427 expect(item).to.be.not.null;428 expect(item.Owner).to.be.equal(nullPublicKey);429 });430}431432export async function433approveExpectSuccess(collectionId: number,434 tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {435 await usingApi(async (api: ApiPromise) => {436 const allowanceBefore =437 await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;438 const approveNftTx = await api.tx.nft.approve(approved.address, collectionId, tokenId, amount);439 const events = await submitTransactionAsync(owner, approveNftTx);440 const result = getCreateItemResult(events);441 // tslint:disable-next-line:no-unused-expression442 expect(result.success).to.be.true;443 const allowanceAfter =444 await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;445 expect(allowanceAfter.toNumber() - allowanceBefore.toNumber()).to.be.equal(amount);446 });447}448449export async function450transferFromExpectSuccess(collectionId: number,451 tokenId: number,452 accountApproved: IKeyringPair,453 accountFrom: IKeyringPair,454 accountTo: IKeyringPair,455 value: number = 1,456 type: string = 'NFT') {457 await usingApi(async (api: ApiPromise) => {458 let balanceBefore = new BN(0);459 if (type === 'Fungible') {460 balanceBefore = await api.query.nft.balance(collectionId, accountTo.address) as unknown as BN;461 }462 const transferFromTx = await api.tx.nft.transferFrom(463 accountFrom.address, accountTo.address, collectionId, tokenId, value);464 const events = await submitTransactionAsync(accountFrom, transferFromTx);465 const result = getCreateItemResult(events);466 // tslint:disable-next-line:no-unused-expression467 expect(result.success).to.be.true;468 if (type === 'NFT') {469 const nftItemData = await api.query.nft.nftItemList(collectionId, tokenId) as unknown as ITokenDataType;470 expect(nftItemData.Owner.toString()).to.be.equal(accountTo.address);471 }472 if (type === 'Fungible') {473 const balanceAfter = await api.query.nft.balance(collectionId, accountTo.address) as unknown as BN;474 expect(balanceAfter.sub(balanceBefore).toNumber()).to.be.equal(value);475 }476 if (type === 'ReFungible') {477 const nftItemData =478 await api.query.nft.reFungibleItemList(collectionId, tokenId) as unknown as IReFungibleTokenDataType;479 expect(nftItemData.Owner[0].Owner.toString()).to.be.equal(accountTo.address);480 expect(nftItemData.Owner[0].Fraction.toNumber()).to.be.equal(value);481 }482 });483}484485export async function486transferFromExpectFail(collectionId: number,487 tokenId: number,488 accountApproved: IKeyringPair,489 accountFrom: IKeyringPair,490 accountTo: IKeyringPair,491 value: number = 1) {492 await usingApi(async (api: ApiPromise) => {493 const transferFromTx = await api.tx.nft.transferFrom(494 accountFrom.address, accountTo.address, collectionId, tokenId, value);495 const events = await expect(submitTransactionExpectFailAsync(accountApproved, transferFromTx)).to.be.rejected;496 const result = getCreateCollectionResult(events);497 // tslint:disable-next-line:no-unused-expression498 expect(result.success).to.be.false;499 });500}501502export async function503transferExpectSuccess(collectionId: number,504 tokenId: number,505 sender: IKeyringPair,506 recipient: IKeyringPair,507 value: number = 1,508 type: string = 'NFT') {509 await usingApi(async (api: ApiPromise) => {510 let balanceBefore = new BN(0);511 if (type === 'Fungible') {512 balanceBefore = await api.query.nft.balance(collectionId, recipient.address) as unknown as BN;513 }514 const transferTx = await api.tx.nft.transfer(recipient.address, collectionId, tokenId, value);515 const events = await submitTransactionAsync(sender, transferTx);516 const result = getCreateItemResult(events);517 // tslint:disable-next-line:no-unused-expression518 expect(result.success).to.be.true;519 if (type === 'NFT') {520 const nftItemData = await api.query.nft.nftItemList(collectionId, tokenId) as unknown as ITokenDataType;521 expect(nftItemData.Owner.toString()).to.be.equal(recipient.address);522 }523 if (type === 'Fungible') {524 const balanceAfter = await api.query.nft.balance(collectionId, recipient.address) as unknown as BN;525 expect(balanceAfter.sub(balanceBefore).toNumber()).to.be.equal(value);526 }527 if (type === 'ReFungible') {528 const nftItemData =529 await api.query.nft.reFungibleItemList(collectionId, tokenId) as unknown as IReFungibleTokenDataType;530 expect(nftItemData.Owner[0].Owner.toString()).to.be.equal(recipient.address);531 expect(nftItemData.Owner[0].Fraction.toNumber()).to.be.equal(value);532 }533 });534}535536export async function537transferExpectFail(collectionId: number,538 tokenId: number,539 sender: IKeyringPair,540 recipient: IKeyringPair,541 value: number = 1,542 type: string = 'NFT') {543 await usingApi(async (api: ApiPromise) => {544 const transferTx = await api.tx.nft.transfer(recipient.address, collectionId, tokenId, value);545 const events = await expect(submitTransactionExpectFailAsync(sender, transferTx)).to.be.rejected;546 if (events && Array.isArray(events)) {547 const result = getCreateCollectionResult(events);548 // tslint:disable-next-line:no-unused-expression549 expect(result.success).to.be.false;550 }551 });552}553554export async function555approveExpectFail(collectionId: number,556 tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {557 await usingApi(async (api: ApiPromise) => {558 const approveNftTx = await api.tx.nft.approve(approved.address, collectionId, tokenId, amount);559 const events = await expect(submitTransactionExpectFailAsync(owner, approveNftTx)).to.be.rejected;560 const result = getCreateCollectionResult(events);561 // tslint:disable-next-line:no-unused-expression562 expect(result.success).to.be.false;563 });564}565566export async function createItemExpectSuccess(567 sender: IKeyringPair, collectionId: number, createMode: string, owner: string = '') {568 let newItemId: number = 0;569 await usingApi(async (api) => {570 const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);571 const Aitem: any = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON();572 const AItemBalance = new BigNumber(Aitem.Value);573574 if (owner === '') {575 owner = sender.address;576 }577578 let tx;579 if (createMode === 'Fungible') {580 const createData = {fungible: {value: 10}};581 tx = api.tx.nft.createItem(collectionId, owner, createData);582 } else {583 tx = api.tx.nft.createItem(collectionId, owner, createMode);584 }585 const events = await submitTransactionAsync(sender, tx);586 const result = getCreateItemResult(events);587588 const BItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);589 const Bitem: any = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON();590 const BItemBalance = new BigNumber(Bitem.Value);591592 // What to expect593 // tslint:disable-next-line:no-unused-expression594 expect(result.success).to.be.true;595 if (createMode === 'Fungible') {596 expect(BItemBalance.minus(AItemBalance).toNumber()).to.be.equal(10);597 } else {598 expect(BItemCount).to.be.equal(AItemCount + 1);599 }600 expect(collectionId).to.be.equal(result.collectionId);601 expect(BItemCount).to.be.equal(result.itemId);602 newItemId = result.itemId;603 });604 return newItemId;605}606607export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {608 await usingApi(async (api) => {609610 // Run the transaction611 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');612 const events = await submitTransactionAsync(sender, tx);613 const result = getGenericResult(events);614615 // Get the collection616 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();617618 // What to expect619 // tslint:disable-next-line:no-unused-expression620 expect(result.success).to.be.true;621 expect(collection.Access).to.be.equal('WhiteList');622 });623}624625export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {626 await usingApi(async (api) => {627628 // Run the transaction629 const tx = api.tx.nft.setMintPermission(collectionId, true);630 const events = await submitTransactionAsync(sender, tx);631 const result = getGenericResult(events);632633 // Get the collection634 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();635636 // What to expect637 expect(result.success).to.be.true;638 expect(collection.MintMode).to.be.equal(true);639 });640}641642export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {643 await usingApi(async (api) => {644645 const whiteListedBefore = (await api.query.nft.whiteList(collectionId, address)).toJSON();646647 // Run the transaction648 const tx = api.tx.nft.addToWhiteList(collectionId, address);649 const events = await submitTransactionAsync(sender, tx);650 const result = getGenericResult(events);651652 const whiteListedAfter = (await api.query.nft.whiteList(collectionId, address)).toJSON();653654 // What to expect655 // tslint:disable-next-line:no-unused-expression656 expect(result.success).to.be.true;657 // tslint:disable-next-line: no-unused-expression658 expect(whiteListedBefore).to.be.false;659 // tslint:disable-next-line: no-unused-expression660 expect(whiteListedAfter).to.be.true;661 });662}663664export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)665 : Promise<ICollectionInterface | null> => {666 return await api.query.nft.collection(collectionId) as unknown as ICollectionInterface;667};668669export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {670 // set global object - collectionsCount671 return (await api.query.nft.createdCollectionCount() as unknown as BN).toNumber();672};