git.delta.rocks / unique-network / refs/commits / ff1beacfa78e

difftreelog

source

tests/src/allowLists.test.ts20.9 KiBsourcehistory
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 itSub and/or modify5// itSub 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 itSub 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';1920describe('Integration Test ext. Allow list tests', () => {21  let alice: IKeyringPair;22  let bob: IKeyringPair;23  let charlie: IKeyringPair;2425  before(async () => {26    await usingPlaygrounds(async (helper, privateKey) => {27      const donor = privateKey('//Alice');28      [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);29    });30  });3132  itSub('Owner can add address to allow list', async ({helper}) => {33    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});34    await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});35    const allowList = await helper.nft.getAllowList(collectionId);36    expect(allowList).to.be.deep.contains({Substrate: bob.address});37  });3839  itSub('Admin can add address to allow list', async ({helper}) => {40    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});41    await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});4243    await helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});44    const allowList = await helper.nft.getAllowList(collectionId);45    expect(allowList).to.be.deep.contains({Substrate: charlie.address});46  });4748  itSub('Non-privileged user cannot add address to allow list', async ({helper}) => {49    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});50    const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});51    await expect(addToAllowListTx()).to.be.rejectedWith(/common\.NoPermission/);52  });5354  itSub('Nobody can add address to allow list of non-existing collection', async ({helper}) => {55    const collectionId = (1<<32) - 1;56    const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});57    await expect(addToAllowListTx()).to.be.rejectedWith(/common\.CollectionNotFound/);58  });5960  itSub('Nobody can add address to allow list of destroyed collection', async ({helper}) => {61    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});62    await helper.collection.burn(alice, collectionId);63    const addToAllowListTx = async () => helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});64    await expect(addToAllowListTx()).to.be.rejectedWith(/common\.CollectionNotFound/);65  });6667  itSub('If address is already added to allow list, nothing happens', async ({helper}) => {68    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});69    await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});70    await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});71    const allowList = await helper.nft.getAllowList(collectionId);72    expect(allowList).to.be.deep.contains({Substrate: bob.address});73  });7475  itSub('Owner can remove address from allow list', async ({helper}) => {76    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});77    await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});7879    await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});8081    const allowList = await helper.nft.getAllowList(collectionId);8283    expect(allowList).to.be.not.deep.contains({Substrate: bob.address});84  });8586  itSub('Admin can remove address from allow list', async ({helper}) => {87    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});88    await helper.nft.addAdmin(alice, collectionId, {Substrate: charlie.address});89    await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});90    await helper.collection.removeFromAllowList(charlie, collectionId, {Substrate: bob.address});9192    const allowList = await helper.nft.getAllowList(collectionId);9394    expect(allowList).to.be.not.deep.contains({Substrate: bob.address});95  });9697  itSub('Non-privileged user cannot remove address from allow list', async ({helper}) => {98    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});99    await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});100    const removeTx = async () => helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address});101    await expect(removeTx()).to.be.rejectedWith(/common\.NoPermission/);102    const allowList = await helper.nft.getAllowList(collectionId);103104    expect(allowList).to.be.deep.contains({Substrate: charlie.address});105  });106107  itSub('Nobody can remove address from allow list of non-existing collection', async ({helper}) => {108    const collectionId = (1<<32) - 1;109    const removeTx = async () => helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address});110    await expect(removeTx()).to.be.rejectedWith(/common\.CollectionNotFound/);111  });112113  itSub('Nobody can remove address from allow list of deleted collection', async ({helper}) => {114    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});115    await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});116    await helper.collection.burn(alice, collectionId);117    const removeTx = async () => helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});118119    await expect(removeTx()).to.be.rejectedWith(/common\.CollectionNotFound/);120  });121122  itSub('If address is already removed from allow list, nothing happens', async ({helper}) => {123    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});124    await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});125    await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});126    const allowListBefore = await helper.nft.getAllowList(collectionId);127    expect(allowListBefore).to.be.not.deep.contains({Substrate: bob.address});128129    await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});130131    const allowListAfter = await helper.nft.getAllowList(collectionId);132    expect(allowListAfter).to.be.not.deep.contains({Substrate: bob.address});133  });134135  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}) => {136    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});137    const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});138    await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});139    await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});140141    const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});142    await expect(transferResult()).to.be.rejectedWith(/common\.AddressNotInAllowlist/);143  });144145  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}) => {146    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});147    const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});148    await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});149    await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});150    await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});151    await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});152    await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});153154    const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});155    await expect(transferResult()).to.be.rejectedWith(/common\.AddressNotInAllowlist/);156  });157158  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}) => {159    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});160    const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});161    await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});162    await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});163164    const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});165    await expect(transferResult()).to.be.rejectedWith(/common\.AddressNotInAllowlist/);166  });167168  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}) => {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: alice.address});173    await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});174175    await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});176    await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});177178    const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});179    await expect(transferResult()).to.be.rejectedWith(/common\.AddressNotInAllowlist/);180  });181182  itSub('If Public Access mode is set to AllowList, tokens can’t be destroyed by a non-allowlisted address (even if itSub owned them before enabling AllowList mode)', async ({helper}) => {183    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});184    const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});185    await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});186    const burnTx = async () => helper.nft.burnToken(bob, collectionId, tokenId);187    await expect(burnTx()).to.be.rejectedWith(/common\.NoPermission/);188  });189190  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}) => {191    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});192    const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});193    await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});194    const approveTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});195    await expect(approveTx()).to.be.rejectedWith(/common\.AddressNotInAllowlist/);196  });197198  itSub('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async ({helper}) => {199    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});200    const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});201    await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});202    await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});203    await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});204    await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});205    const owner = await helper.nft.getTokenOwner(collectionId, tokenId);206    expect(owner.Substrate).to.be.equal(charlie.address);207  });208209  itSub('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transferFrom.', async ({helper}) => {210    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});211    const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});212    await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});213    await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});214    await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});215    await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});216217    await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});218    const owner = await helper.nft.getTokenOwner(collectionId, tokenId);219    expect(owner.Substrate).to.be.equal(charlie.address);220  });221222  itSub('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async ({helper}) => {223    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});224    const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});225    await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});226    await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});227    await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});228229    await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});230    const owner = await helper.nft.getTokenOwner(collectionId, tokenId);231    expect(owner.Substrate).to.be.equal(charlie.address);232  });233234  itSub('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async ({helper}) => {235    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});236    const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});237    await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});238    await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});239    await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});240    await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});241242    await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});243    const owner = await helper.nft.getTokenOwner(collectionId, tokenId);244    expect(owner.Substrate).to.be.equal(charlie.address);245  });246247  itSub('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner', async ({helper}) => {248    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});249    await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});250    const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});251    const token = await helper.nft.getToken(collectionId, tokenId);252    expect(token).to.be.not.null;253  });254255  itSub('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin', async ({helper}) => {256    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});257    await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});258    await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});259    const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});260    const token = await helper.nft.getToken(collectionId, tokenId);261    expect(token).to.be.not.null;262  });263264  itSub('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 ({helper}) => {265    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});266    await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});267    await helper.collection.addToAllowList(alice, collectionId, {Substrate: bob.address});268    const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});269    await expect(mintTokenTx()).to.be.rejectedWith(/common\.PublicMintingNotAllowed/);270  });271272  itSub('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 ({helper}) => {273    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});274    await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});275    const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});276    await expect(mintTokenTx()).to.be.rejectedWith(/common\.PublicMintingNotAllowed/);277  });278279  itSub('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner', async ({helper}) => {280    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});281    await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});282    const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});283    const owner = await helper.nft.getTokenOwner(collectionId, tokenId);284    expect(owner.Substrate).to.be.equal(alice.address);285  });286287  itSub('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin', async ({helper}) => {288    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});289    await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});290    await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});291    const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});292    const owner = await helper.nft.getTokenOwner(collectionId, tokenId);293    expect(owner.Substrate).to.be.equal(bob.address);294  });295296  itSub('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 ({helper}) => {297    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});298    await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});299    const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});300    await expect(mintTokenTx()).to.be.rejectedWith(/common\.AddressNotInAllowlist/);301  });302303  itSub('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 ({helper}) => {304    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});305    await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});306    await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});307    const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});308    const owner = await helper.nft.getTokenOwner(collectionId, tokenId);309    expect(owner.Substrate).to.be.equal(bob.address);310  });311});