1import { getApiConnection } from "../substrate/substrate-api";2import { expectTxFailure } from "./util/helpers";3import { NftIdTuple, getChildren } from './util/fetch';4import { burnNft, createCollection, sendNft, mintNft } from "./util/tx";56import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';89chai.use(chaiAsPromised);10const expect = chai.expect;1112describe("integration test: burn nft", () => {13 const Alice = "//Alice";14 const Bob = "//Bob";1516 let api: any;17 before(async () => {18 api = await getApiConnection();19 });2021 it("burn nft", async () => {22 await createCollection(23 api,24 Alice,25 "test-metadata",26 null,27 "test-symbol"28 ).then(async (collectionId) => {29 const nftId = await mintNft(30 api,31 Alice,32 Alice,33 collectionId,34 "nft-metadata"35 );36 await burnNft(api, Alice, collectionId, nftId);37 });38 });3940 it("burn nft with children", async () => {41 const collectionId = await createCollection(42 api,43 Alice,44 "test-metadata",45 null,46 "test-symbol"47 );4849 const parentNftId = await mintNft(50 api,51 Alice,52 Alice,53 collectionId,54 "nft-metadata"55 );5657 const childNftId = await mintNft(58 api,59 Alice,60 Alice,61 collectionId,62 "nft-metadata"63 );6465 const newOwnerNFT: NftIdTuple = [collectionId, parentNftId];6667 await sendNft(api, "sent", Alice, collectionId, childNftId, newOwnerNFT);6869 const childrenBefore = await getChildren(api, collectionId, parentNftId);70 expect(childrenBefore.length === 1, 'Error: parent NFT should have children')71 .to.be.true;7273 let child = childrenBefore[0];74 expect(child.collectionId.eq(collectionId), 'Error: invalid child collection Id')75 .to.be.true;7677 expect(child.nftId.eq(childNftId), 'Error: invalid child NFT Id')78 .to.be.true;7980 await burnNft(api, Alice, collectionId, parentNftId);8182 const childrenAfter = await getChildren(api, collectionId, parentNftId);8384 expect(childrenAfter.length === 0, 'Error: children should be burned').to.be.true;85 });8687 it("burn child nft", async () => {88 const collectionId = await createCollection(89 api,90 Alice,91 "test-metadata",92 null,93 "test-symbol"94 );9596 const parentNftId = await mintNft(97 api,98 Alice,99 Alice,100 collectionId,101 "nft-metadata"102 );103104 const childNftId = await mintNft(105 api,106 Alice,107 Alice,108 collectionId,109 "nft-metadata"110 );111112 const newOwnerNFT: NftIdTuple = [collectionId, parentNftId];113114 await sendNft(api, "sent", Alice, collectionId, childNftId, newOwnerNFT);115116 const childrenBefore = await getChildren(api, collectionId, parentNftId);117 expect(childrenBefore.length === 1, 'Error: parent NFT should have children')118 .to.be.true;119120 let child = childrenBefore[0];121 expect(child.collectionId.eq(collectionId), 'Error: invalid child collection Id')122 .to.be.true;123124 expect(child.nftId.eq(childNftId), 'Error: invalid child NFT Id')125 .to.be.true;126127 await burnNft(api, Alice, collectionId, childNftId);128129 const childrenAfter = await getChildren(api, collectionId, parentNftId);130131 expect(childrenAfter.length === 0, 'Error: children should be burned').to.be.true;132 });133134 it("[negative] burn non-existing NFT", async () => {135 await createCollection(136 api,137 Alice,138 "test-metadata",139 null,140 "test-symbol"141 ).then(async (collectionId) => {142 const tx = burnNft(api, Alice, collectionId, 99999);143 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);144 });145 });146147 it("[negative] burn not an owner NFT user", async () => {148 await createCollection(149 api,150 Alice,151 "test-metadata",152 null,153 "test-symbol"154 ).then(async (collectionId) => {155 const nftId = await mintNft(156 api,157 Alice,158 Alice,159 collectionId,160 "nft-metadata"161 );162 const tx = burnNft(api, Bob, collectionId, nftId);163 await expectTxFailure(/rmrkCore\.NoPermission/, tx);164 });165 });166167 after(() => {168 api.disconnect();169 });170});