git.delta.rocks / unique-network / refs/commits / 4d4a023748fc

difftreelog

source

tests/src/createCollection.test.ts7.7 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {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({filename: __filename});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({filename: __filename});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 = async () => 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 = async () => 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 = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'A'.repeat(17)});128    await expect(mintCollectionTx()).to.be.rejectedWith('Verification Error');129  });130  131  itSub('(!negative test!) fails when bad limits are set', async ({helper}) => {132    const mintCollectionTx = async () => 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 = async () => 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 = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', properties: props});154    await expect(mintCollectionTx()).to.be.rejectedWith('Verification Error');155  });156});