1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import { default as usingApi, submitTransactionAsync } from "./substrate/substrate-api";4import { createCollectionExpectSuccess, createCollectionExpectFailure } from "./util/helpers";5import type { AccountId, EventRecord } from '@polkadot/types/interfaces';6import privateKey from './substrate/privateKey';7import { nullPublicKey } from './accounts'; 89chai.use(chaiAsPromised);10const expect = chai.expect;1112function getDestroyResult(events: EventRecord[]): boolean {13 let success: boolean = false;14 events.forEach(({ phase, event: { data, method, section } }) => {15 16 if (method == 'ExtrinsicSuccess') {17 success = true;18 }19 });20 return success;21}2223async function destroyCollectionExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {24 await usingApi(async (api) => {25 26 const alicePrivateKey = privateKey(senderSeed);27 const tx = api.tx.nft.destroyCollection(collectionId);28 const events = await submitTransactionAsync(alicePrivateKey, tx);29 const result = getDestroyResult(events);3031 32 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();3334 35 expect(result).to.be.true;36 expect(collection).to.be.not.null;37 expect(collection.Owner).to.be.equal(nullPublicKey);38 });39}4041async function destroyCollectionExpectFailure(collectionId: number, senderSeed: string = '//Alice') {42 await usingApi(async (api) => {43 44 const alicePrivateKey = privateKey(senderSeed);45 const tx = api.tx.nft.destroyCollection(collectionId);46 const events = await submitTransactionAsync(alicePrivateKey, tx);47 const result = getDestroyResult(events);4849 50 expect(result).to.be.false;51 });52}5354describe('integration test: ext. destroyCollection():', () => {55 it('NFT collection can be destroyed', async () => {56 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');57 await destroyCollectionExpectSuccess(collectionId);58 });59 it('Fungible collection can be destroyed', async () => {60 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'Fungible');61 await destroyCollectionExpectSuccess(collectionId);62 });63 it('ReFungible collection can be destroyed', async () => {64 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'ReFungible');65 await destroyCollectionExpectSuccess(collectionId);66 });67});6869describe('(!negative test!) integration test: ext. destroyCollection():', () => {70 it('(!negative test!) Destroy a collection that never existed', async () => {71 await usingApi(async (api) => {72 73 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;74 await destroyCollectionExpectFailure(collectionId);75 });76 });77 it('(!negative test!) Destroy a collection that has already been destroyed', async () => {78 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');79 await destroyCollectionExpectSuccess(collectionId);80 await destroyCollectionExpectFailure(collectionId);81 });82 it('(!negative test!) Destroy a collection using non-owner account', async () => {83 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');84 await destroyCollectionExpectFailure(collectionId, '//Bob');85 await destroyCollectionExpectSuccess(collectionId, '//Alice');86 });87});