--- a/tests/src/approve.test.ts +++ b/tests/src/approve.test.ts @@ -15,26 +15,8 @@ // along with Unique Network. If not, see . import {IKeyringPair} from '@polkadot/types/types'; -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; -import { - approveExpectFail, - approveExpectSuccess, - createCollectionExpectSuccess, - createItemExpectSuccess, -} from './util/helpers'; -import {usingPlaygrounds} from './util/playgrounds'; - -let donor: IKeyringPair; - -before(async () => { - await usingPlaygrounds(async (_, privateKey) => { - donor = privateKey('//Alice'); - }); -}); +import {expect, itSub, Pallets, usingPlaygrounds} from './util/playgrounds'; -chai.use(chaiAsPromised); -const expect = chai.expect; describe('Integration Test approve(spender, collection_id, item_id, amount):', () => { let alice: IKeyringPair; @@ -42,89 +24,76 @@ let charlie: IKeyringPair; before(async () => { - await usingPlaygrounds(async (helper) => { + await usingPlaygrounds(async (helper, privateKey) => { + const donor = privateKey('//Alice'); [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor); }); }); - it('[nft] Execute the extrinsic and check approvedList', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address}); - await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}); - expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true; - }); + itSub('[nft] Execute the extrinsic and check approvedList', async ({helper}) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address}); + await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}); + expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true; }); - it('[fungible] Execute the extrinsic and check approvedList', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0); - await helper.ft.mintTokens(alice, collectionId, alice.address, 10n); - const tokenId = await helper.ft.getLastTokenId(collectionId); - await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}); - const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); - expect(amount).to.be.equal(BigInt(1)); - }); + itSub('[fungible] Execute the extrinsic and check approvedList', async ({helper}) => { + const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0); + await helper.ft.mintTokens(alice, collectionId, 10n, {Substrate: alice.address}); + const tokenId = await helper.ft.getLastTokenId(collectionId); + await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}); + const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); + expect(amount).to.be.equal(BigInt(1)); }); - it('[refungible] Execute the extrinsic and check approvedList', async function() { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n}); - await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}); - const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); - expect(amount).to.be.equal(BigInt(1)); - }); + itSub.ifWithPallets('[refungible] Execute the extrinsic and check approvedList', [Pallets.ReFungible], async ({helper}) => { + const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n}); + await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}); + const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); + expect(amount).to.be.equal(BigInt(1)); }); - it('[nft] Remove approval by using 0 amount', async () => { - await usingPlaygrounds(async (helper) => { - const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const collectionId = collection.collectionId; - const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address}); - await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}); - expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true; - await helper.signTransaction(alice, helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0)); - expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false; - }); + itSub('[nft] Remove approval by using 0 amount', async ({helper}) => { + const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const collectionId = collection.collectionId; + const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address}); + await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}); + expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true; + await helper.signTransaction(alice, helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0)); + expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false; }); - it('[fungible] Remove approval by using 0 amount', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0); - await helper.ft.mintTokens(alice, collectionId, alice.address, 10n); - const tokenId = await helper.ft.getLastTokenId(collectionId); - await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}); - const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); - expect(amountBefore).to.be.equal(BigInt(1)); + itSub('[fungible] Remove approval by using 0 amount', async ({helper}) => { + const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0); + await helper.ft.mintTokens(alice, collectionId, 10n, {Substrate: alice.address}); + const tokenId = await helper.ft.getLastTokenId(collectionId); + await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}); + const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); + expect(amountBefore).to.be.equal(BigInt(1)); - await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n); - const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); - expect(amountAfter).to.be.equal(BigInt(0)); - }); + await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n); + const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); + expect(amountAfter).to.be.equal(BigInt(0)); }); - it('[refungible] Remove approval by using 0 amount', async function() { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n}); - await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}); - const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); - expect(amountBefore).to.be.equal(BigInt(1)); + itSub.ifWithPallets('[refungible] Remove approval by using 0 amount', [Pallets.ReFungible], async ({helper}) => { + const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n}); + await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}); + const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); + expect(amountBefore).to.be.equal(BigInt(1)); - await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n); - const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); - expect(amountAfter).to.be.equal(BigInt(0)); - }); + await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n); + const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); + expect(amountAfter).to.be.equal(BigInt(0)); }); - it('can`t be called by collection owner on non-owned item when OwnerCanTransfer == false', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address}); - const approveTokenTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address}); - await expect(approveTokenTx()).to.be.rejected; - }); + itSub('can`t be called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address}); + const approveTokenTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address}); + await expect(approveTokenTx()).to.be.rejected; }); }); @@ -134,39 +103,34 @@ let charlie: IKeyringPair; before(async () => { - await usingPlaygrounds(async (helper) => { + await usingPlaygrounds(async (helper, privateKey) => { + const donor = privateKey('//Alice'); [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor); }); }); - it('NFT', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address}); - await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}); - expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.true; - }); + itSub('NFT', async ({helper}) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address}); + await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}); + expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.true; }); - it('Fungible up to an approved amount', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0); - await helper.ft.mintTokens(alice, collectionId, bob.address, 10n); - const tokenId = await helper.ft.getLastTokenId(collectionId); - await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}); - const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, {Substrate: bob.address}); - expect(amount).to.be.equal(BigInt(1)); - }); + itSub('Fungible up to an approved amount', async ({helper}) => { + const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0); + await helper.ft.mintTokens(alice, collectionId, 10n, bob.address); + const tokenId = await helper.ft.getLastTokenId(collectionId); + await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}); + const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, {Substrate: bob.address}); + expect(amount).to.be.equal(BigInt(1)); }); - it('ReFungible up to an approved amount', async function() { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n}); - await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}, 100n); - const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, {Substrate: bob.address}); - expect(amount).to.be.equal(BigInt(100n)); - }); + itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => { + const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n}); + await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}, 100n); + const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, {Substrate: bob.address}); + expect(amount).to.be.equal(BigInt(100n)); }); }); @@ -176,45 +140,40 @@ let charlie: IKeyringPair; before(async () => { - await usingPlaygrounds(async (helper) => { + await usingPlaygrounds(async (helper, privateKey) => { + const donor = privateKey('//Alice'); [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor); }); }); - it('NFT', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address}); - await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}); - await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); - const owner = await helper.nft.getTokenOwner(collectionId, tokenId); - expect(owner.Substrate).to.be.equal(alice.address); - }); + itSub('NFT', async ({helper}) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address}); + await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}); + await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); + const owner = await helper.nft.getTokenOwner(collectionId, tokenId); + expect(owner.Substrate).to.be.equal(alice.address); }); - it('Fungible up to an approved amount', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0); - await helper.ft.mintTokens(alice, collectionId, bob.address, 10n); - const tokenId = await helper.ft.getLastTokenId(collectionId); - await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}); - const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address}); - await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n); - const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address}); - expect(after - before).to.be.equal(BigInt(1)); - }); + itSub('Fungible up to an approved amount', async ({helper}) => { + const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0); + await helper.ft.mintTokens(alice, collectionId, 10n, bob.address); + const tokenId = await helper.ft.getLastTokenId(collectionId); + await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}); + const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address}); + await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n); + const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address}); + expect(after - before).to.be.equal(BigInt(1)); }); - it('ReFungible up to an approved amount', async function() { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n}); - await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}); - const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address}); - await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n); - const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address}); - expect(after - before).to.be.equal(BigInt(1)); - }); + itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => { + const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n}); + await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}); + const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address}); + await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n); + const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address}); + expect(after - before).to.be.equal(BigInt(1)); }); }); @@ -224,52 +183,47 @@ let charlie: IKeyringPair; before(async () => { - await usingPlaygrounds(async (helper) => { + await usingPlaygrounds(async (helper, privateKey) => { + const donor = privateKey('//Alice'); [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor); }); }); - it('NFT', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address}); - await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}); - await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); - const owner = await helper.nft.getTokenOwner(collectionId, tokenId); - expect(owner.Substrate).to.be.equal(alice.address); - const transferTokenFromTx = async () => helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); - await expect(transferTokenFromTx()).to.be.rejected; - }); + itSub('NFT', async ({helper}) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address}); + await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}); + await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); + const owner = await helper.nft.getTokenOwner(collectionId, tokenId); + expect(owner.Substrate).to.be.equal(alice.address); + const transferTokenFromTx = async () => helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); + await expect(transferTokenFromTx()).to.be.rejected; }); - it('Fungible up to an approved amount', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0); - await helper.ft.mintTokens(alice, collectionId, bob.address, 10n); - const tokenId = await helper.ft.getLastTokenId(collectionId); - await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}); - const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address}); - await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n); - const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address}); - expect(after - before).to.be.equal(BigInt(1)); + itSub('Fungible up to an approved amount', async ({helper}) => { + const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0); + await helper.ft.mintTokens(alice, collectionId, 10n, bob.address); + const tokenId = await helper.ft.getLastTokenId(collectionId); + await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}); + const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address}); + await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n); + const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address}); + expect(after - before).to.be.equal(BigInt(1)); - const transferTokenFromTx = async () => helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n); - await expect(transferTokenFromTx()).to.be.rejected; - }); + const transferTokenFromTx = async () => helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n); + await expect(transferTokenFromTx()).to.be.rejected; }); - it('ReFungible up to an approved amount', async function() { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n}); - await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}, 100n); - const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address}); - await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 100n); - const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address}); - expect(after - before).to.be.equal(BigInt(100)); - const transferTokenFromTx = async () => helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 100n); - await expect(transferTokenFromTx()).to.be.rejected; - }); + itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => { + const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n}); + await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}, 100n); + const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address}); + await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 100n); + const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address}); + expect(after - before).to.be.equal(BigInt(100)); + const transferTokenFromTx = async () => helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 100n); + await expect(transferTokenFromTx()).to.be.rejected; }); }); @@ -280,28 +234,27 @@ let dave: IKeyringPair; before(async () => { - await usingPlaygrounds(async (helper) => { + await usingPlaygrounds(async (helper, privateKey) => { + const donor = privateKey('//Alice'); [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor); }); }); - 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 () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0); - await helper.ft.mintTokens(alice, collectionId, alice.address, 10n); - const tokenId = await helper.ft.getLastTokenId(collectionId); - await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 10n); + 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}) => { + const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0); + await helper.ft.mintTokens(alice, collectionId, 10n, alice.address); + const tokenId = await helper.ft.getLastTokenId(collectionId); + await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 10n); - const charlieBefore = await helper.ft.getBalance(collectionId, {Substrate: charlie.address}); - await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address}, 2n); - const charlieAfter = await helper.ft.getBalance(collectionId, {Substrate: charlie.address}); - expect(charlieAfter - charlieBefore).to.be.equal(BigInt(2)); + const charlieBefore = await helper.ft.getBalance(collectionId, {Substrate: charlie.address}); + await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address}, 2n); + const charlieAfter = await helper.ft.getBalance(collectionId, {Substrate: charlie.address}); + expect(charlieAfter - charlieBefore).to.be.equal(BigInt(2)); - const daveBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address}); - await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: alice.address}, {Substrate: dave.address}, 8n); - const daveAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address}); - expect(daveAfter - daveBefore).to.be.equal(BigInt(8)); - }); + const daveBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address}); + await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: alice.address}, {Substrate: dave.address}, 8n); + const daveAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address}); + expect(daveAfter - daveBefore).to.be.equal(BigInt(8)); }); }); @@ -311,57 +264,52 @@ let charlie: IKeyringPair; before(async () => { - await usingPlaygrounds(async (helper) => { + await usingPlaygrounds(async (helper, privateKey) => { + const donor = privateKey('//Alice'); [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor); }); }); - it('NFT', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address}); - await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}); - expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true; - await helper.signTransaction(alice, helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0)); - expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false; - const transferTokenFromTx = async () => helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: bob.address}); - await expect(transferTokenFromTx()).to.be.rejected; - }); + itSub('NFT', async ({helper}) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address}); + await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}); + expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true; + await helper.signTransaction(alice, helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0)); + expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false; + const transferTokenFromTx = async () => helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: bob.address}); + await expect(transferTokenFromTx()).to.be.rejected; }); - it('Fungible', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0); - await helper.ft.mintTokens(alice, collectionId, alice.address, 10n); - const tokenId = await helper.ft.getLastTokenId(collectionId); - await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}); - const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); - expect(amountBefore).to.be.equal(BigInt(1)); + itSub('Fungible', async ({helper}) => { + const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0); + await helper.ft.mintTokens(alice, collectionId, 10n, alice.address); + const tokenId = await helper.ft.getLastTokenId(collectionId); + await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}); + const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); + expect(amountBefore).to.be.equal(BigInt(1)); - await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n); - const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); - expect(amountAfter).to.be.equal(BigInt(0)); + await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n); + const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); + expect(amountAfter).to.be.equal(BigInt(0)); - const transferTokenFromTx = async () => helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 1n); - await expect(transferTokenFromTx()).to.be.rejected; - }); + const transferTokenFromTx = async () => helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 1n); + await expect(transferTokenFromTx()).to.be.rejected; }); - it('ReFungible', async function() { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n}); - await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}); - const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); - expect(amountBefore).to.be.equal(BigInt(1)); + itSub.ifWithPallets('ReFungible', [Pallets.ReFungible], async ({helper}) => { + const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n}); + await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}); + const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); + expect(amountBefore).to.be.equal(BigInt(1)); - await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n); - const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); - expect(amountAfter).to.be.equal(BigInt(0)); + await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n); + const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}); + expect(amountAfter).to.be.equal(BigInt(0)); - const transferTokenFromTx = async () => helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 100n); - await expect(transferTokenFromTx()).to.be.rejected; - }); + const transferTokenFromTx = async () => helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 100n); + await expect(transferTokenFromTx()).to.be.rejected; }); }); @@ -371,38 +319,33 @@ let charlie: IKeyringPair; before(async () => { - await usingPlaygrounds(async (helper) => { + await usingPlaygrounds(async (helper, privateKey) => { + const donor = privateKey('//Alice'); [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor); }); }); - it('1 for NFT', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address}); - const approveTx = async () => helper.signTransaction(bob, helper.api?.tx.unique.approve({Substrate: charlie.address}, collectionId, tokenId, 2)); - await expect(approveTx()).to.be.rejected; - expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.false; - }); + itSub('1 for NFT', async ({helper}) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address}); + const approveTx = async () => helper.signTransaction(bob, helper.api?.tx.unique.approve({Substrate: charlie.address}, collectionId, tokenId, 2)); + await expect(approveTx()).to.be.rejected; + expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.false; }); - it('Fungible', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0); - await helper.ft.mintTokens(alice, collectionId, alice.address, 10n); - const tokenId = await helper.ft.getLastTokenId(collectionId); - const approveTx = async () => helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 11n); - await expect(approveTx()).to.be.rejected; - }); + itSub('Fungible', async ({helper}) => { + const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0); + await helper.ft.mintTokens(alice, collectionId, 10n, alice.address); + const tokenId = await helper.ft.getLastTokenId(collectionId); + const approveTx = async () => helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 11n); + await expect(approveTx()).to.be.rejected; }); - it('ReFungible', async function() { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n}); - const approveTx = async () => helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 101n); - await expect(approveTx()).to.be.rejected; - }); + itSub.ifWithPallets('ReFungible', [Pallets.ReFungible], async ({helper}) => { + const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n}); + const approveTx = async () => helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 101n); + await expect(approveTx()).to.be.rejected; }); }); @@ -413,67 +356,62 @@ let dave: IKeyringPair; before(async () => { - await usingPlaygrounds(async (helper) => { + await usingPlaygrounds(async (helper, privateKey) => { + const donor = privateKey('//Alice'); [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor); }); }); - it('NFT', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true}); - const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: charlie.address}); + itSub('NFT', async ({helper}) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true}); + const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: charlie.address}); - await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}); - const owner1 = await helper.nft.getTokenOwner(collectionId, tokenId); - expect(owner1.Substrate).to.be.equal(dave.address); + await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}); + const owner1 = await helper.nft.getTokenOwner(collectionId, tokenId); + expect(owner1.Substrate).to.be.equal(dave.address); - await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address}); - await helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}); - const owner2 = await helper.nft.getTokenOwner(collectionId, tokenId); - expect(owner2.Substrate).to.be.equal(alice.address); - }); + await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address}); + await helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}); + const owner2 = await helper.nft.getTokenOwner(collectionId, tokenId); + expect(owner2.Substrate).to.be.equal(alice.address); }); - it('Fungible up to an approved amount', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0); - await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true}); - await helper.ft.mintTokens(alice, collectionId, charlie.address, 10n); - const tokenId = await helper.ft.getLastTokenId(collectionId); + itSub('Fungible up to an approved amount', async ({helper}) => { + const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0); + await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true}); + await helper.ft.mintTokens(alice, collectionId, 10n, charlie.address); + const tokenId = await helper.ft.getLastTokenId(collectionId); - const daveBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address}); - await helper.ft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n); - const daveBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address}); - expect(daveBalanceAfter - daveBalanceBefore).to.be.equal(BigInt(1)); + const daveBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address}); + await helper.ft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n); + const daveBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address}); + expect(daveBalanceAfter - daveBalanceBefore).to.be.equal(BigInt(1)); - await helper.collection.addAdmin(alice ,collectionId, {Substrate: bob.address}); + await helper.collection.addAdmin(alice ,collectionId, {Substrate: bob.address}); - const aliceBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: alice.address}); - await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n); - const aliceBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: alice.address}); - expect(aliceBalanceAfter - aliceBalanceBefore).to.be.equal(BigInt(1)); - }); + const aliceBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: alice.address}); + await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n); + const aliceBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: alice.address}); + expect(aliceBalanceAfter - aliceBalanceBefore).to.be.equal(BigInt(1)); }); - it('ReFungible up to an approved amount', async function() { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true}); - const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: charlie.address, pieces: 100n}); + itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => { + const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true}); + const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: charlie.address, pieces: 100n}); - const daveBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address}); - await helper.rft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n); - const daveAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address}); - expect(daveAfter - daveBefore).to.be.equal(BigInt(1)); + const daveBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address}); + await helper.rft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n); + const daveAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address}); + expect(daveAfter - daveBefore).to.be.equal(BigInt(1)); - await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address}); + await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address}); - const aliceBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address}); - await helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n); - const aliceAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address}); - expect(aliceAfter - aliceBefore).to.be.equal(BigInt(1)); - }); + const aliceBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address}); + await helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n); + const aliceAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address}); + expect(aliceAfter - aliceBefore).to.be.equal(BigInt(1)); }); }); @@ -484,45 +422,48 @@ let dave: IKeyringPair; before(async () => { - await usingPlaygrounds(async (helper) => { + await usingPlaygrounds(async (helper, privateKey) => { + const donor = privateKey('//Alice'); [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor); }); }); - it.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. Fungible', async () => { - const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}}); - await createItemExpectSuccess(alice, collectionId, 'Fungible', alice.address); - await approveExpectSuccess(collectionId, 0, alice, bob.address, 1); - await approveExpectSuccess(collectionId, 0, alice, charlie.address, 1); + itSub.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. Fungible', async ({helper}) => { + const collection = await helper.ft.mintCollection(alice, {}); + await collection.mint(alice, 10n); + await collection.approveTokens(alice, {Substrate: bob.address}, 1n); + await collection.approveTokens(alice, {Substrate: charlie.address}, 1n); // const allowances1 = await getAllowance(collectionId, 0, Alice.address, Bob.address); // const allowances2 = await getAllowance(collectionId, 0, Alice.address, Charlie.address); // expect(allowances1 + allowances2).to.be.eq(BigInt(2)); }); - it.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. ReFungible', async () => { - const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}}); - const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', alice.address); - await approveExpectSuccess(collectionId, itemId, alice, bob.address, 1); - await approveExpectSuccess(collectionId, itemId, alice, charlie.address, 1); + itSub.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. ReFungible', async ({helper}) => { + const collection = await helper.rft.mintCollection(alice, {}); + const token = await collection.mintToken(alice, 10n); + await token.approve(alice, {Substrate: bob.address}, 1n); + await token.approve(alice, {Substrate: charlie.address}, 1n); // const allowances1 = await getAllowance(collectionId, itemId, Alice.address, Bob.address); // const allowances2 = await getAllowance(collectionId, itemId, Alice.address, Charlie.address); // expect(allowances1 + allowances2).to.be.eq(BigInt(2)); }); // Canceled by changing approve logic - 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 () => { - const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}}); - await createItemExpectSuccess(alice, collectionId, 'Fungible', dave.address); - await approveExpectSuccess(collectionId, 0, dave, bob.address, 5); - await approveExpectFail(collectionId, 0, dave, charlie, 6); + 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}) => { + const collection = await helper.ft.mintCollection(alice, {}); + await collection.mint(alice, 10n, {Substrate: dave.address}); + await collection.approveTokens(dave, {Substrate: bob.address}, 5n); + await expect(collection.approveTokens(dave, {Substrate: charlie.address}, 6n)) + .to.be.rejectedWith('this test would fail (since it is skipped), replace this expecting message with what would have been received'); }); // Canceled by changing approve logic - it.skip('Cannot approve for more than total users amount (owned: 100, approval 1: 50 - should succeed, approval 2: 51 - should fail). ReFungible', async () => { - const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}}); - const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', dave.address); - await approveExpectSuccess(collectionId, itemId, dave, bob.address, 50); - await approveExpectFail(collectionId, itemId, dave, charlie, 51); + 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}) => { + const collection = await helper.rft.mintCollection(alice, {}); + const token = await collection.mintToken(alice, 100n, {Substrate: dave.address}); + await token.approve(dave, {Substrate: bob.address}, 50n); + await expect(token.approve(dave, {Substrate: charlie.address}, 51n)) + .to.be.rejectedWith('this test would fail (since it is skipped), replace this expecting message with what would have been received'); }); }); @@ -532,19 +473,18 @@ let charlie: IKeyringPair; before(async () => { - await usingPlaygrounds(async (helper) => { + await usingPlaygrounds(async (helper, privateKey) => { + const donor = privateKey('//Alice'); [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor); }); }); - it('can be called by collection admin on non-owned item', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address}); - await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address}); - const approveTx = async () => helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}); - await expect(approveTx()).to.be.rejected; - }); + itSub('can be called by collection admin on non-owned item', async ({helper}) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address}); + await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address}); + const approveTx = async () => helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}); + await expect(approveTx()).to.be.rejected; }); }); @@ -554,139 +494,112 @@ let charlie: IKeyringPair; before(async () => { - await usingPlaygrounds(async (helper) => { + await usingPlaygrounds(async (helper, privateKey) => { + const donor = privateKey('//Alice'); [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor); }); }); - it('[nft] Approve for a collection that does not exist', async () => { - await usingPlaygrounds(async (helper) => { - const collectionId = 1 << 32 - 1; - const approveTx = async () => helper.nft.approveToken(bob, collectionId, 1, {Substrate: charlie.address}); - await expect(approveTx()).to.be.rejected; - }); + itSub('[nft] Approve for a collection that does not exist', async ({helper}) => { + const collectionId = 1 << 32 - 1; + const approveTx = async () => helper.nft.approveToken(bob, collectionId, 1, {Substrate: charlie.address}); + await expect(approveTx()).to.be.rejected; }); - it('[fungible] Approve for a collection that does not exist', async () => { - await usingPlaygrounds(async (helper) => { - const collectionId = 1 << 32 - 1; - const approveTx = async () => helper.ft.approveToken(bob, collectionId, 1, {Substrate: charlie.address}); - await expect(approveTx()).to.be.rejected; - }); + itSub('[fungible] Approve for a collection that does not exist', async ({helper}) => { + const collectionId = 1 << 32 - 1; + const approveTx = async () => helper.ft.approveToken(bob, collectionId, 1, {Substrate: charlie.address}); + await expect(approveTx()).to.be.rejected; }); - it('[refungible] Approve for a collection that does not exist', async function() { - await usingPlaygrounds(async (helper) => { - const collectionId = 1 << 32 - 1; - const approveTx = async () => helper.rft.approveToken(bob, collectionId, 1, {Substrate: charlie.address}); - await expect(approveTx()).to.be.rejected; - }); + itSub.ifWithPallets('[refungible] Approve for a collection that does not exist', [Pallets.ReFungible], async ({helper}) => { + const collectionId = 1 << 32 - 1; + const approveTx = async () => helper.rft.approveToken(bob, collectionId, 1, {Substrate: charlie.address}); + await expect(approveTx()).to.be.rejected; }); - it('[nft] Approve for a collection that was destroyed', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - await helper.nft.burn(alice, collectionId); - const approveTx = async () => helper.nft.approveToken(alice, collectionId, 1, {Substrate: bob.address}); - await expect(approveTx()).to.be.rejected; - }); + itSub('[nft] Approve for a collection that was destroyed', async ({helper}) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.nft.burn(alice, collectionId); + const approveTx = async () => helper.nft.approveToken(alice, collectionId, 1, {Substrate: bob.address}); + await expect(approveTx()).to.be.rejected; }); - it('[fungible] Approve for a collection that was destroyed', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - await helper.ft.burn(alice, collectionId); - const approveTx = async () => helper.ft.approveToken(alice, collectionId, 1, {Substrate: bob.address}); - await expect(approveTx()).to.be.rejected; - }); + itSub('[fungible] Approve for a collection that was destroyed', async ({helper}) => { + const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.ft.burn(alice, collectionId); + const approveTx = async () => helper.ft.approveToken(alice, collectionId, 1, {Substrate: bob.address}); + await expect(approveTx()).to.be.rejected; }); - it('[refungible] Approve for a collection that was destroyed', async function() { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - await helper.rft.burn(alice, collectionId); - const approveTx = async () => helper.rft.approveToken(alice, collectionId, 1, {Substrate: bob.address}); - await expect(approveTx()).to.be.rejected; - }); + itSub.ifWithPallets('[refungible] Approve for a collection that was destroyed', [Pallets.ReFungible], async ({helper}) => { + const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.rft.burn(alice, collectionId); + const approveTx = async () => helper.rft.approveToken(alice, collectionId, 1, {Substrate: bob.address}); + await expect(approveTx()).to.be.rejected; }); - - it('[nft] Approve transfer of a token that does not exist', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const approveTx = async () => helper.nft.approveToken(alice, collectionId, 2, {Substrate: bob.address}); - await expect(approveTx()).to.be.rejected; - }); + + itSub('[nft] Approve transfer of a token that does not exist', async ({helper}) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const approveTx = async () => helper.nft.approveToken(alice, collectionId, 2, {Substrate: bob.address}); + await expect(approveTx()).to.be.rejected; }); - it('[refungible] Approve transfer of a token that does not exist', async function() { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const approveTx = async () => helper.rft.approveToken(alice, collectionId, 2, {Substrate: bob.address}); - await expect(approveTx()).to.be.rejected; - }); + itSub.ifWithPallets('[refungible] Approve transfer of a token that does not exist', [Pallets.ReFungible], async ({helper}) => { + const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const approveTx = async () => helper.rft.approveToken(alice, collectionId, 2, {Substrate: bob.address}); + await expect(approveTx()).to.be.rejected; }); - it('[nft] Approve using the address that does not own the approved token', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address}); - const approveTx = async () => helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}); - await expect(approveTx()).to.be.rejected; - }); + itSub('[nft] Approve using the address that does not own the approved token', async ({helper}) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address}); + const approveTx = async () => helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}); + await expect(approveTx()).to.be.rejected; }); - it('[fungible] Approve using the address that does not own the approved token', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - await helper.ft.mintTokens(alice, collectionId, alice.address, 10n); - const tokenId = await helper.ft.getLastTokenId(collectionId); - const approveTx = async () => helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}); - await expect(approveTx()).to.be.rejected; - }); + itSub('[fungible] Approve using the address that does not own the approved token', async ({helper}) => { + const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.ft.mintTokens(alice, collectionId, 10n, alice.address); + const tokenId = await helper.ft.getLastTokenId(collectionId); + const approveTx = async () => helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}); + await expect(approveTx()).to.be.rejected; }); - it('[refungible] Approve using the address that does not own the approved token', async function() { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n}); - const approveTx = async () => helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}); - await expect(approveTx()).to.be.rejected; - }); + itSub.ifWithPallets('[refungible] Approve using the address that does not own the approved token', [Pallets.ReFungible], async ({helper}) => { + const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n}); + const approveTx = async () => helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}); + await expect(approveTx()).to.be.rejected; }); - it('should fail if approved more ReFungibles than owned', async function() { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n}); - await helper.rft.transferToken(alice, collectionId, tokenId, {Substrate: bob.address}, 100n); - await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 100n); + itSub.ifWithPallets('should fail if approved more ReFungibles than owned', [Pallets.ReFungible], async ({helper}) => { + const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n}); + await helper.rft.transferToken(alice, collectionId, tokenId, {Substrate: bob.address}, 100n); + await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 100n); - const approveTx = async () => helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 101n); - await expect(approveTx()).to.be.rejected; - }); + const approveTx = async () => helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 101n); + await expect(approveTx()).to.be.rejected; }); - it('should fail if approved more Fungibles than owned', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - await helper.ft.mintTokens(alice, collectionId, alice.address, 10n); - const tokenId = await helper.ft.getLastTokenId(collectionId); + itSub('should fail if approved more Fungibles than owned', async ({helper}) => { + const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.ft.mintTokens(alice, collectionId, 10n, alice.address); + const tokenId = await helper.ft.getLastTokenId(collectionId); - await helper.ft.transferToken(alice, collectionId, tokenId, {Substrate: bob.address}, 10n); - await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 10n); - const approveTx = async () => helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 11n); - await expect(approveTx()).to.be.rejected; - }); + await helper.ft.transferToken(alice, collectionId, tokenId, {Substrate: bob.address}, 10n); + await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 10n); + const approveTx = async () => helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 11n); + await expect(approveTx()).to.be.rejected; }); - it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => { - await usingPlaygrounds(async (helper) => { - const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); - const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address}); - await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: false}); + itSub('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address}); + await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: false}); - const approveTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address}); - await expect(approveTx()).to.be.rejected; - }); + const approveTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address}); + await expect(approveTx()).to.be.rejected; }); });