1234567891011121314151617import {expect} from 'chai';18import usingApi, {executeTransaction, submitTransactionAsync} from './substrate/substrate-api';19import {createCollectionWithPropsExpectFailure, createCollectionExpectFailure, createCollectionExpectSuccess, getCreateCollectionResult, getDetailedCollectionInfo, createCollectionWithPropsExpectSuccess} 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 () => {38 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});39 });4041 it('create new collection with properties #1', async () => {42 await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'},43 properties: [{key: 'key1', value: 'val1'}],44 propPerm: [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}]});45 });4647 it('create new collection with properties #2', async () => {48 await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'},49 properties: [{key: 'key1', value: 'val1'}],50 propPerm: [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}]});51 });5253 it('create new collection with properties #3', async () => {54 await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'},55 properties: [{key: 'key1', value: 'val1'}],56 propPerm: [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}]});57 });5859 it('Create new collection with extra fields', async () => {60 await usingApi(async (api, privateKeyWrapper) => {61 const alice = privateKeyWrapper('//Alice');62 const bob = privateKeyWrapper('//Bob');63 const tx = api.tx.unique.createCollectionEx({64 mode: {Fungible: 8},65 permissions: {66 access: 'AllowList',67 },68 name: [1],69 description: [2],70 tokenPrefix: '0x000000',71 pendingSponsor: bob.address,72 limits: {73 accountTokenOwnershipLimit: 3,74 },75 });76 const events = await submitTransactionAsync(alice, tx);77 const result = getCreateCollectionResult(events);7879 const collection = (await getDetailedCollectionInfo(api, result.collectionId))!;80 expect(collection.owner.toString()).to.equal(alice.address);81 expect(collection.mode.asFungible.toNumber()).to.equal(8);82 expect(collection.permissions.access.toHuman()).to.equal('AllowList');83 expect(collection.name.map(v => v.toNumber())).to.deep.equal([1]);84 expect(collection.description.map(v => v.toNumber())).to.deep.equal([2]);85 expect(collection.tokenPrefix.toString()).to.equal('0x000000');86 expect(collection.sponsorship.asUnconfirmed.toString()).to.equal(bob.address);87 expect(collection.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.equal(3);88 });89 });9091 it('New collection is not external', async () => {92 await usingApi(async (api, privateKeyWrapper) => {93 const alice = privateKeyWrapper('//Alice');94 const tx = api.tx.unique.createCollectionEx({ });95 const events = await submitTransactionAsync(alice, tx);96 const result = getCreateCollectionResult(events);9798 const collection = (await getDetailedCollectionInfo(api, result.collectionId))!;99 expect(collection.readOnly.toHuman()).to.be.false;100 });101 });102});103104describe('(!negative test!) integration test: ext. createCollection():', () => {105 it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {106 await createCollectionExpectFailure({name: 'A'.repeat(65), mode: {type: 'NFT'}});107 });108 it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => {109 await createCollectionExpectFailure({description: 'A'.repeat(257), mode: {type: 'NFT'}});110 });111 it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => {112 await createCollectionExpectFailure({tokenPrefix: 'A'.repeat(17), mode: {type: 'NFT'}});113 });114 it('fails when bad limits are set', async () => {115 await usingApi(async (api, privateKeyWrapper) => {116 const alice = privateKeyWrapper('//Alice');117 const tx = api.tx.unique.createCollectionEx({mode: 'NFT', limits: {tokenLimit: 0}});118 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/^common.CollectionTokenLimitExceeded$/);119 });120 });121122 it('(!negative test!) create collection with incorrect property limit (64 elements)', async () => {123 const props = [];124125 for (let i = 0; i < 65; i++) {126 props.push({key: `key${i}`, value: `value${i}`});127 }128129 await createCollectionWithPropsExpectFailure({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}, properties: props});130 });131132 it('(!negative test!) create collection with incorrect property limit (40 kb)', async () => {133 const props = [];134135 for (let i = 0; i < 32; i++) {136 props.push({key: `key${i}`.repeat(80), value: `value${i}`.repeat(80)});137 }138139 await createCollectionWithPropsExpectFailure({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}, properties: props});140 });141});