git.delta.rocks / unique-network / refs/commits / e4369d04bed4

difftreelog

source

js-packages/tests/createCollection.test.ts8.5 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 type {IKeyringPair} from '@polkadot/types/types';18import {usingPlaygrounds, expect, itSub, Pallets} from './util/index.js';19import {CollectionFlag} from '@unique/playgrounds/types.js';20import type {ICollectionCreationOptions, IProperty} from '@unique/playgrounds/types.js';21import {UniqueHelper} from '@unique/playgrounds/unique.js';2223async function mintCollectionHelper(helper: UniqueHelper, signer: IKeyringPair, options: ICollectionCreationOptions, type?: 'nft' | 'fungible' | 'refungible') {24  let collection;25  if(type === 'nft') {26    collection = await helper.nft.mintCollection(signer, options);27  } else if(type === 'fungible') {28    collection = await helper.ft.mintCollection(signer, options, 0);29  } else {30    collection = await helper.rft.mintCollection(signer, options);31  }32  const data = await collection.getData();33  expect(data?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(signer.address));34  expect(data?.name).to.be.equal(options.name);35  expect(data?.description).to.be.equal(options.description);36  expect(data?.raw.tokenPrefix).to.be.equal(options.tokenPrefix);37  if(options.properties) {38    expect(data?.raw.properties).to.be.deep.equal(options.properties);39  }40  if(options.adminList) {41    expect(data?.admins).to.be.deep.equal(options.adminList);42  }4344  if(options.flags) {45    if((options.flags[0] & 64) != 0)46      expect(data?.raw.flags.erc721metadata).to.be.true;47    if((options.flags[0] & 128) != 0)48      expect(data?.raw.flags.foreign).to.be.false;49  }5051  if(options.tokenPropertyPermissions) {52    expect(data?.raw.tokenPropertyPermissions).to.be.deep.equal(options.tokenPropertyPermissions);53  }5455  return collection;56}5758describe('integration test: ext. createCollection():', () => {59  let alice: IKeyringPair;60  let bob: IKeyringPair;6162  before(async () => {63    await usingPlaygrounds(async (helper, privateKey) => {64      const donor = await privateKey({url: import.meta.url});65      [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);66    });67  });68  itSub('Create new NFT collection', async ({helper}) => {69    await mintCollectionHelper(helper, alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 'nft');70  });71  itSub('Create new NFT collection whith collection_name of maximum length (64 bytes)', async ({helper}) => {72    await mintCollectionHelper(helper, alice, {name: 'A'.repeat(64), description: 'descr', tokenPrefix: 'COL'}, 'nft');73  });74  itSub('Create new NFT collection whith collection_description of maximum length (256 bytes)', async ({helper}) => {75    await mintCollectionHelper(helper, alice, {name: 'name', description: 'A'.repeat(256), tokenPrefix: 'COL'}, 'nft');76  });77  itSub('Create new NFT collection whith token_prefix of maximum length (16 bytes)', async ({helper}) => {78    await mintCollectionHelper(helper, alice, {name: 'name', description: 'descr', tokenPrefix: 'A'.repeat(16)}, 'nft');79  });8081  itSub('Create new Fungible collection', async ({helper}) => {82    await mintCollectionHelper(helper, alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'}, 'fungible');83  });8485  itSub.ifWithPallets('Create new ReFungible collection', [Pallets.ReFungible], async ({helper}) => {86    await mintCollectionHelper(helper, alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'}, 'refungible');87  });8889  itSub('create new collection with properties', async ({helper}) => {90    await mintCollectionHelper(helper, alice, {91      name: 'name', description: 'descr', tokenPrefix: 'COL',92      properties: [{key: 'key1', value: 'val1'}],93      tokenPropertyPermissions: [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}],94    }, 'nft');95  });9697  itSub('create new collection with admin', async ({helper}) => {98    await mintCollectionHelper(helper, alice, {99      name: 'name', description: 'descr', tokenPrefix: 'COL',100      adminList: [{Substrate: bob.address}],101    }, 'nft');102  });103104  itSub('create new collection with flags', async ({helper}) => {105    await mintCollectionHelper(helper, alice, {106      name: 'name', description: 'descr', tokenPrefix: 'COL',107      flags: [CollectionFlag.Erc721metadata],108    }, 'nft');109  });110111  itSub('Create new collection with extra fields', async ({helper}) => {112    const collection = await mintCollectionHelper(helper, alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'}, 'fungible');113    await collection.setPermissions(alice, {access: 'AllowList'});114    await collection.setLimits(alice, {accountTokenOwnershipLimit: 3});115    const data = await collection.getData();116    const limits = await collection.getEffectiveLimits();117    const raw = data?.raw;118119    expect(data?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(alice.address));120    expect(data?.name).to.be.equal('name');121    expect(data?.description).to.be.equal('descr');122    expect(raw.permissions.access).to.be.equal('AllowList');123    expect(raw.mode).to.be.deep.equal({Fungible: '0'});124    expect(limits.accountTokenOwnershipLimit).to.be.equal(3);125  });126127  itSub('New collection is not external', async ({helper}) => {128    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});129    const data = await collection.getData();130    expect(data?.raw.readOnly).to.be.false;131  });132});133134describe('(!negative test!) integration test: ext. createCollection():', () => {135  let alice: IKeyringPair;136137  before(async () => {138    await usingPlaygrounds(async (helper, privateKey) => {139      const donor = await privateKey({url: import.meta.url});140      [alice] = await helper.arrange.createAccounts([100n], donor);141    });142  });143144  itSub('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async ({helper}) => {145    const mintCollectionTx = () => helper.nft.mintCollection(alice, {name: 'A'.repeat(65), description: 'descr', tokenPrefix: 'COL'});146    await expect(mintCollectionTx()).to.be.rejectedWith('Verification Error');147  });148  itSub('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async ({helper}) => {149    const mintCollectionTx = () => helper.nft.mintCollection(alice, {name: 'name', description: 'A'.repeat(257), tokenPrefix: 'COL'});150    await expect(mintCollectionTx()).to.be.rejectedWith('Verification Error');151  });152  itSub('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async ({helper}) => {153    const mintCollectionTx = () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'A'.repeat(17)});154    await expect(mintCollectionTx()).to.be.rejectedWith('Verification Error');155  });156157  itSub('(!negative test!) fails when bad limits are set', async ({helper}) => {158    const mintCollectionTx = () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', limits: {tokenLimit: 0}});159    await expect(mintCollectionTx()).to.be.rejectedWith(/common\.CollectionTokenLimitExceeded/);160  });161162  itSub('(!negative test!) create collection with incorrect property limit (64 elements)', async ({helper}) => {163    const props: IProperty[] = [];164165    for(let i = 0; i < 65; i++) {166      props.push({key: `key${i}`, value: `value${i}`});167    }168    const mintCollectionTx = () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', properties: props});169    await expect(mintCollectionTx()).to.be.rejectedWith('Verification Error');170  });171172  itSub('(!negative test!) create collection with incorrect property limit (40 kb)', async ({helper}) => {173    const props: IProperty[] = [];174175    for(let i = 0; i < 32; i++) {176      props.push({key: `key${i}`.repeat(80), value: `value${i}`.repeat(80)});177    }178179    const mintCollectionTx = () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', properties: props});180    await expect(mintCollectionTx()).to.be.rejectedWith('Verification Error');181  });182});