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

difftreelog

source

tests/src/createCollection.test.ts6.2 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 {expect} from 'chai';18import usingApi, {executeTransaction, submitTransactionAsync} from './substrate/substrate-api';19import {createCollectionWithPropsExpectFailure, createCollectionExpectFailure, createCollectionExpectSuccess, getCreateCollectionResult, getDetailedCollectionInfo, createCollectionWithPropsExpectSuccess} from './util/helpers';2021describe('integration test: ext. createCollection():', () => {22  it('Create new NFT collection', async () => {23    await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});24  });25  it('Create new NFT collection whith collection_name of maximum length (64 bytes)', async () => {26    await createCollectionExpectSuccess({name: 'A'.repeat(64)});27  });28  it('Create new NFT collection whith collection_description of maximum length (256 bytes)', async () => {29    await createCollectionExpectSuccess({description: 'A'.repeat(256)});30  });31  it('Create new NFT collection whith token_prefix of maximum length (16 bytes)', async () => {32    await createCollectionExpectSuccess({tokenPrefix: 'A'.repeat(16)});33  });34  it('Create new Fungible collection', async () => {35    await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});36  });37  it('Create new ReFungible collection', async () => {38    await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});39  });4041  it('create new collection with properties #1', async () => {42    await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'},43      properties: [{key: 'key1', value: 'val1'}],44      propPerm:   [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}]});45  });4647  it('create new collection with properties #2', async () => {48    await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'},49      properties: [{key: 'key1', value: 'val1'}],50      propPerm:   [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}]});51  });5253  it('create new collection with properties #3', async () => {54    await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'},55      properties: [{key: 'key1', value: 'val1'}],56      propPerm:   [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}]});57  });5859  it('Create new collection with extra fields', async () => {60    await usingApi(async (api, privateKeyWrapper) => {61      const alice = privateKeyWrapper('//Alice');62      const bob = privateKeyWrapper('//Bob');63      const tx = api.tx.unique.createCollectionEx({64        mode: {Fungible: 8},65        permissions: {66          access: 'AllowList',67        },68        name: [1],69        description: [2],70        tokenPrefix: '0x000000',71        pendingSponsor: bob.address,72        limits: {73          accountTokenOwnershipLimit: 3,74        },75      });76      const events = await submitTransactionAsync(alice, tx);77      const result = getCreateCollectionResult(events);7879      const collection = (await getDetailedCollectionInfo(api, result.collectionId))!;80      expect(collection.owner.toString()).to.equal(alice.address);81      expect(collection.mode.asFungible.toNumber()).to.equal(8);82      expect(collection.permissions.access.toHuman()).to.equal('AllowList');83      expect(collection.name.map(v => v.toNumber())).to.deep.equal([1]);84      expect(collection.description.map(v => v.toNumber())).to.deep.equal([2]);85      expect(collection.tokenPrefix.toString()).to.equal('0x000000');86      expect(collection.sponsorship.asUnconfirmed.toString()).to.equal(bob.address);87      expect(collection.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.equal(3);88    });89  });90});9192describe('(!negative test!) integration test: ext. createCollection():', () => {93  it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {94    await createCollectionExpectFailure({name: 'A'.repeat(65), mode: {type: 'NFT'}});95  });96  it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => {97    await createCollectionExpectFailure({description: 'A'.repeat(257), mode: {type: 'NFT'}});98  });99  it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => {100    await createCollectionExpectFailure({tokenPrefix: 'A'.repeat(17), mode: {type: 'NFT'}});101  });102  it('fails when bad limits are set', async () => {103    await usingApi(async (api, privateKeyWrapper) => {104      const alice = privateKeyWrapper('//Alice');105      const tx = api.tx.unique.createCollectionEx({mode: 'NFT', limits: {tokenLimit: 0}});106      await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/^common.CollectionTokenLimitExceeded$/);107    });108  });109110  it('(!negative test!) create collection with incorrect property limit (64 elements)', async () => {111    const props = [];112113    for (let i = 0; i < 65; i++) {114      props.push({key: `key${i}`, value: `value${i}`});115    }116117    await createCollectionWithPropsExpectFailure({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}, properties: props});118  });119120  it('(!negative test!) create collection with incorrect property limit (40 kb)', async () => {121    const props = [];122123    for (let i = 0; i < 32; i++) {124      props.push({key: `key${i}`.repeat(80), value: `value${i}`.repeat(80)});125    }126127    await createCollectionWithPropsExpectFailure({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}, properties: props});128  });129});