git.delta.rocks / unique-network / refs/commits / 9ebd2fc6196e

difftreelog

source

tests/src/allowLists.test.ts15.3 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 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 privateKey from './substrate/privateKey';21import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';22import {23  addToAllowListExpectSuccess,24  createCollectionExpectSuccess,25  createItemExpectSuccess,26  destroyCollectionExpectSuccess,27  enableAllowListExpectSuccess,28  normalizeAccountId,29  addCollectionAdminExpectSuccess,30  addToAllowListExpectFail,31  removeFromAllowListExpectSuccess,32  removeFromAllowListExpectFailure,33  addToAllowListAgainExpectSuccess,34  transferExpectFailure,35  approveExpectSuccess,36  approveExpectFail,37  transferExpectSuccess,38  transferFromExpectSuccess,39  setMintPermissionExpectSuccess,40  createItemExpectFailure,41} from './util/helpers';4243chai.use(chaiAsPromised);44const expect = chai.expect;4546let alice: IKeyringPair;47let bob: IKeyringPair;48let charlie: IKeyringPair;4950describe('Integration Test ext. Allow list tests', () => {5152  before(async () => {53    await usingApi(async () => {54      alice = privateKey('//Alice');55      bob = privateKey('//Bob');56      charlie = privateKey('//Charlie');57    });58  });5960  it('Owner can add address to allow list', async () => {61    const collectionId = await createCollectionExpectSuccess();62    await addToAllowListExpectSuccess(alice, collectionId, bob.address);63  });6465  it('Admin can add address to allow list', async () => {66    const collectionId = await createCollectionExpectSuccess();67    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);68    await addToAllowListExpectSuccess(bob, collectionId, charlie.address);69  });7071  it('Non-privileged user cannot add address to allow list', async () => {72    const collectionId = await createCollectionExpectSuccess();73    await addToAllowListExpectFail(bob, collectionId, charlie.address);74  });7576  it('Nobody can add address to allow list of non-existing collection', async () => {77    const collectionId = (1<<32) - 1;78    await addToAllowListExpectFail(alice, collectionId, bob.address);79  });8081  it('Nobody can add address to allow list of destroyed collection', async () => {82    const collectionId = await createCollectionExpectSuccess();83    await destroyCollectionExpectSuccess(collectionId, '//Alice');84    await addToAllowListExpectFail(alice, collectionId, bob.address);85  });8687  it('If address is already added to allow list, nothing happens', async () => {88    const collectionId = await createCollectionExpectSuccess();89    await addToAllowListExpectSuccess(alice, collectionId, bob.address);90    await addToAllowListAgainExpectSuccess(alice, collectionId, bob.address);91  });9293  it('Owner can remove address from allow list', async () => {94    const collectionId = await createCollectionExpectSuccess();95    await addToAllowListExpectSuccess(alice, collectionId, bob.address);96    await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(bob));97  });9899  it('Admin can remove address from allow list', async () => {100    const collectionId = await createCollectionExpectSuccess();101    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);102    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);103    await removeFromAllowListExpectSuccess(bob, collectionId, normalizeAccountId(charlie));104  });105106  it('Non-privileged user cannot remove address from allow list', async () => {107    const collectionId = await createCollectionExpectSuccess();108    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);109    await removeFromAllowListExpectFailure(bob, collectionId, normalizeAccountId(charlie));110  });111112  it('Nobody can remove address from allow list of non-existing collection', async () => {113    const collectionId = (1<<32) - 1;114    await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie));115  });116117  it('Nobody can remove address from allow list of deleted collection', async () => {118    const collectionId = await createCollectionExpectSuccess();119    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);120    await destroyCollectionExpectSuccess(collectionId, '//Alice');121    await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie));122  });123124  it('If address is already removed from allow list, nothing happens', async () => {125    const collectionId = await createCollectionExpectSuccess();126    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);127    await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));128    await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));129  });130131  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 () => {132    const collectionId = await createCollectionExpectSuccess();133    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);134    await enableAllowListExpectSuccess(alice, collectionId);135    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);136137    await transferExpectFailure(138      collectionId,139      itemId,140      alice,141      charlie,142      1,143    );144  });145146  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 () => {147    const collectionId = await createCollectionExpectSuccess();148    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);149    await enableAllowListExpectSuccess(alice, collectionId);150    await addToAllowListExpectSuccess(alice, collectionId, alice.address);151    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);152    await approveExpectSuccess(collectionId, itemId, alice, charlie.address);153    await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice));154155    await transferExpectFailure(156      collectionId,157      itemId,158      alice,159      charlie,160      1,161    );162  });163164  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 () => {165    const collectionId = await createCollectionExpectSuccess();166    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);167    await enableAllowListExpectSuccess(alice, collectionId);168    await addToAllowListExpectSuccess(alice, collectionId, alice.address);169170    await transferExpectFailure(171      collectionId,172      itemId,173      alice,174      charlie,175      1,176    );177  });178179  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 () => {180    const collectionId = await createCollectionExpectSuccess();181    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);182    await enableAllowListExpectSuccess(alice, collectionId);183    await addToAllowListExpectSuccess(alice, collectionId, alice.address);184    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);185    await approveExpectSuccess(collectionId, itemId, alice, charlie.address);186    await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice));187188    await transferExpectFailure(189      collectionId,190      itemId,191      alice,192      charlie,193      1,194    );195  });196197  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 () => {198    const collectionId = await createCollectionExpectSuccess();199    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);200    await enableAllowListExpectSuccess(alice, collectionId);201202    await usingApi(async (api) => {203      const tx = api.tx.unique.burnItem(collectionId, itemId, /*normalizeAccountId(Alice.address),*/ 11);204      const badTransaction = async function () {205        await submitTransactionExpectFailAsync(alice, tx);206      };207      await expect(badTransaction()).to.be.rejected;208    });209  });210211  it('If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method)', async () => {212    const collectionId = await createCollectionExpectSuccess();213    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);214    await enableAllowListExpectSuccess(alice, collectionId);215    await approveExpectFail(collectionId, itemId, alice, bob);216  });217218  it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async () => {219    const collectionId = await createCollectionExpectSuccess();220    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);221    await enableAllowListExpectSuccess(alice, collectionId);222    await addToAllowListExpectSuccess(alice, collectionId, alice.address);223    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);224    await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');225  });226227  it('If Public Access mode is set to AllowList, tokens can be transferred to a alowlisted address with transferFrom.', async () => {228    const collectionId = await createCollectionExpectSuccess();229    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);230    await enableAllowListExpectSuccess(alice, collectionId);231    await addToAllowListExpectSuccess(alice, collectionId, alice.address);232    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);233    await approveExpectSuccess(collectionId, itemId, alice, charlie.address);234    await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');235  });236237  it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async () => {238    const collectionId = await createCollectionExpectSuccess();239    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);240    await enableAllowListExpectSuccess(alice, collectionId);241    await addToAllowListExpectSuccess(alice, collectionId, alice.address);242    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);243    await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');244  });245246  it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async () => {247    const collectionId = await createCollectionExpectSuccess();248    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);249    await enableAllowListExpectSuccess(alice, collectionId);250    await addToAllowListExpectSuccess(alice, collectionId, alice.address);251    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);252    await approveExpectSuccess(collectionId, itemId, alice, charlie.address);253    await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');254  });255256  it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner', async () => {257    const collectionId = await createCollectionExpectSuccess();258    await enableAllowListExpectSuccess(alice, collectionId);259    await setMintPermissionExpectSuccess(alice, collectionId, false);260    await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);261  });262263  it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin', async () => {264    const collectionId = await createCollectionExpectSuccess();265    await enableAllowListExpectSuccess(alice, collectionId);266    await setMintPermissionExpectSuccess(alice, collectionId, false);267    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);268    await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);269  });270271  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 () => {272    const collectionId = await createCollectionExpectSuccess();273    await enableAllowListExpectSuccess(alice, collectionId);274    await setMintPermissionExpectSuccess(alice, collectionId, false);275    await addToAllowListExpectSuccess(alice, collectionId, bob.address);276    await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);277  });278279  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 () => {280    const collectionId = await createCollectionExpectSuccess();281    await enableAllowListExpectSuccess(alice, collectionId);282    await setMintPermissionExpectSuccess(alice, collectionId, false);283    await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);284  });285286  it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner', async () => {287    const collectionId = await createCollectionExpectSuccess();288    await enableAllowListExpectSuccess(alice, collectionId);289    await setMintPermissionExpectSuccess(alice, collectionId, true);290    await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);291  });292293  it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin', async () => {294    const collectionId = await createCollectionExpectSuccess();295    await enableAllowListExpectSuccess(alice, collectionId);296    await setMintPermissionExpectSuccess(alice, collectionId, true);297    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);298    await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);299  });300301  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 () => {302    const collectionId = await createCollectionExpectSuccess();303    await enableAllowListExpectSuccess(alice, collectionId);304    await setMintPermissionExpectSuccess(alice, collectionId, true);305    await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);306  });307308  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 () => {309    const collectionId = await createCollectionExpectSuccess();310    await enableAllowListExpectSuccess(alice, collectionId);311    await setMintPermissionExpectSuccess(alice, collectionId, true);312    await addToAllowListExpectSuccess(alice, collectionId, bob.address);313    await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);314  });315});