git.delta.rocks / unique-network / refs/commits / 6d28dd8067cd

difftreelog

source

tests/src/rmrk/burnNft.seqtest.ts4.2 KiBsourcehistory
1import {getApiConnection} from '../substrate/substrate-api';2import {expectTxFailure, requirePallets, Pallets} 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 function() {18    api = await getApiConnection();19    await requirePallets(this, [Pallets.RmrkCore]);20  });212223  it('burn nft', async () => {24    await createCollection(25      api,26      alice,27      'test-metadata',28      null,29      'test-symbol',30    ).then(async (collectionId) => {31      const nftId = await mintNft(32        api,33        alice,34        alice,35        collectionId,36        'nft-metadata',37      );38      await burnNft(api, alice, collectionId, nftId);39    });40  });4142  it('burn nft with children', async () => {43    const collectionId = await createCollection(44      api,45      alice,46      'test-metadata',47      null,48      'test-symbol',49    );5051    const parentNftId = await mintNft(52      api,53      alice,54      alice,55      collectionId,56      'nft-metadata',57    );5859    const childNftId = await mintNft(60      api,61      alice,62      alice,63      collectionId,64      'nft-metadata',65    );6667    const newOwnerNFT: NftIdTuple = [collectionId, parentNftId];6869    await sendNft(api, 'sent', alice, collectionId, childNftId, newOwnerNFT);7071    const childrenBefore = await getChildren(api, collectionId, parentNftId);72    expect(childrenBefore.length === 1, 'Error: parent NFT should have children')73      .to.be.true;7475    const child = childrenBefore[0];76    expect(child.collectionId.eq(collectionId), 'Error: invalid child collection Id')77      .to.be.true;7879    expect(child.nftId.eq(childNftId), 'Error: invalid child NFT Id')80      .to.be.true;8182    await burnNft(api, alice, collectionId, parentNftId);8384    const childrenAfter = await getChildren(api, collectionId, parentNftId);8586    expect(childrenAfter.length === 0, 'Error: children should be burned').to.be.true;87  });8889  it('burn child nft', async () => {90    const collectionId = await createCollection(91      api,92      alice,93      'test-metadata',94      null,95      'test-symbol',96    );9798    const parentNftId = await mintNft(99      api,100      alice,101      alice,102      collectionId,103      'nft-metadata',104    );105106    const childNftId = await mintNft(107      api,108      alice,109      alice,110      collectionId,111      'nft-metadata',112    );113114    const newOwnerNFT: NftIdTuple = [collectionId, parentNftId];115116    await sendNft(api, 'sent', alice, collectionId, childNftId, newOwnerNFT);117118    const childrenBefore = await getChildren(api, collectionId, parentNftId);119    expect(childrenBefore.length === 1, 'Error: parent NFT should have children')120      .to.be.true;121122    const child = childrenBefore[0];123    expect(child.collectionId.eq(collectionId), 'Error: invalid child collection Id')124      .to.be.true;125126    expect(child.nftId.eq(childNftId), 'Error: invalid child NFT Id')127      .to.be.true;128129    await burnNft(api, alice, collectionId, childNftId);130131    const childrenAfter = await getChildren(api, collectionId, parentNftId);132133    expect(childrenAfter.length === 0, 'Error: children should be burned').to.be.true;134  });135136  it('[negative] burn non-existing NFT', async () => {137    await createCollection(138      api,139      alice,140      'test-metadata',141      null,142      'test-symbol',143    ).then(async (collectionId) => {144      const tx = burnNft(api, alice, collectionId, 99999);145      await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);146    });147  });148149  it('[negative] burn not an owner NFT user', async () => {150    await createCollection(151      api,152      alice,153      'test-metadata',154      null,155      'test-symbol',156    ).then(async (collectionId) => {157      const nftId = await mintNft(158        api,159        alice,160        alice,161        collectionId,162        'nft-metadata',163      );164      const tx = burnNft(api, bob, collectionId, nftId);165      await expectTxFailure(/rmrkCore\.NoPermission/, tx);166    });167  });168169  after(async() => { await api.disconnect(); });170});