git.delta.rocks / unique-network / refs/commits / 21b4b8a50083

difftreelog

Use executeExtrinsic

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

3 files changed

modifiedtests/src/burnItem.test.tsdiffbeforeafterboth
182 });182 });
183183
184 itSub('Zero burn NFT', async ({helper}) => {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'});185 const collection = await helper.nft.mintCollection(alice, {name: 'Coll', description: 'Desc', tokenPrefix: 'T'});
187 const tokenAlice = await collection.mintToken(alice, {Substrate: alice.address});186 const tokenAlice = await collection.mintToken(alice, {Substrate: alice.address});
188 const tokenBob = await collection.mintToken(alice, {Substrate: bob.address});187 const tokenBob = await collection.mintToken(alice, {Substrate: bob.address});
189 188
190 // 1. Zero burn of own tokens allowed:189 // 1. Zero burn of own tokens allowed:
191 await helper.signTransaction(alice, api.tx.unique.burnItem(collection.collectionId, tokenAlice.tokenId, 0));190 await helper.executeExtrinsic(alice, 'api.tx.unique.burnItem', [collection.collectionId, tokenAlice.tokenId, 0]);
192 // 2. Zero burn of non-owned tokens not allowed:191 // 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');192 await expect(helper.executeExtrinsic(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:193 // 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');194 await expect(helper.executeExtrinsic(alice, 'api.tx.unique.burnItem', [collection.collectionId, 9999, 0])).to.be.rejectedWith('common.TokenNotFound');
196 expect(await tokenAlice.doesExist()).to.be.true;195 expect(await tokenAlice.doesExist()).to.be.true;
197 expect(await tokenAlice.getOwner()).to.deep.eq({Substrate: alice.address});196 expect(await tokenAlice.getOwner()).to.deep.eq({Substrate: alice.address});
198 expect(await tokenBob.getOwner()).to.deep.eq({Substrate: bob.address});197 expect(await tokenBob.getOwner()).to.deep.eq({Substrate: bob.address});
211 await approvedNft.approve(bob, {Substrate: alice.address});210 await approvedNft.approve(bob, {Substrate: alice.address});
212211
213 // 1. Zero burnFrom of non-existing tokens not allowed:212 // 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');213 await expect(helper.executeExtrinsic(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:214 // 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');215 await expect(helper.executeExtrinsic(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:216 // 3. Zero burnFrom of approved tokens allowed:
218 await helper.signTransaction(alice, api.tx.unique.burnFrom(collection.collectionId, {Substrate: bob.address}, approvedNft.tokenId, 0));217 await helper.executeExtrinsic(alice, 'api.tx.unique.burnFrom', [collection.collectionId, {Substrate: bob.address}, approvedNft.tokenId, 0]);
219218
220 // 4.1 approvedNft still approved:219 // 4.1 approvedNft still approved:
221 expect(await approvedNft.isApproved({Substrate: alice.address})).to.be.true;220 expect(await approvedNft.isApproved({Substrate: alice.address})).to.be.true;
modifiedtests/src/transfer.test.tsdiffbeforeafterboth
193 });193 });
194194
195 itSub('Zero transfer NFT', async ({helper}) => {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'});196 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});197 const tokenAlice = await collection.mintToken(alice, {Substrate: alice.address});
199 const tokenBob = await collection.mintToken(alice, {Substrate: bob.address});198 const tokenBob = await collection.mintToken(alice, {Substrate: bob.address});
200 // 1. Zero transfer of own tokens allowed:199 // 1. Zero transfer of own tokens allowed:
201 await helper.signTransaction(alice, api.tx.unique.transfer({Substrate: bob.address}, collection.collectionId, tokenAlice.tokenId, 0));200 await helper.executeExtrinsic(alice, 'api.tx.unique.transfer', [{Substrate: bob.address}, collection.collectionId, tokenAlice.tokenId, 0]);
202 // 2. Zero transfer of non-owned tokens not allowed:201 // 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');202 await expect(helper.executeExtrinsic(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:203 // 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');204 await expect(helper.executeExtrinsic(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});205 expect(await tokenAlice.getOwner()).to.deep.eq({Substrate: alice.address});
207 expect(await tokenBob.getOwner()).to.deep.eq({Substrate: bob.address});206 expect(await tokenBob.getOwner()).to.deep.eq({Substrate: bob.address});
208 // 4. Storage is not corrupted:207 // 4. Storage is not corrupted:
modifiedtests/src/transferFrom.test.tsdiffbeforeafterboth
351 });351 });
352352
353 itSub('zero transfer NFT', async ({helper}) => {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'});354 const collection = await helper.nft.mintCollection(alice, {name: 'Zero', description: 'Zero transfer', tokenPrefix: 'TF'});
356 const notApprovedNft = await collection.mintToken(alice, {Substrate: bob.address});355 const notApprovedNft = await collection.mintToken(alice, {Substrate: bob.address});
357 const approvedNft = await collection.mintToken(alice, {Substrate: bob.address});356 const approvedNft = await collection.mintToken(alice, {Substrate: bob.address});
358 await approvedNft.approve(bob, {Substrate: alice.address});357 await approvedNft.approve(bob, {Substrate: alice.address});
359358
360 // 1. Cannot zero transferFrom (non-existing token)359 // 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');360 await expect(helper.executeExtrinsic(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)361 // 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');362 await expect(helper.executeExtrinsic(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):363 // 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));364 await helper.executeExtrinsic(alice, 'api.tx.unique.transferFrom', [{Substrate: bob.address}, {Substrate: alice.address}, collection.collectionId, approvedNft.tokenId, 0]);
366365
367 // 4.1 approvedNft still approved:366 // 4.1 approvedNft still approved:
368 expect(await approvedNft.isApproved({Substrate: alice.address})).to.be.true;367 expect(await approvedNft.isApproved({Substrate: alice.address})).to.be.true;