difftreelog
test(approve) fix with updated playgrounds
in: master
1 file changed
tests/src/approve.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 chai from 'chai';18import {expect, itSub, Pallets, usingPlaygrounds} from './util/playgrounds';19import chaiAsPromised from 'chai-as-promised';20import {21 approveExpectFail,22 approveExpectSuccess,23 createCollectionExpectSuccess,24 createItemExpectSuccess,25} from './util/helpers';26import {usingPlaygrounds} from './util/playgrounds';271928let donor: IKeyringPair;292030before(async () => {31 await usingPlaygrounds(async (_, privateKey) => {32 donor = privateKey('//Alice');33 });34});3536chai.use(chaiAsPromised);37const expect = chai.expect;3839describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {21describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {40 let alice: IKeyringPair;22 let alice: IKeyringPair;41 let bob: IKeyringPair;23 let bob: IKeyringPair;42 let charlie: IKeyringPair;24 let charlie: IKeyringPair;432544 before(async () => {26 before(async () => {45 await usingPlaygrounds(async (helper) => {27 await usingPlaygrounds(async (helper, privateKey) => {28 const donor = privateKey('//Alice');46 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);29 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);47 });30 });48 });31 });493250 it('[nft] Execute the extrinsic and check approvedList', async () => {33 itSub('[nft] Execute the extrinsic and check approvedList', async ({helper}) => {51 await usingPlaygrounds(async (helper) => {52 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});34 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});53 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});35 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});54 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});36 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});55 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;37 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;56 });57 });38 });583959 it('[fungible] Execute the extrinsic and check approvedList', async () => {40 itSub('[fungible] Execute the extrinsic and check approvedList', async ({helper}) => {60 await usingPlaygrounds(async (helper) => {61 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);41 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);62 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);42 await helper.ft.mintTokens(alice, collectionId, 10n, {Substrate: alice.address});63 const tokenId = await helper.ft.getLastTokenId(collectionId);43 const tokenId = await helper.ft.getLastTokenId(collectionId);64 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});44 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});65 const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});45 const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});66 expect(amount).to.be.equal(BigInt(1));46 expect(amount).to.be.equal(BigInt(1));67 });68 });47 });694870 it('[refungible] Execute the extrinsic and check approvedList', async function() {49 itSub.ifWithPallets('[refungible] Execute the extrinsic and check approvedList', [Pallets.ReFungible], async ({helper}) => {71 await usingPlaygrounds(async (helper) => {72 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});50 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});73 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});51 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});74 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});52 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});75 const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});53 const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});76 expect(amount).to.be.equal(BigInt(1));54 expect(amount).to.be.equal(BigInt(1));77 });78 });55 });795680 it('[nft] Remove approval by using 0 amount', async () => {57 itSub('[nft] Remove approval by using 0 amount', async ({helper}) => {81 await usingPlaygrounds(async (helper) => {82 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});58 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});83 const collectionId = collection.collectionId;59 const collectionId = collection.collectionId;84 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});60 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});85 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});61 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});86 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;62 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;87 await helper.signTransaction(alice, helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0));63 await helper.signTransaction(alice, helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0));88 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;64 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;89 });90 });65 });916692 it('[fungible] Remove approval by using 0 amount', async () => {67 itSub('[fungible] Remove approval by using 0 amount', async ({helper}) => {93 await usingPlaygrounds(async (helper) => {94 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);68 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);95 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);69 await helper.ft.mintTokens(alice, collectionId, 10n, {Substrate: alice.address});96 const tokenId = await helper.ft.getLastTokenId(collectionId);70 const tokenId = await helper.ft.getLastTokenId(collectionId);97 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});71 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});98 const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});72 const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});99 expect(amountBefore).to.be.equal(BigInt(1));73 expect(amountBefore).to.be.equal(BigInt(1));10074101 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);75 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);102 const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});76 const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});103 expect(amountAfter).to.be.equal(BigInt(0));77 expect(amountAfter).to.be.equal(BigInt(0));104 });105 });78 });10679107 it('[refungible] Remove approval by using 0 amount', async function() {80 itSub.ifWithPallets('[refungible] Remove approval by using 0 amount', [Pallets.ReFungible], async ({helper}) => {108 await usingPlaygrounds(async (helper) => {109 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});81 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});110 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});82 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});111 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});83 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});112 const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});84 const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});113 expect(amountBefore).to.be.equal(BigInt(1));85 expect(amountBefore).to.be.equal(BigInt(1));11486115 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);87 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);116 const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});88 const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});117 expect(amountAfter).to.be.equal(BigInt(0));89 expect(amountAfter).to.be.equal(BigInt(0));118 });119 });90 });12091121 it('can`t be called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {92 itSub('can`t be called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => {122 await usingPlaygrounds(async (helper) => {123 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});93 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});124 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});94 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});125 const approveTokenTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});95 const approveTokenTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});126 await expect(approveTokenTx()).to.be.rejected;96 await expect(approveTokenTx()).to.be.rejected;127 });128 });97 });129});98});13099134 let charlie: IKeyringPair;103 let charlie: IKeyringPair;135104136 before(async () => {105 before(async () => {137 await usingPlaygrounds(async (helper) => {106 await usingPlaygrounds(async (helper, privateKey) => {107 const donor = privateKey('//Alice');138 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);108 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);139 });109 });140 });110 });141111142 it('NFT', async () => {112 itSub('NFT', async ({helper}) => {143 await usingPlaygrounds(async (helper) => {144 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});113 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});145 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});114 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});146 await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});115 await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});147 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.true;116 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.true;148 });149 });117 });150118151 it('Fungible up to an approved amount', async () => {119 itSub('Fungible up to an approved amount', async ({helper}) => {152 await usingPlaygrounds(async (helper) => {153 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);120 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);154 await helper.ft.mintTokens(alice, collectionId, bob.address, 10n);121 await helper.ft.mintTokens(alice, collectionId, 10n, bob.address);155 const tokenId = await helper.ft.getLastTokenId(collectionId);122 const tokenId = await helper.ft.getLastTokenId(collectionId);156 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});123 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});157 const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, {Substrate: bob.address});124 const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, {Substrate: bob.address});158 expect(amount).to.be.equal(BigInt(1));125 expect(amount).to.be.equal(BigInt(1));159 });160 });126 });161127162 it('ReFungible up to an approved amount', async function() {128 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {163 await usingPlaygrounds(async (helper) => {164 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});129 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});165 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});130 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});166 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}, 100n);131 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}, 100n);167 const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, {Substrate: bob.address});132 const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, {Substrate: bob.address});168 expect(amount).to.be.equal(BigInt(100n));133 expect(amount).to.be.equal(BigInt(100n));169 });170 });134 });171});135});172136176 let charlie: IKeyringPair;140 let charlie: IKeyringPair;177141178 before(async () => {142 before(async () => {179 await usingPlaygrounds(async (helper) => {143 await usingPlaygrounds(async (helper, privateKey) => {144 const donor = privateKey('//Alice');180 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);145 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);181 });146 });182 });147 });183148184 it('NFT', async () => {149 itSub('NFT', async ({helper}) => {185 await usingPlaygrounds(async (helper) => {186 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});150 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});187 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});151 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});188 await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});152 await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});189 await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});153 await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});190 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);154 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);191 expect(owner.Substrate).to.be.equal(alice.address);155 expect(owner.Substrate).to.be.equal(alice.address);192 });193 });156 });194157195 it('Fungible up to an approved amount', async () => {158 itSub('Fungible up to an approved amount', async ({helper}) => {196 await usingPlaygrounds(async (helper) => {197 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);159 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);198 await helper.ft.mintTokens(alice, collectionId, bob.address, 10n);160 await helper.ft.mintTokens(alice, collectionId, 10n, bob.address);199 const tokenId = await helper.ft.getLastTokenId(collectionId);161 const tokenId = await helper.ft.getLastTokenId(collectionId);200 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});162 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});201 const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});163 const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});202 await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);164 await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);203 const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});165 const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});204 expect(after - before).to.be.equal(BigInt(1));166 expect(after - before).to.be.equal(BigInt(1));205 });206 });167 });207168208 it('ReFungible up to an approved amount', async function() {169 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {209 await usingPlaygrounds(async (helper) => {210 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});170 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});211 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});171 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});212 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});172 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});213 const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});173 const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});214 await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);174 await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);215 const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});175 const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});216 expect(after - before).to.be.equal(BigInt(1));176 expect(after - before).to.be.equal(BigInt(1));217 });218 });177 });219});178});220179224 let charlie: IKeyringPair;183 let charlie: IKeyringPair;225184226 before(async () => {185 before(async () => {227 await usingPlaygrounds(async (helper) => {186 await usingPlaygrounds(async (helper, privateKey) => {187 const donor = privateKey('//Alice');228 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);188 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);229 });189 });230 });190 });231191232 it('NFT', async () => {192 itSub('NFT', async ({helper}) => {233 await usingPlaygrounds(async (helper) => {234 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});193 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});235 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});194 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});236 await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});195 await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});237 await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});196 await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});238 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);197 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);239 expect(owner.Substrate).to.be.equal(alice.address);198 expect(owner.Substrate).to.be.equal(alice.address);240 const transferTokenFromTx = async () => helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});199 const transferTokenFromTx = async () => helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});241 await expect(transferTokenFromTx()).to.be.rejected;200 await expect(transferTokenFromTx()).to.be.rejected;242 });243 });201 });244202245 it('Fungible up to an approved amount', async () => {203 itSub('Fungible up to an approved amount', async ({helper}) => {246 await usingPlaygrounds(async (helper) => {247 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);204 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);248 await helper.ft.mintTokens(alice, collectionId, bob.address, 10n);205 await helper.ft.mintTokens(alice, collectionId, 10n, bob.address);249 const tokenId = await helper.ft.getLastTokenId(collectionId);206 const tokenId = await helper.ft.getLastTokenId(collectionId);250 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});207 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});251 const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});208 const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});252 await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);209 await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);253 const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});210 const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});254 expect(after - before).to.be.equal(BigInt(1));211 expect(after - before).to.be.equal(BigInt(1));255212256 const transferTokenFromTx = async () => helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);213 const transferTokenFromTx = async () => helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);257 await expect(transferTokenFromTx()).to.be.rejected;214 await expect(transferTokenFromTx()).to.be.rejected;258 });259 });215 });260216261 it('ReFungible up to an approved amount', async function() {217 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {262 await usingPlaygrounds(async (helper) => {263 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});218 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});264 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});219 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});265 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}, 100n);220 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}, 100n);266 const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});221 const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});267 await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 100n);222 await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 100n);268 const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});223 const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});269 expect(after - before).to.be.equal(BigInt(100));224 expect(after - before).to.be.equal(BigInt(100));270 const transferTokenFromTx = async () => helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 100n);225 const transferTokenFromTx = async () => helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 100n);271 await expect(transferTokenFromTx()).to.be.rejected;226 await expect(transferTokenFromTx()).to.be.rejected;272 });273 });227 });274});228});275229280 let dave: IKeyringPair;234 let dave: IKeyringPair;281235282 before(async () => {236 before(async () => {283 await usingPlaygrounds(async (helper) => {237 await usingPlaygrounds(async (helper, privateKey) => {238 const donor = privateKey('//Alice');284 [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);239 [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);285 });240 });286 });241 });287242288 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 () => {243 itSub('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 ({helper}) => {289 await usingPlaygrounds(async (helper) => {290 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);244 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);291 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);245 await helper.ft.mintTokens(alice, collectionId, 10n, alice.address);292 const tokenId = await helper.ft.getLastTokenId(collectionId);246 const tokenId = await helper.ft.getLastTokenId(collectionId);293 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 10n);247 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 10n);294248295 const charlieBefore = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});249 const charlieBefore = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});296 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address}, 2n);250 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address}, 2n);297 const charlieAfter = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});251 const charlieAfter = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});298 expect(charlieAfter - charlieBefore).to.be.equal(BigInt(2));252 expect(charlieAfter - charlieBefore).to.be.equal(BigInt(2));299253300 const daveBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});254 const daveBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});301 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: alice.address}, {Substrate: dave.address}, 8n);255 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: alice.address}, {Substrate: dave.address}, 8n);302 const daveAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});256 const daveAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});303 expect(daveAfter - daveBefore).to.be.equal(BigInt(8));257 expect(daveAfter - daveBefore).to.be.equal(BigInt(8));304 });305 });258 });306});259});307260311 let charlie: IKeyringPair;264 let charlie: IKeyringPair;312265313 before(async () => {266 before(async () => {314 await usingPlaygrounds(async (helper) => {267 await usingPlaygrounds(async (helper, privateKey) => {268 const donor = privateKey('//Alice');315 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);269 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);316 });270 });317 });271 });318272319 it('NFT', async () => {273 itSub('NFT', async ({helper}) => {320 await usingPlaygrounds(async (helper) => {321 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});274 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});322 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});275 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});323 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});276 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});324 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;277 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;325 await helper.signTransaction(alice, helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0));278 await helper.signTransaction(alice, helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0));326 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;279 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;327 const transferTokenFromTx = async () => helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: bob.address});280 const transferTokenFromTx = async () => helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: bob.address});328 await expect(transferTokenFromTx()).to.be.rejected;281 await expect(transferTokenFromTx()).to.be.rejected;329 });330 });282 });331283332 it('Fungible', async () => {284 itSub('Fungible', async ({helper}) => {333 await usingPlaygrounds(async (helper) => {334 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);285 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);335 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);286 await helper.ft.mintTokens(alice, collectionId, 10n, alice.address);336 const tokenId = await helper.ft.getLastTokenId(collectionId);287 const tokenId = await helper.ft.getLastTokenId(collectionId);337 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});288 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});338 const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});289 const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});339 expect(amountBefore).to.be.equal(BigInt(1));290 expect(amountBefore).to.be.equal(BigInt(1));340291341 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);292 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);342 const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});293 const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});343 expect(amountAfter).to.be.equal(BigInt(0));294 expect(amountAfter).to.be.equal(BigInt(0));344295345 const transferTokenFromTx = async () => helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 1n);296 const transferTokenFromTx = async () => helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 1n);346 await expect(transferTokenFromTx()).to.be.rejected;297 await expect(transferTokenFromTx()).to.be.rejected;347 });348 });298 });349299350 it('ReFungible', async function() {300 itSub.ifWithPallets('ReFungible', [Pallets.ReFungible], async ({helper}) => {351 await usingPlaygrounds(async (helper) => {352 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});301 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});353 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});302 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});354 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});303 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});355 const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});304 const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});356 expect(amountBefore).to.be.equal(BigInt(1));305 expect(amountBefore).to.be.equal(BigInt(1));357306358 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);307 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);359 const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});308 const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});360 expect(amountAfter).to.be.equal(BigInt(0));309 expect(amountAfter).to.be.equal(BigInt(0));361310362 const transferTokenFromTx = async () => helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 100n);311 const transferTokenFromTx = async () => helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 100n);363 await expect(transferTokenFromTx()).to.be.rejected;312 await expect(transferTokenFromTx()).to.be.rejected;364 });365 });313 });366});314});367315371 let charlie: IKeyringPair;319 let charlie: IKeyringPair;372320373 before(async () => {321 before(async () => {374 await usingPlaygrounds(async (helper) => {322 await usingPlaygrounds(async (helper, privateKey) => {323 const donor = privateKey('//Alice');375 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);324 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);376 });325 });377 });326 });378327379 it('1 for NFT', async () => {328 itSub('1 for NFT', async ({helper}) => {380 await usingPlaygrounds(async (helper) => {381 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});329 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});382 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});330 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});383 const approveTx = async () => helper.signTransaction(bob, helper.api?.tx.unique.approve({Substrate: charlie.address}, collectionId, tokenId, 2));331 const approveTx = async () => helper.signTransaction(bob, helper.api?.tx.unique.approve({Substrate: charlie.address}, collectionId, tokenId, 2));384 await expect(approveTx()).to.be.rejected;332 await expect(approveTx()).to.be.rejected;385 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.false;333 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.false;386 });387 });334 });388335389 it('Fungible', async () => {336 itSub('Fungible', async ({helper}) => {390 await usingPlaygrounds(async (helper) => {391 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);337 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);392 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);338 await helper.ft.mintTokens(alice, collectionId, 10n, alice.address);393 const tokenId = await helper.ft.getLastTokenId(collectionId);339 const tokenId = await helper.ft.getLastTokenId(collectionId);394 const approveTx = async () => helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 11n);340 const approveTx = async () => helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 11n);395 await expect(approveTx()).to.be.rejected;341 await expect(approveTx()).to.be.rejected;396 });397 });342 });398343399 it('ReFungible', async function() {344 itSub.ifWithPallets('ReFungible', [Pallets.ReFungible], async ({helper}) => {400 await usingPlaygrounds(async (helper) => {401 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});345 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});402 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});346 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});403 const approveTx = async () => helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 101n);347 const approveTx = async () => helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 101n);404 await expect(approveTx()).to.be.rejected;348 await expect(approveTx()).to.be.rejected;405 });406 });349 });407});350});408351413 let dave: IKeyringPair;356 let dave: IKeyringPair;414357415 before(async () => {358 before(async () => {416 await usingPlaygrounds(async (helper) => {359 await usingPlaygrounds(async (helper, privateKey) => {360 const donor = privateKey('//Alice');417 [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);361 [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);418 });362 });419 });363 });420364421 it('NFT', async () => {365 itSub('NFT', async ({helper}) => {422 await usingPlaygrounds(async (helper) => {423 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});366 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});424 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});367 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});425 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: charlie.address});368 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: charlie.address});426369427 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address});370 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address});428 const owner1 = await helper.nft.getTokenOwner(collectionId, tokenId);371 const owner1 = await helper.nft.getTokenOwner(collectionId, tokenId);429 expect(owner1.Substrate).to.be.equal(dave.address);372 expect(owner1.Substrate).to.be.equal(dave.address);430373431 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});374 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});432 await helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address});375 await helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address});433 const owner2 = await helper.nft.getTokenOwner(collectionId, tokenId);376 const owner2 = await helper.nft.getTokenOwner(collectionId, tokenId);434 expect(owner2.Substrate).to.be.equal(alice.address);377 expect(owner2.Substrate).to.be.equal(alice.address);435 });436 });378 });437379438 it('Fungible up to an approved amount', async () => {380 itSub('Fungible up to an approved amount', async ({helper}) => {439 await usingPlaygrounds(async (helper) => {440 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);381 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);441 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});382 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});442 await helper.ft.mintTokens(alice, collectionId, charlie.address, 10n);383 await helper.ft.mintTokens(alice, collectionId, 10n, charlie.address);443 const tokenId = await helper.ft.getLastTokenId(collectionId);384 const tokenId = await helper.ft.getLastTokenId(collectionId);444385445 const daveBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});386 const daveBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});446 await helper.ft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n);387 await helper.ft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n);447 const daveBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});388 const daveBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});448 expect(daveBalanceAfter - daveBalanceBefore).to.be.equal(BigInt(1));389 expect(daveBalanceAfter - daveBalanceBefore).to.be.equal(BigInt(1));449390450 await helper.collection.addAdmin(alice ,collectionId, {Substrate: bob.address});391 await helper.collection.addAdmin(alice ,collectionId, {Substrate: bob.address});451392452 const aliceBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: alice.address});393 const aliceBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: alice.address});453 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n);394 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n);454 const aliceBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: alice.address});395 const aliceBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: alice.address});455 expect(aliceBalanceAfter - aliceBalanceBefore).to.be.equal(BigInt(1));396 expect(aliceBalanceAfter - aliceBalanceBefore).to.be.equal(BigInt(1));456 });457 });397 });458398459 it('ReFungible up to an approved amount', async function() {399 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {460 await usingPlaygrounds(async (helper) => {461 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});400 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});462 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});401 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});463 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: charlie.address, pieces: 100n});402 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: charlie.address, pieces: 100n});464403465 const daveBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address});404 const daveBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address});466 await helper.rft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n);405 await helper.rft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n);467 const daveAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address});406 const daveAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address});468 expect(daveAfter - daveBefore).to.be.equal(BigInt(1));407 expect(daveAfter - daveBefore).to.be.equal(BigInt(1));469408470 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});409 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});471410472 const aliceBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});411 const aliceBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});473 await helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n);412 await helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n);474 const aliceAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});413 const aliceAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});475 expect(aliceAfter - aliceBefore).to.be.equal(BigInt(1));414 expect(aliceAfter - aliceBefore).to.be.equal(BigInt(1));476 });477 });415 });478});416});479417484 let dave: IKeyringPair;422 let dave: IKeyringPair;485423486 before(async () => {424 before(async () => {487 await usingPlaygrounds(async (helper) => {425 await usingPlaygrounds(async (helper, privateKey) => {426 const donor = privateKey('//Alice');488 [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);427 [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);489 });428 });490 });429 });491430492 it.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. Fungible', async () => {431 itSub.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. Fungible', async ({helper}) => {493 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});432 const collection = await helper.ft.mintCollection(alice, {});494 await createItemExpectSuccess(alice, collectionId, 'Fungible', alice.address);433 await collection.mint(alice, 10n);495 await approveExpectSuccess(collectionId, 0, alice, bob.address, 1);434 await collection.approveTokens(alice, {Substrate: bob.address}, 1n);496 await approveExpectSuccess(collectionId, 0, alice, charlie.address, 1);435 await collection.approveTokens(alice, {Substrate: charlie.address}, 1n);497 // const allowances1 = await getAllowance(collectionId, 0, Alice.address, Bob.address);436 // const allowances1 = await getAllowance(collectionId, 0, Alice.address, Bob.address);498 // const allowances2 = await getAllowance(collectionId, 0, Alice.address, Charlie.address);437 // const allowances2 = await getAllowance(collectionId, 0, Alice.address, Charlie.address);499 // expect(allowances1 + allowances2).to.be.eq(BigInt(2));438 // expect(allowances1 + allowances2).to.be.eq(BigInt(2));500 });439 });501440502 it.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. ReFungible', async () => {441 itSub.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. ReFungible', async ({helper}) => {503 const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});442 const collection = await helper.rft.mintCollection(alice, {});504 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', alice.address);443 const token = await collection.mintToken(alice, 10n);505 await approveExpectSuccess(collectionId, itemId, alice, bob.address, 1);444 await token.approve(alice, {Substrate: bob.address}, 1n);506 await approveExpectSuccess(collectionId, itemId, alice, charlie.address, 1);445 await token.approve(alice, {Substrate: charlie.address}, 1n);507 // const allowances1 = await getAllowance(collectionId, itemId, Alice.address, Bob.address);446 // const allowances1 = await getAllowance(collectionId, itemId, Alice.address, Bob.address);508 // const allowances2 = await getAllowance(collectionId, itemId, Alice.address, Charlie.address);447 // const allowances2 = await getAllowance(collectionId, itemId, Alice.address, Charlie.address);509 // expect(allowances1 + allowances2).to.be.eq(BigInt(2));448 // expect(allowances1 + allowances2).to.be.eq(BigInt(2));510 });449 });511450512 // Canceled by changing approve logic451 // Canceled by changing approve logic513 it.skip('Cannot approve for more than total user`s amount (owned: 10, approval 1: 5 - should succeed, approval 2: 6 - should fail). Fungible', async () => {452 itSub.skip('Cannot approve for more than total user\'s amount (owned: 10, approval 1: 5 - should succeed, approval 2: 6 - should fail). Fungible', async ({helper}) => {514 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});453 const collection = await helper.ft.mintCollection(alice, {});515 await createItemExpectSuccess(alice, collectionId, 'Fungible', dave.address);454 await collection.mint(alice, 10n, {Substrate: dave.address});516 await approveExpectSuccess(collectionId, 0, dave, bob.address, 5);455 await collection.approveTokens(dave, {Substrate: bob.address}, 5n);517 await approveExpectFail(collectionId, 0, dave, charlie, 6);456 await expect(collection.approveTokens(dave, {Substrate: charlie.address}, 6n))457 .to.be.rejectedWith('this test would fail (since it is skipped), replace this expecting message with what would have been received');518 });458 });519459520 // Canceled by changing approve logic460 // Canceled by changing approve logic521 it.skip('Cannot approve for more than total users amount (owned: 100, approval 1: 50 - should succeed, approval 2: 51 - should fail). ReFungible', async () => {461 itSub.skip('Cannot approve for more than total user\'s amount (owned: 100, approval 1: 50 - should succeed, approval 2: 51 - should fail). ReFungible', async ({helper}) => {522 const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});462 const collection = await helper.rft.mintCollection(alice, {});523 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', dave.address);463 const token = await collection.mintToken(alice, 100n, {Substrate: dave.address});524 await approveExpectSuccess(collectionId, itemId, dave, bob.address, 50);464 await token.approve(dave, {Substrate: bob.address}, 50n);525 await approveExpectFail(collectionId, itemId, dave, charlie, 51);465 await expect(token.approve(dave, {Substrate: charlie.address}, 51n))466 .to.be.rejectedWith('this test would fail (since it is skipped), replace this expecting message with what would have been received');526 });467 });527});468});528469532 let charlie: IKeyringPair;473 let charlie: IKeyringPair;533474534 before(async () => {475 before(async () => {535 await usingPlaygrounds(async (helper) => {476 await usingPlaygrounds(async (helper, privateKey) => {477 const donor = privateKey('//Alice');536 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);478 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);537 });479 });538 });480 });539481540 it('can be called by collection admin on non-owned item', async () => {482 itSub('can be called by collection admin on non-owned item', async ({helper}) => {541 await usingPlaygrounds(async (helper) => {542 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});483 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});543 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});484 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});544 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});485 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});545 const approveTx = async () => helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});486 const approveTx = async () => helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});546 await expect(approveTx()).to.be.rejected;487 await expect(approveTx()).to.be.rejected;547 });548 });488 });549});489});550490554 let charlie: IKeyringPair;494 let charlie: IKeyringPair;555495556 before(async () => {496 before(async () => {557 await usingPlaygrounds(async (helper) => {497 await usingPlaygrounds(async (helper, privateKey) => {498 const donor = privateKey('//Alice');558 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);499 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);559 });500 });560 });501 });561502562 it('[nft] Approve for a collection that does not exist', async () => {503 itSub('[nft] Approve for a collection that does not exist', async ({helper}) => {563 await usingPlaygrounds(async (helper) => {564 const collectionId = 1 << 32 - 1;504 const collectionId = 1 << 32 - 1;565 const approveTx = async () => helper.nft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});505 const approveTx = async () => helper.nft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});566 await expect(approveTx()).to.be.rejected;506 await expect(approveTx()).to.be.rejected;567 });568 });507 });569508570 it('[fungible] Approve for a collection that does not exist', async () => {509 itSub('[fungible] Approve for a collection that does not exist', async ({helper}) => {571 await usingPlaygrounds(async (helper) => {572 const collectionId = 1 << 32 - 1;510 const collectionId = 1 << 32 - 1;573 const approveTx = async () => helper.ft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});511 const approveTx = async () => helper.ft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});574 await expect(approveTx()).to.be.rejected;512 await expect(approveTx()).to.be.rejected;575 });576 });513 });577514578 it('[refungible] Approve for a collection that does not exist', async function() {515 itSub.ifWithPallets('[refungible] Approve for a collection that does not exist', [Pallets.ReFungible], async ({helper}) => {579 await usingPlaygrounds(async (helper) => {580 const collectionId = 1 << 32 - 1;516 const collectionId = 1 << 32 - 1;581 const approveTx = async () => helper.rft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});517 const approveTx = async () => helper.rft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});582 await expect(approveTx()).to.be.rejected;518 await expect(approveTx()).to.be.rejected;583 });584 });519 });585520586 it('[nft] Approve for a collection that was destroyed', async () => {521 itSub('[nft] Approve for a collection that was destroyed', async ({helper}) => {587 await usingPlaygrounds(async (helper) => {588 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});522 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});589 await helper.nft.burn(alice, collectionId);523 await helper.nft.burn(alice, collectionId);590 const approveTx = async () => helper.nft.approveToken(alice, collectionId, 1, {Substrate: bob.address});524 const approveTx = async () => helper.nft.approveToken(alice, collectionId, 1, {Substrate: bob.address});591 await expect(approveTx()).to.be.rejected;525 await expect(approveTx()).to.be.rejected;592 });593 });526 });594527595 it('[fungible] Approve for a collection that was destroyed', async () => {528 itSub('[fungible] Approve for a collection that was destroyed', async ({helper}) => {596 await usingPlaygrounds(async (helper) => {597 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});529 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});598 await helper.ft.burn(alice, collectionId);530 await helper.ft.burn(alice, collectionId);599 const approveTx = async () => helper.ft.approveToken(alice, collectionId, 1, {Substrate: bob.address});531 const approveTx = async () => helper.ft.approveToken(alice, collectionId, 1, {Substrate: bob.address});600 await expect(approveTx()).to.be.rejected;532 await expect(approveTx()).to.be.rejected;601 });602 });533 });603534604 it('[refungible] Approve for a collection that was destroyed', async function() {535 itSub.ifWithPallets('[refungible] Approve for a collection that was destroyed', [Pallets.ReFungible], async ({helper}) => {605 await usingPlaygrounds(async (helper) => {606 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});536 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});607 await helper.rft.burn(alice, collectionId);537 await helper.rft.burn(alice, collectionId);608 const approveTx = async () => helper.rft.approveToken(alice, collectionId, 1, {Substrate: bob.address});538 const approveTx = async () => helper.rft.approveToken(alice, collectionId, 1, {Substrate: bob.address});609 await expect(approveTx()).to.be.rejected;539 await expect(approveTx()).to.be.rejected;610 });611 });540 });612541 613 it('[nft] Approve transfer of a token that does not exist', async () => {542 itSub('[nft] Approve transfer of a token that does not exist', async ({helper}) => {614 await usingPlaygrounds(async (helper) => {615 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});543 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});616 const approveTx = async () => helper.nft.approveToken(alice, collectionId, 2, {Substrate: bob.address});544 const approveTx = async () => helper.nft.approveToken(alice, collectionId, 2, {Substrate: bob.address});617 await expect(approveTx()).to.be.rejected;545 await expect(approveTx()).to.be.rejected;618 });619 });546 });620547621 it('[refungible] Approve transfer of a token that does not exist', async function() {548 itSub.ifWithPallets('[refungible] Approve transfer of a token that does not exist', [Pallets.ReFungible], async ({helper}) => {622 await usingPlaygrounds(async (helper) => {623 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});549 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});624 const approveTx = async () => helper.rft.approveToken(alice, collectionId, 2, {Substrate: bob.address});550 const approveTx = async () => helper.rft.approveToken(alice, collectionId, 2, {Substrate: bob.address});625 await expect(approveTx()).to.be.rejected;551 await expect(approveTx()).to.be.rejected;626 });627 });552 });628553629 it('[nft] Approve using the address that does not own the approved token', async () => {554 itSub('[nft] Approve using the address that does not own the approved token', async ({helper}) => {630 await usingPlaygrounds(async (helper) => {631 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});555 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});632 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});556 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});633 const approveTx = async () => helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});557 const approveTx = async () => helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});634 await expect(approveTx()).to.be.rejected;558 await expect(approveTx()).to.be.rejected;635 });636 });559 });637560638 it('[fungible] Approve using the address that does not own the approved token', async () => {561 itSub('[fungible] Approve using the address that does not own the approved token', async ({helper}) => {639 await usingPlaygrounds(async (helper) => {640 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});562 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});641 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);563 await helper.ft.mintTokens(alice, collectionId, 10n, alice.address);642 const tokenId = await helper.ft.getLastTokenId(collectionId);564 const tokenId = await helper.ft.getLastTokenId(collectionId);643 const approveTx = async () => helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});565 const approveTx = async () => helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});644 await expect(approveTx()).to.be.rejected;566 await expect(approveTx()).to.be.rejected;645 });646 });567 });647568648 it('[refungible] Approve using the address that does not own the approved token', async function() {569 itSub.ifWithPallets('[refungible] Approve using the address that does not own the approved token', [Pallets.ReFungible], async ({helper}) => {649 await usingPlaygrounds(async (helper) => {650 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});570 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});651 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});571 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});652 const approveTx = async () => helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});572 const approveTx = async () => helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});653 await expect(approveTx()).to.be.rejected;573 await expect(approveTx()).to.be.rejected;654 });655 });574 });656575657 it('should fail if approved more ReFungibles than owned', async function() {576 itSub.ifWithPallets('should fail if approved more ReFungibles than owned', [Pallets.ReFungible], async ({helper}) => {658 await usingPlaygrounds(async (helper) => {659 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});577 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});660 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});578 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});661 await helper.rft.transferToken(alice, collectionId, tokenId, {Substrate: bob.address}, 100n);579 await helper.rft.transferToken(alice, collectionId, tokenId, {Substrate: bob.address}, 100n);662 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 100n);580 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 100n);663581664 const approveTx = async () => helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 101n);582 const approveTx = async () => helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 101n);665 await expect(approveTx()).to.be.rejected;583 await expect(approveTx()).to.be.rejected;666 });667 });584 });668585669 it('should fail if approved more Fungibles than owned', async () => {586 itSub('should fail if approved more Fungibles than owned', async ({helper}) => {670 await usingPlaygrounds(async (helper) => {671 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});587 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});672 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);588 await helper.ft.mintTokens(alice, collectionId, 10n, alice.address);673 const tokenId = await helper.ft.getLastTokenId(collectionId);589 const tokenId = await helper.ft.getLastTokenId(collectionId);674590675 await helper.ft.transferToken(alice, collectionId, tokenId, {Substrate: bob.address}, 10n);591 await helper.ft.transferToken(alice, collectionId, tokenId, {Substrate: bob.address}, 10n);676 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 10n);592 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 10n);677 const approveTx = async () => helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 11n);593 const approveTx = async () => helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 11n);678 await expect(approveTx()).to.be.rejected;594 await expect(approveTx()).to.be.rejected;679 });680 });595 });681596682 it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {597 itSub('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => {683 await usingPlaygrounds(async (helper) => {684 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});598 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});685 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});599 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});686 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: false});600 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: false});687601688 const approveTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});602 const approveTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});689 await expect(approveTx()).to.be.rejected;603 await expect(approveTx()).to.be.rejected;690 });691 });604 });692});605});693606