git.delta.rocks / unique-network / refs/commits / 837dcd6dcc35

difftreelog

source

tests/src/createCollection.test.ts6.8 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, requirePallets, Pallets} 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 function() {38    await requirePallets(this, [Pallets.ReFungible]);3940    await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});41  });4243  it('create new collection with properties #1', async () => {44    await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'},45      properties: [{key: 'key1', value: 'val1'}],46      propPerm:   [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}]});47  });4849  it('create new collection with properties #2', async () => {50    await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'},51      properties: [{key: 'key1', value: 'val1'}],52      propPerm:   [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}]});53  });5455  it('create new collection with properties #3', async () => {56    await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'},57      properties: [{key: 'key1', value: 'val1'}],58      propPerm:   [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}]});59  });6061  it('Create new collection with extra fields', async () => {62    await usingApi(async (api, privateKeyWrapper) => {63      const alice = privateKeyWrapper('//Alice');64      const bob = privateKeyWrapper('//Bob');65      const tx = api.tx.unique.createCollectionEx({66        mode: {Fungible: 8},67        permissions: {68          access: 'AllowList',69        },70        name: [1],71        description: [2],72        tokenPrefix: '0x000000',73        pendingSponsor: bob.address,74        limits: {75          accountTokenOwnershipLimit: 3,76        },77      });78      const events = await submitTransactionAsync(alice, tx);79      const result = getCreateCollectionResult(events);8081      const collection = (await getDetailedCollectionInfo(api, result.collectionId))!;82      expect(collection.owner.toString()).to.equal(alice.address);83      expect(collection.mode.asFungible.toNumber()).to.equal(8);84      expect(collection.permissions.access.toHuman()).to.equal('AllowList');85      expect(collection.name.map(v => v.toNumber())).to.deep.equal([1]);86      expect(collection.description.map(v => v.toNumber())).to.deep.equal([2]);87      expect(collection.tokenPrefix.toString()).to.equal('0x000000');88      expect(collection.sponsorship.asUnconfirmed.toString()).to.equal(bob.address);89      expect(collection.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.equal(3);90    });91  });9293  it('New collection is not external', async () => {94    await usingApi(async (api, privateKeyWrapper) => {95      const alice = privateKeyWrapper('//Alice');96      const tx = api.tx.unique.createCollectionEx({ });97      const events = await submitTransactionAsync(alice, tx);98      const result = getCreateCollectionResult(events);99100      const collection = (await getDetailedCollectionInfo(api, result.collectionId))!;101      expect(collection.readOnly.toHuman()).to.be.false;102    });103  });104});105106describe('(!negative test!) integration test: ext. createCollection():', () => {107  it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {108    await createCollectionExpectFailure({name: 'A'.repeat(65), mode: {type: 'NFT'}});109  });110  it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => {111    await createCollectionExpectFailure({description: 'A'.repeat(257), mode: {type: 'NFT'}});112  });113  it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => {114    await createCollectionExpectFailure({tokenPrefix: 'A'.repeat(17), mode: {type: 'NFT'}});115  });116  it('fails when bad limits are set', async () => {117    await usingApi(async (api, privateKeyWrapper) => {118      const alice = privateKeyWrapper('//Alice');119      const tx = api.tx.unique.createCollectionEx({mode: 'NFT', limits: {tokenLimit: 0}});120      await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/^common.CollectionTokenLimitExceeded$/);121    });122  });123124  it('(!negative test!) create collection with incorrect property limit (64 elements)', async () => {125    const props = [];126127    for (let i = 0; i < 65; i++) {128      props.push({key: `key${i}`, value: `value${i}`});129    }130131    await createCollectionWithPropsExpectFailure({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}, properties: props});132  });133134  it('(!negative test!) create collection with incorrect property limit (40 kb)', async () => {135    const props = [];136137    for (let i = 0; i < 32; i++) {138      props.push({key: `key${i}`.repeat(80), value: `value${i}`.repeat(80)});139    }140141    await createCollectionWithPropsExpectFailure({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}, properties: props});142  });143});