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

difftreelog

source

tests/src/createCollection.test.ts6.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 {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', 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', tokenOwner: false, mutable: true, collectionAdmin: false}]});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', tokenOwner: true, mutable: false, collectionAdmin: false}]});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        variableOnChainSchema: '0x222222',77        constOnChainSchema: '0x333333',78        metaUpdatePermission: 'Admin',79      });80      const events = await submitTransactionAsync(alice, tx);81      const result = getCreateCollectionResult(events);8283      const collection = (await getDetailedCollectionInfo(api, result.collectionId))!;84      expect(collection.owner.toString()).to.equal(alice.address);85      expect(collection.mode.asFungible.toNumber()).to.equal(8);86      expect(collection.access.isAllowList).to.be.true;87      expect(collection.name.map(v => v.toNumber())).to.deep.equal([1]);88      expect(collection.description.map(v => v.toNumber())).to.deep.equal([2]);89      expect(collection.tokenPrefix.toString()).to.equal('0x000000');90      expect(collection.offchainSchema.toString()).to.equal('0x111111');91      expect(collection.schemaVersion.isUnique).to.be.true;92      expect(collection.sponsorship.asUnconfirmed.toString()).to.equal(bob.address);93      expect(collection.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.equal(3);94      expect(collection.variableOnChainSchema.toString()).to.equal('0x222222');95      expect(collection.constOnChainSchema.toString()).to.equal('0x333333');96      expect(collection.metaUpdatePermission.isAdmin).to.be.true;97    });98  });99});100101describe('(!negative test!) integration test: ext. createCollection():', () => {102  it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {103    await createCollectionExpectFailure({name: 'A'.repeat(65), mode: {type: 'NFT'}});104  });105  it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => {106    await createCollectionExpectFailure({description: 'A'.repeat(257), mode: {type: 'NFT'}});107  });108  it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => {109    await createCollectionExpectFailure({tokenPrefix: 'A'.repeat(17), mode: {type: 'NFT'}});110  });111  it('fails when bad limits are set', async () => {112    await usingApi(async api => {113      const alice = privateKey('//Alice');114      const tx = api.tx.unique.createCollectionEx({mode: 'NFT', limits: {tokenLimit: 0}});115      await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/^common.CollectionTokenLimitExceeded$/);116    });117  });118119  it('(!negative test!) create collection with incorrect property limit (64 elements)', async () => {120    const props = [];121122    for (let i = 0; i < 65; i++) {123      props.push({key: `key${i}`, value: `value${i}`});124    }125126    await createCollectionWithPropsExpectFailure({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}, properties: props});127  });128129  it('(!negative test!) create collection with incorrect property limit (40 kb)', async () => {130    const props = [];131132    for (let i = 0; i < 32; i++) {133      props.push({key: `key${i}`.repeat(80), value: `value${i}`.repeat(80)});134    }135136    await createCollectionWithPropsExpectFailure({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}, properties: props});137  });138});