From b1123c37498facd6f39810fc152f657ef1ddab6f Mon Sep 17 00:00:00 2001 From: rkv Date: Wed, 07 Sep 2022 08:38:58 +0000 Subject: [PATCH] allowLists migrated --- --- a/tests/src/allowLists.test.ts +++ b/tests/src/allowLists.test.ts @@ -17,31 +17,19 @@ import {IKeyringPair} from '@polkadot/types/types'; import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; -import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api'; -import { - addToAllowListExpectSuccess, - createCollectionExpectSuccess, - createItemExpectSuccess, - destroyCollectionExpectSuccess, - enableAllowListExpectSuccess, - normalizeAccountId, - addCollectionAdminExpectSuccess, - addToAllowListExpectFail, - removeFromAllowListExpectSuccess, - removeFromAllowListExpectFailure, - addToAllowListAgainExpectSuccess, - transferExpectFailure, - approveExpectSuccess, - approveExpectFail, - transferExpectSuccess, - transferFromExpectSuccess, - setMintPermissionExpectSuccess, - createItemExpectFailure, -} from './util/helpers'; +import { usingPlaygrounds } from './util/playgrounds'; chai.use(chaiAsPromised); const expect = chai.expect; +let donor: IKeyringPair; + +before(async () => { + await usingPlaygrounds(async (_, privateKeyWrapper) => { + donor = privateKeyWrapper('//Alice'); + }); +}); + let alice: IKeyringPair; let bob: IKeyringPair; let charlie: IKeyringPair; @@ -49,266 +37,363 @@ describe('Integration Test ext. Allow list tests', () => { before(async () => { - await usingApi(async (api, privateKeyWrapper) => { - alice = privateKeyWrapper('//Alice'); - bob = privateKeyWrapper('//Bob'); - charlie = privateKeyWrapper('//Charlie'); + await usingPlaygrounds(async (helper) => { + [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor); }); }); it('Owner can add address to allow list', async () => { - const collectionId = await createCollectionExpectSuccess(); - await addToAllowListExpectSuccess(alice, collectionId, bob.address); + await usingPlaygrounds(async (helper) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address}); + const allowList = await helper.nft.getAllowList(collectionId); + expect(allowList).to.be.deep.contains({Substrate: bob.address}); + }); }); it('Admin can add address to allow list', async () => { - const collectionId = await createCollectionExpectSuccess(); - await addCollectionAdminExpectSuccess(alice, collectionId, bob.address); - await addToAllowListExpectSuccess(bob, collectionId, charlie.address); + await usingPlaygrounds(async (helper) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address}); + + await helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address}); + const allowList = await helper.nft.getAllowList(collectionId); + expect(allowList).to.be.deep.contains({Substrate: charlie.address}); + }); }); it('Non-privileged user cannot add address to allow list', async () => { - const collectionId = await createCollectionExpectSuccess(); - await addToAllowListExpectFail(bob, collectionId, charlie.address); + await usingPlaygrounds(async (helper) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address}); + expect(addToAllowListTx()).to.be.rejected; + }); }); it('Nobody can add address to allow list of non-existing collection', async () => { const collectionId = (1<<32) - 1; - await addToAllowListExpectFail(alice, collectionId, bob.address); + await usingPlaygrounds(async (helper) => { + const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address}); + expect(addToAllowListTx()).to.be.rejected; + }); }); it('Nobody can add address to allow list of destroyed collection', async () => { - const collectionId = await createCollectionExpectSuccess(); - await destroyCollectionExpectSuccess(collectionId, '//Alice'); - await addToAllowListExpectFail(alice, collectionId, bob.address); + await usingPlaygrounds(async (helper) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.collection.burn(alice, collectionId); + const addToAllowListTx = async () => helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address}); + expect(addToAllowListTx()).to.be.rejected; + }); }); it('If address is already added to allow list, nothing happens', async () => { - const collectionId = await createCollectionExpectSuccess(); - await addToAllowListExpectSuccess(alice, collectionId, bob.address); - await addToAllowListAgainExpectSuccess(alice, collectionId, bob.address); + await usingPlaygrounds(async (helper) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address}); + const allowList = await helper.nft.getAllowList(collectionId); + expect(allowList).to.be.deep.contains({Substrate: bob.address}); + }); }); it('Owner can remove address from allow list', async () => { - const collectionId = await createCollectionExpectSuccess(); - await addToAllowListExpectSuccess(alice, collectionId, bob.address); - await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(bob)); + await usingPlaygrounds(async (helper) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address}); + + //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later. + await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(alice); + + const allowList = await helper.nft.getAllowList(collectionId); + + expect(allowList).to.be.not.deep.contains({Substrate: bob.address}); + }); }); it('Admin can remove address from allow list', async () => { - const collectionId = await createCollectionExpectSuccess(); - await addCollectionAdminExpectSuccess(alice, collectionId, bob.address); - await addToAllowListExpectSuccess(alice, collectionId, charlie.address); - await removeFromAllowListExpectSuccess(bob, collectionId, normalizeAccountId(charlie)); + await usingPlaygrounds(async (helper) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.nft.addAdmin(alice, collectionId, {Substrate: charlie.address}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address}); + //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later. + await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(charlie); + + const allowList = await helper.nft.getAllowList(collectionId); + + expect(allowList).to.be.not.deep.contains({Substrate: bob.address}); + }); }); it('Non-privileged user cannot remove address from allow list', async () => { - const collectionId = await createCollectionExpectSuccess(); - await addToAllowListExpectSuccess(alice, collectionId, charlie.address); - await removeFromAllowListExpectFailure(bob, collectionId, normalizeAccountId(charlie)); + await usingPlaygrounds(async (helper) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address}); + //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later. + await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: charlie.address}).signAndSend(bob); + + const allowList = await helper.nft.getAllowList(collectionId); + + expect(allowList).to.be.deep.contains({Substrate: charlie.address}); + }); }); it('Nobody can remove address from allow list of non-existing collection', async () => { const collectionId = (1<<32) - 1; - await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie)); + await usingPlaygrounds(async (helper) => { + //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later. + await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: charlie.address}).signAndSend(bob); + + const allowList = await helper.nft.getAllowList(collectionId); + + expect(allowList).to.be.not.deep.contains({Substrate: charlie.address}); + }); }); it('Nobody can remove address from allow list of deleted collection', async () => { - const collectionId = await createCollectionExpectSuccess(); - await addToAllowListExpectSuccess(alice, collectionId, charlie.address); - await destroyCollectionExpectSuccess(collectionId, '//Alice'); - await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie)); + await usingPlaygrounds(async (helper) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address}); + await helper.collection.burn(alice, collectionId); + + //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later. + const removeTx = async () => helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(alice); + + expect(removeTx()).to.be.rejected; + }); }); it('If address is already removed from allow list, nothing happens', async () => { - const collectionId = await createCollectionExpectSuccess(); - await addToAllowListExpectSuccess(alice, collectionId, charlie.address); - await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie)); - await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie)); + await usingPlaygrounds(async (helper) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address}); + + //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later. + await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(alice); + const allowListBefore = await helper.nft.getAllowList(collectionId); + expect(allowListBefore).to.be.not.deep.contains({Substrate: bob.address}); + + await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(alice); + + const allowListAfter = await helper.nft.getAllowList(collectionId); + expect(allowListAfter).to.be.not.deep.contains({Substrate: bob.address}); + }); }); it('If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom. Test1', async () => { - const collectionId = await createCollectionExpectSuccess(); - const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address); - await enableAllowListExpectSuccess(alice, collectionId); - await addToAllowListExpectSuccess(alice, collectionId, charlie.address); + 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.setPermissions(alice, collectionId, {access: 'AllowList'}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address}); - await transferExpectFailure( - collectionId, - itemId, - alice, - charlie, - 1, - ); + const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address}); + expect(transferResult()).to.be.rejected; + }); }); it('If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom. Test2', async () => { - const collectionId = await createCollectionExpectSuccess(); - const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address); - await enableAllowListExpectSuccess(alice, collectionId); - await addToAllowListExpectSuccess(alice, collectionId, alice.address); - await addToAllowListExpectSuccess(alice, collectionId, charlie.address); - await approveExpectSuccess(collectionId, itemId, alice, charlie.address); - await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice)); + 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.setPermissions(alice, collectionId, {access: 'AllowList'}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address}); + await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address}); - await transferExpectFailure( - collectionId, - itemId, - alice, - charlie, - 1, - ); + //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later. + await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: alice.address}).signAndSend(alice); + + const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address}); + expect(transferResult()).to.be.rejected; + }); }); it('If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom. Test1', async () => { - const collectionId = await createCollectionExpectSuccess(); - const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address); - await enableAllowListExpectSuccess(alice, collectionId); - await addToAllowListExpectSuccess(alice, collectionId, alice.address); + 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.setPermissions(alice, collectionId, {access: 'AllowList'}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address}); - await transferExpectFailure( - collectionId, - itemId, - alice, - charlie, - 1, - ); + const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address}); + expect(transferResult()).to.be.rejected; + }); }); it('If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom. Test2', async () => { - const collectionId = await createCollectionExpectSuccess(); - const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address); - await enableAllowListExpectSuccess(alice, collectionId); - await addToAllowListExpectSuccess(alice, collectionId, alice.address); - await addToAllowListExpectSuccess(alice, collectionId, charlie.address); - await approveExpectSuccess(collectionId, itemId, alice, charlie.address); - await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice)); + 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.setPermissions(alice, collectionId, {access: 'AllowList'}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address}); - await transferExpectFailure( - collectionId, - itemId, - alice, - charlie, - 1, - ); + await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address}); + + //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later. + await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: alice.address}).signAndSend(alice); + + const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address}); + expect(transferResult()).to.be.rejected; + }); }); it('If Public Access mode is set to AllowList, tokens can’t be destroyed by a non-allowlisted address (even if it owned them before enabling AllowList mode)', async () => { - const collectionId = await createCollectionExpectSuccess(); - const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address); - await enableAllowListExpectSuccess(alice, collectionId); - - await usingApi(async (api) => { - const tx = api.tx.unique.burnItem(collectionId, itemId, /*normalizeAccountId(Alice.address),*/ 11); - const badTransaction = async function () { - await submitTransactionExpectFailAsync(alice, tx); - }; - await expect(badTransaction()).to.be.rejected; + 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.setPermissions(alice, collectionId, {access: 'AllowList'}); + const burnTx = async () => helper.nft.burnToken(bob, collectionId, tokenId); + expect(burnTx()).to.be.rejected; }); }); it('If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method)', async () => { - const collectionId = await createCollectionExpectSuccess(); - const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address); - await enableAllowListExpectSuccess(alice, collectionId); - await approveExpectFail(collectionId, itemId, alice, bob); + 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.setPermissions(alice, collectionId, {access: 'AllowList'}); + const approveTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}); + await expect(approveTx()).to.be.rejected; + }); }); it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async () => { - const collectionId = await createCollectionExpectSuccess(); - const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address); - await enableAllowListExpectSuccess(alice, collectionId); - await addToAllowListExpectSuccess(alice, collectionId, alice.address); - await addToAllowListExpectSuccess(alice, collectionId, charlie.address); - await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT'); + 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.setPermissions(alice, collectionId, {access: 'AllowList'}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address}); + await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address}); + const owner = await helper.nft.getTokenOwner(collectionId, tokenId); + expect(owner.Substrate).to.be.equal(charlie.address); + }); }); - it('If Public Access mode is set to AllowList, tokens can be transferred to a alowlisted address with transferFrom.', async () => { - const collectionId = await createCollectionExpectSuccess(); - const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address); - await enableAllowListExpectSuccess(alice, collectionId); - await addToAllowListExpectSuccess(alice, collectionId, alice.address); - await addToAllowListExpectSuccess(alice, collectionId, charlie.address); - await approveExpectSuccess(collectionId, itemId, alice, charlie.address); - await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT'); + it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transferFrom.', 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.setPermissions(alice, collectionId, {access: 'AllowList'}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address}); + await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address}); + + await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address}); + const owner = await helper.nft.getTokenOwner(collectionId, tokenId); + expect(owner.Substrate).to.be.equal(charlie.address); + }); }); it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async () => { - const collectionId = await createCollectionExpectSuccess(); - const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address); - await enableAllowListExpectSuccess(alice, collectionId); - await addToAllowListExpectSuccess(alice, collectionId, alice.address); - await addToAllowListExpectSuccess(alice, collectionId, charlie.address); - await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT'); + 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.setPermissions(alice, collectionId, {access: 'AllowList'}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address}); + + await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address}); + const owner = await helper.nft.getTokenOwner(collectionId, tokenId); + expect(owner.Substrate).to.be.equal(charlie.address); + }); }); it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async () => { - const collectionId = await createCollectionExpectSuccess(); - const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address); - await enableAllowListExpectSuccess(alice, collectionId); - await addToAllowListExpectSuccess(alice, collectionId, alice.address); - await addToAllowListExpectSuccess(alice, collectionId, charlie.address); - await approveExpectSuccess(collectionId, itemId, alice, charlie.address); - await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT'); + 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.setPermissions(alice, collectionId, {access: 'AllowList'}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address}); + await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address}); + + await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address}); + const owner = await helper.nft.getTokenOwner(collectionId, tokenId); + expect(owner.Substrate).to.be.equal(charlie.address); + }); }); it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner', async () => { - const collectionId = await createCollectionExpectSuccess(); - await enableAllowListExpectSuccess(alice, collectionId); - await setMintPermissionExpectSuccess(alice, collectionId, false); - await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address); + await usingPlaygrounds(async (helper) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false}); + const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address}); + const token = await helper.nft.getToken(collectionId, tokenId); + expect(token).to.be.not.null; + }); }); it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin', async () => { - const collectionId = await createCollectionExpectSuccess(); - await enableAllowListExpectSuccess(alice, collectionId); - await setMintPermissionExpectSuccess(alice, collectionId, false); - await addCollectionAdminExpectSuccess(alice, collectionId, bob.address); - await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address); + await usingPlaygrounds(async (helper) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false}); + await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address}); + const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address}); + const token = await helper.nft.getToken(collectionId, tokenId); + expect(token).to.be.not.null; + }); }); it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and allow-listed address', async () => { - const collectionId = await createCollectionExpectSuccess(); - await enableAllowListExpectSuccess(alice, collectionId); - await setMintPermissionExpectSuccess(alice, collectionId, false); - await addToAllowListExpectSuccess(alice, collectionId, bob.address); - await createItemExpectFailure(bob, collectionId, 'NFT', bob.address); + await usingPlaygrounds(async (helper) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false}); + await helper.collection.addToAllowList(alice, collectionId, {Substrate: bob.address}); + const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address}); + await expect(mintTokenTx()).to.be.rejected; + }); }); it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-allow listed address', async () => { - const collectionId = await createCollectionExpectSuccess(); - await enableAllowListExpectSuccess(alice, collectionId); - await setMintPermissionExpectSuccess(alice, collectionId, false); - await createItemExpectFailure(bob, collectionId, 'NFT', bob.address); + await usingPlaygrounds(async (helper) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false}); + const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address}); + await expect(mintTokenTx()).to.be.rejected; + }); }); it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner', async () => { - const collectionId = await createCollectionExpectSuccess(); - await enableAllowListExpectSuccess(alice, collectionId); - await setMintPermissionExpectSuccess(alice, collectionId, true); - await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address); + await usingPlaygrounds(async (helper) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true}); + const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address}); + const owner = await helper.nft.getTokenOwner(collectionId, tokenId); + expect(owner.Substrate).to.be.equal(alice.address); + }); }); it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin', async () => { - const collectionId = await createCollectionExpectSuccess(); - await enableAllowListExpectSuccess(alice, collectionId); - await setMintPermissionExpectSuccess(alice, collectionId, true); - await addCollectionAdminExpectSuccess(alice, collectionId, bob.address); - await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address); + await usingPlaygrounds(async (helper) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true}); + await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address}); + const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address}); + const owner = await helper.nft.getTokenOwner(collectionId, tokenId); + expect(owner.Substrate).to.be.equal(bob.address); + }); }); it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-allow listed address', async () => { - const collectionId = await createCollectionExpectSuccess(); - await enableAllowListExpectSuccess(alice, collectionId); - await setMintPermissionExpectSuccess(alice, collectionId, true); - await createItemExpectFailure(bob, collectionId, 'NFT', bob.address); + await usingPlaygrounds(async (helper) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true}); + const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address}); + await expect(mintTokenTx()).to.be.rejected; + }); }); it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by non-privileged and allow listed address', async () => { - const collectionId = await createCollectionExpectSuccess(); - await enableAllowListExpectSuccess(alice, collectionId); - await setMintPermissionExpectSuccess(alice, collectionId, true); - await addToAllowListExpectSuccess(alice, collectionId, bob.address); - await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address); + await usingPlaygrounds(async (helper) => { + const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true}); + await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address}); + const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address}); + const owner = await helper.nft.getTokenOwner(collectionId, tokenId); + expect(owner.Substrate).to.be.equal(bob.address); + }); }); }); -- gitstuff