1234567891011121314151617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import {usingPlaygrounds} from './util/playgrounds';20import {IKeyringPair} from '@polkadot/types/types';21import {IProperty} from './util/playgrounds/types';2223chai.use(chaiAsPromised);24const expect = chai.expect;2526let donor: IKeyringPair;2728before(async () => {29 await usingPlaygrounds(async (_, privateKey) => {30 donor = privateKey('//Alice');31 });32});3334let alice: IKeyringPair;3536describe('integration test: ext. createCollection():', () => {37 before(async () => {38 await usingPlaygrounds(async (helper) => {39 [alice] = await helper.arrange.createAccounts([100n], donor);40 });41 });42 it('Create new NFT collection', async () => {43 await usingPlaygrounds(async (helper) => {44 await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});45 });46 });47 it('Create new NFT collection whith collection_name of maximum length (64 bytes)', async () => {48 await usingPlaygrounds(async (helper) => {49 await helper.nft.mintCollection(alice, {name: 'A'.repeat(64), description: 'descr', tokenPrefix: 'COL'});50 });51 });52 it('Create new NFT collection whith collection_description of maximum length (256 bytes)', async () => {53 await usingPlaygrounds(async (helper) => {54 await helper.nft.mintCollection(alice, {name: 'name', description: 'A'.repeat(256), tokenPrefix: 'COL'});55 });56 });57 it('Create new NFT collection whith token_prefix of maximum length (16 bytes)', async () => {58 await usingPlaygrounds(async (helper) => {59 await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'A'.repeat(16)});60 });61 });62 it('Create new Fungible collection', async () => {63 await usingPlaygrounds(async (helper) => {64 await helper.ft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'}, 0);65 });66 });67 it('Create new ReFungible collection', async function() {68 await usingPlaygrounds(async (helper) => {69 await helper.rft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});70 });71 });7273 it('create new collection with properties', async () => {74 await usingPlaygrounds(async (helper) => {75 await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL',76 properties: [{key: 'key1', value: 'val1'}],77 tokenPropertyPermissions: [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}],78 });79 });80 });8182 it('Create new collection with extra fields', async () => {83 await usingPlaygrounds(async (helper) => {84 const collection = await helper.ft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'}, 8);85 await collection.setPermissions(alice, {access: 'AllowList'});86 await collection.setLimits(alice, {accountTokenOwnershipLimit: 3});87 const data = await collection.getData();88 const limits = await collection.getEffectiveLimits();89 const raw = data?.raw;9091 expect(data?.normalizedOwner).to.be.equal(alice.address);92 expect(data?.name).to.be.equal('name');93 expect(data?.description).to.be.equal('descr');94 expect(raw.permissions.access).to.be.equal('AllowList');95 expect(raw.mode).to.be.deep.equal({Fungible: '8'});96 expect(limits.accountTokenOwnershipLimit).to.be.equal(3);97 });98 });99100 it('New collection is not external', async () => {101 await usingPlaygrounds(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 });107});108109describe('(!negative test!) integration test: ext. createCollection():', () => {110 it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {111 await usingPlaygrounds(async (helper) => {112 const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'A'.repeat(65), description: 'descr', tokenPrefix: 'COL'});113 await expect(mintCollectionTx()).to.be.rejected;114 });115 });116 it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => {117 await usingPlaygrounds(async (helper) => {118 const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'A'.repeat(257), tokenPrefix: 'COL'});119 await expect(mintCollectionTx()).to.be.rejected;120 });121 });122 it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => {123 await usingPlaygrounds(async (helper) => {124 const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'A'.repeat(17)});125 await expect(mintCollectionTx()).to.be.rejected;126 });127 });128 it('(!negative test!) fails when bad limits are set', async () => {129 await usingPlaygrounds(async (helper) => {130 const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', limits: {tokenLimit: 0}});131 await expect(mintCollectionTx()).to.be.rejected;132 });133 });134135 it('(!negative test!) create collection with incorrect property limit (64 elements)', async () => {136 const props: IProperty[] = [];137138 for (let i = 0; i < 65; i++) {139 props.push({key: `key${i}`, value: `value${i}`});140 }141 await usingPlaygrounds(async (helper) => {142 const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', properties: props});143 await expect(mintCollectionTx()).to.be.rejected;144 });145 });146147 it('(!negative test!) create collection with incorrect property limit (40 kb)', async () => {148 const props: IProperty[] = [];149150 for (let i = 0; i < 32; i++) {151 props.push({key: `key${i}`.repeat(80), value: `value${i}`.repeat(80)});152 }153 await usingPlaygrounds(async (helper) => {154 const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', properties: props});155 await expect(mintCollectionTx()).to.be.rejected;156 });157 });158});