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

difftreelog

source

tests/src/allowLists.test.ts14.7 KiBsourcehistory
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import {IKeyringPair} from '@polkadot/types/types';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';11import {12  addToAllowListExpectSuccess,13  createCollectionExpectSuccess,14  createItemExpectSuccess,15  destroyCollectionExpectSuccess,16  enableAllowListExpectSuccess,17  normalizeAccountId,18  addCollectionAdminExpectSuccess,19  addToAllowListExpectFail,20  removeFromAllowListExpectSuccess,21  removeFromAllowListExpectFailure,22  addToAllowListAgainExpectSuccess,23  transferExpectFailure,24  approveExpectSuccess,25  approveExpectFail,26  transferExpectSuccess,27  transferFromExpectSuccess,28  setMintPermissionExpectSuccess,29  createItemExpectFailure,30} from './util/helpers';3132chai.use(chaiAsPromised);33const expect = chai.expect;3435let alice: IKeyringPair;36let bob: IKeyringPair;37let charlie: IKeyringPair;3839describe('Integration Test ext. Allow list tests', () => {4041  before(async () => {42    await usingApi(async () => {43      alice = privateKey('//Alice');44      bob = privateKey('//Bob');45      charlie = privateKey('//Charlie');46    });47  });4849  it('Owner can add address to allow list', async () => {50    const collectionId = await createCollectionExpectSuccess();51    await addToAllowListExpectSuccess(alice, collectionId, bob.address);52  });5354  it('Admin can add address to allow list', async () => {55    const collectionId = await createCollectionExpectSuccess();56    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);57    await addToAllowListExpectSuccess(bob, collectionId, charlie.address);58  });5960  it('Non-privileged user cannot add address to allow list', async () => {61    const collectionId = await createCollectionExpectSuccess();62    await addToAllowListExpectFail(bob, collectionId, charlie.address);63  });6465  it('Nobody can add address to allow list of non-existing collection', async () => {66    const collectionId = (1<<32) - 1;67    await addToAllowListExpectFail(alice, collectionId, bob.address);68  });6970  it('Nobody can add address to allow list of destroyed collection', async () => {71    const collectionId = await createCollectionExpectSuccess();72    await destroyCollectionExpectSuccess(collectionId, '//Alice');73    await addToAllowListExpectFail(alice, collectionId, bob.address);74  });7576  it('If address is already added to allow list, nothing happens', async () => {77    const collectionId = await createCollectionExpectSuccess();78    await addToAllowListExpectSuccess(alice, collectionId, bob.address);79    await addToAllowListAgainExpectSuccess(alice, collectionId, bob.address);80  });8182  it('Owner can remove address from allow list', async () => {83    const collectionId = await createCollectionExpectSuccess();84    await addToAllowListExpectSuccess(alice, collectionId, bob.address);85    await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(bob));86  });8788  it('Admin can remove address from allow list', async () => {89    const collectionId = await createCollectionExpectSuccess();90    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);91    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);92    await removeFromAllowListExpectSuccess(bob, collectionId, normalizeAccountId(charlie));93  });9495  it('Non-privileged user cannot remove address from allow list', async () => {96    const collectionId = await createCollectionExpectSuccess();97    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);98    await removeFromAllowListExpectFailure(bob, collectionId, normalizeAccountId(charlie));99  });100101  it('Nobody can remove address from allow list of non-existing collection', async () => {102    const collectionId = (1<<32) - 1;103    await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie));104  });105106  it('Nobody can remove address from allow list of deleted collection', async () => {107    const collectionId = await createCollectionExpectSuccess();108    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);109    await destroyCollectionExpectSuccess(collectionId, '//Alice');110    await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie));111  });112113  it('If address is already removed from allow list, nothing happens', async () => {114    const collectionId = await createCollectionExpectSuccess();115    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);116    await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));117    await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));118  });119120  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 () => {121    const collectionId = await createCollectionExpectSuccess();122    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);123    await enableAllowListExpectSuccess(alice, collectionId);124    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);125126    await transferExpectFailure(127      collectionId,128      itemId,129      alice,130      charlie,131      1,132    );133  });134135  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 () => {136    const collectionId = await createCollectionExpectSuccess();137    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);138    await enableAllowListExpectSuccess(alice, collectionId);139    await addToAllowListExpectSuccess(alice, collectionId, alice.address);140    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);141    await approveExpectSuccess(collectionId, itemId, alice, charlie.address);142    await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice));143144    await transferExpectFailure(145      collectionId,146      itemId,147      alice,148      charlie,149      1,150    );151  });152153  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 () => {154    const collectionId = await createCollectionExpectSuccess();155    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);156    await enableAllowListExpectSuccess(alice, collectionId);157    await addToAllowListExpectSuccess(alice, collectionId, alice.address);158159    await transferExpectFailure(160      collectionId,161      itemId,162      alice,163      charlie,164      1,165    );166  });167168  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 () => {169    const collectionId = await createCollectionExpectSuccess();170    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);171    await enableAllowListExpectSuccess(alice, collectionId);172    await addToAllowListExpectSuccess(alice, collectionId, alice.address);173    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);174    await approveExpectSuccess(collectionId, itemId, alice, charlie.address);175    await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice));176177    await transferExpectFailure(178      collectionId,179      itemId,180      alice,181      charlie,182      1,183    );184  });185186  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 () => {187    const collectionId = await createCollectionExpectSuccess();188    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);189    await enableAllowListExpectSuccess(alice, collectionId);190191    await usingApi(async (api) => {192      const tx = api.tx.unique.burnItem(collectionId, itemId, /*normalizeAccountId(Alice.address),*/ 11);193      const badTransaction = async function () {194        await submitTransactionExpectFailAsync(alice, tx);195      };196      await expect(badTransaction()).to.be.rejected;197    });198  });199200  it('If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method)', async () => {201    const collectionId = await createCollectionExpectSuccess();202    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);203    await enableAllowListExpectSuccess(alice, collectionId);204    await approveExpectFail(collectionId, itemId, alice, bob);205  });206207  it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async () => {208    const collectionId = await createCollectionExpectSuccess();209    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);210    await enableAllowListExpectSuccess(alice, collectionId);211    await addToAllowListExpectSuccess(alice, collectionId, alice.address);212    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);213    await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');214  });215216  it('If Public Access mode is set to AllowList, tokens can be transferred to a alowlisted address with transferFrom.', async () => {217    const collectionId = await createCollectionExpectSuccess();218    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);219    await enableAllowListExpectSuccess(alice, collectionId);220    await addToAllowListExpectSuccess(alice, collectionId, alice.address);221    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);222    await approveExpectSuccess(collectionId, itemId, alice, charlie.address);223    await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');224  });225226  it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async () => {227    const collectionId = await createCollectionExpectSuccess();228    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);229    await enableAllowListExpectSuccess(alice, collectionId);230    await addToAllowListExpectSuccess(alice, collectionId, alice.address);231    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);232    await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');233  });234235  it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async () => {236    const collectionId = await createCollectionExpectSuccess();237    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);238    await enableAllowListExpectSuccess(alice, collectionId);239    await addToAllowListExpectSuccess(alice, collectionId, alice.address);240    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);241    await approveExpectSuccess(collectionId, itemId, alice, charlie.address);242    await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');243  });244245  it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner', async () => {246    const collectionId = await createCollectionExpectSuccess();247    await enableAllowListExpectSuccess(alice, collectionId);248    await setMintPermissionExpectSuccess(alice, collectionId, false);249    await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);250  });251252  it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin', async () => {253    const collectionId = await createCollectionExpectSuccess();254    await enableAllowListExpectSuccess(alice, collectionId);255    await setMintPermissionExpectSuccess(alice, collectionId, false);256    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);257    await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);258  });259260  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 () => {261    const collectionId = await createCollectionExpectSuccess();262    await enableAllowListExpectSuccess(alice, collectionId);263    await setMintPermissionExpectSuccess(alice, collectionId, false);264    await addToAllowListExpectSuccess(alice, collectionId, bob.address);265    await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);266  });267268  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 () => {269    const collectionId = await createCollectionExpectSuccess();270    await enableAllowListExpectSuccess(alice, collectionId);271    await setMintPermissionExpectSuccess(alice, collectionId, false);272    await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);273  });274275  it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner', async () => {276    const collectionId = await createCollectionExpectSuccess();277    await enableAllowListExpectSuccess(alice, collectionId);278    await setMintPermissionExpectSuccess(alice, collectionId, true);279    await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);280  });281282  it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin', async () => {283    const collectionId = await createCollectionExpectSuccess();284    await enableAllowListExpectSuccess(alice, collectionId);285    await setMintPermissionExpectSuccess(alice, collectionId, true);286    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);287    await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);288  });289290  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 () => {291    const collectionId = await createCollectionExpectSuccess();292    await enableAllowListExpectSuccess(alice, collectionId);293    await setMintPermissionExpectSuccess(alice, collectionId, true);294    await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);295  });296297  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 () => {298    const collectionId = await createCollectionExpectSuccess();299    await enableAllowListExpectSuccess(alice, collectionId);300    await setMintPermissionExpectSuccess(alice, collectionId, true);301    await addToAllowListExpectSuccess(alice, collectionId, bob.address);302    await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);303  });304});