difftreelog
Check errors explicitly
in: master
1 file changed
tests/src/approve.test.tsdiffbeforeafterboth49 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 });545455 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 });626263 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);808081 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 });858586 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);929293 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 });979798 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 });105105128 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 });133133134 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 });142142169 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 });174174175 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 });185185203 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 });208208209 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);218218219 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 });222222223 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 });235235255 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);259259260 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 });266266302302303 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);304 const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, owner);304 const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, owner);305 expect(amountAfter).to.be.equal(BigInt(0));305 expect(amountAfter).to.be.equal(0n);306306307 const transferTokenFromTx = helper.ft.transferTokenFrom(bob, collectionId, tokenId, owner, {Substrate: charlie.address}, 1n);307 const transferTokenFromTx = helper.ft.transferTokenFrom(bob, collectionId, tokenId, owner, {Substrate: charlie.address}, 1n);308 await expect(transferTokenFromTx).to.be.rejectedWith('common.ApprovedValueTooLow');308 await expect(transferTokenFromTx).to.be.rejectedWith('common.ApprovedValueTooLow');341 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'});342 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)});343 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);344 await expect(result).to.be.rejected;344 await expect(result).to.be.rejectedWith('nonfungible.NonfungibleItemsHaveNoAmount');345 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;346 });346 });347347350 await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));350 await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));351 const tokenId = await helper.ft.getLastTokenId(collectionId);351 const tokenId = await helper.ft.getLastTokenId(collectionId);352 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);353 await expect(result).to.be.rejected;353 await expect(result).to.be.rejectedWith('common.CantApproveMoreThanOwned');354 });354 });355355356 itSub.ifWithPallets('ReFungible', [Pallets.ReFungible], async ({helper}) => {356 itSub.ifWithPallets('ReFungible', [Pallets.ReFungible], async ({helper}) => {357 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'});358 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});359 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);360 await expect(result).to.be.rejected;360 await expect(result).to.be.rejectedWith('common.CantApproveMoreThanOwned');361 });361 });362 });362 });363363373 });373 });374 });374 });375375376 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}) => {377 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'});378 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)});379 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});379 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});380 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});381 await expect(result).to.be.rejected;381 await expect(approveTx).to.be.rejectedWith('common.CantApproveMoreThanOwned');382 });382 });383 });383 });384384395 });395 });396396397 itSub('[nft] Approve for a collection that does not exist', async ({helper}) => {397 itSub('[nft] Approve for a collection that does not exist', async ({helper}) => {398 const collectionId = 1 << 32 - 1;398 const collectionId = 999999;399 await expect((helper.nft as any)[testCase.method](bob, collectionId, 1, {Substrate: charlie.address})).to.be.rejected;399 const approveTx = (helper.nft as any)[testCase.method](bob, collectionId, 1, {Substrate: charlie.address});400 await expect(approveTx).to.be.rejectedWith('common.CollectionNotFound');400 });401 });401402402 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}) => {403 const collectionId = 1 << 32 - 1;404 const collectionId = 999999;404 const approveTx = () => (helper.ft as any)[testCase.method](bob, collectionId, 1, {Substrate: charlie.address});405 const approveTx = (helper.ft as any)[testCase.method](bob, collectionId, 1, {Substrate: charlie.address});405 await expect(approveTx()).to.be.rejected;406 await expect(approveTx).to.be.rejectedWith('common.CollectionNotFound');406 });407 });407408408 itSub.ifWithPallets('[refungible] Approve for a collection that does not exist', [Pallets.ReFungible], async ({helper}) => {409 itSub.ifWithPallets('[refungible] Approve for a collection that does not exist', [Pallets.ReFungible], async ({helper}) => {409 const collectionId = 1 << 32 - 1;410 const collectionId = 999999;410 const approveTx = () => (helper.rft as any)[testCase.method](bob, collectionId, 1, {Substrate: charlie.address});411 const approveTx = (helper.rft as any)[testCase.method](bob, collectionId, 1, {Substrate: charlie.address});411 await expect(approveTx()).to.be.rejected;412 await expect(approveTx).to.be.rejectedWith('common.CollectionNotFound');412 });413 });413414414 itSub('[nft] Approve for a collection that was destroyed', async ({helper}) => {415 itSub('[nft] Approve for a collection that was destroyed', async ({helper}) => {415 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});416 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});416 await helper.nft.burn(alice, collectionId);417 await helper.nft.burn(alice, collectionId);417 const approveTx = () => (helper.nft as any)[testCase.method](alice, collectionId, 1, {Substrate: bob.address});418 const approveTx = (helper.nft as any)[testCase.method](alice, collectionId, 1, {Substrate: bob.address});418 await expect(approveTx()).to.be.rejected;419 await expect(approveTx).to.be.rejectedWith('common.CollectionNotFound');419 });420 });420421421 itSub('[fungible] Approve for a collection that was destroyed', async ({helper}) => {422 itSub('[fungible] Approve for a collection that was destroyed', async ({helper}) => {422 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});423 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});423 await helper.ft.burn(alice, collectionId);424 await helper.ft.burn(alice, collectionId);424 const approveTx = () => (helper.ft as any)[testCase.method](alice, collectionId, 1, {Substrate: bob.address});425 const approveTx = (helper.ft as any)[testCase.method](alice, collectionId, 1, {Substrate: bob.address});425 await expect(approveTx()).to.be.rejected;426 await expect(approveTx).to.be.rejectedWith('common.CollectionNotFound');426 });427 });427428428 itSub.ifWithPallets('[refungible] Approve for a collection that was destroyed', [Pallets.ReFungible], async ({helper}) => {429 itSub.ifWithPallets('[refungible] Approve for a collection that was destroyed', [Pallets.ReFungible], async ({helper}) => {429 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});430 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});430 await helper.rft.burn(alice, collectionId);431 await helper.rft.burn(alice, collectionId);431 const approveTx = () => (helper.rft as any)[testCase.method](alice, collectionId, 1, {Substrate: bob.address});432 const approveTx = (helper.rft as any)[testCase.method](alice, collectionId, 1, {Substrate: bob.address});432 await expect(approveTx()).to.be.rejected;433 await expect(approveTx).to.be.rejectedWith('common.CollectionNotFound');433 });434 });434435435 itSub('[nft] Approve transfer of a token that does not exist', async ({helper}) => {436 itSub('[nft] Approve transfer of a token that does not exist', async ({helper}) => {436 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});437 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});437 const approveTx = () => (helper.nft as any)[testCase.method](alice, collectionId, 2, {Substrate: bob.address});438 const approveTx = (helper.nft as any)[testCase.method](alice, collectionId, 2, {Substrate: bob.address});438 await expect(approveTx()).to.be.rejected;439 await expect(approveTx).to.be.rejectedWith('common.TokenNotFound');439 });440 });440441441 itSub.ifWithPallets('[refungible] Approve transfer of a token that does not exist', [Pallets.ReFungible], async ({helper}) => {442 itSub.ifWithPallets('[refungible] Approve transfer of a token that does not exist', [Pallets.ReFungible], async ({helper}) => {442 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});443 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});443 const approveTx = () => (helper.rft as any)[testCase.method](alice, collectionId, 2, {Substrate: bob.address});444 const approveTx = (helper.rft as any)[testCase.method](alice, collectionId, 2, {Substrate: bob.address});444 await expect(approveTx()).to.be.rejected;445 await expect(approveTx).to.be.rejectedWith('common.CantApproveMoreThanOwned'); // TODO: why the error is not common.TokenNotFound445 });446 });446447447 itSub('[nft] Approve using the address that does not own the approved token', async ({helper}) => {448 itSub('[nft] Approve using the address that does not own the approved token', async ({helper}) => {448 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});449 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});449 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice)});450 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice)});450 const approveTx = () => (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address});451 const approveTx = (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address});451 await expect(approveTx()).to.be.rejected;452 await expect(approveTx).to.be.rejectedWith('common.CantApproveMoreThanOwned');452 });453 });453454454 itSub('[fungible] Approve using the address that does not own the approved token', async ({helper}) => {455 itSub('[fungible] Approve using the address that does not own the approved token', async ({helper}) => {455 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});456 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});456 await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));457 await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));457 const tokenId = await helper.ft.getLastTokenId(collectionId);458 const tokenId = await helper.ft.getLastTokenId(collectionId);458 const approveTx = () => (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address});459 const approveTx = (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address});459 await expect(approveTx()).to.be.rejected;460 await expect(approveTx).to.be.rejectedWith('common.CantApproveMoreThanOwned');460 });461 });461462462 itSub.ifWithPallets('[refungible] Approve using the address that does not own the approved token', [Pallets.ReFungible], async ({helper}) => {463 itSub.ifWithPallets('[refungible] Approve using the address that does not own the approved token', [Pallets.ReFungible], async ({helper}) => {463 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});464 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});464 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});465 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});465 const approveTx = () => (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address});466 const approveTx = (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address});466 await expect(approveTx()).to.be.rejected;467 await expect(approveTx).to.be.rejectedWith('common.CantApproveMoreThanOwned');467 });468 });468469469 itSub.ifWithPallets('should fail if approved more ReFungibles than owned', [Pallets.ReFungible], async ({helper}) => {470 itSub.ifWithPallets('should fail if approved more ReFungibles than owned', [Pallets.ReFungible], async ({helper}) => {472 await helper.rft.transferToken(alice, collectionId, tokenId, testCase.account(bob), 100n);473 await helper.rft.transferToken(alice, collectionId, tokenId, testCase.account(bob), 100n);473 await (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 100n);474 await (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 100n);474475475 const approveTx = () => (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 101n);476 const approveTx = (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 101n);476 await expect(approveTx()).to.be.rejected;477 await expect(approveTx).to.be.rejectedWith('common.CantApproveMoreThanOwned');477 });478 });478479479 itSub('should fail if approved more Fungibles than owned', async ({helper}) => {480 itSub('should fail if approved more Fungibles than owned', async ({helper}) => {483484484 await helper.ft.transferToken(alice, collectionId, tokenId, testCase.account(bob), 10n);485 await helper.ft.transferToken(alice, collectionId, tokenId, testCase.account(bob), 10n);485 await (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 10n);486 await (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 10n);486 const approveTx = () => (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 11n);487 const approveTx = (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 11n);487 await expect(approveTx()).to.be.rejected;488 await expect(approveTx).to.be.rejectedWith('common.CantApproveMoreThanOwned');488 });489 });489490490 itSub('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => {491 itSub('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => {491 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});492 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});492 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});493 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});493 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: false});494 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: false});494495495 const approveTx = () => (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: charlie.address});496 const approveTx = (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: charlie.address});496 await expect(approveTx()).to.be.rejected;497 await expect(approveTx).to.be.rejectedWith('common.CantApproveMoreThanOwned');497 });498 });498 });499 });499});500});577 const daveBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});578 const daveBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});578 await helper.ft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n);579 await helper.ft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n);579 const daveBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});580 const daveBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});580 expect(daveBalanceAfter - daveBalanceBefore).to.be.equal(BigInt(1));581 expect(daveBalanceAfter - daveBalanceBefore).to.be.equal(1n);581582582 await helper.collection.addAdmin(alice ,collectionId, {Substrate: bob.address});583 await helper.collection.addAdmin(alice ,collectionId, {Substrate: bob.address});583584584 const aliceBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: alice.address});585 const aliceBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: alice.address});585 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n);586 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n);586 const aliceBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: alice.address});587 const aliceBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: alice.address});587 expect(aliceBalanceAfter - aliceBalanceBefore).to.be.equal(BigInt(1));588 expect(aliceBalanceAfter - aliceBalanceBefore).to.be.equal(1n);588 });589 });589590590 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {591 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {595 const daveBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address});596 const daveBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address});596 await helper.rft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n);597 await helper.rft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n);597 const daveAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address});598 const daveAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address});598 expect(daveAfter - daveBefore).to.be.equal(BigInt(1));599 expect(daveAfter - daveBefore).to.be.equal(1n);599600600 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});601 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});601602602 const aliceBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});603 const aliceBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});603 await helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n);604 await helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n);604 const aliceAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});605 const aliceAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});605 expect(aliceAfter - aliceBefore).to.be.equal(BigInt(1));606 expect(aliceAfter - aliceBefore).to.be.equal(1n);606 });607 });607});608});608609626 await collection.approveTokens(alice, {Substrate: charlie.address}, 1n);627 await collection.approveTokens(alice, {Substrate: charlie.address}, 1n);627 // const allowances1 = await getAllowance(collectionId, 0, Alice.address, Bob.address);628 // const allowances1 = await getAllowance(collectionId, 0, Alice.address, Bob.address);628 // const allowances2 = await getAllowance(collectionId, 0, Alice.address, Charlie.address);629 // const allowances2 = await getAllowance(collectionId, 0, Alice.address, Charlie.address);629 // expect(allowances1 + allowances2).to.be.eq(BigInt(2));630 // expect(allowances1 + allowances2).to.be.eq(2n);630 });631 });631632632 itSub.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. ReFungible', async ({helper}) => {633 itSub.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. ReFungible', async ({helper}) => {636 await token.approve(alice, {Substrate: charlie.address}, 1n);637 await token.approve(alice, {Substrate: charlie.address}, 1n);637 // const allowances1 = await getAllowance(collectionId, itemId, Alice.address, Bob.address);638 // const allowances1 = await getAllowance(collectionId, itemId, Alice.address, Bob.address);638 // const allowances2 = await getAllowance(collectionId, itemId, Alice.address, Charlie.address);639 // const allowances2 = await getAllowance(collectionId, itemId, Alice.address, Charlie.address);639 // expect(allowances1 + allowances2).to.be.eq(BigInt(2));640 // expect(allowances1 + allowances2).to.be.eq(2n);640 });641 });641642642 // Canceled by changing approve logic643 // Canceled by changing approve logic