123456import {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 addToWhiteListExpectSuccess,13 createCollectionExpectSuccess,14 createItemExpectSuccess,15 destroyCollectionExpectSuccess,16 enableWhiteListExpectSuccess,17 normalizeAccountId,18 addCollectionAdminExpectSuccess,19 addToWhiteListExpectFail,20 removeFromWhiteListExpectSuccess,21 removeFromWhiteListExpectFailure,22 addToWhiteListAgainExpectSuccess,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. White 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 white list', async () => {50 const collectionId = await createCollectionExpectSuccess();51 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);52 });5354 it('Admin can add address to white list', async () => {55 const collectionId = await createCollectionExpectSuccess();56 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);57 await addToWhiteListExpectSuccess(bob, collectionId, charlie.address);58 });5960 it('Non-privileged user cannot add address to white list', async () => {61 const collectionId = await createCollectionExpectSuccess();62 await addToWhiteListExpectFail(bob, collectionId, charlie.address);63 });6465 it('Nobody can add address to white list of non-existing collection', async () => {66 const collectionId = (1<<32) - 1;67 await addToWhiteListExpectFail(alice, collectionId, bob.address);68 });6970 it('Nobody can add address to white list of destroyed collection', async () => {71 const collectionId = await createCollectionExpectSuccess();72 await destroyCollectionExpectSuccess(collectionId, '//Alice');73 await addToWhiteListExpectFail(alice, collectionId, bob.address);74 });7576 it('If address is already added to white list, nothing happens', async () => {77 const collectionId = await createCollectionExpectSuccess();78 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);79 await addToWhiteListAgainExpectSuccess(alice, collectionId, bob.address);80 });8182 it('Owner can remove address from white list', async () => {83 const collectionId = await createCollectionExpectSuccess();84 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);85 await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(bob));86 });8788 it('Admin can remove address from white list', async () => {89 const collectionId = await createCollectionExpectSuccess();90 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);91 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);92 await removeFromWhiteListExpectSuccess(bob, collectionId, normalizeAccountId(charlie));93 });9495 it('Non-privileged user cannot remove address from white list', async () => {96 const collectionId = await createCollectionExpectSuccess();97 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);98 await removeFromWhiteListExpectFailure(bob, collectionId, normalizeAccountId(charlie));99 });100101 it('Nobody can remove address from white list of non-existing collection', async () => {102 const collectionId = (1<<32) - 1;103 await removeFromWhiteListExpectFailure(alice, collectionId, normalizeAccountId(charlie));104 });105106 it('Nobody can remove address from white list of deleted collection', async () => {107 const collectionId = await createCollectionExpectSuccess();108 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);109 await destroyCollectionExpectSuccess(collectionId, '//Alice');110 await removeFromWhiteListExpectFailure(alice, collectionId, normalizeAccountId(charlie));111 });112113 it('If address is already removed from white list, nothing happens', async () => {114 const collectionId = await createCollectionExpectSuccess();115 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);116 await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));117 await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));118 });119120 it('If Public Access mode is set to WhiteList, tokens can’t be transferred from a non-whitelisted address with transfer or transferFrom. Test1', async () => {121 const collectionId = await createCollectionExpectSuccess();122 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);123 await enableWhiteListExpectSuccess(alice, collectionId);124 await addToWhiteListExpectSuccess(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 WhiteList, tokens can’t be transferred from a non-whitelisted address with transfer or transferFrom. Test2', async () => {136 const collectionId = await createCollectionExpectSuccess();137 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);138 await enableWhiteListExpectSuccess(alice, collectionId);139 await addToWhiteListExpectSuccess(alice, collectionId, alice.address);140 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);141 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);142 await removeFromWhiteListExpectSuccess(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 WhiteList, tokens can’t be transferred to a non-whitelisted address with transfer or transferFrom. Test1', async () => {154 const collectionId = await createCollectionExpectSuccess();155 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);156 await enableWhiteListExpectSuccess(alice, collectionId);157 await addToWhiteListExpectSuccess(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 WhiteList, tokens can’t be transferred to a non-whitelisted address with transfer or transferFrom. Test2', async () => {169 const collectionId = await createCollectionExpectSuccess();170 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);171 await enableWhiteListExpectSuccess(alice, collectionId);172 await addToWhiteListExpectSuccess(alice, collectionId, alice.address);173 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);174 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);175 await removeFromWhiteListExpectSuccess(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 WhiteList, tokens can’t be destroyed by a non-whitelisted address (even if it owned them before enabling WhiteList mode)', async () => {187 const collectionId = await createCollectionExpectSuccess();188 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);189 await enableWhiteListExpectSuccess(alice, collectionId);190191 await usingApi(async (api) => {192 const tx = api.tx.nft.burnItem(collectionId, itemId, 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 WhiteList, token transfers can’t be Approved by a non-whitelisted address (see Approve method)', async () => {201 const collectionId = await createCollectionExpectSuccess();202 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);203 await enableWhiteListExpectSuccess(alice, collectionId);204 await approveExpectFail(collectionId, itemId, alice, bob);205 });206207 it('If Public Access mode is set to WhiteList, tokens can be transferred to a whitelisted address with transfer.', async () => {208 const collectionId = await createCollectionExpectSuccess();209 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);210 await enableWhiteListExpectSuccess(alice, collectionId);211 await addToWhiteListExpectSuccess(alice, collectionId, alice.address);212 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);213 await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');214 });215216 it('If Public Access mode is set to WhiteList, tokens can be transferred to a whitelisted address with transferFrom.', async () => {217 const collectionId = await createCollectionExpectSuccess();218 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);219 await enableWhiteListExpectSuccess(alice, collectionId);220 await addToWhiteListExpectSuccess(alice, collectionId, alice.address);221 await addToWhiteListExpectSuccess(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 WhiteList, tokens can be transferred from a whitelisted address with transfer', async () => {227 const collectionId = await createCollectionExpectSuccess();228 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);229 await enableWhiteListExpectSuccess(alice, collectionId);230 await addToWhiteListExpectSuccess(alice, collectionId, alice.address);231 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);232 await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');233 });234235 it('If Public Access mode is set to WhiteList, tokens can be transferred from a whitelisted address with transferFrom', async () => {236 const collectionId = await createCollectionExpectSuccess();237 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);238 await enableWhiteListExpectSuccess(alice, collectionId);239 await addToWhiteListExpectSuccess(alice, collectionId, alice.address);240 await addToWhiteListExpectSuccess(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 WhiteList, and Mint Permission is set to false, tokens can be created by owner', async () => {246 const collectionId = await createCollectionExpectSuccess();247 await enableWhiteListExpectSuccess(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 WhiteList, and Mint Permission is set to false, tokens can be created by admin', async () => {253 const collectionId = await createCollectionExpectSuccess();254 await enableWhiteListExpectSuccess(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 WhiteList, and Mint Permission is set to false, tokens cannot be created by non-privileged and white-listed address', async () => {261 const collectionId = await createCollectionExpectSuccess();262 await enableWhiteListExpectSuccess(alice, collectionId);263 await setMintPermissionExpectSuccess(alice, collectionId, false);264 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);265 await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);266 });267268 it('If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-white listed address', async () => {269 const collectionId = await createCollectionExpectSuccess();270 await enableWhiteListExpectSuccess(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 WhiteList, and Mint Permission is set to true, tokens can be created by owner', async () => {276 const collectionId = await createCollectionExpectSuccess();277 await enableWhiteListExpectSuccess(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 WhiteList, and Mint Permission is set to true, tokens can be created by admin', async () => {283 const collectionId = await createCollectionExpectSuccess();284 await enableWhiteListExpectSuccess(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 WhiteList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-white listed address', async () => {291 const collectionId = await createCollectionExpectSuccess();292 await enableWhiteListExpectSuccess(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 WhiteList, and Mint Permission is set to true, tokens can be created by non-privileged and white listed address', async () => {298 const collectionId = await createCollectionExpectSuccess();299 await enableWhiteListExpectSuccess(alice, collectionId);300 await setMintPermissionExpectSuccess(alice, collectionId, true);301 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);302 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);303 });304});