git.delta.rocks / unique-network / refs/commits / d41cda7482d4

difftreelog

source

tests/src/rmrk/removeResource.test.ts7.9 KiBsourcehistory
1import {expect} from 'chai';2import privateKey from '../substrate/privateKey';3import {executeTransaction, getApiConnection} from '../substrate/substrate-api';4import {getNft, NftIdTuple} from './util/fetch';5import {expectTxFailure} from './util/helpers';6import {7  acceptNft, acceptResourceRemoval, addNftBasicResource,8  createBase,9  createCollection,10  mintNft, removeNftResource, sendNft,11} from './util/tx';1213141516describe('Integration test: remove nft resource', () => {17  let api: any;18  let ss58Format: string;19  before(async () => {20    api = await getApiConnection();21    ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;22  });2324  const Alice = '//Alice';25  const Bob = '//Bob';26  const src = 'test-basic-src';27  const metadata = 'test-basic-metadata';28  const license = 'test-basic-license';29  const thumb = 'test-basic-thumb';3031  it('deleting a resource directly by the NFT owner', async () => {32    const collectionIdAlice = await createCollection(33      api,34      Alice,35      'test-metadata',36      null,37      'test-symbol',38    );3940    const nftAlice = await mintNft(41      api,42      Alice,43      Alice,44      collectionIdAlice,45      'nft-metadata',46    );4748    const resourceId = await addNftBasicResource(49      api,50      Alice,51      'added',52      collectionIdAlice,53      nftAlice,54      src,55      metadata,56      license,57      thumb,58    );5960    await removeNftResource(api, 'removed', Alice, collectionIdAlice, nftAlice, resourceId);61  });6263  it('deleting resources indirectly by the NFT owner', async () => {64    const collectionIdAlice = await createCollection(65      api,66      Alice,67      'test-metadata',68      null,69      'test-symbol',70    );7172    const parentNftId = await mintNft(api, Alice, Alice, collectionIdAlice, 'parent-nft-metadata');73    const childNftId = await mintNft(api, Alice, Alice, collectionIdAlice, 'child-nft-metadata');7475    const resourceId = await addNftBasicResource(76      api,77      Alice,78      'added',79      collectionIdAlice,80      childNftId,81      src,82      metadata,83      license,84      thumb,85    );8687    const newOwnerNFT: NftIdTuple = [collectionIdAlice, parentNftId];8889    await sendNft(api, 'sent', Alice, collectionIdAlice, childNftId, newOwnerNFT);9091    await removeNftResource(api, 'removed', Alice, collectionIdAlice, childNftId, resourceId);92  });9394  it('deleting a resource by the collection owner', async () => {95    const collectionIdAlice = await createCollection(96      api,97      Alice,98      'test-metadata',99      null,100      'test-symbol',101    );102103    const nftBob = await mintNft(104      api,105      Alice,106      Bob,107      collectionIdAlice,108      'nft-metadata',109    );110111    const resourceId = await addNftBasicResource(112      api,113      Alice,114      'pending',115      collectionIdAlice,116      nftBob,117      src,118      metadata,119      license,120      thumb,121    );122123    await removeNftResource(api, 'pending', Alice, collectionIdAlice, nftBob, resourceId);124    await acceptResourceRemoval(api, Bob, collectionIdAlice, nftBob, resourceId);125  });126127  it('deleting a resource in a nested NFT by the collection owner', async () => {128    const collectionIdAlice = await createCollection(129      api,130      Alice,131      'test-metadata',132      null,133      'test-symbol',134    );135136    const parentNftId = await mintNft(137      api,138      Alice,139      Bob,140      collectionIdAlice,141      'parent-nft-metadata',142    );143    const childNftId = await mintNft(144      api,145      Alice,146      Bob,147      collectionIdAlice,148      'child-nft-metadata',149    );150151    const resourceId = await addNftBasicResource(152      api,153      Alice,154      'pending',155      collectionIdAlice,156      childNftId,157      src,158      metadata,159      license,160      thumb,161    );162163    const newOwnerNFT: NftIdTuple = [collectionIdAlice, parentNftId];164165    await sendNft(api, 'sent', Bob, collectionIdAlice, childNftId, newOwnerNFT);166167    await removeNftResource(api, 'pending', Alice, collectionIdAlice, childNftId, resourceId);168    await acceptResourceRemoval(api, Bob, collectionIdAlice, childNftId, resourceId);169  });170171  it('[negative]: can\'t delete a resource in a non-existing collection', async () => {172    const collectionIdAlice = await createCollection(173      api,174      Alice,175      'test-metadata',176      null,177      'test-symbol',178    );179180    const nftAlice = await mintNft(181      api,182      Alice,183      Alice,184      collectionIdAlice,185      'nft-metadata',186    );187188    const resourceId = await addNftBasicResource(189      api,190      Alice,191      'added',192      collectionIdAlice,193      nftAlice,194      src,195      metadata,196      license,197      thumb,198    );199200    const tx = removeNftResource(api, 'removed', Alice, 0xFFFFFFFF, nftAlice, resourceId);201    await expectTxFailure(/rmrkCore\.CollectionUnknown/, tx); // FIXME: inappropriate error message (NoAvailableNftId)202  });203204  it('[negative]: only collection owner can delete a resource', async () => {205    const collectionIdAlice = await createCollection(206      api,207      Alice,208      'test-metadata',209      null,210      'test-symbol',211    );212213    const nftAlice = await mintNft(214      api,215      Alice,216      Alice,217      collectionIdAlice,218      'nft-metadata',219    );220221    const resourceId = await addNftBasicResource(222      api,223      Alice,224      'added',225      collectionIdAlice,226      nftAlice,227      src,228      metadata,229      license,230      thumb,231    );232233    const tx = removeNftResource(api, 'removed', Bob, collectionIdAlice, nftAlice, resourceId);234    await expectTxFailure(/rmrkCore\.NoPermission/, tx);235  });236237  it('[negative]: cannot delete a resource that does not exist', async () => {238    const collectionIdAlice = await createCollection(239      api,240      Alice,241      'test-metadata',242      null,243      'test-symbol',244    );245246    const nftAlice = await mintNft(247      api,248      Alice,249      Alice,250      collectionIdAlice,251      'nft-metadata',252    );253254    const tx = removeNftResource(api, 'removed', Alice, collectionIdAlice, nftAlice, 127);255    await expectTxFailure(/rmrkCore\.ResourceDoesntExist/, tx);256  });257258  it('[negative]: Cannot accept deleting resource without owner attempt do delete it', async () => {259    const collectionIdAlice = await createCollection(260      api,261      Alice,262      'test-metadata',263      null,264      'test-symbol',265    );266267    const nftBob = await mintNft(268      api,269      Alice,270      Bob,271      collectionIdAlice,272      'nft-metadata',273    );274275    const resourceId = await addNftBasicResource(276      api,277      Alice,278      'pending',279      collectionIdAlice,280      nftBob,281      src,282      metadata,283      license,284      thumb,285    );286287    const tx = acceptResourceRemoval(api, Bob, collectionIdAlice, nftBob, resourceId);288    await expectTxFailure(/rmrkCore\.ResourceNotPending/, tx);289  });290291  it('[negative]: cannot confirm the deletion of a non-existing resource', async () => {292    const collectionIdAlice = await createCollection(293      api,294      Alice,295      'test-metadata',296      null,297      'test-symbol',298    );299300    const nftBob = await mintNft(301      api,302      Alice,303      Bob,304      collectionIdAlice,305      'nft-metadata',306    );307308    const tx = acceptResourceRemoval(api, Bob, collectionIdAlice, nftBob, 127);309    await expectTxFailure(/rmrkCore\.ResourceDoesntExist/, tx);310  });311312  it('[negative]: Non-owner user cannot confirm the deletion of resource', async () => {313    const collectionIdAlice = await createCollection(314      api,315      Alice,316      'test-metadata',317      null,318      'test-symbol',319    );320321    const nftAlice = await mintNft(322      api,323      Alice,324      Alice,325      collectionIdAlice,326      'nft-metadata',327    );328329    const resourceId = await addNftBasicResource(330      api,331      Alice,332      'added',333      collectionIdAlice,334      nftAlice,335      src,336      metadata,337      license,338      thumb,339    );340341    const tx = acceptResourceRemoval(api, Bob, collectionIdAlice, nftAlice, resourceId);342    await expectTxFailure(/rmrkCore\.NoPermission/, tx);343  });344345  after(() => {346    api.disconnect();347  });348});