1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util/playgrounds';1920describe('Integration Test: Set Permissions', () => {21 let alice: IKeyringPair;22 let bob: IKeyringPair;2324 before(async () => {25 await usingPlaygrounds(async (helper, privateKey) => {26 const donor = await privateKey({filename: __filename});27 [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);28 });29 });3031 itSub('can all be enabled twice', async ({helper}) => {32 const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-1', tokenPrefix: 'SP'});33 expect((await collection.getData())?.raw.permissions.access).to.not.equal('AllowList');3435 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true, tokenOwner: true, restricted: [1, 2]}});36 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true, tokenOwner: true, restricted: [1, 2]}});37 38 const permissions = (await collection.getData())?.raw.permissions;39 expect(permissions).to.be.deep.equal({40 access: 'AllowList', 41 mintMode: true, 42 nesting: {collectionAdmin: true, tokenOwner: true, restricted: [1, 2]},43 });44 });4546 itSub('can all be disabled twice', async ({helper}) => {47 const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-2', tokenPrefix: 'SP'});48 expect((await collection.getData())?.raw.permissions.access).to.equal('Normal');4950 await collection.setPermissions(alice, {access: 'AllowList', nesting: {collectionAdmin: false, tokenOwner: true, restricted: [1, 2]}});51 expect((await collection.getData())?.raw.permissions).to.be.deep.equal({52 access: 'AllowList', 53 mintMode: false, 54 nesting: {collectionAdmin: false, tokenOwner: true, restricted: [1, 2]},55 });5657 await collection.setPermissions(alice, {access: 'Normal', mintMode: false, nesting: {}});58 await collection.setPermissions(alice, {access: 'Normal', mintMode: false, nesting: {}});59 expect((await collection.getData())?.raw.permissions).to.be.deep.equal({60 access: 'Normal', 61 mintMode: false, 62 nesting: {collectionAdmin: false, tokenOwner: false, restricted: null},63 });64 });6566 itSub('collection admin can set permissions', async ({helper}) => {67 const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-2', tokenPrefix: 'SP'});68 await collection.addAdmin(alice, {Substrate: bob.address});69 await collection.setPermissions(bob, {access: 'AllowList', mintMode: true});70 71 expect((await collection.getData())?.raw.permissions.access).to.equal('AllowList');72 expect((await collection.getData())?.raw.permissions.mintMode).to.equal(true);73 });74});7576describe('Negative Integration Test: Set Permissions', () => {77 let alice: IKeyringPair;78 let bob: IKeyringPair;7980 before(async () => {81 await usingPlaygrounds(async (helper, privateKey) => {82 const donor = await privateKey({filename: __filename});83 [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);84 });85 });8687 itSub('fails on not existing collection', async ({helper}) => {88 const collectionId = (1 << 32) - 1;89 await expect(helper.collection.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true}))90 .to.be.rejectedWith(/common\.CollectionNotFound/);91 });9293 itSub('fails on removed collection', async ({helper}) => {94 const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-Neg-1', tokenPrefix: 'SP'});95 await collection.burn(alice);9697 await expect(collection.setPermissions(alice, {access: 'AllowList', mintMode: true}))98 .to.be.rejectedWith(/common\.CollectionNotFound/);99 });100101 itSub('fails when non-owner tries to set permissions', async ({helper}) => {102 const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-Neg-2', tokenPrefix: 'SP'});103104 await expect(collection.setPermissions(bob, {access: 'AllowList', mintMode: true}))105 .to.be.rejectedWith(/common\.NoPermission/);106 });107});