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

difftreelog

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

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

3 files changed

modifiedtests/src/burnItem.test.tsdiffbeforeafterboth
181 expect(await collection.getBalance({Substrate: alice.address})).to.eq(10n);181 expect(await collection.getBalance({Substrate: alice.address})).to.eq(10n);
182 });182 });
183
184 itSub('Zero burn NFT', async ({helper}) => {
185 const api = helper.getApi();
186 const collection = await helper.nft.mintCollection(alice, {name: 'Coll', description: 'Desc', tokenPrefix: 'T'});
187 const tokenAlice = await collection.mintToken(alice, {Substrate: alice.address});
188 const tokenBob = await collection.mintToken(alice, {Substrate: bob.address});
189
190 // 1. Zero burn of own tokens allowed:
191 await helper.signTransaction(alice, api.tx.unique.burnItem(collection.collectionId, tokenAlice.tokenId, 0));
192 // 2. Zero burn of non-owned tokens not allowed:
193 await expect(helper.signTransaction(alice, api.tx.unique.burnItem(collection.collectionId, tokenBob.tokenId, 0))).to.be.rejectedWith('common.NoPermission');
194 // 3. Zero burn of non-existing tokens not allowed:
195 await expect(helper.signTransaction(alice, api.tx.unique.burnItem(collection.collectionId, 9999, 0))).to.be.rejectedWith('common.TokenNotFound');
196 expect(await tokenAlice.doesExist()).to.be.true;
197 expect(await tokenAlice.getOwner()).to.deep.eq({Substrate: alice.address});
198 expect(await tokenBob.getOwner()).to.deep.eq({Substrate: bob.address});
199 // 4. Storage is not corrupted:
200 await tokenAlice.transfer(alice, {Substrate: bob.address});
201 await tokenBob.transfer(alice, {Substrate: alice.address});
202 expect(await tokenAlice.getOwner()).to.deep.eq({Substrate: bob.address});
203 expect(await tokenBob.getOwner()).to.deep.eq({Substrate: alice.address});
204 });
205
206 itSub('zero burnFrom NFT', async ({helper}) => {
207 const api = helper.getApi();
208 const collection = await helper.nft.mintCollection(alice, {name: 'Zero', description: 'Zero transfer', tokenPrefix: 'TF'});
209 const notApprovedNft = await collection.mintToken(alice, {Substrate: bob.address});
210 const approvedNft = await collection.mintToken(alice, {Substrate: bob.address});
211 await approvedNft.approve(bob, {Substrate: alice.address});
212
213 // 1. Zero burnFrom of non-existing tokens not allowed:
214 await expect(helper.signTransaction(alice, api.tx.unique.burnFrom(collection.collectionId, {Substrate: bob.address}, 9999, 0))).to.be.rejectedWith('common.ApprovedValueTooLow');
215 // 2. Zero burnFrom of not approved tokens not allowed:
216 await expect(helper.signTransaction(alice, api.tx.unique.burnFrom(collection.collectionId, {Substrate: bob.address}, notApprovedNft.tokenId, 0))).to.be.rejectedWith('common.NoPermission');
217 // 3. Zero burnFrom of approved tokens allowed:
218 await helper.signTransaction(alice, api.tx.unique.burnFrom(collection.collectionId, {Substrate: bob.address}, approvedNft.tokenId, 0));
219
220 // 4.1 approvedNft still approved:
221 expect(await approvedNft.isApproved({Substrate: alice.address})).to.be.true;
222 // 4.2 bob is still the owner:
223 expect(await approvedNft.getOwner()).to.deep.eq({Substrate: bob.address});
224 expect(await notApprovedNft.getOwner()).to.deep.eq({Substrate: bob.address});
225 // 4.3 Alice can burn approved nft:
226 await approvedNft.burnFrom(alice, {Substrate: bob.address});
227 expect(await approvedNft.doesExist()).to.be.false;
228 });
183});229});
184230
modifiedtests/src/transfer.test.tsdiffbeforeafterboth
--- a/tests/src/transfer.test.ts
+++ b/tests/src/transfer.test.ts
@@ -122,6 +122,7 @@
     });
   });
 
+
   itSub('[nft] Transfer with not existed collection_id', async ({helper}) => {
     const collectionId = (1 << 32) - 1;
     await expect(helper.nft.transferToken(alice, collectionId, 1, {Substrate: bob.address}))
@@ -191,6 +192,26 @@
       .to.be.rejectedWith(/common\.TokenValueTooLow/);
   });
 
+  itSub('Zero transfer NFT', async ({helper}) => {
+    const api = helper.getApi();
+    const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-3-NFT', description: '', tokenPrefix: 'T'});
+    const tokenAlice = await collection.mintToken(alice, {Substrate: alice.address});
+    const tokenBob = await collection.mintToken(alice, {Substrate: bob.address});
+    // 1. Zero transfer of own tokens allowed:
+    await helper.signTransaction(alice, api.tx.unique.transfer({Substrate: bob.address}, collection.collectionId, tokenAlice.tokenId, 0));
+    // 2. Zero transfer of non-owned tokens not allowed:
+    await expect(helper.signTransaction(alice, api.tx.unique.transfer({Substrate: alice.address}, collection.collectionId, tokenBob.tokenId, 0))).to.be.rejectedWith('common.NoPermission');
+    // 3. Zero transfer of non-existing tokens not allowed:
+    await expect(helper.signTransaction(alice, api.tx.unique.transfer({Substrate: alice.address}, collection.collectionId, 10, 0))).to.be.rejectedWith('common.TokenNotFound');
+    expect(await tokenAlice.getOwner()).to.deep.eq({Substrate: alice.address});
+    expect(await tokenBob.getOwner()).to.deep.eq({Substrate: bob.address});
+    // 4. Storage is not corrupted:
+    await tokenAlice.transfer(alice, {Substrate: bob.address});
+    await tokenBob.transfer(alice, {Substrate: alice.address});
+    expect(await tokenAlice.getOwner()).to.deep.eq({Substrate: bob.address});
+    expect(await tokenBob.getOwner()).to.deep.eq({Substrate: alice.address});
+  });
+
   itSub('[nft] Transfer with deleted item_id', async ({helper}) => {
     const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-3-NFT', description: '', tokenPrefix: 'T'});
     const nft = await collection.mintToken(alice);
modifiedtests/src/transferFrom.test.tsdiffbeforeafterboth
--- a/tests/src/transferFrom.test.ts
+++ b/tests/src/transferFrom.test.ts
@@ -349,4 +349,28 @@
       {Substrate: charlie.address},
     )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);
   });
+
+  itSub('zero transfer NFT', async ({helper}) => {
+    const api = helper.getApi();
+    const collection = await helper.nft.mintCollection(alice, {name: 'Zero', description: 'Zero transfer', tokenPrefix: 'TF'});
+    const notApprovedNft = await collection.mintToken(alice, {Substrate: bob.address});
+    const approvedNft = await collection.mintToken(alice, {Substrate: bob.address});
+    await approvedNft.approve(bob, {Substrate: alice.address});
+
+    // 1. Cannot zero transferFrom (non-existing token)
+    await expect(helper.signTransaction(alice, api.tx.unique.transferFrom({Substrate: bob.address}, {Substrate: alice.address}, collection.collectionId, 9999, 0))).to.be.rejectedWith('common.ApprovedValueTooLow');
+    // 2. Cannot zero transferFrom (not approved token)
+    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');
+    // 3. Can zero transferFrom (approved token):
+    await helper.signTransaction(alice, api.tx.unique.transferFrom({Substrate: bob.address}, {Substrate: alice.address}, collection.collectionId, approvedNft.tokenId, 0));
+
+    // 4.1 approvedNft still approved:
+    expect(await approvedNft.isApproved({Substrate: alice.address})).to.be.true;
+    // 4.2 bob is still the owner:
+    expect(await approvedNft.getOwner()).to.deep.eq({Substrate: bob.address});
+    expect(await notApprovedNft.getOwner()).to.deep.eq({Substrate: bob.address});
+    // 4.3 Alice can transfer approved nft:
+    await approvedNft.transferFrom(alice, {Substrate: bob.address}, {Substrate: alice.address});
+    expect(await approvedNft.getOwner()).to.deep.eq({Substrate: alice.address});
+  });
 });