1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {usingPlaygrounds, expect, itSub, Pallets} from './util';19import {CollectionFlag, ICollectionCreationOptions, IProperty} from './util/playgrounds/types';20import {UniqueHelper} from './util/playgrounds/unique';2122async function mintCollectionHelper(helper: UniqueHelper, signer: IKeyringPair, options: ICollectionCreationOptions, type?: 'nft' | 'fungible' | 'refungible') {23 let collection;24 if(type === 'nft') {25 collection = await helper.nft.mintCollection(signer, options);26 } else if(type === 'fungible') {27 collection = await helper.ft.mintCollection(signer, options, 0);28 } else {29 collection = await helper.rft.mintCollection(signer, options);30 }31 const data = await collection.getData();32 expect(data?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(signer.address));33 expect(data?.name).to.be.equal(options.name);34 expect(data?.description).to.be.equal(options.description);35 expect(data?.raw.tokenPrefix).to.be.equal(options.tokenPrefix);36 if(options.properties) {37 expect(data?.raw.properties).to.be.deep.equal(options.properties);38 }39 if(options.adminList) {40 expect(data?.admins).to.be.deep.equal(options.adminList);41 }4243 if(options.flags) {44 if((options.flags[0] & 64) != 0)45 expect(data?.raw.flags.erc721metadata).to.be.true;46 if((options.flags[0] & 128) != 0)47 expect(data?.raw.flags.foreign).to.be.false;48 }4950 if(options.tokenPropertyPermissions) {51 expect(data?.raw.tokenPropertyPermissions).to.be.deep.equal(options.tokenPropertyPermissions);52 }5354 return collection;55}5657describe('integration test: ext. createCollection():', () => {58 let alice: IKeyringPair;59 let bob: IKeyringPair;6061 before(async () => {62 await usingPlaygrounds(async (helper, privateKey) => {63 const donor = await privateKey({url: import.meta.url});64 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);65 });66 });67 itSub('Create new NFT collection', async ({helper}) => {68 await mintCollectionHelper(helper, alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 'nft');69 });70 itSub('Create new NFT collection whith collection_name of maximum length (64 bytes)', async ({helper}) => {71 await mintCollectionHelper(helper, alice, {name: 'A'.repeat(64), description: 'descr', tokenPrefix: 'COL'}, 'nft');72 });73 itSub('Create new NFT collection whith collection_description of maximum length (256 bytes)', async ({helper}) => {74 await mintCollectionHelper(helper, alice, {name: 'name', description: 'A'.repeat(256), tokenPrefix: 'COL'}, 'nft');75 });76 itSub('Create new NFT collection whith token_prefix of maximum length (16 bytes)', async ({helper}) => {77 await mintCollectionHelper(helper, alice, {name: 'name', description: 'descr', tokenPrefix: 'A'.repeat(16)}, 'nft');78 });7980 itSub('Create new Fungible collection', async ({helper}) => {81 await mintCollectionHelper(helper, alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'}, 'fungible');82 });8384 itSub.ifWithPallets('Create new ReFungible collection', [Pallets.ReFungible], async ({helper}) => {85 await mintCollectionHelper(helper, alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'}, 'refungible');86 });8788 itSub('create new collection with properties', async ({helper}) => {89 await mintCollectionHelper(helper, alice, {90 name: 'name', description: 'descr', tokenPrefix: 'COL',91 properties: [{key: 'key1', value: 'val1'}],92 tokenPropertyPermissions: [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}],93 }, 'nft');94 });9596 itSub('create new collection with admin', async ({helper}) => {97 await mintCollectionHelper(helper, alice, {98 name: 'name', description: 'descr', tokenPrefix: 'COL',99 adminList: [{Substrate: bob.address}],100 }, 'nft');101 });102103 itSub('create new collection with flags', async ({helper}) => {104 await mintCollectionHelper(helper, alice, {105 name: 'name', description: 'descr', tokenPrefix: 'COL',106 flags: [CollectionFlag.Erc721metadata],107 }, 'nft');108109 110111 await expect(mintCollectionHelper(helper, alice, {112 name: 'name', description: 'descr', tokenPrefix: 'COL',113 flags: [CollectionFlag.Foreign],114 }, 'nft')).to.be.rejectedWith(/common.NoPermission/);115116 await expect(mintCollectionHelper(helper, alice, {117 name: 'name', description: 'descr', tokenPrefix: 'COL',118 flags: [CollectionFlag.Erc721metadata, CollectionFlag.Foreign],119 }, 'nft')).to.be.rejectedWith(/common.NoPermission/);120 });121122 itSub('Create new collection with extra fields', async ({helper}) => {123 const collection = await mintCollectionHelper(helper, alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'}, 'fungible');124 await collection.setPermissions(alice, {access: 'AllowList'});125 await collection.setLimits(alice, {accountTokenOwnershipLimit: 3});126 const data = await collection.getData();127 const limits = await collection.getEffectiveLimits();128 const raw = data?.raw;129130 expect(data?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(alice.address));131 expect(data?.name).to.be.equal('name');132 expect(data?.description).to.be.equal('descr');133 expect(raw.permissions.access).to.be.equal('AllowList');134 expect(raw.mode).to.be.deep.equal({Fungible: '0'});135 expect(limits.accountTokenOwnershipLimit).to.be.equal(3);136 });137138 itSub('New collection is not external', async ({helper}) => {139 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});140 const data = await collection.getData();141 expect(data?.raw.readOnly).to.be.false;142 });143});144145describe('(!negative test!) integration test: ext. createCollection():', () => {146 let alice: IKeyringPair;147148 before(async () => {149 await usingPlaygrounds(async (helper, privateKey) => {150 const donor = await privateKey({url: import.meta.url});151 [alice] = await helper.arrange.createAccounts([100n], donor);152 });153 });154155 itSub('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async ({helper}) => {156 const mintCollectionTx = () => helper.nft.mintCollection(alice, {name: 'A'.repeat(65), description: 'descr', tokenPrefix: 'COL'});157 await expect(mintCollectionTx()).to.be.rejectedWith('Verification Error');158 });159 itSub('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async ({helper}) => {160 const mintCollectionTx = () => helper.nft.mintCollection(alice, {name: 'name', description: 'A'.repeat(257), tokenPrefix: 'COL'});161 await expect(mintCollectionTx()).to.be.rejectedWith('Verification Error');162 });163 itSub('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async ({helper}) => {164 const mintCollectionTx = () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'A'.repeat(17)});165 await expect(mintCollectionTx()).to.be.rejectedWith('Verification Error');166 });167168 itSub('(!negative test!) fails when bad limits are set', async ({helper}) => {169 const mintCollectionTx = () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', limits: {tokenLimit: 0}});170 await expect(mintCollectionTx()).to.be.rejectedWith(/common\.CollectionTokenLimitExceeded/);171 });172173 itSub('(!negative test!) create collection with incorrect property limit (64 elements)', async ({helper}) => {174 const props: IProperty[] = [];175176 for(let i = 0; i < 65; i++) {177 props.push({key: `key${i}`, value: `value${i}`});178 }179 const mintCollectionTx = () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', properties: props});180 await expect(mintCollectionTx()).to.be.rejectedWith('Verification Error');181 });182183 itSub('(!negative test!) create collection with incorrect property limit (40 kb)', async ({helper}) => {184 const props: IProperty[] = [];185186 for(let i = 0; i < 32; i++) {187 props.push({key: `key${i}`.repeat(80), value: `value${i}`.repeat(80)});188 }189190 const mintCollectionTx = () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', properties: props});191 await expect(mintCollectionTx()).to.be.rejectedWith('Verification Error');192 });193});