1import {getApiConnection} from '../substrate/substrate-api';2import {requirePallets, Pallets} from '../deprecated-helpers/helpers';3import {NftIdTuple} from './util/fetch';4import {expectTxFailure} from './util/helpers';5import {6 acceptResourceRemoval, addNftBasicResource, createCollection, mintNft, removeNftResource, sendNft,7} from './util/tx';89101112describe('Integration test: remove nft resource', () => {13 let api: any;14 before(async function() {15 api = await getApiConnection();16 await requirePallets(this, [Pallets.RmrkCore]);17 });1819 const alice = '//Alice';20 const bob = '//Bob';21 const src = 'test-basic-src';22 const metadata = 'test-basic-metadata';23 const license = 'test-basic-license';24 const thumb = 'test-basic-thumb';2526 it('deleting a resource directly by the NFT owner', async () => {27 const collectionIdAlice = await createCollection(28 api,29 alice,30 'test-metadata',31 null,32 'test-symbol',33 );3435 const nftAlice = await mintNft(36 api,37 alice,38 alice,39 collectionIdAlice,40 'nft-metadata',41 );4243 const resourceId = await addNftBasicResource(44 api,45 alice,46 'added',47 collectionIdAlice,48 nftAlice,49 src,50 metadata,51 license,52 thumb,53 );5455 await removeNftResource(api, 'removed', alice, collectionIdAlice, nftAlice, resourceId);56 });5758 it('deleting resources indirectly by the NFT owner', async () => {59 const collectionIdAlice = await createCollection(60 api,61 alice,62 'test-metadata',63 null,64 'test-symbol',65 );6667 const parentNftId = await mintNft(api, alice, alice, collectionIdAlice, 'parent-nft-metadata');68 const childNftId = await mintNft(api, alice, alice, collectionIdAlice, 'child-nft-metadata');6970 const resourceId = await addNftBasicResource(71 api,72 alice,73 'added',74 collectionIdAlice,75 childNftId,76 src,77 metadata,78 license,79 thumb,80 );8182 const newOwnerNFT: NftIdTuple = [collectionIdAlice, parentNftId];8384 await sendNft(api, 'sent', alice, collectionIdAlice, childNftId, newOwnerNFT);8586 await removeNftResource(api, 'removed', alice, collectionIdAlice, childNftId, resourceId);87 });8889 it('deleting a resource by the collection owner', async () => {90 const collectionIdAlice = await createCollection(91 api,92 alice,93 'test-metadata',94 null,95 'test-symbol',96 );9798 const nftBob = await mintNft(99 api,100 alice,101 bob,102 collectionIdAlice,103 'nft-metadata',104 );105106 const resourceId = await addNftBasicResource(107 api,108 alice,109 'pending',110 collectionIdAlice,111 nftBob,112 src,113 metadata,114 license,115 thumb,116 );117118 await removeNftResource(api, 'pending', alice, collectionIdAlice, nftBob, resourceId);119 await acceptResourceRemoval(api, bob, collectionIdAlice, nftBob, resourceId);120 });121122 it('deleting a resource in a nested NFT by the collection owner', async () => {123 const collectionIdAlice = await createCollection(124 api,125 alice,126 'test-metadata',127 null,128 'test-symbol',129 );130131 const parentNftId = await mintNft(132 api,133 alice,134 bob,135 collectionIdAlice,136 'parent-nft-metadata',137 );138 const childNftId = await mintNft(139 api,140 alice,141 bob,142 collectionIdAlice,143 'child-nft-metadata',144 );145146 const resourceId = await addNftBasicResource(147 api,148 alice,149 'pending',150 collectionIdAlice,151 childNftId,152 src,153 metadata,154 license,155 thumb,156 );157158 const newOwnerNFT: NftIdTuple = [collectionIdAlice, parentNftId];159160 await sendNft(api, 'sent', bob, collectionIdAlice, childNftId, newOwnerNFT);161162 await removeNftResource(api, 'pending', alice, collectionIdAlice, childNftId, resourceId);163 await acceptResourceRemoval(api, bob, collectionIdAlice, childNftId, resourceId);164 });165166 it('[negative]: can\'t delete a resource in a non-existing collection', async () => {167 const collectionIdAlice = await createCollection(168 api,169 alice,170 'test-metadata',171 null,172 'test-symbol',173 );174175 const nftAlice = await mintNft(176 api,177 alice,178 alice,179 collectionIdAlice,180 'nft-metadata',181 );182183 const resourceId = await addNftBasicResource(184 api,185 alice,186 'added',187 collectionIdAlice,188 nftAlice,189 src,190 metadata,191 license,192 thumb,193 );194195 const tx = removeNftResource(api, 'removed', alice, 0xFFFFFFFF, nftAlice, resourceId);196 await expectTxFailure(/rmrkCore\.CollectionUnknown/, tx); 197 });198199 it('[negative]: only collection owner can delete a resource', async () => {200 const collectionIdAlice = await createCollection(201 api,202 alice,203 'test-metadata',204 null,205 'test-symbol',206 );207208 const nftAlice = await mintNft(209 api,210 alice,211 alice,212 collectionIdAlice,213 'nft-metadata',214 );215216 const resourceId = await addNftBasicResource(217 api,218 alice,219 'added',220 collectionIdAlice,221 nftAlice,222 src,223 metadata,224 license,225 thumb,226 );227228 const tx = removeNftResource(api, 'removed', bob, collectionIdAlice, nftAlice, resourceId);229 await expectTxFailure(/rmrkCore\.NoPermission/, tx);230 });231232 it('[negative]: cannot delete a resource that does not exist', async () => {233 const collectionIdAlice = await createCollection(234 api,235 alice,236 'test-metadata',237 null,238 'test-symbol',239 );240241 const nftAlice = await mintNft(242 api,243 alice,244 alice,245 collectionIdAlice,246 'nft-metadata',247 );248249 const tx = removeNftResource(api, 'removed', alice, collectionIdAlice, nftAlice, 127);250 await expectTxFailure(/rmrkCore\.ResourceDoesntExist/, tx);251 });252253 it('[negative]: Cannot accept deleting resource without owner attempt do delete it', async () => {254 const collectionIdAlice = await createCollection(255 api,256 alice,257 'test-metadata',258 null,259 'test-symbol',260 );261262 const nftBob = await mintNft(263 api,264 alice,265 bob,266 collectionIdAlice,267 'nft-metadata',268 );269270 const resourceId = await addNftBasicResource(271 api,272 alice,273 'pending',274 collectionIdAlice,275 nftBob,276 src,277 metadata,278 license,279 thumb,280 );281282 const tx = acceptResourceRemoval(api, bob, collectionIdAlice, nftBob, resourceId);283 await expectTxFailure(/rmrkCore\.ResourceNotPending/, tx);284 });285286 it('[negative]: cannot confirm the deletion of a non-existing resource', async () => {287 const collectionIdAlice = await createCollection(288 api,289 alice,290 'test-metadata',291 null,292 'test-symbol',293 );294295 const nftBob = await mintNft(296 api,297 alice,298 bob,299 collectionIdAlice,300 'nft-metadata',301 );302303 const tx = acceptResourceRemoval(api, bob, collectionIdAlice, nftBob, 127);304 await expectTxFailure(/rmrkCore\.ResourceDoesntExist/, tx);305 });306307 it('[negative]: Non-owner user cannot confirm the deletion of resource', async () => {308 const collectionIdAlice = await createCollection(309 api,310 alice,311 'test-metadata',312 null,313 'test-symbol',314 );315316 const nftAlice = await mintNft(317 api,318 alice,319 alice,320 collectionIdAlice,321 'nft-metadata',322 );323324 const resourceId = await addNftBasicResource(325 api,326 alice,327 'added',328 collectionIdAlice,329 nftAlice,330 src,331 metadata,332 license,333 thumb,334 );335336 const tx = acceptResourceRemoval(api, bob, collectionIdAlice, nftAlice, resourceId);337 await expectTxFailure(/rmrkCore\.NoPermission/, tx);338 });339340 after(() => {341 api.disconnect();342 });343});