git.delta.rocks / unique-network / refs/commits / 13d4a7ecf461

difftreelog

source

tests/src/createCollection.test.ts4.9 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 {createCollectionExpectFailure, createCollectionExpectSuccess, getCreateCollectionResult, getDetailedCollectionInfo} 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  });41  it('Create new collection with extra fields', async () => {42    await usingApi(async api => {43      const alice = privateKey('//Alice');44      const bob = privateKey('//Bob');45      const tx = api.tx.unique.createCollectionEx({46        mode: {Fungible: 8},47        access: 'AllowList',48        name: [1],49        description: [2],50        tokenPrefix: '0x000000',51        offchainSchema: '0x111111',52        schemaVersion: 'Unique',53        pendingSponsor: bob.address,54        limits: {55          accountTokenOwnershipLimit: 3,56        },57        variableOnChainSchema: '0x222222',58        constOnChainSchema: '0x333333',59        metaUpdatePermission: 'Admin',60      });61      const events = await submitTransactionAsync(alice, tx);62      const result = getCreateCollectionResult(events);6364      const collection = (await getDetailedCollectionInfo(api, result.collectionId))!;65      expect(collection.owner.toString()).to.equal(alice.address);66      expect(collection.mode.asFungible.toNumber()).to.equal(8);67      expect(collection.access.isAllowList).to.be.true;68      expect(collection.name.map(v => v.toNumber())).to.deep.equal([1]);69      expect(collection.description.map(v => v.toNumber())).to.deep.equal([2]);70      expect(collection.tokenPrefix.toString()).to.equal('0x000000');71      expect(collection.offchainSchema.toString()).to.equal('0x111111');72      expect(collection.schemaVersion.isUnique).to.be.true;73      expect(collection.sponsorship.asUnconfirmed.toString()).to.equal(bob.address);74      expect(collection.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.equal(3);75      expect(collection.variableOnChainSchema.toString()).to.equal('0x222222');76      expect(collection.constOnChainSchema.toString()).to.equal('0x333333');77      expect(collection.metaUpdatePermission.isAdmin).to.be.true;78    });79  });80});8182describe('(!negative test!) integration test: ext. createCollection():', () => {83  it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {84    await createCollectionExpectFailure({name: 'A'.repeat(65), mode: {type: 'NFT'}});85  });86  it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => {87    await createCollectionExpectFailure({description: 'A'.repeat(257), mode: {type: 'NFT'}});88  });89  it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => {90    await createCollectionExpectFailure({tokenPrefix: 'A'.repeat(17), mode: {type: 'NFT'}});91  });92  it('fails when bad limits are set', async () => {93    await usingApi(async api => {94      const alice = privateKey('//Alice');95      const tx = api.tx.unique.createCollectionEx({mode: 'NFT', limits: {tokenLimit: 0}});96      await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/^common.CollectionTokenLimitExceeded$/);97    });98  });99});