1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import {itSub, usingPlaygrounds} from './util/playgrounds';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425describe('Integration Test setMintPermission', () => {26 let alice: IKeyringPair;27 let bob: IKeyringPair;2829 before(async () => {30 await usingPlaygrounds(async (helper, privateKey) => {31 const donor = privateKey('//Alice');32 [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);33 });34 });3536 itSub('ensure allow-listed non-privileged address can mint tokens', async ({helper}) => {37 const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-1', description: '', tokenPrefix: 'SMP'});38 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});39 await collection.addToAllowList(alice, {Substrate: bob.address});4041 await expect(collection.mintToken(bob, {Substrate: bob.address})).to.not.be.rejected;42 });4344 itSub('can be enabled twice', async ({helper}) => {45 const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-2', description: '', tokenPrefix: 'SMP'});46 expect((await collection.getData())?.raw.permissions.access).to.not.equal('AllowList');4748 await collection.setPermissions(alice, {mintMode: true});49 await collection.setPermissions(alice, {mintMode: true});50 expect((await collection.getData())?.raw.permissions.mintMode).to.be.true;51 });5253 itSub('can be disabled twice', async ({helper}) => {54 const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-3', description: '', tokenPrefix: 'SMP'});55 expect((await collection.getData())?.raw.permissions.access).to.equal('Normal');5657 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});58 expect((await collection.getData())?.raw.permissions.access).to.equal('AllowList');59 expect((await collection.getData())?.raw.permissions.mintMode).to.equal(true);6061 await collection.setPermissions(alice, {access: 'Normal', mintMode: false});62 await collection.setPermissions(alice, {access: 'Normal', mintMode: false});63 expect((await collection.getData())?.raw.permissions.access).to.equal('Normal');64 expect((await collection.getData())?.raw.permissions.mintMode).to.equal(false);65 });6667 itSub('Collection admin success on set', async ({helper}) => {68 const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-4', description: '', tokenPrefix: 'SMP'});69 await collection.addAdmin(alice, {Substrate: bob.address});70 await collection.setPermissions(bob, {access: 'AllowList', mintMode: true});71 72 expect((await collection.getData())?.raw.permissions.access).to.equal('AllowList');73 expect((await collection.getData())?.raw.permissions.mintMode).to.equal(true);74 });75});7677describe('Negative Integration Test setMintPermission', () => {78 let alice: IKeyringPair;79 let bob: IKeyringPair;8081 before(async () => {82 await usingPlaygrounds(async (helper, privateKey) => {83 const donor = privateKey('//Alice');84 [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);85 });86 });8788 itSub('fails on not existing collection', async ({helper}) => {89 const collectionId = (1 << 32) - 1;90 await expect(helper.collection.setPermissions(alice, collectionId, {mintMode: true}))91 .to.be.rejectedWith(/common\.CollectionNotFound/);92 });9394 itSub('fails on removed collection', async ({helper}) => {95 const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-Neg-1', tokenPrefix: 'SMP'});96 await collection.burn(alice);9798 await expect(collection.setPermissions(alice, {mintMode: true}))99 .to.be.rejectedWith(/common\.CollectionNotFound/);100 });101102 itSub('fails when non-owner tries to set mint status', async ({helper}) => {103 const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-Neg-2', tokenPrefix: 'SMP'});104105 await expect(collection.setPermissions(bob, {mintMode: true}))106 .to.be.rejectedWith(/common\.NoPermission/);107 });108109 itSub('ensure non-allow-listed non-privileged address can\'t mint tokens', async ({helper}) => {110 const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-Neg-3', tokenPrefix: 'SMP'});111 await collection.setPermissions(alice, {mintMode: true});112113 await expect(collection.mintToken(bob, {Substrate: bob.address}))114 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);115 });116});