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

difftreelog

source

tests/src/rmrk/removeResource.seqtest.ts7.7 KiBsourcehistory
1import {getApiConnection} from '../substrate/substrate-api';2import {NftIdTuple} from './util/fetch';3import {expectTxFailure, requirePallets, Pallets} from './util/helpers';4import {5  acceptResourceRemoval, addNftBasicResource, createCollection, mintNft, removeNftResource, sendNft,6} from './util/tx';7891011describe('Integration test: remove nft resource', () => {12  let api: any;13  before(async function() {14    api = await getApiConnection();15    await requirePallets(this, [Pallets.RmrkCore]);16  });1718  const alice = '//Alice';19  const bob = '//Bob';20  const src = 'test-basic-src';21  const metadata = 'test-basic-metadata';22  const license = 'test-basic-license';23  const thumb = 'test-basic-thumb';2425  it('deleting a resource directly by the NFT owner', async () => {26    const collectionIdAlice = await createCollection(27      api,28      alice,29      'test-metadata',30      null,31      'test-symbol',32    );3334    const nftAlice = await mintNft(35      api,36      alice,37      alice,38      collectionIdAlice,39      'nft-metadata',40    );4142    const resourceId = await addNftBasicResource(43      api,44      alice,45      'added',46      collectionIdAlice,47      nftAlice,48      src,49      metadata,50      license,51      thumb,52    );5354    await removeNftResource(api, 'removed', alice, collectionIdAlice, nftAlice, resourceId);55  });5657  it('deleting resources indirectly by the NFT owner', async () => {58    const collectionIdAlice = await createCollection(59      api,60      alice,61      'test-metadata',62      null,63      'test-symbol',64    );6566    const parentNftId = await mintNft(api, alice, alice, collectionIdAlice, 'parent-nft-metadata');67    const childNftId = await mintNft(api, alice, alice, collectionIdAlice, 'child-nft-metadata');6869    const resourceId = await addNftBasicResource(70      api,71      alice,72      'added',73      collectionIdAlice,74      childNftId,75      src,76      metadata,77      license,78      thumb,79    );8081    const newOwnerNFT: NftIdTuple = [collectionIdAlice, parentNftId];8283    await sendNft(api, 'sent', alice, collectionIdAlice, childNftId, newOwnerNFT);8485    await removeNftResource(api, 'removed', alice, collectionIdAlice, childNftId, resourceId);86  });8788  it('deleting a resource by the collection owner', async () => {89    const collectionIdAlice = await createCollection(90      api,91      alice,92      'test-metadata',93      null,94      'test-symbol',95    );9697    const nftBob = await mintNft(98      api,99      alice,100      bob,101      collectionIdAlice,102      'nft-metadata',103    );104105    const resourceId = await addNftBasicResource(106      api,107      alice,108      'pending',109      collectionIdAlice,110      nftBob,111      src,112      metadata,113      license,114      thumb,115    );116117    await removeNftResource(api, 'pending', alice, collectionIdAlice, nftBob, resourceId);118    await acceptResourceRemoval(api, bob, collectionIdAlice, nftBob, resourceId);119  });120121  it('deleting a resource in a nested NFT by the collection owner', async () => {122    const collectionIdAlice = await createCollection(123      api,124      alice,125      'test-metadata',126      null,127      'test-symbol',128    );129130    const parentNftId = await mintNft(131      api,132      alice,133      bob,134      collectionIdAlice,135      'parent-nft-metadata',136    );137    const childNftId = await mintNft(138      api,139      alice,140      bob,141      collectionIdAlice,142      'child-nft-metadata',143    );144145    const resourceId = await addNftBasicResource(146      api,147      alice,148      'pending',149      collectionIdAlice,150      childNftId,151      src,152      metadata,153      license,154      thumb,155    );156157    const newOwnerNFT: NftIdTuple = [collectionIdAlice, parentNftId];158159    await sendNft(api, 'sent', bob, collectionIdAlice, childNftId, newOwnerNFT);160161    await removeNftResource(api, 'pending', alice, collectionIdAlice, childNftId, resourceId);162    await acceptResourceRemoval(api, bob, collectionIdAlice, childNftId, resourceId);163  });164165  it('[negative]: can\'t delete a resource in a non-existing collection', async () => {166    const collectionIdAlice = await createCollection(167      api,168      alice,169      'test-metadata',170      null,171      'test-symbol',172    );173174    const nftAlice = await mintNft(175      api,176      alice,177      alice,178      collectionIdAlice,179      'nft-metadata',180    );181182    const resourceId = await addNftBasicResource(183      api,184      alice,185      'added',186      collectionIdAlice,187      nftAlice,188      src,189      metadata,190      license,191      thumb,192    );193194    const tx = removeNftResource(api, 'removed', alice, 0xFFFFFFFF, nftAlice, resourceId);195    await expectTxFailure(/rmrkCore\.CollectionUnknown/, tx); // FIXME: inappropriate error message (NoAvailableNftId)196  });197198  it('[negative]: only collection owner can delete a resource', async () => {199    const collectionIdAlice = await createCollection(200      api,201      alice,202      'test-metadata',203      null,204      'test-symbol',205    );206207    const nftAlice = await mintNft(208      api,209      alice,210      alice,211      collectionIdAlice,212      'nft-metadata',213    );214215    const resourceId = await addNftBasicResource(216      api,217      alice,218      'added',219      collectionIdAlice,220      nftAlice,221      src,222      metadata,223      license,224      thumb,225    );226227    const tx = removeNftResource(api, 'removed', bob, collectionIdAlice, nftAlice, resourceId);228    await expectTxFailure(/rmrkCore\.NoPermission/, tx);229  });230231  it('[negative]: cannot delete a resource that does not exist', async () => {232    const collectionIdAlice = await createCollection(233      api,234      alice,235      'test-metadata',236      null,237      'test-symbol',238    );239240    const nftAlice = await mintNft(241      api,242      alice,243      alice,244      collectionIdAlice,245      'nft-metadata',246    );247248    const tx = removeNftResource(api, 'removed', alice, collectionIdAlice, nftAlice, 127);249    await expectTxFailure(/rmrkCore\.ResourceDoesntExist/, tx);250  });251252  it('[negative]: Cannot accept deleting resource without owner attempt do delete it', async () => {253    const collectionIdAlice = await createCollection(254      api,255      alice,256      'test-metadata',257      null,258      'test-symbol',259    );260261    const nftBob = await mintNft(262      api,263      alice,264      bob,265      collectionIdAlice,266      'nft-metadata',267    );268269    const resourceId = await addNftBasicResource(270      api,271      alice,272      'pending',273      collectionIdAlice,274      nftBob,275      src,276      metadata,277      license,278      thumb,279    );280281    const tx = acceptResourceRemoval(api, bob, collectionIdAlice, nftBob, resourceId);282    await expectTxFailure(/rmrkCore\.ResourceNotPending/, tx);283  });284285  it('[negative]: cannot confirm the deletion of a non-existing resource', async () => {286    const collectionIdAlice = await createCollection(287      api,288      alice,289      'test-metadata',290      null,291      'test-symbol',292    );293294    const nftBob = await mintNft(295      api,296      alice,297      bob,298      collectionIdAlice,299      'nft-metadata',300    );301302    const tx = acceptResourceRemoval(api, bob, collectionIdAlice, nftBob, 127);303    await expectTxFailure(/rmrkCore\.ResourceDoesntExist/, tx);304  });305306  it('[negative]: Non-owner user cannot confirm the deletion of resource', async () => {307    const collectionIdAlice = await createCollection(308      api,309      alice,310      'test-metadata',311      null,312      'test-symbol',313    );314315    const nftAlice = await mintNft(316      api,317      alice,318      alice,319      collectionIdAlice,320      'nft-metadata',321    );322323    const resourceId = await addNftBasicResource(324      api,325      alice,326      'added',327      collectionIdAlice,328      nftAlice,329      src,330      metadata,331      license,332      thumb,333    );334335    const tx = acceptResourceRemoval(api, bob, collectionIdAlice, nftAlice, resourceId);336    await expectTxFailure(/rmrkCore\.NoPermission/, tx);337  });338339  after(async() => { await api.disconnect(); });340});