git.delta.rocks / unique-network / refs/commits / 792a004ac69c

difftreelog

createCollection migrated

rkv2022-09-12parent: #8df2058.patch.diff
in: master

1 file changed

modifiedtests/src/createCollection.test.tsdiffbeforeafterboth
before · tests/src/createCollection.test.ts
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});
after · tests/src/createCollection.test.ts
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 chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import {usingPlaygrounds} from './util/playgrounds';20import {IKeyringPair} from '@polkadot/types/types';21import {IProperty} from './util/playgrounds/types';2223chai.use(chaiAsPromised);24const expect = chai.expect;2526let donor: IKeyringPair;2728before(async () => {29  await usingPlaygrounds(async (_, privateKey) => {30    donor = privateKey('//Alice');31  });32});3334let alice: IKeyringPair;3536describe('integration test: ext. createCollection():', () => {37  before(async () => {38    await usingPlaygrounds(async (helper) => {39      [alice] = await helper.arrange.createAccounts([100n], donor);40    });41  });42  it('Create new NFT collection', async () => {43    await usingPlaygrounds(async (helper) => {44      await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});45    });46  });47  it('Create new NFT collection whith collection_name of maximum length (64 bytes)', async () => {48    await usingPlaygrounds(async (helper) => {49      await helper.nft.mintCollection(alice, {name: 'A'.repeat(64), description: 'descr', tokenPrefix: 'COL'});50    });51  });52  it('Create new NFT collection whith collection_description of maximum length (256 bytes)', async () => {53    await usingPlaygrounds(async (helper) => {54      await helper.nft.mintCollection(alice, {name: 'name', description: 'A'.repeat(256), tokenPrefix: 'COL'});55    });56  });57  it('Create new NFT collection whith token_prefix of maximum length (16 bytes)', async () => {58    await usingPlaygrounds(async (helper) => {59      await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'A'.repeat(16)});60    });61  });62  it('Create new Fungible collection', async () => {63    await usingPlaygrounds(async (helper) => {64      await helper.ft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'}, 0);65    });66  });67  it('Create new ReFungible collection', async function() {68    await usingPlaygrounds(async (helper) => {69      await helper.rft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});70    });71  });7273  it('create new collection with properties', async () => {74    await usingPlaygrounds(async (helper) => {75      await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL',76        properties: [{key: 'key1', value: 'val1'}],77        tokenPropertyPermissions: [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}],78      });79    });80  });8182  it('Create new collection with extra fields', async () => {83    await usingPlaygrounds(async (helper) => {84      const collection = await helper.ft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'}, 8);85      await collection.setPermissions(alice, {access: 'AllowList'});86      await collection.setLimits(alice, {accountTokenOwnershipLimit: 3});87      const data = await collection.getData();88      const limits = await collection.getEffectiveLimits();89      const raw = data?.raw;9091      expect(data?.normalizedOwner).to.be.equal(alice.address);92      expect(data?.name).to.be.equal('name');93      expect(data?.description).to.be.equal('descr');94      expect(raw.permissions.access).to.be.equal('AllowList');95      expect(raw.mode).to.be.deep.equal({Fungible: '8'});96      expect(limits.accountTokenOwnershipLimit).to.be.equal(3);97    });98  });99100  it('New collection is not external', async () => {101    await usingPlaygrounds(async (helper) => {102      const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});103      const data = await collection.getData();104      expect(data?.raw.readOnly).to.be.false;105    });106  });107});108109describe('(!negative test!) integration test: ext. createCollection():', () => {110  it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {111    await usingPlaygrounds(async (helper) => {112      const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'A'.repeat(65), description: 'descr', tokenPrefix: 'COL'});113      await expect(mintCollectionTx()).to.be.rejected;114    });115  });116  it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => {117    await usingPlaygrounds(async (helper) => {118      const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'A'.repeat(257), tokenPrefix: 'COL'});119      await expect(mintCollectionTx()).to.be.rejected;120    });121  });122  it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => {123    await usingPlaygrounds(async (helper) => {124      const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'A'.repeat(17)});125      await expect(mintCollectionTx()).to.be.rejected;126    });127  });128  it('(!negative test!) fails when bad limits are set', async () => {129    await usingPlaygrounds(async (helper) => {130      const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', limits: {tokenLimit: 0}});131      await expect(mintCollectionTx()).to.be.rejected;132    });133  });134135  it('(!negative test!) create collection with incorrect property limit (64 elements)', async () => {136    const props: IProperty[] = [];137138    for (let i = 0; i < 65; i++) {139      props.push({key: `key${i}`, value: `value${i}`});140    }141    await usingPlaygrounds(async (helper) => {142      const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', properties: props});143      await expect(mintCollectionTx()).to.be.rejected;144    });145  });146147  it('(!negative test!) create collection with incorrect property limit (40 kb)', async () => {148    const props: IProperty[] = [];149150    for (let i = 0; i < 32; i++) {151      props.push({key: `key${i}`.repeat(80), value: `value${i}`.repeat(80)});152    }153    await usingPlaygrounds(async (helper) => {154      const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', properties: props});155      await expect(mintCollectionTx()).to.be.rejected;156    });157  });158});