1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {usingPlaygrounds, expect, itSub, Pallets} from './util';19import {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 }3940 if(options.tokenPropertyPermissions) {41 expect(data?.raw.tokenPropertyPermissions).to.be.deep.equal(options.tokenPropertyPermissions);42 }4344 return collection;45}4647describe('integration test: ext. createCollection():', () => {48 let alice: IKeyringPair;4950 before(async () => {51 await usingPlaygrounds(async (helper, privateKey) => {52 const donor = await privateKey({url: import.meta.url});53 [alice] = await helper.arrange.createAccounts([100n], donor);54 });55 });56 itSub('Create new NFT collection', async ({helper}) => {57 await mintCollectionHelper(helper, alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 'nft');58 });59 itSub('Create new NFT collection whith collection_name of maximum length (64 bytes)', async ({helper}) => {60 await mintCollectionHelper(helper, alice, {name: 'A'.repeat(64), description: 'descr', tokenPrefix: 'COL'}, 'nft');61 });62 itSub('Create new NFT collection whith collection_description of maximum length (256 bytes)', async ({helper}) => {63 await mintCollectionHelper(helper, alice, {name: 'name', description: 'A'.repeat(256), tokenPrefix: 'COL'}, 'nft');64 });65 itSub('Create new NFT collection whith token_prefix of maximum length (16 bytes)', async ({helper}) => {66 await mintCollectionHelper(helper, alice, {name: 'name', description: 'descr', tokenPrefix: 'A'.repeat(16)}, 'nft');67 });6869 itSub('Create new Fungible collection', async ({helper}) => {70 await mintCollectionHelper(helper, alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'}, 'fungible');71 });7273 itSub.ifWithPallets('Create new ReFungible collection', [Pallets.ReFungible], async ({helper}) => {74 await mintCollectionHelper(helper, alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'}, 'refungible');75 });7677 itSub('create new collection with properties', async ({helper}) => {78 await mintCollectionHelper(helper, alice, {79 name: 'name', description: 'descr', tokenPrefix: 'COL',80 properties: [{key: 'key1', value: 'val1'}],81 tokenPropertyPermissions: [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}],82 }, 'nft');83 });8485 itSub('Create new collection with extra fields', async ({helper}) => {86 const collection = await mintCollectionHelper(helper, alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'}, 'fungible');87 await collection.setPermissions(alice, {access: 'AllowList'});88 await collection.setLimits(alice, {accountTokenOwnershipLimit: 3});89 const data = await collection.getData();90 const limits = await collection.getEffectiveLimits();91 const raw = data?.raw;9293 expect(data?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(alice.address));94 expect(data?.name).to.be.equal('name');95 expect(data?.description).to.be.equal('descr');96 expect(raw.permissions.access).to.be.equal('AllowList');97 expect(raw.mode).to.be.deep.equal({Fungible: '0'});98 expect(limits.accountTokenOwnershipLimit).to.be.equal(3);99 });100101 itSub('New collection is not external', async ({helper}) => {102 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});103 const data = await collection.getData();104 expect(data?.raw.readOnly).to.be.false;105 });106});107108describe('(!negative test!) integration test: ext. createCollection():', () => {109 let alice: IKeyringPair;110111 before(async () => {112 await usingPlaygrounds(async (helper, privateKey) => {113 const donor = await privateKey({url: import.meta.url});114 [alice] = await helper.arrange.createAccounts([100n], donor);115 });116 });117118 itSub('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async ({helper}) => {119 const mintCollectionTx = () => helper.nft.mintCollection(alice, {name: 'A'.repeat(65), description: 'descr', tokenPrefix: 'COL'});120 await expect(mintCollectionTx()).to.be.rejectedWith('Verification Error');121 });122 itSub('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async ({helper}) => {123 const mintCollectionTx = () => helper.nft.mintCollection(alice, {name: 'name', description: 'A'.repeat(257), tokenPrefix: 'COL'});124 await expect(mintCollectionTx()).to.be.rejectedWith('Verification Error');125 });126 itSub('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async ({helper}) => {127 const mintCollectionTx = () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'A'.repeat(17)});128 await expect(mintCollectionTx()).to.be.rejectedWith('Verification Error');129 });130131 itSub('(!negative test!) fails when bad limits are set', async ({helper}) => {132 const mintCollectionTx = () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', limits: {tokenLimit: 0}});133 await expect(mintCollectionTx()).to.be.rejectedWith(/common\.CollectionTokenLimitExceeded/);134 });135136 itSub('(!negative test!) create collection with incorrect property limit (64 elements)', async ({helper}) => {137 const props: IProperty[] = [];138139 for(let i = 0; i < 65; i++) {140 props.push({key: `key${i}`, value: `value${i}`});141 }142 const mintCollectionTx = () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', properties: props});143 await expect(mintCollectionTx()).to.be.rejectedWith('Verification Error');144 });145146 itSub('(!negative test!) create collection with incorrect property limit (40 kb)', async ({helper}) => {147 const props: IProperty[] = [];148149 for(let i = 0; i < 32; i++) {150 props.push({key: `key${i}`.repeat(80), value: `value${i}`.repeat(80)});151 }152153 const mintCollectionTx = () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', properties: props});154 await expect(mintCollectionTx()).to.be.rejectedWith('Verification Error');155 });156});