git.delta.rocks / unique-network / refs/commits / 459d9af28807

difftreelog

source

tests/src/createCollection.test.ts6.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 {expect} from 'chai';18import privateKey from './substrate/privateKey';19import usingApi, {executeTransaction, submitTransactionAsync} from './substrate/substrate-api';20import {createCollectionWithPropsExpectFailure, createCollectionExpectFailure, createCollectionExpectSuccess, getCreateCollectionResult, getDetailedCollectionInfo, createCollectionWithPropsExpectSuccess} from './util/helpers';2122describe('integration test: ext. createCollection():', () => {23  it('Create new NFT collection', async () => {24    await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});25  });26  it('Create new NFT collection whith collection_name of maximum length (64 bytes)', async () => {27    await createCollectionExpectSuccess({name: 'A'.repeat(64)});28  });29  it('Create new NFT collection whith collection_description of maximum length (256 bytes)', async () => {30    await createCollectionExpectSuccess({description: 'A'.repeat(256)});31  });32  it('Create new NFT collection whith token_prefix of maximum length (16 bytes)', async () => {33    await createCollectionExpectSuccess({tokenPrefix: 'A'.repeat(16)});34  });35  it('Create new Fungible collection', async () => {36    await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});37  });38  it('Create new ReFungible collection', async () => {39    await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});40  });4142  it('create new collection with properties #1', async () => {43    await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'},44      properties: [{key: 'key1', value: 'val1'}],45      propPerm:   [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}]});46  });4748  it('create new collection with properties #2', async () => {49    await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'},50      properties: [{key: 'key1', value: 'val1'}],51      propPerm:   [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}]});52  });5354  it('create new collection with properties #3', async () => {55    await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'},56      properties: [{key: 'key1', value: 'val1'}],57      propPerm:   [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}]});58  });5960  it('Create new collection with extra fields', async () => {61    await usingApi(async api => {62      const alice = privateKey('//Alice');63      const bob = privateKey('//Bob');64      const tx = api.tx.unique.createCollectionEx({65        mode: {Fungible: 8},66        access: 'AllowList',67        name: [1],68        description: [2],69        tokenPrefix: '0x000000',70        offchainSchema: '0x111111',71        schemaVersion: 'Unique',72        pendingSponsor: bob.address,73        limits: {74          accountTokenOwnershipLimit: 3,75        },76        constOnChainSchema: '0x333333',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.access.isAllowList).to.be.true;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.offchainSchema.toString()).to.equal('0x111111');89      expect(collection.schemaVersion.isUnique).to.be.true;90      expect(collection.sponsorship.asUnconfirmed.toString()).to.equal(bob.address);91      expect(collection.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.equal(3);92      expect(collection.constOnChainSchema.toString()).to.equal('0x333333');93    });94  });95});9697describe('(!negative test!) integration test: ext. createCollection():', () => {98  it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {99    await createCollectionExpectFailure({name: 'A'.repeat(65), mode: {type: 'NFT'}});100  });101  it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => {102    await createCollectionExpectFailure({description: 'A'.repeat(257), mode: {type: 'NFT'}});103  });104  it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => {105    await createCollectionExpectFailure({tokenPrefix: 'A'.repeat(17), mode: {type: 'NFT'}});106  });107  it('fails when bad limits are set', async () => {108    await usingApi(async api => {109      const alice = privateKey('//Alice');110      const tx = api.tx.unique.createCollectionEx({mode: 'NFT', limits: {tokenLimit: 0}});111      await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/^common.CollectionTokenLimitExceeded$/);112    });113  });114115  it('(!negative test!) create collection with incorrect property limit (64 elements)', async () => {116    const props = [];117118    for (let i = 0; i < 65; i++) {119      props.push({key: `key${i}`, value: `value${i}`});120    }121122    await createCollectionWithPropsExpectFailure({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}, properties: props});123  });124125  it('(!negative test!) create collection with incorrect property limit (40 kb)', async () => {126    const props = [];127128    for (let i = 0; i < 32; i++) {129      props.push({key: `key${i}`.repeat(80), value: `value${i}`.repeat(80)});130    }131132    await createCollectionWithPropsExpectFailure({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}, properties: props});133  });134});