1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';21import {22 addToAllowListExpectSuccess,23 createCollectionExpectSuccess,24 createItemExpectSuccess,25 destroyCollectionExpectSuccess,26 enableAllowListExpectSuccess,27 normalizeAccountId,28 addCollectionAdminExpectSuccess,29 addToAllowListExpectFail,30 removeFromAllowListExpectSuccess,31 removeFromAllowListExpectFailure,32 addToAllowListAgainExpectSuccess,33 transferExpectFailure,34 approveExpectSuccess,35 approveExpectFail,36 transferExpectSuccess,37 transferFromExpectSuccess,38 setMintPermissionExpectSuccess,39 createItemExpectFailure,40} from './util/helpers';4142chai.use(chaiAsPromised);43const expect = chai.expect;4445let alice: IKeyringPair;46let bob: IKeyringPair;47let charlie: IKeyringPair;4849describe('Integration Test ext. Allow list tests', () => {5051 before(async () => {52 await usingApi(async (api, privateKeyWrapper) => {53 alice = privateKeyWrapper('//Alice');54 bob = privateKeyWrapper('//Bob');55 charlie = privateKeyWrapper('//Charlie');56 });57 });5859 it('Owner can add address to allow list', async () => {60 const collectionId = await createCollectionExpectSuccess();61 await addToAllowListExpectSuccess(alice, collectionId, bob.address);62 });6364 it('Admin can add address to allow list', async () => {65 const collectionId = await createCollectionExpectSuccess();66 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);67 await addToAllowListExpectSuccess(bob, collectionId, charlie.address);68 });6970 it('Non-privileged user cannot add address to allow list', async () => {71 const collectionId = await createCollectionExpectSuccess();72 await addToAllowListExpectFail(bob, collectionId, charlie.address);73 });7475 it('Nobody can add address to allow list of non-existing collection', async () => {76 const collectionId = (1<<32) - 1;77 await addToAllowListExpectFail(alice, collectionId, bob.address);78 });7980 it('Nobody can add address to allow list of destroyed collection', async () => {81 const collectionId = await createCollectionExpectSuccess();82 await destroyCollectionExpectSuccess(collectionId, '//Alice');83 await addToAllowListExpectFail(alice, collectionId, bob.address);84 });8586 it('If address is already added to allow list, nothing happens', async () => {87 const collectionId = await createCollectionExpectSuccess();88 await addToAllowListExpectSuccess(alice, collectionId, bob.address);89 await addToAllowListAgainExpectSuccess(alice, collectionId, bob.address);90 });9192 it('Owner can remove address from allow list', async () => {93 const collectionId = await createCollectionExpectSuccess();94 await addToAllowListExpectSuccess(alice, collectionId, bob.address);95 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(bob));96 });9798 it('Admin can remove address from allow list', async () => {99 const collectionId = await createCollectionExpectSuccess();100 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);101 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);102 await removeFromAllowListExpectSuccess(bob, collectionId, normalizeAccountId(charlie));103 });104105 it('Non-privileged user cannot remove address from allow list', async () => {106 const collectionId = await createCollectionExpectSuccess();107 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);108 await removeFromAllowListExpectFailure(bob, collectionId, normalizeAccountId(charlie));109 });110111 it('Nobody can remove address from allow list of non-existing collection', async () => {112 const collectionId = (1<<32) - 1;113 await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie));114 });115116 it('Nobody can remove address from allow list of deleted collection', async () => {117 const collectionId = await createCollectionExpectSuccess();118 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);119 await destroyCollectionExpectSuccess(collectionId, '//Alice');120 await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie));121 });122123 it('If address is already removed from allow list, nothing happens', async () => {124 const collectionId = await createCollectionExpectSuccess();125 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);126 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));127 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));128 });129130 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 () => {131 const collectionId = await createCollectionExpectSuccess();132 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);133 await enableAllowListExpectSuccess(alice, collectionId);134 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);135136 await transferExpectFailure(137 collectionId,138 itemId,139 alice,140 charlie,141 1,142 );143 });144145 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 () => {146 const collectionId = await createCollectionExpectSuccess();147 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);148 await enableAllowListExpectSuccess(alice, collectionId);149 await addToAllowListExpectSuccess(alice, collectionId, alice.address);150 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);151 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);152 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice));153154 await transferExpectFailure(155 collectionId,156 itemId,157 alice,158 charlie,159 1,160 );161 });162163 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 () => {164 const collectionId = await createCollectionExpectSuccess();165 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);166 await enableAllowListExpectSuccess(alice, collectionId);167 await addToAllowListExpectSuccess(alice, collectionId, alice.address);168169 await transferExpectFailure(170 collectionId,171 itemId,172 alice,173 charlie,174 1,175 );176 });177178 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 () => {179 const collectionId = await createCollectionExpectSuccess();180 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);181 await enableAllowListExpectSuccess(alice, collectionId);182 await addToAllowListExpectSuccess(alice, collectionId, alice.address);183 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);184 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);185 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice));186187 await transferExpectFailure(188 collectionId,189 itemId,190 alice,191 charlie,192 1,193 );194 });195196 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 () => {197 const collectionId = await createCollectionExpectSuccess();198 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);199 await enableAllowListExpectSuccess(alice, collectionId);200201 await usingApi(async (api) => {202 const tx = api.tx.unique.burnItem(collectionId, itemId, 11);203 const badTransaction = async function () {204 await submitTransactionExpectFailAsync(alice, tx);205 };206 await expect(badTransaction()).to.be.rejected;207 });208 });209210 it('If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method)', async () => {211 const collectionId = await createCollectionExpectSuccess();212 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);213 await enableAllowListExpectSuccess(alice, collectionId);214 await approveExpectFail(collectionId, itemId, alice, bob);215 });216217 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async () => {218 const collectionId = await createCollectionExpectSuccess();219 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);220 await enableAllowListExpectSuccess(alice, collectionId);221 await addToAllowListExpectSuccess(alice, collectionId, alice.address);222 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);223 await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');224 });225226 it('If Public Access mode is set to AllowList, tokens can be transferred to a alowlisted address with transferFrom.', 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 approveExpectSuccess(collectionId, itemId, alice, charlie.address);233 await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');234 });235236 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async () => {237 const collectionId = await createCollectionExpectSuccess();238 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);239 await enableAllowListExpectSuccess(alice, collectionId);240 await addToAllowListExpectSuccess(alice, collectionId, alice.address);241 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);242 await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');243 });244245 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async () => {246 const collectionId = await createCollectionExpectSuccess();247 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);248 await enableAllowListExpectSuccess(alice, collectionId);249 await addToAllowListExpectSuccess(alice, collectionId, alice.address);250 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);251 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);252 await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');253 });254255 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner', async () => {256 const collectionId = await createCollectionExpectSuccess();257 await enableAllowListExpectSuccess(alice, collectionId);258 await setMintPermissionExpectSuccess(alice, collectionId, false);259 await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);260 });261262 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin', async () => {263 const collectionId = await createCollectionExpectSuccess();264 await enableAllowListExpectSuccess(alice, collectionId);265 await setMintPermissionExpectSuccess(alice, collectionId, false);266 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);267 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);268 });269270 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 () => {271 const collectionId = await createCollectionExpectSuccess();272 await enableAllowListExpectSuccess(alice, collectionId);273 await setMintPermissionExpectSuccess(alice, collectionId, false);274 await addToAllowListExpectSuccess(alice, collectionId, bob.address);275 await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);276 });277278 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 () => {279 const collectionId = await createCollectionExpectSuccess();280 await enableAllowListExpectSuccess(alice, collectionId);281 await setMintPermissionExpectSuccess(alice, collectionId, false);282 await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);283 });284285 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner', async () => {286 const collectionId = await createCollectionExpectSuccess();287 await enableAllowListExpectSuccess(alice, collectionId);288 await setMintPermissionExpectSuccess(alice, collectionId, true);289 await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);290 });291292 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin', async () => {293 const collectionId = await createCollectionExpectSuccess();294 await enableAllowListExpectSuccess(alice, collectionId);295 await setMintPermissionExpectSuccess(alice, collectionId, true);296 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);297 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);298 });299300 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 () => {301 const collectionId = await createCollectionExpectSuccess();302 await enableAllowListExpectSuccess(alice, collectionId);303 await setMintPermissionExpectSuccess(alice, collectionId, true);304 await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);305 });306307 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 () => {308 const collectionId = await createCollectionExpectSuccess();309 await enableAllowListExpectSuccess(alice, collectionId);310 await setMintPermissionExpectSuccess(alice, collectionId, true);311 await addToAllowListExpectSuccess(alice, collectionId, bob.address);312 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);313 });314});