git.delta.rocks / unique-network / refs/commits / 4da53d37e189

difftreelog

Merge pull request #925 from UniqueNetwork/tests/fix-false-positive

Yaroslav Bolyukin2023-04-21parents: #642e462 #89fdc73.patch.diff
in: master

1 file changed

modifiedtests/src/approve.test.tsdiffbeforeafterboth
49 const tokenId = await helper.ft.getLastTokenId(collectionId);49 const tokenId = await helper.ft.getLastTokenId(collectionId);
50 await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});50 await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});
51 const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));51 const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));
52 expect(amount).to.be.equal(BigInt(1));52 expect(amount).to.be.equal(1n);
53 });53 });
5454
55 itSub.ifWithPallets('[refungible] Execute the extrinsic and check approvedList', [Pallets.ReFungible], async ({helper}) => {55 itSub.ifWithPallets('[refungible] Execute the extrinsic and check approvedList', [Pallets.ReFungible], async ({helper}) => {
56 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});56 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
57 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});57 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});
58 await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});58 await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});
59 const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));59 const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));
60 expect(amount).to.be.equal(BigInt(1));60 expect(amount).to.be.equal(1n);
61 });61 });
6262
63 itSub('[nft] Remove approval by using 0 amount', async ({helper}) => {63 itSub('[nft] Remove approval by using 0 amount', async ({helper}) => {
76 const tokenId = await helper.ft.getLastTokenId(collectionId);76 const tokenId = await helper.ft.getLastTokenId(collectionId);
77 await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});77 await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});
78 const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));78 const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));
79 expect(amountBefore).to.be.equal(BigInt(1));79 expect(amountBefore).to.be.equal(1n);
8080
81 await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);81 await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
82 const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));82 const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));
83 expect(amountAfter).to.be.equal(BigInt(0));83 expect(amountAfter).to.be.equal(0n);
84 });84 });
8585
86 itSub.ifWithPallets('[refungible] Remove approval by using 0 amount', [Pallets.ReFungible], async ({helper}) => {86 itSub.ifWithPallets('[refungible] Remove approval by using 0 amount', [Pallets.ReFungible], async ({helper}) => {
87 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});87 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
88 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});88 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});
89 await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});89 await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});
90 const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));90 const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));
91 expect(amountBefore).to.be.equal(BigInt(1));91 expect(amountBefore).to.be.equal(1n);
9292
93 await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);93 await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
94 const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));94 const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));
95 expect(amountAfter).to.be.equal(BigInt(0));95 expect(amountAfter).to.be.equal(0n);
96 });96 });
9797
98 itSub('can`t be called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => {98 itSub('can`t be called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => {
99 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});99 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
100 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});100 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});
101 const result = (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: charlie.address});101 const result = (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: charlie.address});
102 await expect(result).to.be.rejected;102 await expect(result).to.be.rejectedWith('common.CantApproveMoreThanOwned');
103 });103 });
104 });104 });
105105
128 const tokenId = await helper.ft.getLastTokenId(collectionId);128 const tokenId = await helper.ft.getLastTokenId(collectionId);
129 await (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});129 await (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});
130 const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, testCase.account(bob));130 const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, testCase.account(bob));
131 expect(amount).to.be.equal(BigInt(1));131 expect(amount).to.be.equal(1n);
132 });132 });
133133
134 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {134 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {
135 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});135 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
136 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob), pieces: 100n});136 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob), pieces: 100n});
137 await (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address}, 100n);137 await (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address}, 100n);
138 const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, testCase.account(bob));138 const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, testCase.account(bob));
139 expect(amount).to.be.equal(BigInt(100n));139 expect(amount).to.be.equal(100n);
140 });140 });
141 });141 });
142142
169 const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});169 const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
170 await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 1n);170 await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 1n);
171 const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});171 const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
172 expect(after - before).to.be.equal(BigInt(1));172 expect(after - before).to.be.equal(1n);
173 });173 });
174174
175 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {175 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {
179 const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});179 const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
180 await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 1n);180 await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 1n);
181 const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});181 const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
182 expect(after - before).to.be.equal(BigInt(1));182 expect(after - before).to.be.equal(1n);
183 });183 });
184 });184 });
185185
203 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);203 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
204 expect(owner.Substrate).to.be.equal(alice.address);204 expect(owner.Substrate).to.be.equal(alice.address);
205 const transferTokenFromTx = () => helper.nft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address});205 const transferTokenFromTx = () => helper.nft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address});
206 await expect(transferTokenFromTx()).to.be.rejected;206 await expect(transferTokenFromTx()).to.be.rejectedWith('common.ApprovedValueTooLow');
207 });207 });
208208
209 itSub('Fungible up to an approved amount', async ({helper}) => {209 itSub('Fungible up to an approved amount', async ({helper}) => {
214 const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});214 const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
215 await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 1n);215 await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 1n);
216 const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});216 const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
217 expect(after - before).to.be.equal(BigInt(1));217 expect(after - before).to.be.equal(1n);
218218
219 const transferTokenFromTx = () => helper.ft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 1n);219 const transferTokenFromTx = () => helper.ft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 1n);
220 await expect(transferTokenFromTx()).to.be.rejected;220 await expect(transferTokenFromTx()).to.be.rejectedWith('common.ApprovedValueTooLow');
221 });221 });
222222
223 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {223 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {
227 const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});227 const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
228 await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 100n);228 await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 100n);
229 const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});229 const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
230 expect(after - before).to.be.equal(BigInt(100));230 expect(after - before).to.be.equal(100n);
231 const transferTokenFromTx = () => helper.rft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 100n);231 const transferTokenFromTx = () => helper.rft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 100n);
232 await expect(transferTokenFromTx()).to.be.rejected;232 await expect(transferTokenFromTx()).to.be.rejectedWith('common.ApprovedValueTooLow');
233 });233 });
234 });234 });
235235
255 const charlieBefore = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});255 const charlieBefore = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});
256 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, testCase.account(alice), {Substrate: charlie.address}, 2n);256 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, testCase.account(alice), {Substrate: charlie.address}, 2n);
257 const charlieAfter = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});257 const charlieAfter = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});
258 expect(charlieAfter - charlieBefore).to.be.equal(BigInt(2));258 expect(charlieAfter - charlieBefore).to.be.equal(2n);
259259
260 const daveBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});260 const daveBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});
261 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, testCase.account(alice), {Substrate: dave.address}, 8n);261 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, testCase.account(alice), {Substrate: dave.address}, 8n);
262 const daveAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});262 const daveAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});
263 expect(daveAfter - daveBefore).to.be.equal(BigInt(8));263 expect(daveAfter - daveBefore).to.be.equal(8n);
264 });264 });
265 });265 });
266266
277 });277 });
278278
279 itSub('NFT', async ({helper}) => {279 itSub('NFT', async ({helper}) => {
280 const owner = testCase.account(alice);
280 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});281 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
281 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice)});282 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: owner});
283
282 await (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});284 await (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});
283 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;285 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;
286
284 await (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);287 await (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
285 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;288 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;
289
286 const transferTokenFromTx = () => helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: bob.address});290 const transferTokenFromTx = helper.nft.transferTokenFrom(bob, collectionId, tokenId, owner, {Substrate: bob.address});
287 await expect(transferTokenFromTx()).to.be.rejected;291 await expect(transferTokenFromTx).to.be.rejectedWith('common.ApprovedValueTooLow');
288 });292 });
289293
290 itSub('Fungible', async ({helper}) => {294 itSub('Fungible', async ({helper}) => {
295 const owner = testCase.account(alice);
291 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);296 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
292 await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));297 await helper.ft.mintTokens(alice, collectionId, 10n, owner);
293 const tokenId = await helper.ft.getLastTokenId(collectionId);298 const tokenId = await helper.ft.getLastTokenId(collectionId);
294 await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});299 await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});
295 const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));300 const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, owner);
296 expect(amountBefore).to.be.equal(BigInt(1));301 expect(amountBefore).to.be.equal(1n);
297302
298 await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);303 await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
299 const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));304 const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, owner);
300 expect(amountAfter).to.be.equal(BigInt(0));305 expect(amountAfter).to.be.equal(0n);
301306
302 const transferTokenFromTx = () => helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 1n);307 const transferTokenFromTx = helper.ft.transferTokenFrom(bob, collectionId, tokenId, owner, {Substrate: charlie.address}, 1n);
303 await expect(transferTokenFromTx()).to.be.rejected;308 await expect(transferTokenFromTx).to.be.rejectedWith('common.ApprovedValueTooLow');
304 });309 });
305310
306 itSub.ifWithPallets('ReFungible', [Pallets.ReFungible], async ({helper}) => {311 itSub.ifWithPallets('ReFungible', [Pallets.ReFungible], async ({helper}) => {
312 const owner = testCase.account(alice);
307 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});313 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
308 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});314 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner, pieces: 100n});
309 await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});315 await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});
310 const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));316 const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, owner);
311 expect(amountBefore).to.be.equal(BigInt(1));317 expect(amountBefore).to.be.equal(1n);
312318
313 await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);319 await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
314 const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));320 const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, owner);
315 expect(amountAfter).to.be.equal(BigInt(0));321 expect(amountAfter).to.be.equal(0n);
316322
317 const transferTokenFromTx = () => helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 100n);323 const transferTokenFromTx = helper.rft.transferTokenFrom(bob, collectionId, tokenId, owner, {Substrate: charlie.address}, 1n);
318 await expect(transferTokenFromTx()).to.be.rejected;324 await expect(transferTokenFromTx).to.be.rejectedWith('common.ApprovedValueTooLow');
319 });325 });
320 });326 });
321327
335 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});341 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
336 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});342 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});
337 const result = (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address}, 2n);343 const result = (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address}, 2n);
338 await expect(result).to.be.rejected;344 await expect(result).to.be.rejectedWith('nonfungible.NonfungibleItemsHaveNoAmount');
339 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.false;345 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.false;
340 });346 });
341347
344 await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));350 await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));
345 const tokenId = await helper.ft.getLastTokenId(collectionId);351 const tokenId = await helper.ft.getLastTokenId(collectionId);
346 const result = (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 11n);352 const result = (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 11n);
347 await expect(result).to.be.rejected;353 await expect(result).to.be.rejectedWith('common.CantApproveMoreThanOwned');
348 });354 });
349355
350 itSub.ifWithPallets('ReFungible', [Pallets.ReFungible], async ({helper}) => {356 itSub.ifWithPallets('ReFungible', [Pallets.ReFungible], async ({helper}) => {
351 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});357 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
352 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});358 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});
353 const result = (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 101n);359 const result = (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 101n);
354 await expect(result).to.be.rejected;360 await expect(result).to.be.rejectedWith('common.CantApproveMoreThanOwned');
355 });361 });
356 });362 });
357363
367 });373 });
368 });374 });
369375
370 itSub('can be called by collection admin on non-owned item', async ({helper}) => {376 itSub('cannot be called by collection admin on non-owned item', async ({helper}) => {
371 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});377 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
372 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice)});378 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice)});
373 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});379 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});
374 const result = (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});380 const approveTx = (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});
375 await expect(result).to.be.rejected;381 await expect(approveTx).to.be.rejectedWith('common.CantApproveMoreThanOwned');
376 });382 });
377 });383 });
378384
379 describe(`[${testCase.method}] Negative Integration Test approve(spender, collection_id, item_id, amount):`, () => {385 describe(`[${testCase.method}] Negative Integration Test approve(spender, collection_id, item_id, amount):`, () => {
380 let alice: IKeyringPair;386 let alice: IKeyringPair;
381 let bob: IKeyringPair;387 let bob: IKeyringPair;
382 let charlie: IKeyringPair;388 let charlie: IKeyringPair;
389 const NONEXISTENT_COLLECTION = (2 ** 32) - 1;
383390
384 before(async () => {391 before(async () => {
385 await usingPlaygrounds(async (helper, privateKey) => {392 await usingPlaygrounds(async (helper, privateKey) => {
389 });396 });
390397
391 itSub('[nft] Approve for a collection that does not exist', async ({helper}) => {398 itSub('[nft] Approve for a collection that does not exist', async ({helper}) => {
392 const collectionId = 1 << 32 - 1;399 const approveTx = (helper.nft as any)[testCase.method](bob, NONEXISTENT_COLLECTION, 1, {Substrate: charlie.address});
393 await expect((helper.nft as any)[testCase.method](bob, collectionId, 1, {Substrate: charlie.address})).to.be.rejected;400 await expect(approveTx).to.be.rejectedWith('common.CollectionNotFound');
394 });401 });
395402
396 itSub('[fungible] Approve for a collection that does not exist', async ({helper}) => {403 itSub('[fungible] Approve for a collection that does not exist', async ({helper}) => {
397 const collectionId = 1 << 32 - 1;404 const approveTx = (helper.ft as any)[testCase.method](bob, NONEXISTENT_COLLECTION, 1, {Substrate: charlie.address});
398 const approveTx = () => (helper.ft as any)[testCase.method](bob, collectionId, 1, {Substrate: charlie.address});
399 await expect(approveTx()).to.be.rejected;405 await expect(approveTx).to.be.rejectedWith('common.CollectionNotFound');
400 });406 });
401407
402 itSub.ifWithPallets('[refungible] Approve for a collection that does not exist', [Pallets.ReFungible], async ({helper}) => {408 itSub.ifWithPallets('[refungible] Approve for a collection that does not exist', [Pallets.ReFungible], async ({helper}) => {
403 const collectionId = 1 << 32 - 1;409 const approveTx = (helper.rft as any)[testCase.method](bob, NONEXISTENT_COLLECTION, 1, {Substrate: charlie.address});
404 const approveTx = () => (helper.rft as any)[testCase.method](bob, collectionId, 1, {Substrate: charlie.address});
405 await expect(approveTx()).to.be.rejected;410 await expect(approveTx).to.be.rejectedWith('common.CollectionNotFound');
406 });411 });
407412
408 itSub('[nft] Approve for a collection that was destroyed', async ({helper}) => {413 itSub('[nft] Approve for a collection that was destroyed', async ({helper}) => {
409 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});414 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
410 await helper.nft.burn(alice, collectionId);415 await helper.nft.burn(alice, collectionId);
411 const approveTx = () => (helper.nft as any)[testCase.method](alice, collectionId, 1, {Substrate: bob.address});416 const approveTx = (helper.nft as any)[testCase.method](alice, collectionId, 1, {Substrate: bob.address});
412 await expect(approveTx()).to.be.rejected;417 await expect(approveTx).to.be.rejectedWith('common.CollectionNotFound');
413 });418 });
414419
415 itSub('[fungible] Approve for a collection that was destroyed', async ({helper}) => {420 itSub('[fungible] Approve for a collection that was destroyed', async ({helper}) => {
416 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});421 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
417 await helper.ft.burn(alice, collectionId);422 await helper.ft.burn(alice, collectionId);
418 const approveTx = () => (helper.ft as any)[testCase.method](alice, collectionId, 1, {Substrate: bob.address});423 const approveTx = (helper.ft as any)[testCase.method](alice, collectionId, 1, {Substrate: bob.address});
419 await expect(approveTx()).to.be.rejected;424 await expect(approveTx).to.be.rejectedWith('common.CollectionNotFound');
420 });425 });
421426
422 itSub.ifWithPallets('[refungible] Approve for a collection that was destroyed', [Pallets.ReFungible], async ({helper}) => {427 itSub.ifWithPallets('[refungible] Approve for a collection that was destroyed', [Pallets.ReFungible], async ({helper}) => {
423 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});428 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
424 await helper.rft.burn(alice, collectionId);429 await helper.rft.burn(alice, collectionId);
425 const approveTx = () => (helper.rft as any)[testCase.method](alice, collectionId, 1, {Substrate: bob.address});430 const approveTx = (helper.rft as any)[testCase.method](alice, collectionId, 1, {Substrate: bob.address});
426 await expect(approveTx()).to.be.rejected;431 await expect(approveTx).to.be.rejectedWith('common.CollectionNotFound');
427 });432 });
428433
429 itSub('[nft] Approve transfer of a token that does not exist', async ({helper}) => {434 itSub('[nft] Approve transfer of a token that does not exist', async ({helper}) => {
430 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});435 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
431 const approveTx = () => (helper.nft as any)[testCase.method](alice, collectionId, 2, {Substrate: bob.address});436 const approveTx = (helper.nft as any)[testCase.method](alice, collectionId, 2, {Substrate: bob.address});
432 await expect(approveTx()).to.be.rejected;437 await expect(approveTx).to.be.rejectedWith('common.TokenNotFound');
433 });438 });
434439
435 itSub.ifWithPallets('[refungible] Approve transfer of a token that does not exist', [Pallets.ReFungible], async ({helper}) => {440 itSub.ifWithPallets('[refungible] Approve transfer of a token that does not exist', [Pallets.ReFungible], async ({helper}) => {
436 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});441 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
437 const approveTx = () => (helper.rft as any)[testCase.method](alice, collectionId, 2, {Substrate: bob.address});442 const approveTx = (helper.rft as any)[testCase.method](alice, collectionId, 2, {Substrate: bob.address});
438 await expect(approveTx()).to.be.rejected;443 await expect(approveTx).to.be.rejectedWith('common.CantApproveMoreThanOwned'); // TODO: why the error is not common.TokenNotFound
439 });444 });
440445
441 itSub('[nft] Approve using the address that does not own the approved token', async ({helper}) => {446 itSub('[nft] Approve using the address that does not own the approved token', async ({helper}) => {
442 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});447 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
443 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice)});448 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice)});
444 const approveTx = () => (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address});449 const approveTx = (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address});
445 await expect(approveTx()).to.be.rejected;450 await expect(approveTx).to.be.rejectedWith('common.CantApproveMoreThanOwned');
446 });451 });
447452
448 itSub('[fungible] Approve using the address that does not own the approved token', async ({helper}) => {453 itSub('[fungible] Approve using the address that does not own the approved token', async ({helper}) => {
449 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});454 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
450 await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));455 await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));
451 const tokenId = await helper.ft.getLastTokenId(collectionId);456 const tokenId = await helper.ft.getLastTokenId(collectionId);
452 const approveTx = () => (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address});457 const approveTx = (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address});
453 await expect(approveTx()).to.be.rejected;458 await expect(approveTx).to.be.rejectedWith('common.CantApproveMoreThanOwned');
454 });459 });
455460
456 itSub.ifWithPallets('[refungible] Approve using the address that does not own the approved token', [Pallets.ReFungible], async ({helper}) => {461 itSub.ifWithPallets('[refungible] Approve using the address that does not own the approved token', [Pallets.ReFungible], async ({helper}) => {
457 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});462 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
458 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});463 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});
459 const approveTx = () => (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address});464 const approveTx = (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address});
460 await expect(approveTx()).to.be.rejected;465 await expect(approveTx).to.be.rejectedWith('common.CantApproveMoreThanOwned');
461 });466 });
462467
463 itSub.ifWithPallets('should fail if approved more ReFungibles than owned', [Pallets.ReFungible], async ({helper}) => {468 itSub.ifWithPallets('should fail if approved more ReFungibles than owned', [Pallets.ReFungible], async ({helper}) => {
466 await helper.rft.transferToken(alice, collectionId, tokenId, testCase.account(bob), 100n);471 await helper.rft.transferToken(alice, collectionId, tokenId, testCase.account(bob), 100n);
467 await (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 100n);472 await (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 100n);
468473
469 const approveTx = () => (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 101n);474 const approveTx = (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 101n);
470 await expect(approveTx()).to.be.rejected;475 await expect(approveTx).to.be.rejectedWith('common.CantApproveMoreThanOwned');
471 });476 });
472477
473 itSub('should fail if approved more Fungibles than owned', async ({helper}) => {478 itSub('should fail if approved more Fungibles than owned', async ({helper}) => {
477482
478 await helper.ft.transferToken(alice, collectionId, tokenId, testCase.account(bob), 10n);483 await helper.ft.transferToken(alice, collectionId, tokenId, testCase.account(bob), 10n);
479 await (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 10n);484 await (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 10n);
480 const approveTx = () => (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 11n);485 const approveTx = (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 11n);
481 await expect(approveTx()).to.be.rejected;486 await expect(approveTx).to.be.rejectedWith('common.CantApproveMoreThanOwned');
482 });487 });
483488
484 itSub('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => {489 itSub('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => {
485 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});490 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
486 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});491 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});
487 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: false});492 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: false});
488493
489 const approveTx = () => (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: charlie.address});494 const approveTx = (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: charlie.address});
490 await expect(approveTx()).to.be.rejected;495 await expect(approveTx).to.be.rejectedWith('common.CantApproveMoreThanOwned');
491 });496 });
492 });497 });
493});498});
571 const daveBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});576 const daveBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});
572 await helper.ft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n);577 await helper.ft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n);
573 const daveBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});578 const daveBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});
574 expect(daveBalanceAfter - daveBalanceBefore).to.be.equal(BigInt(1));579 expect(daveBalanceAfter - daveBalanceBefore).to.be.equal(1n);
575580
576 await helper.collection.addAdmin(alice ,collectionId, {Substrate: bob.address});581 await helper.collection.addAdmin(alice ,collectionId, {Substrate: bob.address});
577582
578 const aliceBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: alice.address});583 const aliceBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
579 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n);584 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n);
580 const aliceBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: alice.address});585 const aliceBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
581 expect(aliceBalanceAfter - aliceBalanceBefore).to.be.equal(BigInt(1));586 expect(aliceBalanceAfter - aliceBalanceBefore).to.be.equal(1n);
582 });587 });
583588
584 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {589 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {
589 const daveBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address});594 const daveBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address});
590 await helper.rft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n);595 await helper.rft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n);
591 const daveAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address});596 const daveAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address});
592 expect(daveAfter - daveBefore).to.be.equal(BigInt(1));597 expect(daveAfter - daveBefore).to.be.equal(1n);
593598
594 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});599 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});
595600
596 const aliceBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});601 const aliceBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
597 await helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n);602 await helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n);
598 const aliceAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});603 const aliceAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
599 expect(aliceAfter - aliceBefore).to.be.equal(BigInt(1));604 expect(aliceAfter - aliceBefore).to.be.equal(1n);
600 });605 });
601});606});
602607
620 await collection.approveTokens(alice, {Substrate: charlie.address}, 1n);625 await collection.approveTokens(alice, {Substrate: charlie.address}, 1n);
621 // const allowances1 = await getAllowance(collectionId, 0, Alice.address, Bob.address);626 // const allowances1 = await getAllowance(collectionId, 0, Alice.address, Bob.address);
622 // const allowances2 = await getAllowance(collectionId, 0, Alice.address, Charlie.address);627 // const allowances2 = await getAllowance(collectionId, 0, Alice.address, Charlie.address);
623 // expect(allowances1 + allowances2).to.be.eq(BigInt(2));628 // expect(allowances1 + allowances2).to.be.eq(2n);
624 });629 });
625630
626 itSub.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. ReFungible', async ({helper}) => {631 itSub.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. ReFungible', async ({helper}) => {
630 await token.approve(alice, {Substrate: charlie.address}, 1n);635 await token.approve(alice, {Substrate: charlie.address}, 1n);
631 // const allowances1 = await getAllowance(collectionId, itemId, Alice.address, Bob.address);636 // const allowances1 = await getAllowance(collectionId, itemId, Alice.address, Bob.address);
632 // const allowances2 = await getAllowance(collectionId, itemId, Alice.address, Charlie.address);637 // const allowances2 = await getAllowance(collectionId, itemId, Alice.address, Charlie.address);
633 // expect(allowances1 + allowances2).to.be.eq(BigInt(2));638 // expect(allowances1 + allowances2).to.be.eq(2n);
634 });639 });
635640
636 // Canceled by changing approve logic641 // Canceled by changing approve logic