difftreelog
allowLists migrated
in: master
1 file changed
tests/src/allowLists.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';21import {22 addToAllowListExpectSuccess,23 createCollectionExpectSuccess,24 createItemExpectSuccess,25 destroyCollectionExpectSuccess,26 enableAllowListExpectSuccess,27 normalizeAccountId,28 addCollectionAdminExpectSuccess,29 addToAllowListExpectFail,30 removeFromAllowListExpectSuccess,31 removeFromAllowListExpectFailure,32 addToAllowListAgainExpectSuccess,33 transferExpectFailure,34 approveExpectSuccess,35 approveExpectFail,36 transferExpectSuccess,37 transferFromExpectSuccess,38 setMintPermissionExpectSuccess,39 createItemExpectFailure,40} from './util/helpers';4142chai.use(chaiAsPromised);43const expect = chai.expect;4445let alice: IKeyringPair;46let bob: IKeyringPair;47let charlie: IKeyringPair;4849describe('Integration Test ext. Allow list tests', () => {5051 before(async () => {52 await usingApi(async (api, privateKeyWrapper) => {53 alice = privateKeyWrapper('//Alice');54 bob = privateKeyWrapper('//Bob');55 charlie = privateKeyWrapper('//Charlie');56 });57 });5859 it('Owner can add address to allow list', async () => {60 const collectionId = await createCollectionExpectSuccess();61 await addToAllowListExpectSuccess(alice, collectionId, bob.address);62 });6364 it('Admin can add address to allow list', async () => {65 const collectionId = await createCollectionExpectSuccess();66 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);67 await addToAllowListExpectSuccess(bob, collectionId, charlie.address);68 });6970 it('Non-privileged user cannot add address to allow list', async () => {71 const collectionId = await createCollectionExpectSuccess();72 await addToAllowListExpectFail(bob, collectionId, charlie.address);73 });7475 it('Nobody can add address to allow list of non-existing collection', async () => {76 const collectionId = (1<<32) - 1;77 await addToAllowListExpectFail(alice, collectionId, bob.address);78 });7980 it('Nobody can add address to allow list of destroyed collection', async () => {81 const collectionId = await createCollectionExpectSuccess();82 await destroyCollectionExpectSuccess(collectionId, '//Alice');83 await addToAllowListExpectFail(alice, collectionId, bob.address);84 });8586 it('If address is already added to allow list, nothing happens', async () => {87 const collectionId = await createCollectionExpectSuccess();88 await addToAllowListExpectSuccess(alice, collectionId, bob.address);89 await addToAllowListAgainExpectSuccess(alice, collectionId, bob.address);90 });9192 it('Owner can remove address from allow list', async () => {93 const collectionId = await createCollectionExpectSuccess();94 await addToAllowListExpectSuccess(alice, collectionId, bob.address);95 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(bob));96 });9798 it('Admin can remove address from allow list', async () => {99 const collectionId = await createCollectionExpectSuccess();100 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);101 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);102 await removeFromAllowListExpectSuccess(bob, collectionId, normalizeAccountId(charlie));103 });104105 it('Non-privileged user cannot remove address from allow list', async () => {106 const collectionId = await createCollectionExpectSuccess();107 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);108 await removeFromAllowListExpectFailure(bob, collectionId, normalizeAccountId(charlie));109 });110111 it('Nobody can remove address from allow list of non-existing collection', async () => {112 const collectionId = (1<<32) - 1;113 await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie));114 });115116 it('Nobody can remove address from allow list of deleted collection', async () => {117 const collectionId = await createCollectionExpectSuccess();118 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);119 await destroyCollectionExpectSuccess(collectionId, '//Alice');120 await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie));121 });122123 it('If address is already removed from allow list, nothing happens', async () => {124 const collectionId = await createCollectionExpectSuccess();125 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);126 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));127 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));128 });129130 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 () => {131 const collectionId = await createCollectionExpectSuccess();132 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);133 await enableAllowListExpectSuccess(alice, collectionId);134 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);135136 await transferExpectFailure(137 collectionId,138 itemId,139 alice,140 charlie,141 1,142 );143 });144145 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 () => {146 const collectionId = await createCollectionExpectSuccess();147 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);148 await enableAllowListExpectSuccess(alice, collectionId);149 await addToAllowListExpectSuccess(alice, collectionId, alice.address);150 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);151 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);152 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice));153154 await transferExpectFailure(155 collectionId,156 itemId,157 alice,158 charlie,159 1,160 );161 });162163 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 () => {164 const collectionId = await createCollectionExpectSuccess();165 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);166 await enableAllowListExpectSuccess(alice, collectionId);167 await addToAllowListExpectSuccess(alice, collectionId, alice.address);168169 await transferExpectFailure(170 collectionId,171 itemId,172 alice,173 charlie,174 1,175 );176 });177178 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 () => {179 const collectionId = await createCollectionExpectSuccess();180 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);181 await enableAllowListExpectSuccess(alice, collectionId);182 await addToAllowListExpectSuccess(alice, collectionId, alice.address);183 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);184 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);185 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice));186187 await transferExpectFailure(188 collectionId,189 itemId,190 alice,191 charlie,192 1,193 );194 });195196 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 () => {197 const collectionId = await createCollectionExpectSuccess();198 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);199 await enableAllowListExpectSuccess(alice, collectionId);200201 await usingApi(async (api) => {202 const tx = api.tx.unique.burnItem(collectionId, itemId, /*normalizeAccountId(Alice.address),*/ 11);203 const badTransaction = async function () {204 await submitTransactionExpectFailAsync(alice, tx);205 };206 await expect(badTransaction()).to.be.rejected;207 });208 });209210 it('If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method)', async () => {211 const collectionId = await createCollectionExpectSuccess();212 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);213 await enableAllowListExpectSuccess(alice, collectionId);214 await approveExpectFail(collectionId, itemId, alice, bob);215 });216217 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async () => {218 const collectionId = await createCollectionExpectSuccess();219 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);220 await enableAllowListExpectSuccess(alice, collectionId);221 await addToAllowListExpectSuccess(alice, collectionId, alice.address);222 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);223 await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');224 });225226 it('If Public Access mode is set to AllowList, tokens can be transferred to a alowlisted address with transferFrom.', async () => {227 const collectionId = await createCollectionExpectSuccess();228 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);229 await enableAllowListExpectSuccess(alice, collectionId);230 await addToAllowListExpectSuccess(alice, collectionId, alice.address);231 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);232 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);233 await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');234 });235236 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async () => {237 const collectionId = await createCollectionExpectSuccess();238 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);239 await enableAllowListExpectSuccess(alice, collectionId);240 await addToAllowListExpectSuccess(alice, collectionId, alice.address);241 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);242 await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');243 });244245 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async () => {246 const collectionId = await createCollectionExpectSuccess();247 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);248 await enableAllowListExpectSuccess(alice, collectionId);249 await addToAllowListExpectSuccess(alice, collectionId, alice.address);250 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);251 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);252 await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');253 });254255 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner', async () => {256 const collectionId = await createCollectionExpectSuccess();257 await enableAllowListExpectSuccess(alice, collectionId);258 await setMintPermissionExpectSuccess(alice, collectionId, false);259 await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);260 });261262 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin', async () => {263 const collectionId = await createCollectionExpectSuccess();264 await enableAllowListExpectSuccess(alice, collectionId);265 await setMintPermissionExpectSuccess(alice, collectionId, false);266 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);267 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);268 });269270 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 () => {271 const collectionId = await createCollectionExpectSuccess();272 await enableAllowListExpectSuccess(alice, collectionId);273 await setMintPermissionExpectSuccess(alice, collectionId, false);274 await addToAllowListExpectSuccess(alice, collectionId, bob.address);275 await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);276 });277278 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 () => {279 const collectionId = await createCollectionExpectSuccess();280 await enableAllowListExpectSuccess(alice, collectionId);281 await setMintPermissionExpectSuccess(alice, collectionId, false);282 await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);283 });284285 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner', async () => {286 const collectionId = await createCollectionExpectSuccess();287 await enableAllowListExpectSuccess(alice, collectionId);288 await setMintPermissionExpectSuccess(alice, collectionId, true);289 await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);290 });291292 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin', async () => {293 const collectionId = await createCollectionExpectSuccess();294 await enableAllowListExpectSuccess(alice, collectionId);295 await setMintPermissionExpectSuccess(alice, collectionId, true);296 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);297 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);298 });299300 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 () => {301 const collectionId = await createCollectionExpectSuccess();302 await enableAllowListExpectSuccess(alice, collectionId);303 await setMintPermissionExpectSuccess(alice, collectionId, true);304 await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);305 });306307 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 () => {308 const collectionId = await createCollectionExpectSuccess();309 await enableAllowListExpectSuccess(alice, collectionId);310 await setMintPermissionExpectSuccess(alice, collectionId, true);311 await addToAllowListExpectSuccess(alice, collectionId, bob.address);312 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);313 });314});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import { usingPlaygrounds } from './util/playgrounds';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425let donor: IKeyringPair;2627before(async () => {28 await usingPlaygrounds(async (_, privateKeyWrapper) => {29 donor = privateKeyWrapper('//Alice');30 });31});3233let alice: IKeyringPair;34let bob: IKeyringPair;35let charlie: IKeyringPair;3637describe('Integration Test ext. Allow list tests', () => {3839 before(async () => {40 await usingPlaygrounds(async (helper) => {41 [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);42 });43 });4445 it('Owner can add address to allow list', async () => {46 await usingPlaygrounds(async (helper) => {47 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});48 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});49 const allowList = await helper.nft.getAllowList(collectionId);50 expect(allowList).to.be.deep.contains({Substrate: bob.address});51 });52 });5354 it('Admin can add address to allow list', async () => {55 await usingPlaygrounds(async (helper) => {56 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});57 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});5859 await helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});60 const allowList = await helper.nft.getAllowList(collectionId);61 expect(allowList).to.be.deep.contains({Substrate: charlie.address});62 });63 });6465 it('Non-privileged user cannot add address to allow list', async () => {66 await usingPlaygrounds(async (helper) => {67 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});68 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});69 expect(addToAllowListTx()).to.be.rejected;70 });71 });7273 it('Nobody can add address to allow list of non-existing collection', async () => {74 const collectionId = (1<<32) - 1;75 await usingPlaygrounds(async (helper) => {76 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});77 expect(addToAllowListTx()).to.be.rejected;78 });79 });8081 it('Nobody can add address to allow list of destroyed collection', async () => {82 await usingPlaygrounds(async (helper) => {83 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});84 await helper.collection.burn(alice, collectionId);85 const addToAllowListTx = async () => helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});86 expect(addToAllowListTx()).to.be.rejected;87 });88 });8990 it('If address is already added to allow list, nothing happens', async () => {91 await usingPlaygrounds(async (helper) => {92 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});93 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});94 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});95 const allowList = await helper.nft.getAllowList(collectionId);96 expect(allowList).to.be.deep.contains({Substrate: bob.address});97 });98 });99100 it('Owner can remove address from allow list', async () => {101 await usingPlaygrounds(async (helper) => {102 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});103 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});104105 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.106 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(alice);107108 const allowList = await helper.nft.getAllowList(collectionId);109110 expect(allowList).to.be.not.deep.contains({Substrate: bob.address});111 });112 });113114 it('Admin can remove address from allow list', async () => {115 await usingPlaygrounds(async (helper) => {116 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});117 await helper.nft.addAdmin(alice, collectionId, {Substrate: charlie.address});118 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});119 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.120 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(charlie);121122 const allowList = await helper.nft.getAllowList(collectionId);123124 expect(allowList).to.be.not.deep.contains({Substrate: bob.address});125 });126 });127128 it('Non-privileged user cannot remove address from allow list', async () => {129 await usingPlaygrounds(async (helper) => {130 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});131 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});132 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.133 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: charlie.address}).signAndSend(bob);134135 const allowList = await helper.nft.getAllowList(collectionId);136137 expect(allowList).to.be.deep.contains({Substrate: charlie.address});138 });139 });140141 it('Nobody can remove address from allow list of non-existing collection', async () => {142 const collectionId = (1<<32) - 1;143 await usingPlaygrounds(async (helper) => {144 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.145 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: charlie.address}).signAndSend(bob);146147 const allowList = await helper.nft.getAllowList(collectionId);148149 expect(allowList).to.be.not.deep.contains({Substrate: charlie.address});150 });151 });152153 it('Nobody can remove address from allow list of deleted collection', async () => {154 await usingPlaygrounds(async (helper) => {155 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});156 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});157 await helper.collection.burn(alice, collectionId);158159 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.160 const removeTx = async () => helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(alice);161162 expect(removeTx()).to.be.rejected;163 });164 });165166 it('If address is already removed from allow list, nothing happens', async () => {167 await usingPlaygrounds(async (helper) => {168 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});169 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});170171 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.172 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(alice);173 const allowListBefore = await helper.nft.getAllowList(collectionId);174 expect(allowListBefore).to.be.not.deep.contains({Substrate: bob.address});175176 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(alice);177178 const allowListAfter = await helper.nft.getAllowList(collectionId);179 expect(allowListAfter).to.be.not.deep.contains({Substrate: bob.address});180 });181 });182183 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 () => {184 await usingPlaygrounds(async (helper) => {185 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});186 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});187 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});188 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});189190 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});191 expect(transferResult()).to.be.rejected;192 });193 });194195 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 () => {196 await usingPlaygrounds(async (helper) => {197 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});198 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});199 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});200 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});201 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});202 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});203204 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.205 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: alice.address}).signAndSend(alice);206207 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});208 expect(transferResult()).to.be.rejected;209 });210 });211212 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 () => {213 await usingPlaygrounds(async (helper) => {214 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});215 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});216 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});217 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});218219 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});220 expect(transferResult()).to.be.rejected;221 });222 });223224 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 () => {225 await usingPlaygrounds(async (helper) => {226 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});227 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});228 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});229 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});230 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});231232 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});233234 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.235 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: alice.address}).signAndSend(alice);236237 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});238 expect(transferResult()).to.be.rejected;239 });240 });241242 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 () => {243 await usingPlaygrounds(async (helper) => {244 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});245 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});246 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});247 const burnTx = async () => helper.nft.burnToken(bob, collectionId, tokenId);248 expect(burnTx()).to.be.rejected;249 });250 });251252 it('If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method)', async () => {253 await usingPlaygrounds(async (helper) => {254 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});255 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});256 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});257 const approveTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});258 await expect(approveTx()).to.be.rejected;259 });260 });261262 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async () => {263 await usingPlaygrounds(async (helper) => {264 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});265 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});266 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});267 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});268 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});269 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});270 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);271 expect(owner.Substrate).to.be.equal(charlie.address);272 });273 });274275 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transferFrom.', async () => {276 await usingPlaygrounds(async (helper) => {277 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});278 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});279 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});280 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});281 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});282 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});283284 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});285 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);286 expect(owner.Substrate).to.be.equal(charlie.address);287 });288 });289290 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async () => {291 await usingPlaygrounds(async (helper) => {292 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});293 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});294 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});295 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});296 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});297298 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});299 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);300 expect(owner.Substrate).to.be.equal(charlie.address);301 });302 });303304 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async () => {305 await usingPlaygrounds(async (helper) => {306 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});307 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});308 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});309 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});310 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});311 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});312313 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});314 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);315 expect(owner.Substrate).to.be.equal(charlie.address);316 });317 });318319 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner', async () => {320 await usingPlaygrounds(async (helper) => {321 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});322 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});323 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});324 const token = await helper.nft.getToken(collectionId, tokenId);325 expect(token).to.be.not.null;326 });327 });328329 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin', async () => {330 await usingPlaygrounds(async (helper) => {331 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});332 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});333 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});334 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});335 const token = await helper.nft.getToken(collectionId, tokenId);336 expect(token).to.be.not.null;337 });338 });339340 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 () => {341 await usingPlaygrounds(async (helper) => {342 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});343 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});344 await helper.collection.addToAllowList(alice, collectionId, {Substrate: bob.address});345 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});346 await expect(mintTokenTx()).to.be.rejected;347 });348 });349350 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 () => {351 await usingPlaygrounds(async (helper) => {352 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});353 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});354 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});355 await expect(mintTokenTx()).to.be.rejected;356 });357 });358359 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner', async () => {360 await usingPlaygrounds(async (helper) => {361 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});362 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});363 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});364 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);365 expect(owner.Substrate).to.be.equal(alice.address);366 });367 });368369 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin', async () => {370 await usingPlaygrounds(async (helper) => {371 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});372 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});373 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});374 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});375 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);376 expect(owner.Substrate).to.be.equal(bob.address);377 });378 });379380 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 () => {381 await usingPlaygrounds(async (helper) => {382 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});383 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});384 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});385 await expect(mintTokenTx()).to.be.rejected;386 });387 });388389 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 () => {390 await usingPlaygrounds(async (helper) => {391 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});392 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});393 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});394 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});395 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);396 expect(owner.Substrate).to.be.equal(bob.address);397 });398 });399});