difftreelog
tests: refactorr playgrounds' minting signature for shorter mint for self
in: master
8 files changed
tests/src/fungible.test.tsdiffbeforeafterboth35 const defaultTokenId = await collection.getLastTokenId();35 const defaultTokenId = await collection.getLastTokenId();36 expect(defaultTokenId).to.be.equal(0);36 expect(defaultTokenId).to.be.equal(0);373738 await collection.mint(alice, {Substrate: alice.address}, U128_MAX);38 await collection.mint(alice, U128_MAX);39 const aliceBalance = await collection.getBalance({Substrate: alice.address});39 const aliceBalance = await collection.getBalance({Substrate: alice.address});40 const itemCountAfter = await collection.getLastTokenId();40 const itemCountAfter = await collection.getLastTokenId();4141494950 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});50 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});515152 await collection.mint(alice, {Substrate: alice.address}, U128_MAX);52 await collection.mint(alice, U128_MAX);535354 await collection.transfer(alice, {Substrate: bob.address}, 1000n);54 await collection.transfer(alice, {Substrate: bob.address}, 1000n);55 await collection.transfer(alice, ethAcc, 900n);55 await collection.transfer(alice, ethAcc, 900n);72 itSub('Transfer token', async ({helper}) => {72 itSub('Transfer token', async ({helper}) => {73 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};73 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};74 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});74 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});75 await collection.mint(alice, {Substrate: alice.address}, 500n);75 await collection.mint(alice, 500n);767677 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(500n);77 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(500n);78 expect(await collection.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;78 expect(await collection.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;88 itSub('Tokens multiple creation', async ({helper}) => {88 itSub('Tokens multiple creation', async ({helper}) => {89 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});89 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});909091 await collection.mintWithOneOwner(alice, {Substrate: alice.address}, [91 await collection.mintWithOneOwner(alice, [92 {value: 500n},92 {value: 500n},93 {value: 400n},93 {value: 400n},94 {value: 300n},94 {value: 300n},9999100 itSub('Burn some tokens ', async ({helper}) => {100 itSub('Burn some tokens ', async ({helper}) => {101 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});101 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});102 await collection.mint(alice, {Substrate: alice.address}, 500n);102 await collection.mint(alice, 500n);103103104 expect(await collection.isTokenExists(0)).to.be.true;104 expect(await collection.isTokenExists(0)).to.be.true;105 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(500n);105 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(500n);110 110 111 itSub('Burn all tokens ', async ({helper}) => {111 itSub('Burn all tokens ', async ({helper}) => {112 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});112 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});113 await collection.mint(alice, {Substrate: alice.address}, 500n);113 await collection.mint(alice, 500n);114114115 expect(await collection.isTokenExists(0)).to.be.true;115 expect(await collection.isTokenExists(0)).to.be.true;116 expect(await collection.burnTokens(alice, 500n)).to.be.true;116 expect(await collection.burnTokens(alice, 500n)).to.be.true;123 itSub('Set allowance for token', async ({helper}) => {123 itSub('Set allowance for token', async ({helper}) => {124 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});124 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});125 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};125 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};126 await collection.mint(alice, {Substrate: alice.address}, 100n);126 await collection.mint(alice, 100n);127127128 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(100n);128 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(100n);129 129 tests/src/limits.test.tsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import usingApi from './substrate/substrate-api';18import {expect, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from './util/playgrounds';19import {20 createCollectionExpectSuccess,21 destroyCollectionExpectSuccess,22 setCollectionLimitsExpectSuccess,23 setCollectionSponsorExpectSuccess,24 confirmSponsorshipExpectSuccess,25 createItemExpectSuccess,26 createItemExpectFailure,27 transferExpectSuccess,28 getFreeBalance,29 waitNewBlocks, burnItemExpectSuccess,30 requirePallets,31 Pallets,32} from './util/helpers';33import {expect} from 'chai';341935describe('Number of tokens per address (NFT)', () => {20describe('Number of tokens per address (NFT)', () => {36 let alice: IKeyringPair;21 let alice: IKeyringPair;372238 before(async () => {23 before(async () => {39 await usingApi(async (api, privateKeyWrapper) => {24 await usingPlaygrounds(async (helper, privateKey) => {40 alice = privateKeyWrapper('//Alice');25 const donor = privateKey('//Alice');26 [alice] = await helper.arrange.createAccounts([10n], donor);41 });27 });42 });28 });432944 it.skip('Collection limits allow greater number than chain limits, chain limits are enforced', async () => {30 itSub.skip('Collection limits allow greater number than chain limits, chain limits are enforced', async ({helper}) => {4546 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});31 const collection = await helper.nft.mintCollection(alice, {});47 await setCollectionLimitsExpectSuccess(alice, collectionId, {accountTokenOwnershipLimit: 20});32 await collection.setLimits(alice, {accountTokenOwnershipLimit: 20});33 48 for(let i = 0; i < 10; i++){34 for(let i = 0; i < 10; i++){49 await createItemExpectSuccess(alice, collectionId, 'NFT');35 await expect(collection.mintToken(alice)).to.be.not.rejected;50 }36 }51 await createItemExpectFailure(alice, collectionId, 'NFT');37 await expect(collection.mintToken(alice)).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);52 for(let i = 1; i < 11; i++) {38 for(let i = 1; i < 11; i++) {53 await burnItemExpectSuccess(alice, collectionId, i);39 await expect(collection.burnToken(alice, i)).to.be.not.rejected;54 }40 }55 await destroyCollectionExpectSuccess(collectionId);41 await collection.burn(alice);56 });42 });43 44 itSub('Collection limits allow lower number than chain limits, collection limits are enforced', async ({helper}) => {45 const collection = await helper.nft.mintCollection(alice, {});46 await collection.setLimits(alice, {accountTokenOwnershipLimit: 1});574758 it('Collection limits allow lower number than chain limits, collection limits are enforced', async () => {48 await collection.mintToken(alice);5960 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});61 await setCollectionLimitsExpectSuccess(alice, collectionId, {accountTokenOwnershipLimit: 1});49 await expect(collection.mintToken(alice)).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);62 await createItemExpectSuccess(alice, collectionId, 'NFT');63 await createItemExpectFailure(alice, collectionId, 'NFT');50 64 await burnItemExpectSuccess(alice, collectionId, 1);51 await collection.burnToken(alice, 1);65 await destroyCollectionExpectSuccess(collectionId);52 await expect(collection.burn(alice)).to.be.not.rejected;66 });53 });67});54});685569describe('Number of tokens per address (ReFungible)', () => {56describe('Number of tokens per address (ReFungible)', () => {70 let alice: IKeyringPair;57 let alice: IKeyringPair;715872 before(async function() {59 before(async function() {73 await requirePallets(this, [Pallets.ReFungible]);60 await usingPlaygrounds(async (helper, privateKey) => {61 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);746275 await usingApi(async (api, privateKeyWrapper) => {63 const donor = privateKey('//Alice');76 alice = privateKeyWrapper('//Alice');64 [alice] = await helper.arrange.createAccounts([10n], donor);77 });65 });78 });66 });796780 it.skip('Collection limits allow greater number than chain limits, chain limits are enforced', async () => {68 itSub.skip('Collection limits allow greater number than chain limits, chain limits are enforced', async ({helper}) => {81 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});69 const collection = await helper.rft.mintCollection(alice, {});82 await setCollectionLimitsExpectSuccess(alice, collectionId, {accountTokenOwnershipLimit: 20});70 await collection.setLimits(alice, {accountTokenOwnershipLimit: 20});71 83 for(let i = 0; i < 10; i++){72 for(let i = 0; i < 10; i++){84 await createItemExpectSuccess(alice, collectionId, 'ReFungible');73 await expect(collection.mintToken(alice, 10n)).to.be.not.rejected;85 }74 }86 await createItemExpectFailure(alice, collectionId, 'ReFungible');75 await expect(collection.mintToken(alice, 10n)).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);87 for(let i = 1; i < 11; i++) {76 for(let i = 1; i < 11; i++) {88 await burnItemExpectSuccess(alice, collectionId, i, 100);77 await expect(collection.burnToken(alice, i, 10n)).to.be.not.rejected;89 }78 }90 await destroyCollectionExpectSuccess(collectionId);79 await collection.burn(alice);91 });80 });928193 it('Collection limits allow lower number than chain limits, collection limits are enforced', async () => {82 itSub('Collection limits allow lower number than chain limits, collection limits are enforced', async ({helper}) => {94 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});83 const collection = await helper.rft.mintCollection(alice, {});95 await setCollectionLimitsExpectSuccess(alice, collectionId, {accountTokenOwnershipLimit: 1});84 await collection.setLimits(alice, {accountTokenOwnershipLimit: 1});8596 await createItemExpectSuccess(alice, collectionId, 'ReFungible');86 await collection.mintToken(alice);97 await createItemExpectFailure(alice, collectionId, 'ReFungible');87 await expect(collection.mintToken(alice)).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);98 await burnItemExpectSuccess(alice, collectionId, 1, 100);88 89 await collection.burnToken(alice, 1);99 await destroyCollectionExpectSuccess(collectionId);90 await expect(collection.burn(alice)).to.be.not.rejected;100 });91 });101});92});1029394// todo:playgrounds skipped ~ postponed103describe.skip('Sponsor timeout (NFT) (only for special chain limits test)', () => {95describe.skip('Sponsor timeout (NFT) (only for special chain limits test)', () => {104 let alice: IKeyringPair;96 /*let alice: IKeyringPair;105 let bob: IKeyringPair;97 let bob: IKeyringPair;106 let charlie: IKeyringPair;98 let charlie: IKeyringPair;10799113 });105 });114 });106 });115107116 it.skip('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {108 itSub.skip('Collection limits have greater timeout value than chain limits, collection limits are enforced', async ({helper}) => {117 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});109 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});118 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 7});110 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 7});119 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');111 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');137 await destroyCollectionExpectSuccess(collectionId);129 await destroyCollectionExpectSuccess(collectionId);138 });130 });139131140 it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {132 itSub('Collection limits have lower timeout value than chain limits, chain limits are enforced', async ({helper}) => {141133142 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});134 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});143 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 1});135 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 1});176 });168 });177 });169 });178170179 it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {171 itSub('Collection limits have greater timeout value than chain limits, collection limits are enforced', async ({helper}) => {180 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});172 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});181 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 7});173 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 7});182 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible');174 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible');202 await destroyCollectionExpectSuccess(collectionId);194 await destroyCollectionExpectSuccess(collectionId);203 });195 });204196205 it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {197 itSub('Collection limits have lower timeout value than chain limits, chain limits are enforced', async ({helper}) => {206198207 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});199 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});208 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 1});200 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 1});243 });235 });244 });236 });245237246 it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {238 itSub('Collection limits have greater timeout value than chain limits, collection limits are enforced', async ({helper}) => {247 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});239 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});248 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 7});240 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 7});249 const tokenId = await createItemExpectSuccess(alice, collectionId, 'ReFungible');241 const tokenId = await createItemExpectSuccess(alice, collectionId, 'ReFungible');267 await destroyCollectionExpectSuccess(collectionId);259 await destroyCollectionExpectSuccess(collectionId);268 });260 });269261270 it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {262 itSub('Collection limits have lower timeout value than chain limits, chain limits are enforced', async ({helper}) => {271263272 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});264 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});273 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 1});265 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 1});290 expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;282 expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;291 //expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);283 //expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);292 await destroyCollectionExpectSuccess(collectionId);284 await destroyCollectionExpectSuccess(collectionId);293 });285 });*/294});286});295287296describe('Collection zero limits (NFT)', () => {288describe('Collection zero limits (NFT)', () => {299 let charlie: IKeyringPair;291 let charlie: IKeyringPair;300292301 before(async () => {293 before(async () => {302 await usingApi(async (api, privateKeyWrapper) => {294 await usingPlaygrounds(async (helper, privateKey) => {303 alice = privateKeyWrapper('//Alice');295 const donor = privateKey('//Alice');304 bob = privateKeyWrapper('//Bob');296 [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);305 charlie = privateKeyWrapper('//Charlie');306 });297 });307 });298 });308299309 it.skip('Limits have 0 in tokens per address field, the chain limits are applied', async () => {300 itSub.skip('Limits have 0 in tokens per address field, the chain limits are applied', async ({helper}) => {310 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});301 const collection = await helper.nft.mintCollection(alice, {});311 await setCollectionLimitsExpectSuccess(alice, collectionId, {accountTokenOwnershipLimit: 0});302 await collection.setLimits(alice, {accountTokenOwnershipLimit: 0});303312 for(let i = 0; i < 10; i++){304 for(let i = 0; i < 10; i++){313 await createItemExpectSuccess(alice, collectionId, 'NFT');305 await collection.mintToken(alice);314 }306 }315 await createItemExpectFailure(alice, collectionId, 'NFT');307 await expect(collection.mintToken(alice)).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);316 });308 });317309318 it('Limits have 0 in sponsor timeout, no limits are applied', async () => {310 itSub('Limits have 0 in sponsor timeout, no limits are applied', async ({helper}) => {311 const collection = await helper.nft.mintCollection(alice, {});312 await collection.setLimits(alice, {sponsorTransferTimeout: 0});313 const token = await collection.mintToken(alice);319314320 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});315 await collection.setSponsor(alice, alice.address);321 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 0});322 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');323 await setCollectionSponsorExpectSuccess(collectionId, alice.address);316 await collection.confirmSponsorship(alice);324 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');317 325 await transferExpectSuccess(collectionId, tokenId, alice, bob);318 await token.transfer(alice, {Substrate: bob.address});326 const aliceBalanceBefore = await getFreeBalance(alice);319 const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);327320328 // check setting SponsorTimeout = 0, success with next block321 // check setting SponsorTimeout = 0, success with next block329 await waitNewBlocks(1);322 await helper.wait.newBlocks(1);330 await transferExpectSuccess(collectionId, tokenId, bob, charlie);323 await token.transfer(bob, {Substrate: charlie.address});331 const aliceBalanceAfterSponsoredTransaction1 = await getFreeBalance(alice);324 const aliceBalanceAfterSponsoredTransaction1 = await helper.balance.getSubstrate(alice.address);332 expect(aliceBalanceAfterSponsoredTransaction1 < aliceBalanceBefore).to.be.true;325 expect(aliceBalanceAfterSponsoredTransaction1 < aliceBalanceBefore).to.be.true;333 //expect(aliceBalanceAfterSponsoredTransaction1).to.be.lessThan(aliceBalanceBefore);334 });326 });335});327});336328340 let charlie: IKeyringPair;332 let charlie: IKeyringPair;341333342 before(async () => {334 before(async () => {343 await usingApi(async (api, privateKeyWrapper) => {335 await usingPlaygrounds(async (helper, privateKey) => {344 alice = privateKeyWrapper('//Alice');336 const donor = privateKey('//Alice');345 bob = privateKeyWrapper('//Bob');337 [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);346 charlie = privateKeyWrapper('//Charlie');347 });338 });348 });339 });349340350 it('Limits have 0 in sponsor timeout, no limits are applied', async () => {341 itSub('Limits have 0 in sponsor timeout, no limits are applied', async ({helper}) => {351 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});342 const collection = await helper.ft.mintCollection(alice, {});352 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 0});343 await collection.setLimits(alice, {sponsorTransferTimeout: 0});353 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible');344 await collection.mint(alice, 3n);354 await setCollectionSponsorExpectSuccess(collectionId, alice.address);355 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');356 await transferExpectSuccess(collectionId, tokenId, alice, bob, 10, 'Fungible');357 const aliceBalanceBefore = await getFreeBalance(alice);358 await transferExpectSuccess(collectionId, tokenId, bob, charlie, 2, 'Fungible');359345346 await collection.setSponsor(alice, alice.address);347 await collection.confirmSponsorship(alice);348 349 await collection.transfer(alice, {Substrate: bob.address}, 2n);350 const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);351360 // check setting SponsorTimeout = 0, success with next block352 // check setting SponsorTimeout = 0, success with next block361 await waitNewBlocks(1);353 await helper.wait.newBlocks(1);362 await transferExpectSuccess(collectionId, tokenId, bob, charlie, 2, 'Fungible');354 await collection.transfer(bob, {Substrate: charlie.address});363 const aliceBalanceAfterSponsoredTransaction1 = await getFreeBalance(alice);355 const aliceBalanceAfterSponsoredTransaction1 = await helper.balance.getSubstrate(alice.address);364 expect(aliceBalanceAfterSponsoredTransaction1 < aliceBalanceBefore).to.be.true;356 expect(aliceBalanceAfterSponsoredTransaction1 < aliceBalanceBefore).to.be.true;365 //expect(aliceBalanceAfterSponsoredTransaction1).to.be.lessThan(aliceBalanceBefore);366 });357 });367});358});368359372 let charlie: IKeyringPair;363 let charlie: IKeyringPair;373364374 before(async function() {365 before(async function() {375 await requirePallets(this, [Pallets.ReFungible]);366 await usingPlaygrounds(async (helper, privateKey) => {367 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);376368377 await usingApi(async (api, privateKeyWrapper) => {369 const donor = privateKey('//Alice');378 alice = privateKeyWrapper('//Alice');379 bob = privateKeyWrapper('//Bob');370 [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);380 charlie = privateKeyWrapper('//Charlie');381 });371 });382 });372 });383373384 it.skip('Limits have 0 in tokens per address field, the chain limits are applied', async () => {374 itSub.skip('Limits have 0 in tokens per address field, the chain limits are applied', async ({helper}) => {385 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});375 const collection = await helper.rft.mintCollection(alice, {});386 await setCollectionLimitsExpectSuccess(alice, collectionId, {accountTokenOwnershipLimit: 0});376 await collection.setLimits(alice, {accountTokenOwnershipLimit: 0});387 for(let i = 0; i < 10; i++){377 for(let i = 0; i < 10; i++){388 await createItemExpectSuccess(alice, collectionId, 'ReFungible');378 await collection.mintToken(alice);389 }379 }390 await createItemExpectFailure(alice, collectionId, 'ReFungible');380 await expect(collection.mintToken(alice)).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);391 });381 });392382393 it('Limits have 0 in sponsor timeout, no limits are applied', async () => {383 itSub('Limits have 0 in sponsor timeout, no limits are applied', async ({helper}) => {384 const collection = await helper.rft.mintCollection(alice, {});385 await collection.setLimits(alice, {sponsorTransferTimeout: 0});386 const token = await collection.mintToken(alice, 3n);394387395 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});388 await collection.setSponsor(alice, alice.address);396 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 0});397 const tokenId = await createItemExpectSuccess(alice, collectionId, 'ReFungible');398 await setCollectionSponsorExpectSuccess(collectionId, alice.address);389 await collection.confirmSponsorship(alice);399 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');390 400 await transferExpectSuccess(collectionId, tokenId, alice, bob, 100, 'ReFungible');391 await token.transfer(alice, {Substrate: bob.address}, 2n);401 await transferExpectSuccess(collectionId, tokenId, bob, charlie, 20, 'ReFungible');402 const aliceBalanceBefore = await getFreeBalance(alice);392 const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);403393404 // check setting SponsorTimeout = 0, success with next block394 // check setting SponsorTimeout = 0, success with next block405 await waitNewBlocks(1);395 await helper.wait.newBlocks(1);406 await transferExpectSuccess(collectionId, tokenId, bob, charlie, 20, 'ReFungible');396 await token.transfer(bob, {Substrate: charlie.address});407 const aliceBalanceAfterSponsoredTransaction1 = await getFreeBalance(alice);397 const aliceBalanceAfterSponsoredTransaction1 = await helper.balance.getSubstrate(alice.address);408 expect(aliceBalanceAfterSponsoredTransaction1 < aliceBalanceBefore).to.be.true;398 expect(aliceBalanceAfterSponsoredTransaction1 < aliceBalanceBefore).to.be.true;409 //expect(aliceBalanceAfterSponsoredTransaction1).to.be.lessThan(aliceBalanceBefore);410 });399 });411 412 it('Effective collection limits', async () => {413 await usingApi(async (api) => {414 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});400});415 await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});416 417 { // Check that limits is undefined418 const collection = await api.rpc.unique.collectionById(collectionId);419 expect(collection.isSome).to.be.true;420 const limits = collection.unwrap().limits;421 expect(limits).to.be.any;422 423 expect(limits.accountTokenOwnershipLimit.toHuman()).to.be.null;424 expect(limits.sponsoredDataSize.toHuman()).to.be.null;425 expect(limits.sponsoredDataRateLimit.toHuman()).to.be.null;426 expect(limits.tokenLimit.toHuman()).to.be.null;427 expect(limits.sponsorTransferTimeout.toHuman()).to.be.null;428 expect(limits.sponsorApproveTimeout.toHuman()).to.be.null;429 expect(limits.ownerCanTransfer.toHuman()).to.be.true;430 expect(limits.ownerCanDestroy.toHuman()).to.be.null;431 expect(limits.transfersEnabled.toHuman()).to.be.null;432 }433 434 { // Check that limits is undefined for non-existent collection435 const limits = await api.rpc.unique.effectiveCollectionLimits(11111);436 expect(limits.toHuman()).to.be.null;437 }438 439 { // Check that default values defined for collection limits440 const limitsOpt = await api.rpc.unique.effectiveCollectionLimits(collectionId);441 expect(limitsOpt.isNone).to.be.false;442 const limits = limitsOpt.unwrap();443 444 expect(limits.accountTokenOwnershipLimit.toHuman()).to.be.eq('100,000');445 expect(limits.sponsoredDataSize.toHuman()).to.be.eq('2,048');446 expect(limits.sponsoredDataRateLimit.toHuman()).to.be.eq('SponsoringDisabled');447 expect(limits.tokenLimit.toHuman()).to.be.eq('4,294,967,295');448 expect(limits.sponsorTransferTimeout.toHuman()).to.be.eq('5');449 expect(limits.sponsorApproveTimeout.toHuman()).to.be.eq('5');450 expect(limits.ownerCanTransfer.toHuman()).to.be.true;451 expect(limits.ownerCanDestroy.toHuman()).to.be.true;452 expect(limits.transfersEnabled.toHuman()).to.be.true;453 }454401455 { //Check the values for collection limits402describe('Effective collection limits (NFT)', () => {456 await setCollectionLimitsExpectSuccess(alice, collectionId, {457 accountTokenOwnershipLimit: 99_999,403 let alice: IKeyringPair;458 sponsoredDataSize: 1024,459 tokenLimit: 123,460 transfersEnabled: false,461 });462404463 const limitsOpt = await api.rpc.unique.effectiveCollectionLimits(collectionId);405 before(async () => {464 expect(limitsOpt.isNone).to.be.false;465 const limits = limitsOpt.unwrap();466 406 await usingPlaygrounds(async (helper, privateKey) => {467 expect(limits.accountTokenOwnershipLimit.toHuman()).to.be.eq('99,999');468 expect(limits.sponsoredDataSize.toHuman()).to.be.eq('1,024');469 expect(limits.sponsoredDataRateLimit.toHuman()).to.be.eq('SponsoringDisabled');470 expect(limits.tokenLimit.toHuman()).to.be.eq('123');471 expect(limits.sponsorTransferTimeout.toHuman()).to.be.eq('5');407 const donor = privateKey('//Alice');472 expect(limits.sponsorApproveTimeout.toHuman()).to.be.eq('5');473 expect(limits.ownerCanTransfer.toHuman()).to.be.true;408 [alice] = await helper.arrange.createAccounts([10n], donor);474 expect(limits.ownerCanDestroy.toHuman()).to.be.true;475 expect(limits.transfersEnabled.toHuman()).to.be.false;476 }477 });409 });478 });410 });411 479});412 itSub('Effective collection limits', async ({helper}) => {413 const collection = await helper.nft.mintCollection(alice, {});414 await collection.setLimits(alice, {ownerCanTransfer: true}); 415 416 { 417 // Check that limits are undefined418 const collectionInfo = await collection.getData();419 const limits = collectionInfo?.raw.limits;420 expect(limits).to.be.any;421 422 expect(limits.accountTokenOwnershipLimit).to.be.null;423 expect(limits.sponsoredDataSize).to.be.null;424 expect(limits.sponsoredDataRateLimit).to.be.null;425 expect(limits.tokenLimit).to.be.null;426 expect(limits.sponsorTransferTimeout).to.be.null;427 expect(limits.sponsorApproveTimeout).to.be.null;428 expect(limits.ownerCanTransfer).to.be.true;429 expect(limits.ownerCanDestroy).to.be.null;430 expect(limits.transfersEnabled).to.be.null;431 }480432433 { // Check that limits is undefined for non-existent collection434 const limits = await helper.collection.getEffectiveLimits(999999);435 expect(limits).to.be.null;436 }481437438 { // Check that default values defined for collection limits439 const limits = await collection.getEffectiveLimits();440441 expect(limits.accountTokenOwnershipLimit).to.be.eq(100000);442 expect(limits.sponsoredDataSize).to.be.eq(2048);443 expect(limits.sponsoredDataRateLimit).to.be.deep.eq({sponsoringDisabled: null});444 expect(limits.tokenLimit).to.be.eq(4294967295);445 expect(limits.sponsorTransferTimeout).to.be.eq(5);446 expect(limits.sponsorApproveTimeout).to.be.eq(5);447 expect(limits.ownerCanTransfer).to.be.true;448 expect(limits.ownerCanDestroy).to.be.true;449 expect(limits.transfersEnabled).to.be.true;450 }451452 { 453 // Check the values for collection limits454 await collection.setLimits(alice, {455 accountTokenOwnershipLimit: 99_999,456 sponsoredDataSize: 1024,457 tokenLimit: 123,458 transfersEnabled: false,459 });460461 const limits = await collection.getEffectiveLimits();462463 expect(limits.accountTokenOwnershipLimit).to.be.eq(99999);464 expect(limits.sponsoredDataSize).to.be.eq(1024);465 expect(limits.sponsoredDataRateLimit).to.be.deep.eq({sponsoringDisabled: null});466 expect(limits.tokenLimit).to.be.eq(123);467 expect(limits.sponsorTransferTimeout).to.be.eq(5);468 expect(limits.sponsorApproveTimeout).to.be.eq(5);469 expect(limits.ownerCanTransfer).to.be.true;470 expect(limits.ownerCanDestroy).to.be.true;471 expect(limits.transfersEnabled).to.be.false;472 }473 });474});482475tests/src/nextSponsoring.test.tsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {ApiPromise} from '@polkadot/api';18import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';19import chai from 'chai';20import chaiAsPromised from 'chai-as-promised';21import {default as usingApi} from './substrate/substrate-api';22import {18import {expect, itSub, Pallets, usingPlaygrounds} from './util/playgrounds';23 createCollectionExpectSuccess,1924 setCollectionSponsorExpectSuccess,25 confirmSponsorshipExpectSuccess,26 createItemExpectSuccess,27 transferExpectSuccess,28 normalizeAccountId,29 getNextSponsored,30 requirePallets,31 Pallets,32} from './util/helpers';3334chai.use(chaiAsPromised);35const expect = chai.expect;20const SPONSORING_TIMEOUT = 5;3637382141 let bob: IKeyringPair;24 let bob: IKeyringPair;422543 before(async () => {26 before(async () => {44 await usingApi(async (api, privateKeyWrapper) => {27 await usingPlaygrounds(async (helper, privateKey) => {45 alice = privateKeyWrapper('//Alice');28 const donor = privateKey('//Alice');46 bob = privateKeyWrapper('//Bob');29 [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);47 });30 });48 });31 });493250 it('NFT', async () => {33 itSub('NFT', async ({helper}) => {51 await usingApi(async (api: ApiPromise) => {5253 // Not existing collection 34 // Non-existing collection54 expect(await getNextSponsored(api, 0, normalizeAccountId(alice), 0)).to.be.equal(-1);35 expect(await helper.collection.getTokenNextSponsored(0, 0, {Substrate: alice.address})).to.be.null;553656 const collectionId = await createCollectionExpectSuccess();37 const collection = await helper.nft.mintCollection(alice, {});57 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);38 const token = await collection.mintToken(alice);583959 // Check with Disabled sponsoring state40 // Check with Disabled sponsoring state60 expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.equal(-1);41 expect(await token.getNextSponsored({Substrate: alice.address})).to.be.null;42 43 // Check with Unconfirmed sponsoring state61 await setCollectionSponsorExpectSuccess(collectionId, bob.address);44 await collection.setSponsor(alice, bob.address);6263 // Check with Unconfirmed sponsoring state64 expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.equal(-1);45 expect(await token.getNextSponsored({Substrate: alice.address})).to.be.null;4647 // Check with Confirmed sponsoring state65 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');48 await collection.confirmSponsorship(bob);6667 // Check with Confirmed sponsoring state68 expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.equal(0);49 expect(await token.getNextSponsored({Substrate: alice.address})).to.be.equal(0);695070 // After transfer51 // Check after transfer71 await transferExpectSuccess(collectionId, itemId, alice, bob, 1);52 await token.transfer(alice, {Substrate: bob.address});72 expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.lessThanOrEqual(5);53 expect(await token.getNextSponsored({Substrate: alice.address})).to.be.lessThanOrEqual(SPONSORING_TIMEOUT);735474 // Not existing token 55 // Non-existing token 75 expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId+1)).to.be.equal(-1);56 expect(await collection.getTokenNextSponsored(0, {Substrate: alice.address})).to.be.null;76 });77 });57 });785879 it('Fungible', async () => {59 itSub('Fungible', async ({helper}) => {80 await usingApi(async (api: ApiPromise) => {8182 const createMode = 'Fungible';60 const collection = await helper.ft.mintCollection(alice, {});83 const funCollectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});61 await collection.mint(alice, 10n);6263 // Check with Disabled sponsoring state84 await createItemExpectSuccess(alice, funCollectionId, createMode);64 expect(await collection.getTokenNextSponsored(0, {Substrate: alice.address})).to.be.null;6585 await setCollectionSponsorExpectSuccess(funCollectionId, bob.address);66 await collection.setSponsor(alice, bob.address);86 await confirmSponsorshipExpectSuccess(funCollectionId, '//Bob');67 await collection.confirmSponsorship(bob);68 69 // Check with Confirmed sponsoring state87 expect(await getNextSponsored(api, funCollectionId, normalizeAccountId(alice), 0)).to.be.equal(0);70 expect(await collection.getTokenNextSponsored(0, {Substrate: alice.address})).to.be.equal(0);887172 // Check after transfer89 await transferExpectSuccess(funCollectionId, 0, alice, bob, 10, 'Fungible');73 await collection.transfer(alice, {Substrate: bob.address});90 expect(await getNextSponsored(api, funCollectionId, normalizeAccountId(alice), 0)).to.be.lessThanOrEqual(5);74 expect(await collection.getTokenNextSponsored(0, {Substrate: alice.address})).to.be.lessThanOrEqual(SPONSORING_TIMEOUT);91 });92 });75 });937694 it('ReFungible', async function() {77 itSub.ifWithPallets('ReFungible', [Pallets.ReFungible], async ({helper}) => {95 await requirePallets(this, [Pallets.ReFungible]);9697 await usingApi(async (api: ApiPromise) => {9899 const createMode = 'ReFungible';78 const collection = await helper.rft.mintCollection(alice, {});100 const refunCollectionId = await createCollectionExpectSuccess({mode: {type: createMode}});79 const token = await collection.mintToken(alice, 10n);8081 // Check with Disabled sponsoring state101 const refunItemId = await createItemExpectSuccess(alice, refunCollectionId, createMode);82 expect(await token.getNextSponsored({Substrate: alice.address})).to.be.null;83102 await setCollectionSponsorExpectSuccess(refunCollectionId, bob.address);84 await collection.setSponsor(alice, bob.address);103 await confirmSponsorshipExpectSuccess(refunCollectionId, '//Bob');85 await collection.confirmSponsorship(bob);8687 // Check with Confirmed sponsoring state104 expect(await getNextSponsored(api, refunCollectionId, normalizeAccountId(alice), refunItemId)).to.be.equal(0);88 expect(await token.getNextSponsored({Substrate: alice.address})).to.be.equal(0);1058990 // Check after transfer106 await transferExpectSuccess(refunCollectionId, refunItemId, alice, bob, 10, 'ReFungible');91 await token.transfer(alice, {Substrate: bob.address});107 expect(await getNextSponsored(api, refunCollectionId, normalizeAccountId(alice), refunItemId)).to.be.lessThanOrEqual(5);92 expect(await token.getNextSponsored({Substrate: alice.address})).to.be.lessThanOrEqual(SPONSORING_TIMEOUT);10893109 // Not existing token 94 // Non-existing token 110 expect(await getNextSponsored(api, refunCollectionId, normalizeAccountId(alice), refunItemId+1)).to.be.equal(-1);95 expect(await collection.getTokenNextSponsored(0, {Substrate: alice.address})).to.be.null;111 });96 });112 });113});97});11498tests/src/refungible.test.tsdiffbeforeafterboth35 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});35 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});363637 const itemCountBefore = await collection.getLastTokenId();37 const itemCountBefore = await collection.getLastTokenId();38 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);38 const token = await collection.mintToken(alice, 100n);39 39 40 const itemCountAfter = await collection.getLastTokenId();40 const itemCountAfter = await collection.getLastTokenId();41 41 48 itSub('Checking RPC methods when interacting with maximum allowed values (MAX_REFUNGIBLE_PIECES)', async ({helper}) => {48 itSub('Checking RPC methods when interacting with maximum allowed values (MAX_REFUNGIBLE_PIECES)', async ({helper}) => {49 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});49 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});50 50 51 const token = await collection.mintToken(alice, {Substrate: alice.address}, MAX_REFUNGIBLE_PIECES);51 const token = await collection.mintToken(alice, MAX_REFUNGIBLE_PIECES);52 52 53 expect(await collection.getTokenBalance(token.tokenId, {Substrate: alice.address})).to.be.equal(MAX_REFUNGIBLE_PIECES);53 expect(await collection.getTokenBalance(token.tokenId, {Substrate: alice.address})).to.be.equal(MAX_REFUNGIBLE_PIECES);54 54 55 await collection.transferToken(alice, token.tokenId, {Substrate: bob.address}, MAX_REFUNGIBLE_PIECES);55 await collection.transferToken(alice, token.tokenId, {Substrate: bob.address}, MAX_REFUNGIBLE_PIECES);56 expect(await collection.getTokenBalance(token.tokenId, {Substrate: bob.address})).to.be.equal(MAX_REFUNGIBLE_PIECES);56 expect(await collection.getTokenBalance(token.tokenId, {Substrate: bob.address})).to.be.equal(MAX_REFUNGIBLE_PIECES);57 expect(await token.getTotalPieces()).to.be.equal(MAX_REFUNGIBLE_PIECES);57 expect(await token.getTotalPieces()).to.be.equal(MAX_REFUNGIBLE_PIECES);58 58 59 await expect(collection.mintToken(alice, {Substrate: alice.address}, MAX_REFUNGIBLE_PIECES + 1n))59 await expect(collection.mintToken(alice, MAX_REFUNGIBLE_PIECES + 1n))60 .to.eventually.be.rejectedWith(/refungible\.WrongRefungiblePieces/);60 .to.eventually.be.rejectedWith(/refungible\.WrongRefungiblePieces/);61 });61 });62 62 666667 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});67 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});686869 const token = await collection.mintToken(alice, {Substrate: alice.address}, 10_000n);69 const token = await collection.mintToken(alice, 10_000n);707071 await token.transfer(alice, {Substrate: bob.address}, 1000n);71 await token.transfer(alice, {Substrate: bob.address}, 1000n);72 await token.transfer(alice, ethAcc, 900n);72 await token.transfer(alice, ethAcc, 900n);88 88 89 itSub('Transfer token pieces', async ({helper}) => {89 itSub('Transfer token pieces', async ({helper}) => {90 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});90 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});91 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);91 const token = await collection.mintToken(alice, 100n);929293 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);93 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);94 expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;94 expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;120120121 itSub('Burn some pieces', async ({helper}) => {121 itSub('Burn some pieces', async ({helper}) => {122 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});122 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});123 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);123 const token = await collection.mintToken(alice, 100n);124 expect(await collection.isTokenExists(token.tokenId)).to.be.true;124 expect(await collection.isTokenExists(token.tokenId)).to.be.true;125 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);125 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);126 expect((await token.burn(alice, 99n)).success).to.be.true;126 expect((await token.burn(alice, 99n)).success).to.be.true;130130131 itSub('Burn all pieces', async ({helper}) => {131 itSub('Burn all pieces', async ({helper}) => {132 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});132 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});133 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);133 const token = await collection.mintToken(alice, 100n);134 134 135 expect(await collection.isTokenExists(token.tokenId)).to.be.true;135 expect(await collection.isTokenExists(token.tokenId)).to.be.true;136 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);136 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);141141142 itSub('Burn some pieces for multiple users', async ({helper}) => {142 itSub('Burn some pieces for multiple users', async ({helper}) => {143 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});143 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});144 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);144 const token = await collection.mintToken(alice, 100n);145145146 expect(await collection.isTokenExists(token.tokenId)).to.be.true;146 expect(await collection.isTokenExists(token.tokenId)).to.be.true;147 147 168168169 itSub('Set allowance for token', async ({helper}) => {169 itSub('Set allowance for token', async ({helper}) => {170 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});170 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});171 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);171 const token = await collection.mintToken(alice, 100n);172 172 173 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);173 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);174174183183184 itSub('Repartition', async ({helper}) => {184 itSub('Repartition', async ({helper}) => {185 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});185 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});186 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);186 const token = await collection.mintToken(alice, 100n);187187188 expect(await token.repartition(alice, 200n)).to.be.true;188 expect(await token.repartition(alice, 200n)).to.be.true;189 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(200n);189 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(200n);207207208 itSub('Repartition with increased amount', async ({helper}) => {208 itSub('Repartition with increased amount', async ({helper}) => {209 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});209 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});210 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);210 const token = await collection.mintToken(alice, 100n);211 await token.repartition(alice, 200n);211 await token.repartition(alice, 200n);212 const chainEvents = helper.chainLog.slice(-1)[0].events.map((x: any) => x.event);212 const chainEvents = helper.chainLog.slice(-1)[0].events.map((x: any) => x.event);213 expect(chainEvents).to.include.deep.members([{213 expect(chainEvents).to.include.deep.members([{225225226 itSub('Repartition with decreased amount', async ({helper}) => {226 itSub('Repartition with decreased amount', async ({helper}) => {227 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});227 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});228 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);228 const token = await collection.mintToken(alice, 100n);229 await token.repartition(alice, 50n);229 await token.repartition(alice, 50n);230 const chainEvents = helper.chainLog.slice(-1)[0].events.map((x: any) => x.event);230 const chainEvents = helper.chainLog.slice(-1)[0].events.map((x: any) => x.event);231 expect(chainEvents).to.include.deep.members([{231 expect(chainEvents).to.include.deep.members([{tests/src/rpc.test.tsdiffbeforeafterboth44 44 45 const collection = await helper.ft.mintCollection(alice, {name: 'RPC-2', tokenPrefix: 'RPC'});45 const collection = await helper.ft.mintCollection(alice, {name: 'RPC-2', tokenPrefix: 'RPC'});46 // mint some maximum (u128) amounts of tokens possible46 // mint some maximum (u128) amounts of tokens possible47 await collection.mint(alice, {Substrate: alice.address}, (1n << 128n) - 1n);47 await collection.mint(alice, (1n << 128n) - 1n);48 48 49 await collection.transfer(alice, {Substrate: bob.address}, 1000n);49 await collection.transfer(alice, {Substrate: bob.address}, 1000n);50 await collection.transfer(alice, ethAcc, 900n);50 await collection.transfer(alice, ethAcc, 900n);tests/src/transfer.test.tsdiffbeforeafterboth545455 itSub('[nft] User can transfer owned token', async ({helper}) => {55 itSub('[nft] User can transfer owned token', async ({helper}) => {56 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-1-NFT', description: '', tokenPrefix: 'T'});56 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-1-NFT', description: '', tokenPrefix: 'T'});57 const nft = await collection.mintToken(alice, {Substrate: alice.address});57 const nft = await collection.mintToken(alice);585859 await nft.transfer(alice, {Substrate: bob.address});59 await nft.transfer(alice, {Substrate: bob.address});60 expect(await nft.getOwner()).to.be.deep.equal({Substrate: bob.address});60 expect(await nft.getOwner()).to.be.deep.equal({Substrate: bob.address});61 });61 });626263 itSub('[fungible] User can transfer owned token', async ({helper}) => {63 itSub('[fungible] User can transfer owned token', async ({helper}) => {64 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-1-FT', description: '', tokenPrefix: 'T'});64 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-1-FT', description: '', tokenPrefix: 'T'});65 await collection.mint(alice, {Substrate: alice.address}, 10n);65 await collection.mint(alice, 10n);666667 await collection.transfer(alice, {Substrate: bob.address}, 9n);67 await collection.transfer(alice, {Substrate: bob.address}, 9n);68 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(9n);68 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(9n);717172 itSub.ifWithPallets('[refungible] User can transfer owned token', [Pallets.ReFungible], async ({helper}) => {72 itSub.ifWithPallets('[refungible] User can transfer owned token', [Pallets.ReFungible], async ({helper}) => {73 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-1-RFT', description: '', tokenPrefix: 'T'});73 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-1-RFT', description: '', tokenPrefix: 'T'});74 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);74 const rft = await collection.mintToken(alice, 10n);757576 await rft.transfer(alice, {Substrate: bob.address}, 9n);76 await rft.transfer(alice, {Substrate: bob.address}, 9n);77 expect(await rft.getBalance({Substrate: bob.address})).to.be.equal(9n);77 expect(await rft.getBalance({Substrate: bob.address})).to.be.equal(9n);92 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-2-FT', description: '', tokenPrefix: 'T'});92 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-2-FT', description: '', tokenPrefix: 'T'});93 await collection.addAdmin(alice, {Substrate: bob.address});93 await collection.addAdmin(alice, {Substrate: bob.address});949495 await collection.mint(bob, {Substrate: bob.address}, 10n);95 await collection.mint(bob, 10n, {Substrate: bob.address});96 await collection.transfer(bob, {Substrate: alice.address}, 1n);96 await collection.transfer(bob, {Substrate: alice.address}, 1n);979798 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(9n);98 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(9n);103 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-2-RFT', description: '', tokenPrefix: 'T'});103 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-2-RFT', description: '', tokenPrefix: 'T'});104 await collection.addAdmin(alice, {Substrate: bob.address});104 await collection.addAdmin(alice, {Substrate: bob.address});105105106 const rft = await collection.mintToken(bob, {Substrate: bob.address}, 10n);106 const rft = await collection.mintToken(bob, 10n, {Substrate: bob.address});107 await rft.transfer(bob, {Substrate: alice.address}, 1n);107 await rft.transfer(bob, {Substrate: alice.address}, 1n);108108109 expect(await rft.getBalance({Substrate: bob.address})).to.be.equal(9n);109 expect(await rft.getBalance({Substrate: bob.address})).to.be.equal(9n);142142143 itSub('[nft] Transfer with deleted collection_id', async ({helper}) => {143 itSub('[nft] Transfer with deleted collection_id', async ({helper}) => {144 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-1-NFT', description: '', tokenPrefix: 'T'});144 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-1-NFT', description: '', tokenPrefix: 'T'});145 const nft = await collection.mintToken(alice, {Substrate: alice.address});145 const nft = await collection.mintToken(alice);146146147 await nft.burn(alice);147 await nft.burn(alice);148 await collection.burn(alice);148 await collection.burn(alice);153153154 itSub('[fungible] Transfer with deleted collection_id', async ({helper}) => {154 itSub('[fungible] Transfer with deleted collection_id', async ({helper}) => {155 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-1-FT', description: '', tokenPrefix: 'T'});155 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-1-FT', description: '', tokenPrefix: 'T'});156 await collection.mint(alice, {Substrate: alice.address}, 10n);156 await collection.mint(alice, 10n);157157158 await collection.burnTokens(alice, 10n);158 await collection.burnTokens(alice, 10n);159 await collection.burn(alice);159 await collection.burn(alice);164 164 165 itSub.ifWithPallets('[refungible] Transfer with deleted collection_id', [Pallets.ReFungible], async ({helper}) => {165 itSub.ifWithPallets('[refungible] Transfer with deleted collection_id', [Pallets.ReFungible], async ({helper}) => {166 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-Neg-1-RFT', description: '', tokenPrefix: 'T'});166 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-Neg-1-RFT', description: '', tokenPrefix: 'T'});167 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);167 const rft = await collection.mintToken(alice, 10n);168168169 await rft.burn(alice, 10n);169 await rft.burn(alice, 10n);170 await collection.burn(alice);170 await collection.burn(alice);193193194 itSub('[nft] Transfer with deleted item_id', async ({helper}) => {194 itSub('[nft] Transfer with deleted item_id', async ({helper}) => {195 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-3-NFT', description: '', tokenPrefix: 'T'});195 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-3-NFT', description: '', tokenPrefix: 'T'});196 const nft = await collection.mintToken(alice, {Substrate: alice.address});196 const nft = await collection.mintToken(alice);197197198 await nft.burn(alice);198 await nft.burn(alice);199199203203204 itSub('[fungible] Transfer with deleted item_id', async ({helper}) => {204 itSub('[fungible] Transfer with deleted item_id', async ({helper}) => {205 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-3-FT', description: '', tokenPrefix: 'T'});205 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-3-FT', description: '', tokenPrefix: 'T'});206 await collection.mint(alice, {Substrate: alice.address}, 10n);206 await collection.mint(alice, 10n);207207208 await collection.burnTokens(alice, 10n);208 await collection.burnTokens(alice, 10n);209209213213214 itSub.ifWithPallets('[refungible] Transfer with deleted item_id', [Pallets.ReFungible], async ({helper}) => {214 itSub.ifWithPallets('[refungible] Transfer with deleted item_id', [Pallets.ReFungible], async ({helper}) => {215 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-Neg-3-RFT', description: '', tokenPrefix: 'T'});215 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-Neg-3-RFT', description: '', tokenPrefix: 'T'});216 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);216 const rft = await collection.mintToken(alice, 10n);217217218 await rft.burn(alice, 10n);218 await rft.burn(alice, 10n);219219223223224 itSub('[nft] Transfer with recipient that is not owner', async ({helper}) => {224 itSub('[nft] Transfer with recipient that is not owner', async ({helper}) => {225 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-4-NFT', description: '', tokenPrefix: 'T'});225 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-4-NFT', description: '', tokenPrefix: 'T'});226 const nft = await collection.mintToken(alice, {Substrate: alice.address});226 const nft = await collection.mintToken(alice);227227228 await expect(nft.transfer(bob, {Substrate: bob.address}))228 await expect(nft.transfer(bob, {Substrate: bob.address}))229 .to.be.rejectedWith(/common\.NoPermission/);229 .to.be.rejectedWith(/common\.NoPermission/);232232233 itSub('[fungible] Transfer with recipient that is not owner', async ({helper}) => {233 itSub('[fungible] Transfer with recipient that is not owner', async ({helper}) => {234 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-4-FT', description: '', tokenPrefix: 'T'});234 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-4-FT', description: '', tokenPrefix: 'T'});235 await collection.mint(alice, {Substrate: alice.address}, 10n);235 await collection.mint(alice, 10n);236236237 await expect(collection.transfer(bob, {Substrate: bob.address}, 9n))237 await expect(collection.transfer(bob, {Substrate: bob.address}, 9n))238 .to.be.rejectedWith(/common\.TokenValueTooLow/);238 .to.be.rejectedWith(/common\.TokenValueTooLow/);242242243 itSub.ifWithPallets('[refungible] Transfer with recipient that is not owner', [Pallets.ReFungible], async ({helper}) => {243 itSub.ifWithPallets('[refungible] Transfer with recipient that is not owner', [Pallets.ReFungible], async ({helper}) => {244 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-1-RFT', description: '', tokenPrefix: 'T'});244 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-1-RFT', description: '', tokenPrefix: 'T'});245 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);245 const rft = await collection.mintToken(alice, 10n);246246247 await expect(rft.transfer(bob, {Substrate: bob.address}, 9n))247 await expect(rft.transfer(bob, {Substrate: bob.address}, 9n))248 .to.be.rejectedWith(/common\.TokenValueTooLow/);248 .to.be.rejectedWith(/common\.TokenValueTooLow/);263 itEth('Transfers to self. In case of same frontend', async ({helper}) => {263 itEth('Transfers to self. In case of same frontend', async ({helper}) => {264 const [owner] = await helper.arrange.createAccounts([10n], donor);264 const [owner] = await helper.arrange.createAccounts([10n], donor);265 const collection = await helper.ft.mintCollection(owner, {});265 const collection = await helper.ft.mintCollection(owner, {});266 await collection.mint(owner, {Substrate: owner.address}, 100n);266 await collection.mint(owner, 100n);267267268 const ownerProxy = helper.address.substrateToEth(owner.address);268 const ownerProxy = helper.address.substrateToEth(owner.address);269269281 itEth('Transfers to self. In case of substrate-evm boundary', async ({helper}) => {281 itEth('Transfers to self. In case of substrate-evm boundary', async ({helper}) => {282 const [owner] = await helper.arrange.createAccounts([10n], donor);282 const [owner] = await helper.arrange.createAccounts([10n], donor);283 const collection = await helper.ft.mintCollection(owner, {});283 const collection = await helper.ft.mintCollection(owner, {});284 await collection.mint(owner, {Substrate: owner.address}, 100n);284 await collection.mint(owner, 100n);285285286 const ownerProxy = helper.address.substrateToEth(owner.address);286 const ownerProxy = helper.address.substrateToEth(owner.address);287287299 itEth('Transfers to self. In case of inside substrate-evm', async ({helper}) => {299 itEth('Transfers to self. In case of inside substrate-evm', async ({helper}) => {300 const [owner] = await helper.arrange.createAccounts([10n], donor);300 const [owner] = await helper.arrange.createAccounts([10n], donor);301 const collection = await helper.ft.mintCollection(owner, {});301 const collection = await helper.ft.mintCollection(owner, {});302 await collection.mint(owner, {Substrate: owner.address}, 100n);302 await collection.mint(owner, 100n);303303304 // transfer to self again304 // transfer to self again305 await collection.transfer(owner, {Substrate: owner.address}, 10n);305 await collection.transfer(owner, {Substrate: owner.address}, 10n);313 itEth('Transfers to self. In case of inside substrate-evm when not enought "Fungibles"', async ({helper}) => {313 itEth('Transfers to self. In case of inside substrate-evm when not enought "Fungibles"', async ({helper}) => {314 const [owner] = await helper.arrange.createAccounts([10n], donor);314 const [owner] = await helper.arrange.createAccounts([10n], donor);315 const collection = await helper.ft.mintCollection(owner, {});315 const collection = await helper.ft.mintCollection(owner, {});316 await collection.mint(owner, {Substrate: owner.address}, 10n);316 await collection.mint(owner, 10n);317317318 // transfer to self again318 // transfer to self again319 await expect(collection.transfer(owner, {Substrate: owner.address}, 11n))319 await expect(collection.transfer(owner, {Substrate: owner.address}, 11n))tests/src/transferFrom.test.tsdiffbeforeafterboth313132 itSub('[nft] Execute the extrinsic and check nftItemList - owner of token', async ({helper}) => {32 itSub('[nft] Execute the extrinsic and check nftItemList - owner of token', async ({helper}) => {33 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-1', description: '', tokenPrefix: 'TF'});33 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-1', description: '', tokenPrefix: 'TF'});34 const nft = await collection.mintToken(alice, {Substrate: alice.address});34 const nft = await collection.mintToken(alice);35 await nft.approve(alice, {Substrate: bob.address});35 await nft.approve(alice, {Substrate: bob.address});36 expect(await nft.isApproved({Substrate: bob.address})).to.be.true;36 expect(await nft.isApproved({Substrate: bob.address})).to.be.true;3737414142 itSub('[fungible] Execute the extrinsic and check nftItemList - owner of token', async ({helper}) => {42 itSub('[fungible] Execute the extrinsic and check nftItemList - owner of token', async ({helper}) => {43 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-2', description: '', tokenPrefix: 'TF'});43 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-2', description: '', tokenPrefix: 'TF'});44 await collection.mint(alice, {Substrate: alice.address}, 10n);44 await collection.mint(alice, 10n);45 await collection.approveTokens(alice, {Substrate: bob.address}, 7n);45 await collection.approveTokens(alice, {Substrate: bob.address}, 7n);46 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(7n);46 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(7n);47 47 535354 itSub.ifWithPallets('[refungible] Execute the extrinsic and check nftItemList - owner of token', [Pallets.ReFungible], async ({helper}) => {54 itSub.ifWithPallets('[refungible] Execute the extrinsic and check nftItemList - owner of token', [Pallets.ReFungible], async ({helper}) => {55 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-3', description: '', tokenPrefix: 'TF'});55 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-3', description: '', tokenPrefix: 'TF'});56 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);56 const rft = await collection.mintToken(alice, 10n);57 await rft.approve(alice, {Substrate: bob.address}, 7n);57 await rft.approve(alice, {Substrate: bob.address}, 7n);58 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(7n);58 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(7n);59 59 66 itSub('Should reduce allowance if value is big', async ({helper}) => {66 itSub('Should reduce allowance if value is big', async ({helper}) => {67 // fungible67 // fungible68 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-4', description: '', tokenPrefix: 'TF'});68 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-4', description: '', tokenPrefix: 'TF'});69 await collection.mint(alice, {Substrate: alice.address}, 500000n);69 await collection.mint(alice, 500000n);707071 await collection.approveTokens(alice, {Substrate: bob.address}, 500000n);71 await collection.approveTokens(alice, {Substrate: bob.address}, 500000n);72 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(500000n);72 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(500000n);118118119 itSub('[nft] transferFrom for not approved address', async ({helper}) => {119 itSub('[nft] transferFrom for not approved address', async ({helper}) => {120 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-1', description: '', tokenPrefix: 'TF'});120 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-1', description: '', tokenPrefix: 'TF'});121 const nft = await collection.mintToken(alice, {Substrate: alice.address});121 const nft = await collection.mintToken(alice);122122123 await expect(nft.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}))123 await expect(nft.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}))124 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);124 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);127127128 itSub('[fungible] transferFrom for not approved address', async ({helper}) => {128 itSub('[fungible] transferFrom for not approved address', async ({helper}) => {129 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-1', description: '', tokenPrefix: 'TF'});129 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-1', description: '', tokenPrefix: 'TF'});130 await collection.mint(alice, {Substrate: alice.address}, 10n);130 await collection.mint(alice, 10n);131131132 await expect(collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 5n))132 await expect(collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 5n))133 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);133 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);138138139 itSub.ifWithPallets('[refungible] transferFrom for not approved address', [Pallets.ReFungible], async({helper}) => {139 itSub.ifWithPallets('[refungible] transferFrom for not approved address', [Pallets.ReFungible], async({helper}) => {140 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-3', description: '', tokenPrefix: 'TF'});140 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-3', description: '', tokenPrefix: 'TF'});141 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);141 const rft = await collection.mintToken(alice, 10n);142142143 await expect(rft.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}))143 await expect(rft.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}))144 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);144 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);149149150 itSub('[nft] transferFrom incorrect token count', async ({helper}) => {150 itSub('[nft] transferFrom incorrect token count', async ({helper}) => {151 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-4', description: '', tokenPrefix: 'TF'});151 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-4', description: '', tokenPrefix: 'TF'});152 const nft = await collection.mintToken(alice, {Substrate: alice.address});152 const nft = await collection.mintToken(alice);153153154 await nft.approve(alice, {Substrate: bob.address});154 await nft.approve(alice, {Substrate: bob.address});155 expect(await nft.isApproved({Substrate: bob.address})).to.be.true;155 expect(await nft.isApproved({Substrate: bob.address})).to.be.true;167167168 itSub('[fungible] transferFrom incorrect token count', async ({helper}) => {168 itSub('[fungible] transferFrom incorrect token count', async ({helper}) => {169 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-5', description: '', tokenPrefix: 'TF'});169 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-5', description: '', tokenPrefix: 'TF'});170 await collection.mint(alice, {Substrate: alice.address}, 10n);170 await collection.mint(alice, 10n);171171172 await collection.approveTokens(alice, {Substrate: bob.address}, 2n);172 await collection.approveTokens(alice, {Substrate: bob.address}, 2n);173 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(2n);173 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(2n);181181182 itSub.ifWithPallets('[refungible] transferFrom incorrect token count', [Pallets.ReFungible], async ({helper}) => {182 itSub.ifWithPallets('[refungible] transferFrom incorrect token count', [Pallets.ReFungible], async ({helper}) => {183 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-6', description: '', tokenPrefix: 'TF'});183 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-6', description: '', tokenPrefix: 'TF'});184 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);184 const rft = await collection.mintToken(alice, 10n);185185186 await rft.approve(alice, {Substrate: bob.address}, 5n);186 await rft.approve(alice, {Substrate: bob.address}, 5n);187 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(5n);187 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(5n);195195196 itSub('[nft] execute transferFrom from account that is not owner of collection', async ({helper}) => {196 itSub('[nft] execute transferFrom from account that is not owner of collection', async ({helper}) => {197 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-7', description: '', tokenPrefix: 'TF'});197 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-7', description: '', tokenPrefix: 'TF'});198 const nft = await collection.mintToken(alice, {Substrate: alice.address});198 const nft = await collection.mintToken(alice);199199200 await expect(nft.approve(charlie, {Substrate: bob.address})).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);200 await expect(nft.approve(charlie, {Substrate: bob.address})).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);201 expect(await nft.isApproved({Substrate: bob.address})).to.be.false;201 expect(await nft.isApproved({Substrate: bob.address})).to.be.false;210210211 itSub('[fungible] execute transferFrom from account that is not owner of collection', async ({helper}) => {211 itSub('[fungible] execute transferFrom from account that is not owner of collection', async ({helper}) => {212 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-8', description: '', tokenPrefix: 'TF'});212 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-8', description: '', tokenPrefix: 'TF'});213 await collection.mint(alice, {Substrate: alice.address}, 10000n);213 await collection.mint(alice, 10000n);214214215 await expect(collection.approveTokens(charlie, {Substrate: bob.address}, 1n)).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);215 await expect(collection.approveTokens(charlie, {Substrate: bob.address}, 1n)).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);216 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(0n);216 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(0n);228228229 itSub.ifWithPallets('[refungible] execute transferFrom from account that is not owner of collection', [Pallets.ReFungible], async ({helper}) => {229 itSub.ifWithPallets('[refungible] execute transferFrom from account that is not owner of collection', [Pallets.ReFungible], async ({helper}) => {230 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-9', description: '', tokenPrefix: 'TF'});230 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-9', description: '', tokenPrefix: 'TF'});231 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10000n);231 const rft = await collection.mintToken(alice, 10000n);232232233 await expect(rft.approve(charlie, {Substrate: bob.address}, 1n)).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);233 await expect(rft.approve(charlie, {Substrate: bob.address}, 1n)).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);234 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(0n);234 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(0n);247 itSub('transferFrom burnt token before approve NFT', async ({helper}) => {247 itSub('transferFrom burnt token before approve NFT', async ({helper}) => {248 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-10', description: '', tokenPrefix: 'TF'});248 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-10', description: '', tokenPrefix: 'TF'});249 await collection.setLimits(alice, {ownerCanTransfer: true});249 await collection.setLimits(alice, {ownerCanTransfer: true});250 const nft = await collection.mintToken(alice, {Substrate: alice.address});250 const nft = await collection.mintToken(alice);251251252 await nft.burn(alice);252 await nft.burn(alice);253 await expect(nft.approve(alice, {Substrate: bob.address})).to.be.rejectedWith(/common\.TokenNotFound/);253 await expect(nft.approve(alice, {Substrate: bob.address})).to.be.rejectedWith(/common\.TokenNotFound/);262 itSub('transferFrom burnt token before approve Fungible', async ({helper}) => {262 itSub('transferFrom burnt token before approve Fungible', async ({helper}) => {263 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-11', description: '', tokenPrefix: 'TF'});263 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-11', description: '', tokenPrefix: 'TF'});264 await collection.setLimits(alice, {ownerCanTransfer: true});264 await collection.setLimits(alice, {ownerCanTransfer: true});265 await collection.mint(alice, {Substrate: alice.address}, 10n);265 await collection.mint(alice, 10n);266266267 await collection.burnTokens(alice, 10n);267 await collection.burnTokens(alice, 10n);268 await expect(collection.approveTokens(alice, {Substrate: bob.address})).to.be.not.rejected;268 await expect(collection.approveTokens(alice, {Substrate: bob.address})).to.be.not.rejected;277 itSub.ifWithPallets('transferFrom burnt token before approve ReFungible', [Pallets.ReFungible], async ({helper}) => {277 itSub.ifWithPallets('transferFrom burnt token before approve ReFungible', [Pallets.ReFungible], async ({helper}) => {278 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-12', description: '', tokenPrefix: 'TF'});278 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-12', description: '', tokenPrefix: 'TF'});279 await collection.setLimits(alice, {ownerCanTransfer: true});279 await collection.setLimits(alice, {ownerCanTransfer: true});280 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);280 const rft = await collection.mintToken(alice, 10n);281281282 await rft.burn(alice, 10n);282 await rft.burn(alice, 10n);283 await expect(rft.approve(alice, {Substrate: bob.address})).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);283 await expect(rft.approve(alice, {Substrate: bob.address})).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);291291292 itSub('transferFrom burnt token after approve NFT', async ({helper}) => {292 itSub('transferFrom burnt token after approve NFT', async ({helper}) => {293 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-13', description: '', tokenPrefix: 'TF'});293 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-13', description: '', tokenPrefix: 'TF'});294 const nft = await collection.mintToken(alice, {Substrate: alice.address});294 const nft = await collection.mintToken(alice);295295296 await nft.approve(alice, {Substrate: bob.address});296 await nft.approve(alice, {Substrate: bob.address});297 expect(await nft.isApproved({Substrate: bob.address})).to.be.true;297 expect(await nft.isApproved({Substrate: bob.address})).to.be.true;307307308 itSub('transferFrom burnt token after approve Fungible', async ({helper}) => {308 itSub('transferFrom burnt token after approve Fungible', async ({helper}) => {309 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-14', description: '', tokenPrefix: 'TF'});309 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-14', description: '', tokenPrefix: 'TF'});310 await collection.mint(alice, {Substrate: alice.address}, 10n);310 await collection.mint(alice, 10n);311311312 await collection.approveTokens(alice, {Substrate: bob.address});312 await collection.approveTokens(alice, {Substrate: bob.address});313 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(1n);313 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(1n);323323324 itSub.ifWithPallets('transferFrom burnt token after approve ReFungible', [Pallets.ReFungible], async ({helper}) => {324 itSub.ifWithPallets('transferFrom burnt token after approve ReFungible', [Pallets.ReFungible], async ({helper}) => {325 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-15', description: '', tokenPrefix: 'TF'});325 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-15', description: '', tokenPrefix: 'TF'});326 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);326 const rft = await collection.mintToken(alice, 10n);327327328 await rft.approve(alice, {Substrate: bob.address}, 10n);328 await rft.approve(alice, {Substrate: bob.address}, 10n);329 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(10n);329 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(10n);tests/src/util/playgrounds/unique.tsdiffbeforeafterboth1678 * @example mintTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq"}, 1000n);1678 * @example mintTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq"}, 1000n);1679 * @returns ```true``` if extrinsic success, otherwise ```false``` 1679 * @returns ```true``` if extrinsic success, otherwise ```false``` 1680 */1680 */1681 async mintTokens(signer: TSigner, collectionId: number, owner: ICrossAccountId | string, amount: bigint): Promise<boolean> {1681 async mintTokens(signer: TSigner, collectionId: number, amount: bigint, owner: ICrossAccountId | string): Promise<boolean> {1682 const creationResult = await this.helper.executeExtrinsic(1682 const creationResult = await this.helper.executeExtrinsic(1683 signer,1683 signer,1684 'api.tx.unique.createItem', [collectionId, (typeof owner === 'string') ? {Substrate: owner} : owner, {1684 'api.tx.unique.createItem', [collectionId, (typeof owner === 'string') ? {Substrate: owner} : owner, {1699 * @param tokens array of tokens with properties and pieces1699 * @param tokens array of tokens with properties and pieces1700 * @returns ```true``` if extrinsic success, otherwise ```false``` 1700 * @returns ```true``` if extrinsic success, otherwise ```false``` 1701 */1701 */1702 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {value: bigint}[]): Promise<boolean> {1702 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, tokens: {value: bigint}[], owner: ICrossAccountId): Promise<boolean> {1703 const rawTokens = [];1703 const rawTokens = [];1704 for (const token of tokens) {1704 for (const token of tokens) {1705 const raw = {Fungible: {Value: token.value}};1705 const raw = {Fungible: {Value: token.value}};2211 return await this.helper.nft.isTokenApproved(this.collectionId, tokenId, toAddressObj);2211 return await this.helper.nft.isTokenApproved(this.collectionId, tokenId, toAddressObj);2212 }2212 }221322132214 async mintToken(signer: TSigner, owner: ICrossAccountId, properties?: IProperty[]) {2214 async mintToken(signer: TSigner, owner: ICrossAccountId = {Substrate: signer.address}, properties?: IProperty[]) {2215 return await this.helper.nft.mintToken(signer, {collectionId: this.collectionId, owner, properties});2215 return await this.helper.nft.mintToken(signer, {collectionId: this.collectionId, owner, properties});2216 }2216 }221722172286 return await this.helper.rft.repartitionToken(signer, this.collectionId, tokenId, amount);2286 return await this.helper.rft.repartitionToken(signer, this.collectionId, tokenId, amount);2287 }2287 }228822882289 async mintToken(signer: TSigner, owner: ICrossAccountId, pieces=100n, properties?: IProperty[]) {2289 async mintToken(signer: TSigner, pieces=1n, owner: ICrossAccountId = {Substrate: signer.address}, properties?: IProperty[]) {2290 return await this.helper.rft.mintToken(signer, {collectionId: this.collectionId, owner, pieces, properties});2290 return await this.helper.rft.mintToken(signer, {collectionId: this.collectionId, owner, pieces, properties});2291 }2291 }229222922293 async mintMultipleTokens(signer: TSigner, tokens: {owner: ICrossAccountId, pieces: bigint, properties?: IProperty[]}[]) {2293 async mintMultipleTokens(signer: TSigner, tokens: {pieces: bigint, owner: ICrossAccountId, properties?: IProperty[]}[]) {2294 return await this.helper.rft.mintMultipleTokens(signer, this.collectionId, tokens);2294 return await this.helper.rft.mintMultipleTokens(signer, this.collectionId, tokens);2295 }2295 }2296229623132313231423142315class UniqueFTCollection extends UniqueCollectionBase {2315class UniqueFTCollection extends UniqueCollectionBase {2316 async mint(signer: TSigner, owner: ICrossAccountId, amount: bigint) {2316 async mint(signer: TSigner, amount=1n, owner: ICrossAccountId = {Substrate: signer.address}) {2317 return await this.helper.ft.mintTokens(signer, this.collectionId, owner, amount);2317 return await this.helper.ft.mintTokens(signer, this.collectionId, amount, owner);2318 }2318 }231923192320 async mintWithOneOwner(signer: TSigner, owner: ICrossAccountId, tokens: {value: bigint}[]) {2320 async mintWithOneOwner(signer: TSigner, tokens: {value: bigint}[], owner: ICrossAccountId = {Substrate: signer.address}) {2321 return await this.helper.ft.mintMultipleTokensWithOneOwner(signer, this.collectionId, owner, tokens);2321 return await this.helper.ft.mintMultipleTokensWithOneOwner(signer, this.collectionId, tokens, owner);2322 }2322 }232323232324 async getBalance(addressObj: ICrossAccountId) {2324 async getBalance(addressObj: ICrossAccountId) {