difftreelog
approve migrated
in: master
1 file changed
tests/src/approve.test.tsdiffbeforeafterboth35 requirePallets,35 requirePallets,36 Pallets,36 Pallets,37} from './util/helpers';37} from './util/helpers';38import { usingPlaygrounds } from './util/playgrounds';383940let donor: IKeyringPair;4142before(async () => {43 await usingPlaygrounds(async (_, privateKeyWrapper) => {44 donor = privateKeyWrapper('//Alice');45 });46});4739chai.use(chaiAsPromised);48chai.use(chaiAsPromised);49const expect = chai.expect;405041describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {51describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {42 let alice: IKeyringPair;52 let alice: IKeyringPair;43 let bob: IKeyringPair;53 let bob: IKeyringPair;44 let charlie: IKeyringPair;54 let charlie: IKeyringPair;455546 before(async () => {56 before(async () => {47 await usingApi(async (api, privateKeyWrapper) => {57 await usingPlaygrounds(async (helper) => {48 alice = privateKeyWrapper('//Alice');58 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);49 bob = privateKeyWrapper('//Bob');50 charlie = privateKeyWrapper('//Charlie');51 });59 });52 });60 });536154 it('[nft] Execute the extrinsic and check approvedList', async () => {62 it('[nft] Execute the extrinsic and check approvedList', async () => {55 const nftCollectionId = await createCollectionExpectSuccess();63 await usingPlaygrounds(async (helper) => {64 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});56 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');65 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});57 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address);66 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});67 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;68 });58 });69 });597060 it('[fungible] Execute the extrinsic and check approvedList', async () => {71 it('[fungible] Execute the extrinsic and check approvedList', async () => {61 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});72 await usingPlaygrounds(async (helper) => {73 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);62 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');74 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);75 const tokenId = await helper.ft.getLastTokenId(collectionId);76 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});63 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);77 const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});78 expect(amount).to.be.equal(BigInt(1));79 });64 });80 });658166 it('[refungible] Execute the extrinsic and check approvedList', async function() {82 it('[refungible] Execute the extrinsic and check approvedList', async function() {67 await requirePallets(this, [Pallets.ReFungible]);83 await usingPlaygrounds(async (helper) => {6869 const reFungibleCollectionId =84 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});70 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});71 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');85 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});72 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address);86 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});87 const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});88 expect(amount).to.be.equal(BigInt(100));89 });73 });90 });749175 it('[nft] Remove approval by using 0 amount', async () => {92 it('[nft] Remove approval by using 0 amount', async () => {76 const nftCollectionId = await createCollectionExpectSuccess();93 await usingPlaygrounds(async (helper) => {94 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});77 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');95 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});78 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address, 1);96 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});97 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;79 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address, 0);98 await helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0).signAndSend(alice);99 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;100 });80 });101 });8110282 it('[fungible] Remove approval by using 0 amount', async () => {103 it('[fungible] Remove approval by using 0 amount', async () => {83 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});104 await usingPlaygrounds(async (helper) => {105 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);84 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');106 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);107 const tokenId = await helper.ft.getLastTokenId(collectionId);108 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});85 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 1);109 const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});110 expect(amountBefore).to.be.equal(BigInt(1));11186 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 0);112 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, undefined, 0n);113 const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});114 expect(amountAfter).to.be.equal(BigInt(0));115 });87 });116 });8811789 it('[refungible] Remove approval by using 0 amount', async function() {118 it('[refungible] Remove approval by using 0 amount', async function() {90 await requirePallets(this, [Pallets.ReFungible]);119 await usingPlaygrounds(async (helper) => {120 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});121 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});122 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});123 const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});124 expect(amountBefore).to.be.equal(BigInt(100));9112592 const reFungibleCollectionId =126 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, undefined, 0n);93 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});94 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');127 const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});95 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 1);96 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 0);128 expect(amountAfter).to.be.equal(BigInt(0));129 });97 });130 });9813199 it('can`t be called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {132 it('can`t be called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {100 const collectionId = await createCollectionExpectSuccess();133 await usingPlaygrounds(async (helper) => {134 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});101 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);135 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});102103 await adminApproveFromExpectFail(collectionId, itemId, alice, bob.address, charlie.address);136 const approveTokenTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});137 await expect(approveTokenTx()).to.be.rejected;138 });104 });139 });105});140});106141110 let charlie: IKeyringPair;145 let charlie: IKeyringPair;111146112 before(async () => {147 before(async () => {113 await usingApi(async (api, privateKeyWrapper) => {148 await usingPlaygrounds(async (helper) => {114 alice = privateKeyWrapper('//Alice');149 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);115 bob = privateKeyWrapper('//Bob');116 charlie = privateKeyWrapper('//Charlie');117 });150 });118 }); 151 });119152120 it('NFT', async () => {153 it('NFT', async () => {121 const collectionId = await createCollectionExpectSuccess();154 await usingPlaygrounds(async (helper) => {155 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});122 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);156 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});123 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);157 await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});158 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.true;159 });124 });160 });125161126 it('Fungible up to an approved amount', async () => {162 it('Fungible up to an approved amount', async () => {127 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});163 await usingPlaygrounds(async (helper) => {164 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);128 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', bob.address); 165 await helper.ft.mintTokens(alice, collectionId, bob.address, 10n);166 const tokenId = await helper.ft.getLastTokenId(collectionId);167 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});129 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);168 const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, {Substrate: bob.address});169 expect(amount).to.be.equal(BigInt(1));170 });130 });171 });131172132 it('ReFungible up to an approved amount', async function() {173 it('ReFungible up to an approved amount', async function() {133 await requirePallets(this, [Pallets.ReFungible]);174 await usingPlaygrounds(async (helper) => {134135 const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});175 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});136 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', bob.address);176 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});137 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);177 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});178 const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, {Substrate: bob.address});179 expect(amount).to.be.equal(BigInt(100));180 });138 });181 });139});182});140183144 let charlie: IKeyringPair;187 let charlie: IKeyringPair;145188146 before(async () => {189 before(async () => {147 await usingApi(async (api, privateKeyWrapper) => {190 await usingPlaygrounds(async (helper) => {148 alice = privateKeyWrapper('//Alice');191 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);149 bob = privateKeyWrapper('//Bob');150 charlie = privateKeyWrapper('//Charlie');151 });192 });152 }); 193 });153194154 it('NFT', async () => {195 it('NFT', async () => {155 const collectionId = await createCollectionExpectSuccess();196 await usingPlaygrounds(async (helper) => {197 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});156 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);198 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});157 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);199 await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});158 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'NFT');200 await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});201 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);202 expect(owner.Substrate).to.be.equal(alice.address);203 });159 });204 });160205161 it('Fungible up to an approved amount', async () => {206 it('Fungible up to an approved amount', async () => {162 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});207 await usingPlaygrounds(async (helper) => {208 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);163 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', bob.address); 209 await helper.ft.mintTokens(alice, collectionId, bob.address, 10n);210 const tokenId = await helper.ft.getLastTokenId(collectionId);164 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);211 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});165 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'Fungible');212 const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});213 await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);214 const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});215 expect(after - before).to.be.equal(BigInt(1));216 });166 });217 });167218168 it('ReFungible up to an approved amount', async function() {219 it('ReFungible up to an approved amount', async function() {169 await requirePallets(this, [Pallets.ReFungible]);220 await usingPlaygrounds(async (helper) => {170171 const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});221 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});172 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', bob.address);222 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});173 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);223 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});174 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'ReFungible');224 const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});225 await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);226 const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});227 expect(after - before).to.be.equal(BigInt(1));228 });175 });229 });176});230});177231181 let charlie: IKeyringPair;235 let charlie: IKeyringPair;182236183 before(async () => {237 before(async () => {184 await usingApi(async (api, privateKeyWrapper) => {238 await usingPlaygrounds(async (helper) => {185 alice = privateKeyWrapper('//Alice');239 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);186 bob = privateKeyWrapper('//Bob');187 charlie = privateKeyWrapper('//Charlie');188 });240 });189 }); 241 });190242191 it('NFT', async () => {243 it('NFT', async () => {192 const collectionId = await createCollectionExpectSuccess();244 await usingPlaygrounds(async (helper) => {245 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});193 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);246 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});194 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);247 await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});195 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'NFT');248 await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});249 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);196 await transferFromExpectFail(collectionId, itemId, charlie, bob, alice, 1);250 expect(owner.Substrate).to.be.equal(alice.address);251 const transferTokenFromTx = async () => helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});252 await expect(transferTokenFromTx()).to.be.rejected;253 });197 });254 });198255199 it('Fungible up to an approved amount', async () => {256 it('Fungible up to an approved amount', async () => {200 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});257 await usingPlaygrounds(async (helper) => {258 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);201 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', bob.address); 259 await helper.ft.mintTokens(alice, collectionId, bob.address, 10n);260 const tokenId = await helper.ft.getLastTokenId(collectionId);202 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);261 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});203 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'Fungible');262 const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});263 await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);204 await transferFromExpectFail(collectionId, itemId, charlie, bob, alice, 1);264 const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});265 expect(after - before).to.be.equal(BigInt(1));266267 const transferTokenFromTx = async () => helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);268 await expect(transferTokenFromTx()).to.be.rejected;269 });205 });270 });206271207 it('ReFungible up to an approved amount', async function() {272 it('ReFungible up to an approved amount', async function() {208 await requirePallets(this, [Pallets.ReFungible]);273 await usingPlaygrounds(async (helper) => {209210 const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});274 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});211 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', bob.address);275 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});212 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);276 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});213 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'ReFungible');277 const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});278 await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 100n);214 await transferFromExpectFail(collectionId, itemId, charlie, bob, alice, 1);279 const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});280 expect(after - before).to.be.equal(BigInt(100));281 const transferTokenFromTx = async () => helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 100n);282 await expect(transferTokenFromTx()).to.be.rejected;283 });215 });284 });216});285});217286222 let dave: IKeyringPair;291 let dave: IKeyringPair;223292224 before(async () => {293 before(async () => {225 await usingApi(async (api, privateKeyWrapper) => {294 await usingPlaygrounds(async (helper) => {226 alice = privateKeyWrapper('//Alice');295 [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);227 bob = privateKeyWrapper('//Bob');228 charlie = privateKeyWrapper('//Charlie');229 dave = privateKeyWrapper('//Dave');230 });296 });231 }); 297 });232298233 it('If a user B is approved to transfer 10 Fungible tokens from user A, they can transfer 2 tokens to user C, which will result in decreasing approval from 10 to 8. Then user B can transfer 8 tokens to user D.', async () => {299 it('If a user B is approved to transfer 10 Fungible tokens from user A, they can transfer 2 tokens to user C, which will result in decreasing approval from 10 to 8. Then user B can transfer 8 tokens to user D.', async () => {234 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});300 await usingPlaygrounds(async (helper) => {301 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);235 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', alice.address); 302 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);303 const tokenId = await helper.ft.getLastTokenId(collectionId);236 await approveExpectSuccess(collectionId, itemId, alice, bob.address, 10);304 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, undefined, 10n);305237 await transferFromExpectSuccess(collectionId, itemId, bob, alice, charlie, 2, 'Fungible');306 const charlieBefore = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});307 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address}, 2n);308 const charlieAfter = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});238 await transferFromExpectSuccess(collectionId, itemId, bob, alice, dave, 8, 'Fungible');309 expect(charlieAfter - charlieBefore).to.be.equal(BigInt(2));310311 const daveBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});312 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: alice.address}, {Substrate: dave.address}, 8n);313 const daveAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});314 expect(daveAfter - daveBefore).to.be.equal(BigInt(8));315 });239 });316 });240});317});241318245 let charlie: IKeyringPair;322 let charlie: IKeyringPair;246323247 before(async () => {324 before(async () => {248 await usingApi(async (api, privateKeyWrapper) => {325 await usingPlaygrounds(async (helper) => {249 alice = privateKeyWrapper('//Alice');326 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);250 bob = privateKeyWrapper('//Bob');251 charlie = privateKeyWrapper('//Charlie');252 });327 });253 });328 });254329255 it('NFT', async () => {330 it('NFT', async () => {256 const collectionId = await createCollectionExpectSuccess();331 await usingPlaygrounds(async (helper) => {332 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});257 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT');333 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});258 await approveExpectSuccess(collectionId, itemId, alice, bob.address, 1);334 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});259 await approveExpectSuccess(collectionId, itemId, alice, bob.address, 0);335 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;336 await helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0).signAndSend(alice);260 await transferFromExpectFail(collectionId, itemId, bob, bob, charlie, 1);337 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;338 const transferTokenFromTx = async () => helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: bob.address});339 await expect(transferTokenFromTx()).to.be.rejected;340 });261 });341 });262342263 it('Fungible', async () => {343 it('Fungible', async () => {264 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});344 await usingPlaygrounds(async (helper) => {345 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);265 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');346 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);347 const tokenId = await helper.ft.getLastTokenId(collectionId);348 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});266 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 1);349 const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});350 expect(amountBefore).to.be.equal(BigInt(1));351267 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 0);352 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, undefined, 0n);268 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, bob, bob, charlie, 1);353 const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});354 expect(amountAfter).to.be.equal(BigInt(0));355356 const transferTokenFromTx = async () => helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 1n);357 await expect(transferTokenFromTx()).to.be.rejected;358 });269 });359 });270360271 it('ReFungible', async function() {361 it('ReFungible', async function() {272 await requirePallets(this, [Pallets.ReFungible]);362 await usingPlaygrounds(async (helper) => {363 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});364 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});365 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});366 const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});367 expect(amountBefore).to.be.equal(BigInt(100));273368274 const reFungibleCollectionId =369 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, undefined, 0n);275 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});276 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');370 const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});277 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 1);371 expect(amountAfter).to.be.equal(BigInt(0));372278 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 0);373 const transferTokenFromTx = async () => helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 100n);279 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, bob, charlie, 1);374 await expect(transferTokenFromTx()).to.be.rejected;375 });280 });376 });281});377});282378286 let charlie: IKeyringPair;382 let charlie: IKeyringPair;287383288 before(async () => {384 before(async () => {289 await usingApi(async (api, privateKeyWrapper) => {385 await usingPlaygrounds(async (helper) => {290 alice = privateKeyWrapper('//Alice');386 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);291 bob = privateKeyWrapper('//Bob');292 charlie = privateKeyWrapper('//Charlie');293 });387 });294 });388 });295389296 it('1 for NFT', async () => {390 it('1 for NFT', async () => {297 const collectionId = await createCollectionExpectSuccess();391 await usingPlaygrounds(async (helper) => {392 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});298 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);393 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});299 await approveExpectFail(collectionId, itemId, bob, charlie, 2);394 await helper.api?.tx.unique.approve({Substrate: charlie.address}, collectionId, tokenId, 2).signAndSend(bob);395 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.false;396 });300 });397 });301398302 it('Fungible', async () => {399 it('Fungible', async () => {303 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});400 await usingPlaygrounds(async (helper) => {401 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);304 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');402 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);305 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, bob, charlie, 11);403 const tokenId = await helper.ft.getLastTokenId(collectionId);404 const approveTx = async () => helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, undefined, 11n);405 await expect(approveTx()).to.be.rejected;406 });306 });407 });307408308 it('ReFungible', async function() {409 it('ReFungible', async function() {309 await requirePallets(this, [Pallets.ReFungible]);410 await usingPlaygrounds(async (helper) => {310311 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});411 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});312 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');412 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});313 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, charlie, 101);413 const approveTx = async () => helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, undefined, 101n);414 await expect(approveTx()).to.be.rejected;415 });314 });416 });315});417});316418321 let dave: IKeyringPair;423 let dave: IKeyringPair;322424323 before(async () => {425 before(async () => {324 await usingApi(async (api, privateKeyWrapper) => {426 await usingPlaygrounds(async (helper) => {325 alice = privateKeyWrapper('//Alice');427 [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);326 bob = privateKeyWrapper('//Bob');327 charlie = privateKeyWrapper('//Charlie');328 dave = privateKeyWrapper('//Dave');329 });428 });330 }); 429 });331430332 it('NFT', async () => {431 it('NFT', async () => {333 const collectionId = await createCollectionExpectSuccess();432 await usingPlaygrounds(async (helper) => {433 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});334 await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});434 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});335 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', charlie.address);435 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: charlie.address});436336 await transferFromExpectSuccess(collectionId, itemId, alice, charlie, dave, 1, 'NFT');437 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address});438 const owner1 = await helper.nft.getTokenOwner(collectionId, tokenId);337 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);439 expect(owner1.Substrate).to.be.equal(dave.address);440441 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});338 await transferFromExpectSuccess(collectionId, itemId, bob, dave, alice, 1, 'NFT');442 await helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address});443 const owner2 = await helper.nft.getTokenOwner(collectionId, tokenId);444 expect(owner2.Substrate).to.be.equal(alice.address);445 });339 });446 });340447341 it('Fungible up to an approved amount', async () => {448 it('Fungible up to an approved amount', async () => {342 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});449 await usingPlaygrounds(async (helper) => {450 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);343 await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});451 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});344 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', charlie.address); 452 await helper.ft.mintTokens(alice, collectionId, charlie.address, 10n);453 const tokenId = await helper.ft.getLastTokenId(collectionId);454345 await transferFromExpectSuccess(collectionId, itemId, alice, charlie, dave, 1, 'Fungible');455 const daveBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});456 await helper.ft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n);457 const daveBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});346 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);458 expect(daveBalanceAfter - daveBalanceBefore).to.be.equal(BigInt(1));459460 await helper.collection.addAdmin(alice ,collectionId, {Substrate: bob.address});461347 await transferFromExpectSuccess(collectionId, itemId, bob, dave, alice, 1, 'Fungible');462 const aliceBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: alice.address});463 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n);464 const aliceBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: alice.address});465 expect(aliceBalanceAfter - aliceBalanceBefore).to.be.equal(BigInt(1));466 });348 });467 });349468350 it('ReFungible up to an approved amount', async function() {469 it('ReFungible up to an approved amount', async function() {351 await requirePallets(this, [Pallets.ReFungible]);470 await usingPlaygrounds(async (helper) => {471 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});472 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});473 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: charlie.address, pieces: 100n});352474353 const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});475 const daveBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address});354 await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});476 await helper.rft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n);355 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', charlie.address);477 const daveAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address});478 expect(daveAfter - daveBefore).to.be.equal(BigInt(1));479480 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});481356 await transferFromExpectSuccess(collectionId, itemId, alice, charlie, dave, 1, 'ReFungible');482 const aliceBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});483 await helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n);357 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);484 const aliceAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});358 await transferFromExpectSuccess(collectionId, itemId, bob, dave, alice, 1, 'ReFungible');485 expect(aliceAfter - aliceBefore).to.be.equal(BigInt(1));486 });359 });487 });360});488});361489366 let dave: IKeyringPair;494 let dave: IKeyringPair;367495368 before(async () => {496 before(async () => {369 await usingApi(async (api, privateKeyWrapper) => {497 await usingPlaygrounds(async (helper) => {370 alice = privateKeyWrapper('//Alice');498 [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);371 bob = privateKeyWrapper('//Bob');372 charlie = privateKeyWrapper('//Charlie');373 dave = privateKeyWrapper('//Dave');374 });499 });375 }); 500 });376501377 it.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. Fungible', async () => {502 it.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. Fungible', async () => {378 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});503 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});417 let charlie: IKeyringPair;542 let charlie: IKeyringPair;418543419 before(async () => {544 before(async () => {420 await usingApi(async (api, privateKeyWrapper) => {545 await usingPlaygrounds(async (helper) => {421 alice = privateKeyWrapper('//Alice');546 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);422 bob = privateKeyWrapper('//Bob');423 charlie = privateKeyWrapper('//Charlie');424 });547 });425 });548 });426549427 it('can be called by collection admin on non-owned item', async () => {550 it('can be called by collection admin on non-owned item', async () => {428 const collectionId = await createCollectionExpectSuccess();551 await usingPlaygrounds(async (helper) => {552 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});429 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);553 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});430431 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);554 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});432 await adminApproveFromExpectFail(collectionId, itemId, bob, alice.address, charlie.address);555 const approveTx = async () => helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});556 await expect(approveTx()).to.be.rejected;557 });433 });558 });434});559});435560439 let charlie: IKeyringPair;564 let charlie: IKeyringPair;440565441 before(async () => {566 before(async () => {442 await usingApi(async (api, privateKeyWrapper) => {567 await usingPlaygrounds(async (helper) => {443 alice = privateKeyWrapper('//Alice');568 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);444 bob = privateKeyWrapper('//Bob');445 charlie = privateKeyWrapper('//Charlie');446 });569 });447 });570 });448571449 it('[nft] Approve for a collection that does not exist', async () => {572 it('[nft] Approve for a collection that does not exist', async () => {450 await usingApi(async (api: ApiPromise) => {573 await usingPlaygrounds(async (helper) => {451 const nftCollectionCount = await getCreatedCollectionCount(api);574 const collectionId = 1 << 32 - 1;452 await approveExpectFail(nftCollectionCount + 1, 1, alice, bob);575 const approveTx = async () => helper.nft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});576 await expect(approveTx()).to.be.rejected;453 });577 });454 });578 });455579456 it('[fungible] Approve for a collection that does not exist', async () => {580 it('[fungible] Approve for a collection that does not exist', async () => {457 await usingApi(async (api: ApiPromise) => {581 await usingPlaygrounds(async (helper) => {458 const fungibleCollectionCount = await getCreatedCollectionCount(api);582 const collectionId = 1 << 32 - 1;459 await approveExpectFail(fungibleCollectionCount + 1, 0, alice, bob);583 const approveTx = async () => helper.ft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});584 await expect(approveTx()).to.be.rejected;460 });585 });461 });586 });462587463 it('[refungible] Approve for a collection that does not exist', async function() {588 it('[refungible] Approve for a collection that does not exist', async function() {464 await requirePallets(this, [Pallets.ReFungible]);589 await usingPlaygrounds(async (helper) => {465466 await usingApi(async (api: ApiPromise) => {467 const reFungibleCollectionCount = await getCreatedCollectionCount(api);590 const collectionId = 1 << 32 - 1;468 await approveExpectFail(reFungibleCollectionCount + 1, 1, alice, bob);591 const approveTx = async () => helper.rft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});592 await expect(approveTx()).to.be.rejected;469 });593 });470 });594 });471595472 it('[nft] Approve for a collection that was destroyed', async () => {596 it('[nft] Approve for a collection that was destroyed', async () => {473 const nftCollectionId = await createCollectionExpectSuccess();597 await usingPlaygrounds(async (helper) => {598 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});474 await destroyCollectionExpectSuccess(nftCollectionId);599 await helper.nft.burn(alice, collectionId);475 await approveExpectFail(nftCollectionId, 1, alice, bob);600 const approveTx = async () => helper.nft.approveToken(alice, collectionId, 1, {Substrate: bob.address});601 await expect(approveTx()).to.be.rejected;602 });476 });603 });477604478 it('Approve for a collection that was destroyed', async () => {605 it('[fungible] Approve for a collection that was destroyed', async () => {479 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});606 await usingPlaygrounds(async (helper) => {607 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});480 await destroyCollectionExpectSuccess(fungibleCollectionId);608 await helper.ft.burn(alice, collectionId);481 await approveExpectFail(fungibleCollectionId, 0, alice, bob);609 const approveTx = async () => helper.ft.approveToken(alice, collectionId, 1, {Substrate: bob.address});610 await expect(approveTx()).to.be.rejected;611 });482 });612 });483613484 it('[refungible] Approve for a collection that was destroyed', async function() {614 it('[refungible] Approve for a collection that was destroyed', async function() {485 await requirePallets(this, [Pallets.ReFungible]);615 await usingPlaygrounds(async (helper) => {486487 const reFungibleCollectionId =616 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});488 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});489 await destroyCollectionExpectSuccess(reFungibleCollectionId);617 await helper.rft.burn(alice, collectionId);490 await approveExpectFail(reFungibleCollectionId, 1, alice, bob);618 const approveTx = async () => helper.rft.approveToken(alice, collectionId, 1, {Substrate: bob.address});619 await expect(approveTx()).to.be.rejected;620 });491 });621 });492622493 it('[nft] Approve transfer of a token that does not exist', async () => {623 it('[nft] Approve transfer of a token that does not exist', async () => {494 const nftCollectionId = await createCollectionExpectSuccess();624 await usingPlaygrounds(async (helper) => {625 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});495 await approveExpectFail(nftCollectionId, 2, alice, bob);626 const approveTx = async () => helper.nft.approveToken(alice, collectionId, 2, {Substrate: bob.address});627 await expect(approveTx()).to.be.rejected;628 });496 });629 });497630498 it('[refungible] Approve transfer of a token that does not exist', async function() {631 it('[refungible] Approve transfer of a token that does not exist', async function() {499 await requirePallets(this, [Pallets.ReFungible]);632 await usingPlaygrounds(async (helper) => {500501 const reFungibleCollectionId =633 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});502 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});503 await approveExpectFail(reFungibleCollectionId, 2, alice, bob);634 const approveTx = async () => helper.rft.approveToken(alice, collectionId, 2, {Substrate: bob.address});635 await expect(approveTx()).to.be.rejected;636 });504 });637 });505638506 it('[nft] Approve using the address that does not own the approved token', async () => {639 it('[nft] Approve using the address that does not own the approved token', async () => {507 const nftCollectionId = await createCollectionExpectSuccess();640 await usingPlaygrounds(async (helper) => {641 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});508 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');642 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});509 await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice);643 const approveTx = async () => helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});644 await expect(approveTx()).to.be.rejected;645 });510 });646 });511647512 it('[fungible] Approve using the address that does not own the approved token', async () => {648 it('[fungible] Approve using the address that does not own the approved token', async () => {513 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});649 await usingPlaygrounds(async (helper) => {650 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});514 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');651 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);515 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice);652 const tokenId = await helper.ft.getLastTokenId(collectionId);653 const approveTx = async () => helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});654 await expect(approveTx()).to.be.rejected;655 });516 });656 });517657518 it('[refungible] Approve using the address that does not own the approved token', async function() {658 it('[refungible] Approve using the address that does not own the approved token', async function() {519 await requirePallets(this, [Pallets.ReFungible]);659 await usingPlaygrounds(async (helper) => {520521 const reFungibleCollectionId =660 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});522 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});523 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');661 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});524 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, alice);662 const approveTx = async () => helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});663 await expect(approveTx()).to.be.rejected;664 });525 });665 });526666527 it('should fail if approved more ReFungibles than owned', async function() {667 it('should fail if approved more ReFungibles than owned', async function() {528 await requirePallets(this, [Pallets.ReFungible]);668 await usingPlaygrounds(async (helper) => {669 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});670 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});671 await helper.rft.transferToken(alice, collectionId, tokenId, {Substrate: bob.address}, 100n);672 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, undefined, 100n);529673530 const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});674 const approveTx = async () => helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, undefined, 101n);531 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'ReFungible');532 await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 100, 'ReFungible');533 await approveExpectSuccess(nftCollectionId, newNftTokenId, bob, alice.address, 100);675 await expect(approveTx()).to.be.rejected;534 await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice, 101);676 });535 });677 });536678537 it('should fail if approved more Fungibles than owned', async () => {679 it('should fail if approved more Fungibles than owned', async () => {538 const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});680 await usingPlaygrounds(async (helper) => {681 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});539 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'Fungible');682 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);540 await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 10, 'Fungible');683 const tokenId = await helper.ft.getLastTokenId(collectionId);684685 await helper.ft.transferToken(alice, collectionId, tokenId, {Substrate: bob.address}, 10n);541 await approveExpectSuccess(nftCollectionId, newNftTokenId, bob, alice.address, 10);686 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, undefined, 10n);542 await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice, 11);687 const approveTx = async () => helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, undefined, 11n);688 await expect(approveTx()).to.be.rejected;689 });543 });690 });544691545 it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {692 it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {546 const collectionId = await createCollectionExpectSuccess();693 await usingPlaygrounds(async (helper) => {694 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});547 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);695 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});548 await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: false});696 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: false});549697550 await approveExpectFail(collectionId, itemId, alice, charlie);698 const approveTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});699 await expect(approveTx()).to.be.rejected;700 });551 });701 });552});702});553703