123456import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';7import { Keyring } from "@polkadot/api";8import { IKeyringPair } from "@polkadot/types/types";9import { 10 createCollectionExpectSuccess, 11 createItemExpectSuccess,12 getGenericResult,13 destroyCollectionExpectSuccess,14 normalizeAccountId15} from './util/helpers';16import { nullPublicKey } from "./accounts";1718import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20chai.use(chaiAsPromised);21const expect = chai.expect;2223let alice: IKeyringPair;24let bob: IKeyringPair;2526describe('integration test: ext. burnItem():', () => {27 before(async () => {28 await usingApi(async (api) => {29 const keyring = new Keyring({ type: 'sr25519' });30 alice = keyring.addFromUri(`//Alice`);31 bob = keyring.addFromUri(`//Bob`);32 });33 });3435 it('Burn item in NFT collection', async () => {36 const createMode = 'NFT';37 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});38 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);3940 await usingApi(async (api) => {41 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);42 const events = await submitTransactionAsync(alice, tx);43 const result = getGenericResult(events);44 45 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();46 47 48 expect(result.success).to.be.true;49 50 expect(item).to.be.null;51 });5253 });54 it('Burn item in Fungible collection', async () => {55 const createMode = 'Fungible';56 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0 }});57 await createItemExpectSuccess(alice, collectionId, createMode); 58 const tokenId = 0; 5960 await usingApi(async (api) => {61 62 const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);63 const events = await submitTransactionAsync(alice, tx);64 const result = getGenericResult(events);65 66 67 const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();68 69 70 expect(result.success).to.be.true;71 expect(balance).to.be.not.null;72 expect(balance.Value).to.be.equal(9);73 });7475 });76 it('Burn item in ReFungible collection', async () => {77 const createMode = 'ReFungible';78 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});79 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);8081 await usingApi(async (api) => {82 const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);83 const events = await submitTransactionAsync(alice, tx);84 const result = getGenericResult(events);85 86 87 const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();88 89 90 expect(result.success).to.be.true;91 expect(balance).to.be.null;92 });9394 });9596 it('Burn owned portion of item in ReFungible collection', async () => {97 const createMode = 'ReFungible';98 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});99 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);100101 await usingApi(async (api) => {102 103 const transfertx = api.tx.nft.transfer(normalizeAccountId(bob.address), collectionId, tokenId, 1);104 const events1 = await submitTransactionAsync(alice, transfertx);105 const result1 = getGenericResult(events1);106107 108 const balanceBefore: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();109110 111 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);112 const events2 = await submitTransactionAsync(bob, tx);113 const result2 = getGenericResult(events2);114115 116 const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();117 118 119 120 expect(result1.success).to.be.true;121 expect(balanceBefore).to.be.not.null;122 expect(balanceBefore.Owner.length).to.be.equal(2);123 expect(balanceBefore.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(alice.address));124 expect(balanceBefore.Owner[0].Fraction).to.be.equal(99);125 expect(balanceBefore.Owner[1].Owner).to.be.deep.equal(normalizeAccountId(bob.address));126 expect(balanceBefore.Owner[1].Fraction).to.be.equal(1);127128 129 expect(result2.success).to.be.true;130 expect(balance).to.be.not.null;131 expect(balance.Owner.length).to.be.equal(1);132 expect(balance.Owner[0].Fraction).to.be.equal(99);133 expect(balance.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(alice.address));134 });135136 });137138});139140describe('Negative integration test: ext. burnItem():', () => {141 before(async () => {142 await usingApi(async (api) => {143 const keyring = new Keyring({ type: 'sr25519' });144 alice = keyring.addFromUri(`//Alice`);145 bob = keyring.addFromUri(`//Bob`);146 });147 });148149 it('Burn a token in a destroyed collection', async () => {150 const createMode = 'NFT';151 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});152 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);153 await destroyCollectionExpectSuccess(collectionId);154155 await usingApi(async (api) => {156 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);157 const badTransaction = async function () { 158 await submitTransactionExpectFailAsync(alice, tx);159 };160 await expect(badTransaction()).to.be.rejected;161 });162163 });164165 it('Burn a token that was never created', async () => {166 const createMode = 'NFT';167 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});168 const tokenId = 10;169170 await usingApi(async (api) => {171 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);172 const badTransaction = async function () { 173 await submitTransactionExpectFailAsync(alice, tx);174 };175 await expect(badTransaction()).to.be.rejected;176 });177178 });179180 it('Burn a token using the address that does not own it', async () => {181 const createMode = 'NFT';182 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});183 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);184185 await usingApi(async (api) => {186 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);187 const badTransaction = async function () { 188 await submitTransactionExpectFailAsync(bob, tx);189 };190 await expect(badTransaction()).to.be.rejected;191 });192193 });194195 it('Transfer a burned a token', async () => {196 const createMode = 'NFT';197 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});198 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);199200 await usingApi(async (api) => {201202 const burntx = api.tx.nft.burnItem(collectionId, tokenId, 0);203 const events1 = await submitTransactionAsync(alice, burntx);204 const result1 = getGenericResult(events1);205 expect(result1.success).to.be.true;206 207 const tx = api.tx.nft.transfer(normalizeAccountId(bob.address), collectionId, tokenId, 0);208 const badTransaction = async function () { 209 await submitTransactionExpectFailAsync(alice, tx);210 };211 await expect(badTransaction()).to.be.rejected;212 });213214 });215216 it('Burn more than owned in Fungible collection', async () => {217 const createMode = 'Fungible';218 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0 }});219 220 await createItemExpectSuccess(alice, collectionId, createMode);221 const tokenId = 0; 222223 await usingApi(async (api) => {224 225 const tx = api.tx.nft.burnItem(collectionId, tokenId, 11);226 const badTransaction = async function () { 227 await submitTransactionExpectFailAsync(alice, tx);228 };229 await expect(badTransaction()).to.be.rejected;230 231 232 const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();233 234 235 expect(balance).to.be.not.null;236 expect(balance.Value).to.be.equal(10);237 });238239 });240241});