git.delta.rocks / unique-network / refs/commits / 571c89e28cac

difftreelog

Add zero transfer[From], burn[From] tests

Max Andreev2022-12-07parent: #c875bc1.patch.diff
in: master

3 files changed

modifiedtests/src/burnItem.test.tsdiffbeforeafterboth
156 expect(await collection.getBalance({Substrate: alice.address})).to.eq(10n);156 expect(await collection.getBalance({Substrate: alice.address})).to.eq(10n);
157 });157 });
158
159 itSub('Zero burn NFT', async ({helper}) => {
160 const api = helper.getApi();
161 const collection = await helper.nft.mintCollection(alice, {name: 'Coll', description: 'Desc', tokenPrefix: 'T'});
162 const tokenAlice = await collection.mintToken(alice, {Substrate: alice.address});
163 const tokenBob = await collection.mintToken(alice, {Substrate: bob.address});
164
165 // 1. Zero burn of own tokens allowed:
166 await helper.signTransaction(alice, api.tx.unique.burnItem(collection.collectionId, tokenAlice.tokenId, 0));
167 // 2. Zero burn of non-owned tokens not allowed:
168 await expect(helper.signTransaction(alice, api.tx.unique.burnItem(collection.collectionId, tokenBob.tokenId, 0))).to.be.rejectedWith('common.NoPermission');
169 // 3. Zero burn of non-existing tokens not allowed:
170 await expect(helper.signTransaction(alice, api.tx.unique.burnItem(collection.collectionId, 9999, 0))).to.be.rejectedWith('common.TokenNotFound');
171 expect(await tokenAlice.doesExist()).to.be.true;
172 expect(await tokenAlice.getOwner()).to.deep.eq({Substrate: alice.address});
173 expect(await tokenBob.getOwner()).to.deep.eq({Substrate: bob.address});
174 // 4. Storage is not corrupted:
175 await tokenAlice.transfer(alice, {Substrate: bob.address});
176 await tokenBob.transfer(alice, {Substrate: alice.address});
177 expect(await tokenAlice.getOwner()).to.deep.eq({Substrate: bob.address});
178 expect(await tokenBob.getOwner()).to.deep.eq({Substrate: alice.address});
179 });
180
181 itSub('zero burnFrom NFT', async ({helper}) => {
182 const api = helper.getApi();
183 const collection = await helper.nft.mintCollection(alice, {name: 'Zero', description: 'Zero transfer', tokenPrefix: 'TF'});
184 const notApprovedNft = await collection.mintToken(alice, {Substrate: bob.address});
185 const approvedNft = await collection.mintToken(alice, {Substrate: bob.address});
186 await approvedNft.approve(bob, {Substrate: alice.address});
187
188 // 1. Zero burnFrom of non-existing tokens not allowed:
189 await expect(helper.signTransaction(alice, api.tx.unique.burnFrom(collection.collectionId, {Substrate: bob.address}, 9999, 0))).to.be.rejectedWith('common.ApprovedValueTooLow');
190 // 2. Zero burnFrom of not approved tokens not allowed:
191 await expect(helper.signTransaction(alice, api.tx.unique.burnFrom(collection.collectionId, {Substrate: bob.address}, notApprovedNft.tokenId, 0))).to.be.rejectedWith('common.NoPermission');
192 // 3. Zero burnFrom of approved tokens allowed:
193 await helper.signTransaction(alice, api.tx.unique.burnFrom(collection.collectionId, {Substrate: bob.address}, approvedNft.tokenId, 0));
194
195 // 4.1 approvedNft still approved:
196 expect(await approvedNft.isApproved({Substrate: alice.address})).to.be.true;
197 // 4.2 bob is still the owner:
198 expect(await approvedNft.getOwner()).to.deep.eq({Substrate: bob.address});
199 expect(await notApprovedNft.getOwner()).to.deep.eq({Substrate: bob.address});
200 // 4.3 Alice can burn approved nft:
201 await approvedNft.burnFrom(alice, {Substrate: bob.address});
202 expect(await approvedNft.doesExist()).to.be.false;
203 });
158});204});
159205
modifiedtests/src/transfer.test.tsdiffbeforeafterboth
191 .to.be.rejectedWith(/common\.TokenValueTooLow/);192 .to.be.rejectedWith(/common\.TokenValueTooLow/);
192 });193 });
194
195 itSub('Zero transfer NFT', async ({helper}) => {
196 const api = helper.getApi();
197 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-3-NFT', description: '', tokenPrefix: 'T'});
198 const tokenAlice = await collection.mintToken(alice, {Substrate: alice.address});
199 const tokenBob = await collection.mintToken(alice, {Substrate: bob.address});
200 // 1. Zero transfer of own tokens allowed:
201 await helper.signTransaction(alice, api.tx.unique.transfer({Substrate: bob.address}, collection.collectionId, tokenAlice.tokenId, 0));
202 // 2. Zero transfer of non-owned tokens not allowed:
203 await expect(helper.signTransaction(alice, api.tx.unique.transfer({Substrate: alice.address}, collection.collectionId, tokenBob.tokenId, 0))).to.be.rejectedWith('common.NoPermission');
204 // 3. Zero transfer of non-existing tokens not allowed:
205 await expect(helper.signTransaction(alice, api.tx.unique.transfer({Substrate: alice.address}, collection.collectionId, 10, 0))).to.be.rejectedWith('common.TokenNotFound');
206 expect(await tokenAlice.getOwner()).to.deep.eq({Substrate: alice.address});
207 expect(await tokenBob.getOwner()).to.deep.eq({Substrate: bob.address});
208 // 4. Storage is not corrupted:
209 await tokenAlice.transfer(alice, {Substrate: bob.address});
210 await tokenBob.transfer(alice, {Substrate: alice.address});
211 expect(await tokenAlice.getOwner()).to.deep.eq({Substrate: bob.address});
212 expect(await tokenBob.getOwner()).to.deep.eq({Substrate: alice.address});
213 });
193214
194 itSub('[nft] Transfer with deleted item_id', async ({helper}) => {215 itSub('[nft] Transfer with deleted item_id', async ({helper}) => {
195 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-3-NFT', description: '', tokenPrefix: 'T'});216 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-3-NFT', description: '', tokenPrefix: 'T'});
modifiedtests/src/transferFrom.test.tsdiffbeforeafterboth
350 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);350 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);
351 });351 });
352
353 itSub('zero transfer NFT', async ({helper}) => {
354 const api = helper.getApi();
355 const collection = await helper.nft.mintCollection(alice, {name: 'Zero', description: 'Zero transfer', tokenPrefix: 'TF'});
356 const notApprovedNft = await collection.mintToken(alice, {Substrate: bob.address});
357 const approvedNft = await collection.mintToken(alice, {Substrate: bob.address});
358 await approvedNft.approve(bob, {Substrate: alice.address});
359
360 // 1. Cannot zero transferFrom (non-existing token)
361 await expect(helper.signTransaction(alice, api.tx.unique.transferFrom({Substrate: bob.address}, {Substrate: alice.address}, collection.collectionId, 9999, 0))).to.be.rejectedWith('common.ApprovedValueTooLow');
362 // 2. Cannot zero transferFrom (not approved token)
363 await expect(helper.signTransaction(alice, api.tx.unique.transferFrom({Substrate: bob.address}, {Substrate: alice.address}, collection.collectionId, notApprovedNft.tokenId, 0))).to.be.rejectedWith('common.NoPermission');
364 // 3. Can zero transferFrom (approved token):
365 await helper.signTransaction(alice, api.tx.unique.transferFrom({Substrate: bob.address}, {Substrate: alice.address}, collection.collectionId, approvedNft.tokenId, 0));
366
367 // 4.1 approvedNft still approved:
368 expect(await approvedNft.isApproved({Substrate: alice.address})).to.be.true;
369 // 4.2 bob is still the owner:
370 expect(await approvedNft.getOwner()).to.deep.eq({Substrate: bob.address});
371 expect(await notApprovedNft.getOwner()).to.deep.eq({Substrate: bob.address});
372 // 4.3 Alice can transfer approved nft:
373 await approvedNft.transferFrom(alice, {Substrate: bob.address}, {Substrate: alice.address});
374 expect(await approvedNft.getOwner()).to.deep.eq({Substrate: alice.address});
375 });
352});376});
353377