difftreelog
tests(allow-list): refactor overabundance of allow-list tests
in: master
8 files changed
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -48,7 +48,6 @@
"testConfirmSponsorship": "mocha --timeout 9999999 -r ts-node/register ./**/confirmSponsorship.test.ts",
"testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",
"testRemoveCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionSponsor.test.ts",
- "testRemoveFromAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromAllowList.test.ts",
"testAllowLists": "mocha --timeout 9999999 -r ts-node/register ./**/allowLists.test.ts",
"testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",
"testContracts": "mocha --timeout 9999999 -r ts-node/register ./**/contracts.test.ts",
@@ -64,8 +63,7 @@
"testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",
"testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",
"testAdminTransferAndBurn": "mocha --timeout 9999999 -r ts-node/register ./**/adminTransferAndBurn.test.ts",
- "testSetMintPermission": "mocha --timeout 9999999 -r ts-node/register ./**/setMintPermission.test.ts",
- "testSetPublicAccessMode": "mocha --timeout 9999999 -r ts-node/register ./**/setPublicAccessMode.test.ts",
+ "testSetPermissions": "mocha --timeout 9999999 -r ts-node/register ./**/setPermissions.test.ts",
"testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",
"testContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/contractSponsoring.test.ts",
"testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",
tests/src/addToAllowList.test.tsdiffbeforeafterboth--- a/tests/src/addToAllowList.test.ts
+++ /dev/null
@@ -1,135 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-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,
- enablePublicMintingExpectSuccess,
- enableAllowListExpectSuccess,
- normalizeAccountId,
- addCollectionAdminExpectSuccess,
- addToAllowListExpectFail,
- getCreatedCollectionCount,
-} from './util/helpers';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-
-let alice: IKeyringPair;
-let bob: IKeyringPair;
-let charlie: IKeyringPair;
-
-describe('Integration Test ext. addToAllowList()', () => {
-
- before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- alice = privateKeyWrapper('//Alice');
- bob = privateKeyWrapper('//Bob');
- });
- });
-
- it('Execute the extrinsic with parameters: Collection ID and address to add to the allow list', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addToAllowListExpectSuccess(alice, collectionId, bob.address);
- });
-
- it('Allowlisted minting: list restrictions', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addToAllowListExpectSuccess(alice, collectionId, bob.address);
- await enableAllowListExpectSuccess(alice, collectionId);
- await enablePublicMintingExpectSuccess(alice, collectionId);
- await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
- });
-});
-
-describe('Negative Integration Test ext. addToAllowList()', () => {
-
- it('Allow list an address in the collection that does not exist', async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- // tslint:disable-next-line: no-bitwise
- const collectionId = await getCreatedCollectionCount(api) + 1;
- const bob = privateKeyWrapper('//Bob');
-
- const tx = api.tx.unique.addToAllowList(collectionId, normalizeAccountId(bob.address));
- await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
- });
- });
-
- it('Allow list an address in the collection that was destroyed', async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- const alice = privateKeyWrapper('//Alice');
- const bob = privateKeyWrapper('//Bob');
- // tslint:disable-next-line: no-bitwise
- const collectionId = await createCollectionExpectSuccess();
- await destroyCollectionExpectSuccess(collectionId);
- const tx = api.tx.unique.addToAllowList(collectionId, normalizeAccountId(bob.address));
- await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
- });
- });
-
- it('Allow list an address in the collection that does not have allow list access enabled', async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- const alice = privateKeyWrapper('//Alice');
- const ferdie = privateKeyWrapper('//Ferdie');
- const collectionId = await createCollectionExpectSuccess();
- await enableAllowListExpectSuccess(alice, collectionId);
- await enablePublicMintingExpectSuccess(alice, collectionId);
- const tx = api.tx.unique.createItem(collectionId, normalizeAccountId(ferdie.address), 'NFT');
- await expect(submitTransactionExpectFailAsync(ferdie, tx)).to.be.rejected;
- });
- });
-
-});
-
-describe('Integration Test ext. addToAllowList() with collection admin permissions:', () => {
-
- before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- alice = privateKeyWrapper('//Alice');
- bob = privateKeyWrapper('//Bob');
- charlie = privateKeyWrapper('//Charlie');
- });
- });
-
- it('Negative. Add to the allow list by regular user', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addToAllowListExpectFail(bob, collectionId, charlie.address);
- });
-
- it('Execute the extrinsic with parameters: Collection ID and address to add to the allow list', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- await addToAllowListExpectSuccess(bob, collectionId, charlie.address);
- });
-
- it('Allowlisted minting: list restrictions', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- await addToAllowListExpectSuccess(bob, collectionId, charlie.address);
-
- // allowed only for collection owner
- await enableAllowListExpectSuccess(alice, collectionId);
- await enablePublicMintingExpectSuccess(alice, collectionId);
-
- await createItemExpectSuccess(charlie, collectionId, 'NFT', charlie.address);
- });
-});
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 {usingPlaygrounds} from './util/playgrounds';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425let donor: IKeyringPair;2627let alice: IKeyringPair;28let bob: IKeyringPair;29let charlie: IKeyringPair;3031describe('Integration Test ext. Allow list tests', () => {3233 before(async () => {34 await usingPlaygrounds(async (helper, privateKey) => {35 donor = privateKey('//Alice');36 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);37 });38 });3940 it('Owner can add address to allow list', async () => {41 await usingPlaygrounds(async (helper) => {42 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});43 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});44 const allowList = await helper.nft.getAllowList(collectionId);45 expect(allowList).to.be.deep.contains({Substrate: bob.address});46 });47 });4849 it('Admin can add address to allow list', async () => {50 await usingPlaygrounds(async (helper) => {51 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});52 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});5354 await helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});55 const allowList = await helper.nft.getAllowList(collectionId);56 expect(allowList).to.be.deep.contains({Substrate: charlie.address});57 });58 });5960 it('Non-privileged user cannot add address to allow list', async () => {61 await usingPlaygrounds(async (helper) => {62 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});63 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});64 await expect(addToAllowListTx()).to.be.rejected;65 });66 });6768 it('Nobody can add address to allow list of non-existing collection', async () => {69 const collectionId = (1<<32) - 1;70 await usingPlaygrounds(async (helper) => {71 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});72 await expect(addToAllowListTx()).to.be.rejected;73 });74 });7576 it('Nobody can add address to allow list of destroyed collection', async () => {77 await usingPlaygrounds(async (helper) => {78 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});79 await helper.collection.burn(alice, collectionId);80 const addToAllowListTx = async () => helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});81 await expect(addToAllowListTx()).to.be.rejected;82 });83 });8485 it('If address is already added to allow list, nothing happens', async () => {86 await usingPlaygrounds(async (helper) => {87 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});88 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});89 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});90 const allowList = await helper.nft.getAllowList(collectionId);91 expect(allowList).to.be.deep.contains({Substrate: bob.address});92 });93 });9495 it('Owner can remove address from allow list', async () => {96 await usingPlaygrounds(async (helper) => {97 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});98 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});99100 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});101102 const allowList = await helper.nft.getAllowList(collectionId);103104 expect(allowList).to.be.not.deep.contains({Substrate: bob.address});105 });106 });107108 it('Admin can remove address from allow list', async () => {109 await usingPlaygrounds(async (helper) => {110 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});111 await helper.nft.addAdmin(alice, collectionId, {Substrate: charlie.address});112 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});113 await helper.collection.removeFromAllowList(charlie, collectionId, {Substrate: bob.address});114115 const allowList = await helper.nft.getAllowList(collectionId);116117 expect(allowList).to.be.not.deep.contains({Substrate: bob.address});118 });119 });120121 it('Non-privileged user cannot remove address from allow list', async () => {122 await usingPlaygrounds(async (helper) => {123 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});124 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});125 const removeTx = async () => helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address});126 await expect(removeTx()).to.be.rejected;127 const allowList = await helper.nft.getAllowList(collectionId);128129 expect(allowList).to.be.deep.contains({Substrate: charlie.address});130 });131 });132133 it('Nobody can remove address from allow list of non-existing collection', async () => {134 const collectionId = (1<<32) - 1;135 await usingPlaygrounds(async (helper) => {136 const removeTx = async () => helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address});137 await expect(removeTx()).to.be.rejected;138 });139 });140141 it('Nobody can remove address from allow list of deleted collection', async () => {142 await usingPlaygrounds(async (helper) => {143 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});144 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});145 await helper.collection.burn(alice, collectionId);146 const removeTx = async () => helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});147148 await expect(removeTx()).to.be.rejected;149 });150 });151152 it('If address is already removed from allow list, nothing happens', async () => {153 await usingPlaygrounds(async (helper) => {154 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});155 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});156 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});157 const allowListBefore = await helper.nft.getAllowList(collectionId);158 expect(allowListBefore).to.be.not.deep.contains({Substrate: bob.address});159160 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});161162 const allowListAfter = await helper.nft.getAllowList(collectionId);163 expect(allowListAfter).to.be.not.deep.contains({Substrate: bob.address});164 });165 });166167 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 () => {168 await usingPlaygrounds(async (helper) => {169 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});170 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});171 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});172 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});173174 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});175 await expect(transferResult()).to.be.rejected;176 });177 });178179 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 () => {180 await usingPlaygrounds(async (helper) => {181 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});182 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});183 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});184 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});185 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});186 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});187 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});188189 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});190 await expect(transferResult()).to.be.rejected;191 });192 });193194 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 () => {195 await usingPlaygrounds(async (helper) => {196 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});197 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});198 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});199 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});200201 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});202 await expect(transferResult()).to.be.rejected;203 });204 });205206 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 () => {207 await usingPlaygrounds(async (helper) => {208 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});209 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});210 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});211 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});212 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});213214 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});215 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});216217 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});218 await expect(transferResult()).to.be.rejected;219 });220 });221222 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 () => {223 await usingPlaygrounds(async (helper) => {224 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});225 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});226 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});227 const burnTx = async () => helper.nft.burnToken(bob, collectionId, tokenId);228 await expect(burnTx()).to.be.rejected;229 });230 });231232 it('If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method)', async () => {233 await usingPlaygrounds(async (helper) => {234 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});235 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});236 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});237 const approveTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});238 await expect(approveTx()).to.be.rejected;239 });240 });241242 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', 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 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});248 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});249 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});250 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);251 expect(owner.Substrate).to.be.equal(charlie.address);252 });253 });254255 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transferFrom.', async () => {256 await usingPlaygrounds(async (helper) => {257 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});258 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});259 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});260 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});261 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});262 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});263264 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});265 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);266 expect(owner.Substrate).to.be.equal(charlie.address);267 });268 });269270 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async () => {271 await usingPlaygrounds(async (helper) => {272 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});273 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});274 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});275 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});276 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});277278 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});279 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);280 expect(owner.Substrate).to.be.equal(charlie.address);281 });282 });283284 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async () => {285 await usingPlaygrounds(async (helper) => {286 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});287 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});288 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});289 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});290 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});291 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});292293 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});294 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);295 expect(owner.Substrate).to.be.equal(charlie.address);296 });297 });298299 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner', async () => {300 await usingPlaygrounds(async (helper) => {301 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});302 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});303 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});304 const token = await helper.nft.getToken(collectionId, tokenId);305 expect(token).to.be.not.null;306 });307 });308309 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin', async () => {310 await usingPlaygrounds(async (helper) => {311 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});312 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});313 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});314 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});315 const token = await helper.nft.getToken(collectionId, tokenId);316 expect(token).to.be.not.null;317 });318 });319320 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 () => {321 await usingPlaygrounds(async (helper) => {322 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});323 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});324 await helper.collection.addToAllowList(alice, collectionId, {Substrate: bob.address});325 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});326 await expect(mintTokenTx()).to.be.rejected;327 });328 });329330 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 () => {331 await usingPlaygrounds(async (helper) => {332 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});333 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});334 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});335 await expect(mintTokenTx()).to.be.rejected;336 });337 });338339 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner', async () => {340 await usingPlaygrounds(async (helper) => {341 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});342 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});343 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});344 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);345 expect(owner.Substrate).to.be.equal(alice.address);346 });347 });348349 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin', async () => {350 await usingPlaygrounds(async (helper) => {351 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});352 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});353 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});354 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});355 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);356 expect(owner.Substrate).to.be.equal(bob.address);357 });358 });359360 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 () => {361 await usingPlaygrounds(async (helper) => {362 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});363 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});364 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});365 await expect(mintTokenTx()).to.be.rejected;366 });367 });368369 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 () => {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.addToAllowList(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 });379});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 {usingPlaygrounds, expect, itSub} from './util/playgrounds';19import {ICollectionPermissions} from './util/playgrounds/types';2021describe('Integration Test ext. Add to Allow List', () => { 22 let alice: IKeyringPair;23 let bob: IKeyringPair;24 let charlie: IKeyringPair;2526 before(async () => {27 await usingPlaygrounds(async (helper, privateKey) => {28 const donor = privateKey('//Alice');29 [alice, bob, charlie] = await helper.arrange.createAccounts([30n, 10n, 10n], donor);30 });31 });3233 describe('Positive', async () => {34 itSub('Owner can add address to allow list', async ({helper}) => {35 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});36 // allow list does not need to be enabled to add someone in advance37 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});38 const allowList = await helper.nft.getAllowList(collectionId);39 expect(allowList).to.deep.contain({Substrate: bob.address});40 });41 42 itSub('Admin can add address to allow list', async ({helper}) => {43 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});44 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});4546 // allow list does not need to be enabled to add someone in advance47 await helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});48 const allowList = await helper.nft.getAllowList(collectionId);49 expect(allowList).to.deep.contain({Substrate: charlie.address});50 });5152 itSub('If address is already added to allow list, nothing happens', async ({helper}) => {53 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});54 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});55 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});56 const allowList = await helper.nft.getAllowList(collectionId);57 expect(allowList).to.deep.contain({Substrate: bob.address});58 });59 });6061 describe('Negative', async () => {62 itSub('Nobody can add address to allow list of non-existing collection', async ({helper}) => {63 const collectionId = (1<<32) - 1;64 await expect(helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address}))65 .to.be.rejectedWith(/common\.CollectionNotFound/);66 });67 68 itSub('Nobody can add address to allow list of destroyed collection', async ({helper}) => {69 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});70 await helper.collection.burn(alice, collectionId);71 await expect(helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address}))72 .to.be.rejectedWith(/common\.CollectionNotFound/);73 });7475 itSub('Non-privileged user cannot add address to allow list', async ({helper}) => {76 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});77 await expect(helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address}))78 .to.be.rejectedWith(/common\.NoPermission/);79 });80 });81});8283describe('Integration Test ext. Remove from Allow List', () => { 84 let alice: IKeyringPair;85 let bob: IKeyringPair;86 let charlie: IKeyringPair;8788 before(async () => {89 await usingPlaygrounds(async (helper, privateKey) => {90 const donor = privateKey('//Alice');91 [alice, bob, charlie] = await helper.arrange.createAccounts([30n, 10n, 10n], donor);92 });93 });9495 describe('Positive', async () => {96 itSub('Owner can remove address from allow list', async ({helper}) => {97 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});98 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});99100 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});101102 const allowList = await helper.nft.getAllowList(collectionId);103104 expect(allowList).to.not.deep.contain({Substrate: bob.address});105 });106107 itSub('Admin can remove address from allow list', async ({helper}) => {108 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});109 await helper.nft.addAdmin(alice, collectionId, {Substrate: charlie.address});110 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});111 await helper.collection.removeFromAllowList(charlie, collectionId, {Substrate: bob.address});112113 const allowList = await helper.nft.getAllowList(collectionId);114 expect(allowList).to.not.deep.contain({Substrate: bob.address});115 });116117 itSub('If address is already removed from allow list, nothing happens', async ({helper}) => {118 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});119 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});120 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});121 const allowListBefore = await helper.nft.getAllowList(collectionId);122 expect(allowListBefore).to.not.deep.contain({Substrate: bob.address});123 124 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});125 126 const allowListAfter = await helper.nft.getAllowList(collectionId);127 expect(allowListAfter).to.not.deep.contain({Substrate: bob.address});128 });129 });130131 describe('Negative', async () => {132 itSub('Non-privileged user cannot remove address from allow list', async ({helper}) => {133 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});134 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});135 await expect(helper.collection.removeFromAllowList(charlie, collectionId, {Substrate: charlie.address}))136 .to.be.rejectedWith(/common\.NoPermission/);137138 const allowList = await helper.nft.getAllowList(collectionId);139 expect(allowList).to.deep.contain({Substrate: charlie.address});140 });141 142 itSub('Nobody can remove address from allow list of non-existing collection', async ({helper}) => {143 const collectionId = (1<<32) - 1;144 await expect(helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address}))145 .to.be.rejectedWith(/common\.CollectionNotFound/);146 });147 148 itSub('Nobody can remove address from allow list of deleted collection', async ({helper}) => {149 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});150 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});151 await helper.collection.burn(alice, collectionId);152 153 await expect(helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address}))154 .to.be.rejectedWith(/common\.CollectionNotFound/);155 });156 });157});158159describe('Integration Test ext. Transfer if included in Allow List', () => { 160 let alice: IKeyringPair;161 let bob: IKeyringPair;162 let charlie: IKeyringPair;163164 before(async () => {165 await usingPlaygrounds(async (helper, privateKey) => {166 const donor = privateKey('//Alice');167 [alice, bob, charlie] = await helper.arrange.createAccounts([30n, 10n, 10n], donor);168 });169 });170171 describe('Positive', async () => {172 itSub('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async ({helper}) => {173 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});174 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});175 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});176 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});177 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});178 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});179 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);180 expect(owner.Substrate).to.be.equal(charlie.address);181 });182 183 itSub('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transferFrom.', async ({helper}) => {184 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});185 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});186 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});187 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});188 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});189 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});190 191 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});192 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);193 expect(owner.Substrate).to.be.equal(charlie.address);194 });195 196 itSub('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', 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 203 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});204 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);205 expect(owner.Substrate).to.be.equal(charlie.address);206 });207 208 itSub('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async ({helper}) => {209 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});210 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});211 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});212 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});213 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});214 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});215 216 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});217 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);218 expect(owner.Substrate).to.be.equal(charlie.address);219 });220 });221222 describe('Negative', async () => {223 itSub('If Public Access mode is set to AllowList, tokens can\'t be transferred from a non-allowlisted address with transfer or transferFrom. Test1', async ({helper}) => {224 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});225 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});226 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});227 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});228 229 await expect(helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address}))230 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);231 });232 233 itSub('If Public Access mode is set to AllowList, tokens can\'t be transferred from a non-allowlisted address with transfer or transferFrom. Test2', async ({helper}) => {234 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});235 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});236 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});237 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});238 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});239 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});240 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});241 242 await expect(helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address}))243 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);244 });245 246 itSub('If Public Access mode is set to AllowList, tokens can\'t be transferred to a non-allowlisted address with transfer or transferFrom. Test1', async ({helper}) => {247 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});248 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});249 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});250 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});251 252 await expect(helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address}))253 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);254 });255 256 itSub('If Public Access mode is set to AllowList, tokens can\'t be transferred to a non-allowlisted address with transfer or transferFrom. Test2', async ({helper}) => {257 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});258 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});259 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});260 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});261 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});262 263 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});264 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});265 266 await expect(helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address}))267 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);268 });269 270 itSub('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 ({helper}) => {271 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});272 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});273 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});274 await expect(helper.nft.burnToken(bob, collectionId, tokenId))275 .to.be.rejectedWith(/common\.NoPermission/);276 });277 278 itSub('If Public Access mode is set to AllowList, token transfers can\'t be Approved by a non-allowlisted address (see Approve method)', async ({helper}) => {279 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});280 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});281 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});282 await expect(helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}))283 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);284 });285 });286});287288describe('Integration Test ext. Mint if included in Allow List', () => { 289 let alice: IKeyringPair;290 let bob: IKeyringPair;291292 before(async () => {293 await usingPlaygrounds(async (helper, privateKey) => {294 const donor = privateKey('//Alice');295 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);296 });297 });298299 const permissionSet: ICollectionPermissions[] = [300 {access: 'Normal', mintMode: false},301 {access: 'Normal', mintMode: true},302 {access: 'AllowList', mintMode: false},303 {access: 'AllowList', mintMode: true},304 ];305306 const testPermissionSuite = async (permissions: ICollectionPermissions) => {307 const allowlistedMintingShouldFail = !permissions.mintMode!;308309 const appropriateRejectionMessage = permissions.mintMode! ? /common\.AddressNotInAllowlist/ : /common\.PublicMintingNotAllowed/;310311 const allowlistedMintingTest = () => itSub(312 `With the condtions above, tokens can${allowlistedMintingShouldFail'\'t'''} be created by allow-listed addresses`, 313 async ({helper}) => {314 const collection = await helper.nft.mintCollection(alice, {});315 await collection.setPermissions(alice, permissions);316 await collection.addToAllowList(alice, {Substrate: bob.address});317318 if (allowlistedMintingShouldFail)319 await expect(collection.mintToken(bob, {Substrate: bob.address})).to.be.rejectedWith(appropriateRejectionMessage);320 else321 await expect(collection.mintToken(bob, {Substrate: bob.address})).to.not.be.rejected;322 },323 );324325326 describe(`Public Access Mode = ${permissions.access}, Mint Mode = ${permissions.mintMode}`, async () => {327 describe('Positive', async () => {328 itSub('With the condtions above, tokens can be created by owner', async ({helper}) => {329 const collection = await helper.nft.mintCollection(alice, {});330 await collection.setPermissions(alice, permissions);331 await expect(collection.mintToken(alice, {Substrate: alice.address})).to.not.be.rejected;332 });333 334 itSub('With the condtions above, tokens can be created by admin', async ({helper}) => {335 const collection = await helper.nft.mintCollection(alice, {});336 await collection.setPermissions(alice, permissions);337 await collection.addAdmin(alice, {Substrate: bob.address});338 await expect(collection.mintToken(bob, {Substrate: bob.address})).to.not.be.rejected;339 });340341 if (!allowlistedMintingShouldFail) allowlistedMintingTest();342 });343344 describe('Negative', async () => {345 itSub('With the condtions above, tokens can\'t be created by non-priviliged non-allow-listed address', async ({helper}) => {346 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});347 await collection.setPermissions(alice, permissions);348 await expect(collection.mintToken(bob, {Substrate: bob.address}))349 .to.be.rejectedWith(appropriateRejectionMessage);350 });351352 if (allowlistedMintingShouldFail) allowlistedMintingTest();353 });354 });355 };356357 for (const permissions of permissionSet) {358 testPermissionSuite(permissions);359 }360});tests/src/mintModes.test.tsdiffbeforeafterboth--- a/tests/src/mintModes.test.ts
+++ /dev/null
@@ -1,148 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-import {IKeyringPair} from '@polkadot/types/types';
-import usingApi from './substrate/substrate-api';
-import {
- addToAllowListExpectSuccess,
- createCollectionExpectSuccess,
- createItemExpectFailure,
- createItemExpectSuccess,
- enableAllowListExpectSuccess,
- setMintPermissionExpectSuccess,
- addCollectionAdminExpectSuccess,
- disableAllowListExpectSuccess,
-} from './util/helpers';
-
-describe('Integration Test public minting', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
-
- before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- alice = privateKeyWrapper('//Alice');
- bob = privateKeyWrapper('//Bob');
- });
- });
-
- it('If the AllowList mode is enabled, then the address added to the allowlist and not the owner or administrator can create tokens', async () => {
- await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await enableAllowListExpectSuccess(alice, collectionId);
- await setMintPermissionExpectSuccess(alice, collectionId, true);
- await addToAllowListExpectSuccess(alice, collectionId, bob.address);
-
- await createItemExpectSuccess(bob, collectionId, 'NFT');
- });
- });
-
- it('If the AllowList mode is enabled, address not included in allowlist that is regular user cannot create tokens', async () => {
- await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await enableAllowListExpectSuccess(alice, collectionId);
- await setMintPermissionExpectSuccess(alice, collectionId, true);
- await createItemExpectFailure(bob, collectionId, 'NFT');
- });
- });
-
- it('If the AllowList mode is enabled, address not included in allowlist that is admin can create tokens', async () => {
- await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await enableAllowListExpectSuccess(alice, collectionId);
- await setMintPermissionExpectSuccess(alice, collectionId, true);
- await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- await createItemExpectSuccess(bob, collectionId, 'NFT');
- });
- });
-
- it('If the AllowList mode is enabled, address not included in allowlist that is owner can create tokens', async () => {
- await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await enableAllowListExpectSuccess(alice, collectionId);
- await setMintPermissionExpectSuccess(alice, collectionId, true);
- await createItemExpectSuccess(alice, collectionId, 'NFT');
- });
- });
-
- it('If the AllowList mode is disabled, owner can create tokens', async () => {
- await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await disableAllowListExpectSuccess(alice, collectionId);
- await setMintPermissionExpectSuccess(alice, collectionId, true);
- await createItemExpectSuccess(alice, collectionId, 'NFT');
- });
- });
-
- it('If the AllowList mode is disabled, collection admin can create tokens', async () => {
- await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await disableAllowListExpectSuccess(alice, collectionId);
- await setMintPermissionExpectSuccess(alice, collectionId, true);
- await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- await createItemExpectSuccess(bob, collectionId, 'NFT');
- });
- });
-
- it('If the AllowList mode is disabled, regular user can`t create tokens', async () => {
- await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await disableAllowListExpectSuccess(alice, collectionId);
- await setMintPermissionExpectSuccess(alice, collectionId, true);
- await createItemExpectFailure(bob, collectionId, 'NFT');
- });
- });
-});
-
-describe('Integration Test private minting', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
-
- before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- alice = privateKeyWrapper('//Alice');
- bob = privateKeyWrapper('//Bob');
- });
- });
-
- it('Address that is the not owner or not admin cannot create tokens', async () => {
- await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await enableAllowListExpectSuccess(alice, collectionId);
- await setMintPermissionExpectSuccess(alice, collectionId, false);
- await addToAllowListExpectSuccess(alice, collectionId, bob.address);
- await createItemExpectFailure(bob, collectionId, 'NFT');
- });
- });
-
- it('Address that is collection owner can create tokens', async () => {
- await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await disableAllowListExpectSuccess(alice, collectionId);
- await setMintPermissionExpectSuccess(alice, collectionId, false);
- await createItemExpectSuccess(alice, collectionId, 'NFT');
- });
- });
-
- it('Address that is admin can create tokens', async () => {
- await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await disableAllowListExpectSuccess(alice, collectionId);
- await setMintPermissionExpectSuccess(alice, collectionId, false);
- await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- await createItemExpectSuccess(bob, collectionId, 'NFT');
- });
- });
-});
tests/src/removeFromAllowList.test.tsdiffbeforeafterboth--- a/tests/src/removeFromAllowList.test.ts
+++ /dev/null
@@ -1,134 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-import {IKeyringPair} from '@polkadot/types/types';
-import {itSub, usingPlaygrounds, expect} from './util/playgrounds';
-
-describe('Integration Test removeFromAllowList', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
-
- before(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
- [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);
- });
- });
-
- itSub('ensure bob is not in allowlist after removal', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'RemoveFromAllowList-1', tokenPrefix: 'RFAL'});
-
- const collectionInfo = await collection.getData();
- expect(collectionInfo!.raw.permissions.access).to.not.equal('AllowList');
-
- await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});
- await collection.addToAllowList(alice, {Substrate: bob.address});
- expect(await collection.getAllowList()).to.deep.contains({Substrate: bob.address});
-
- await collection.removeFromAllowList(alice, {Substrate: bob.address});
- expect(await collection.getAllowList()).to.be.empty;
- });
-
- itSub('allows removal from collection with unset allowlist status', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'RemoveFromAllowList-2', tokenPrefix: 'RFAL'});
-
- await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});
- await collection.addToAllowList(alice, {Substrate: bob.address});
- expect(await collection.getAllowList()).to.deep.contains({Substrate: bob.address});
-
- await collection.setPermissions(alice, {access: 'Normal'});
-
- await collection.removeFromAllowList(alice, {Substrate: bob.address});
- expect(await collection.getAllowList()).to.be.empty;
- });
-});
-
-describe('Negative Integration Test removeFromAllowList', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
-
- before(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
- [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);
- });
- });
-
- itSub('fails on removal from not existing collection', async ({helper}) => {
- const nonExistentCollectionId = (1 << 32) - 1;
- await expect(helper.collection.removeFromAllowList(alice, nonExistentCollectionId, {Substrate: alice.address}))
- .to.be.rejectedWith(/common\.CollectionNotFound/);
- });
-
- itSub('fails on removal from removed collection', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'RemoveFromAllowList-3', tokenPrefix: 'RFAL'});
- await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});
- await collection.addToAllowList(alice, {Substrate: bob.address});
-
- await collection.burn(alice);
- await expect(collection.removeFromAllowList(alice, {Substrate: bob.address}))
- .to.be.rejectedWith(/common\.CollectionNotFound/);
- });
-});
-
-describe('Integration Test removeFromAllowList with collection admin permissions', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
- let charlie: IKeyringPair;
-
- before(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
- [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);
- });
- });
-
- itSub('ensure address is not in allowlist after removal', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'RemoveFromAllowList-4', tokenPrefix: 'RFAL'});
-
- await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});
- await collection.addAdmin(alice, {Substrate: bob.address});
-
- await collection.addToAllowList(bob, {Substrate: charlie.address});
- await collection.removeFromAllowList(bob, {Substrate: charlie.address});
-
- expect(await collection.getAllowList()).to.be.empty;
- });
-
- itSub('Collection admin allowed to remove from allowlist with unset allowlist status', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'RemoveFromAllowList-5', tokenPrefix: 'RFAL'});
-
- await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});
- await collection.addAdmin(alice, {Substrate: bob.address});
- await collection.addToAllowList(alice, {Substrate: charlie.address});
-
- await collection.setPermissions(bob, {access: 'Normal'});
- await collection.removeFromAllowList(bob, {Substrate: charlie.address});
-
- expect(await collection.getAllowList()).to.be.empty;
- });
-
- itSub('Regular user can`t remove from allowlist', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'RemoveFromAllowList-6', tokenPrefix: 'RFAL'});
-
- await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});
- await collection.addToAllowList(alice, {Substrate: charlie.address});
-
- await expect(collection.removeFromAllowList(bob, {Substrate: charlie.address}))
- .to.be.rejectedWith(/common\.NoPermission/);
- expect(await collection.getAllowList()).to.deep.contain({Substrate: charlie.address});
- });
-});
tests/src/setMintPermission.test.tsdiffbeforeafterboth--- a/tests/src/setMintPermission.test.ts
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-import {IKeyringPair} from '@polkadot/types/types';
-import {itSub, usingPlaygrounds, expect} from './util/playgrounds';
-
-describe('Integration Test setMintPermission', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
-
- before(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
- [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);
- });
- });
-
- itSub('ensure allow-listed non-privileged address can mint tokens', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-1', description: '', tokenPrefix: 'SMP'});
- await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});
- await collection.addToAllowList(alice, {Substrate: bob.address});
-
- await expect(collection.mintToken(bob, {Substrate: bob.address})).to.not.be.rejected;
- });
-
- itSub('can be enabled twice', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-2', description: '', tokenPrefix: 'SMP'});
- expect((await collection.getData())?.raw.permissions.access).to.not.equal('AllowList');
-
- await collection.setPermissions(alice, {mintMode: true});
- await collection.setPermissions(alice, {mintMode: true});
- expect((await collection.getData())?.raw.permissions.mintMode).to.be.true;
- });
-
- itSub('can be disabled twice', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-3', description: '', tokenPrefix: 'SMP'});
- expect((await collection.getData())?.raw.permissions.access).to.equal('Normal');
-
- await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});
- expect((await collection.getData())?.raw.permissions.access).to.equal('AllowList');
- expect((await collection.getData())?.raw.permissions.mintMode).to.equal(true);
-
- await collection.setPermissions(alice, {access: 'Normal', mintMode: false});
- await collection.setPermissions(alice, {access: 'Normal', mintMode: false});
- expect((await collection.getData())?.raw.permissions.access).to.equal('Normal');
- expect((await collection.getData())?.raw.permissions.mintMode).to.equal(false);
- });
-
- itSub('Collection admin success on set', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-4', description: '', tokenPrefix: 'SMP'});
- await collection.addAdmin(alice, {Substrate: bob.address});
- await collection.setPermissions(bob, {access: 'AllowList', mintMode: true});
-
- expect((await collection.getData())?.raw.permissions.access).to.equal('AllowList');
- expect((await collection.getData())?.raw.permissions.mintMode).to.equal(true);
- });
-});
-
-describe('Negative Integration Test setMintPermission', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
-
- before(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
- [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);
- });
- });
-
- itSub('fails on not existing collection', async ({helper}) => {
- const collectionId = (1 << 32) - 1;
- await expect(helper.collection.setPermissions(alice, collectionId, {mintMode: true}))
- .to.be.rejectedWith(/common\.CollectionNotFound/);
- });
-
- itSub('fails on removed collection', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-Neg-1', tokenPrefix: 'SMP'});
- await collection.burn(alice);
-
- await expect(collection.setPermissions(alice, {mintMode: true}))
- .to.be.rejectedWith(/common\.CollectionNotFound/);
- });
-
- itSub('fails when non-owner tries to set mint status', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-Neg-2', tokenPrefix: 'SMP'});
-
- await expect(collection.setPermissions(bob, {mintMode: true}))
- .to.be.rejectedWith(/common\.NoPermission/);
- });
-
- itSub('ensure non-allow-listed non-privileged address can\'t mint tokens', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-Neg-3', tokenPrefix: 'SMP'});
- await collection.setPermissions(alice, {mintMode: true});
-
- await expect(collection.mintToken(bob, {Substrate: bob.address}))
- .to.be.rejectedWith(/common\.AddressNotInAllowlist/);
- });
-});
tests/src/setPermissions.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/setPermissions.test.ts
@@ -0,0 +1,107 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {itSub, usingPlaygrounds, expect} from './util/playgrounds';
+
+describe('Integration Test: Set Permissions', () => {
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+
+ before(async () => {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ const donor = privateKey('//Alice');
+ [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);
+ });
+ });
+
+ itSub('can all be enabled twice', async ({helper}) => {
+ const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-1', tokenPrefix: 'SP'});
+ expect((await collection.getData())?.raw.permissions.access).to.not.equal('AllowList');
+
+ await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true, tokenOwner: true, restricted: [1, 2]}});
+ await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true, tokenOwner: true, restricted: [1, 2]}});
+
+ const permissions = (await collection.getData())?.raw.permissions;
+ expect(permissions).to.be.deep.equal({
+ access: 'AllowList',
+ mintMode: true,
+ nesting: {collectionAdmin: true, tokenOwner: true, restricted: [1, 2]},
+ });
+ });
+
+ itSub('can all be disabled twice', async ({helper}) => {
+ const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-2', tokenPrefix: 'SP'});
+ expect((await collection.getData())?.raw.permissions.access).to.equal('Normal');
+
+ await collection.setPermissions(alice, {access: 'AllowList', nesting: {collectionAdmin: false, tokenOwner: true, restricted: [1, 2]}});
+ expect((await collection.getData())?.raw.permissions).to.be.deep.equal({
+ access: 'AllowList',
+ mintMode: false,
+ nesting: {collectionAdmin: false, tokenOwner: true, restricted: [1, 2]},
+ });
+
+ await collection.setPermissions(alice, {access: 'Normal', mintMode: false, nesting: {}});
+ await collection.setPermissions(alice, {access: 'Normal', mintMode: false, nesting: {}});
+ expect((await collection.getData())?.raw.permissions).to.be.deep.equal({
+ access: 'Normal',
+ mintMode: false,
+ nesting: {collectionAdmin: false, tokenOwner: false, restricted: null},
+ });
+ });
+
+ itSub('collection admin can set permissions', async ({helper}) => {
+ const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-2', tokenPrefix: 'SP'});
+ await collection.addAdmin(alice, {Substrate: bob.address});
+ await collection.setPermissions(bob, {access: 'AllowList', mintMode: true});
+
+ expect((await collection.getData())?.raw.permissions.access).to.equal('AllowList');
+ expect((await collection.getData())?.raw.permissions.mintMode).to.equal(true);
+ });
+});
+
+describe('Negative Integration Test: Set Permissions', () => {
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+
+ before(async () => {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ const donor = privateKey('//Alice');
+ [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);
+ });
+ });
+
+ itSub('fails on not existing collection', async ({helper}) => {
+ const collectionId = (1 << 32) - 1;
+ await expect(helper.collection.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true}))
+ .to.be.rejectedWith(/common\.CollectionNotFound/);
+ });
+
+ itSub('fails on removed collection', async ({helper}) => {
+ const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-Neg-1', tokenPrefix: 'SP'});
+ await collection.burn(alice);
+
+ await expect(collection.setPermissions(alice, {access: 'AllowList', mintMode: true}))
+ .to.be.rejectedWith(/common\.CollectionNotFound/);
+ });
+
+ itSub('fails when non-owner tries to set permissions', async ({helper}) => {
+ const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-Neg-2', tokenPrefix: 'SP'});
+
+ await expect(collection.setPermissions(bob, {access: 'AllowList', mintMode: true}))
+ .to.be.rejectedWith(/common\.NoPermission/);
+ });
+});
\ No newline at end of file
tests/src/setPublicAccessMode.test.tsdiffbeforeafterboth--- a/tests/src/setPublicAccessMode.test.ts
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-// https://unique-network.readthedocs.io/en/latest/jsapi.html#setschemaversion
-import {IKeyringPair} from '@polkadot/types/types';
-import {itSub, usingPlaygrounds, expect} from './util/playgrounds';
-
-describe('Integration Test setPublicAccessMode(): ', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
-
- before(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
- [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);
- });
- });
-
- itSub('Runs extrinsic with collection id parameters, sets the allowlist mode for the collection', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'PublicAccess-1', tokenPrefix: 'TF'});
- await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});
- await collection.addToAllowList(alice, {Substrate: bob.address});
-
- await expect(collection.mintToken(bob, {Substrate: bob.address})).to.be.not.rejected;
- });
-
- itSub('Allowlisted collection limits', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'PublicAccess-2', tokenPrefix: 'TF'});
- await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});
-
- await expect(collection.mintToken(bob, {Substrate: bob.address}))
- .to.be.rejectedWith(/common\.AddressNotInAllowlist/);
- });
-
- itSub('setPublicAccessMode by collection admin', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'PublicAccess-Neg-4', tokenPrefix: 'TF'});
- await collection.addAdmin(alice, {Substrate: bob.address});
-
- await expect(collection.setPermissions(bob, {access: 'AllowList'})).to.be.not.rejected;
- });
-});
-
-describe('Negative Integration Test ext. setPublicAccessMode(): ', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
-
- before(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
- [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);
- });
- });
-
- itSub('Sets a non-existent collection', async ({helper}) => {
- const collectionId = (1 << 32) - 1;
- await expect(helper.collection.setPermissions(alice, collectionId, {access: 'AllowList'}))
- .to.be.rejectedWith(/common\.CollectionNotFound/);
- });
-
- itSub('Sets the collection that has been deleted', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'PublicAccess-Neg-1', tokenPrefix: 'TF'});
- await collection.burn(alice);
-
- await expect(collection.setPermissions(alice, {access: 'AllowList'}))
- .to.be.rejectedWith(/common\.CollectionNotFound/);
- });
-
- itSub('Re-sets the list mode already set in quantity', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'PublicAccess-Neg-2', tokenPrefix: 'TF'});
- await collection.setPermissions(alice, {access: 'AllowList'});
- await collection.setPermissions(alice, {access: 'AllowList'});
- });
-
- itSub('Executes method as a malefactor', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'PublicAccess-Neg-3', tokenPrefix: 'TF'});
-
- await expect(collection.setPermissions(bob, {access: 'AllowList'}))
- .to.be.rejectedWith(/common\.NoPermission/);
- });
-});