1234567891011121314151617import {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 constOnChainSchema: '0x333333',77 metaUpdatePermission: 'Admin',78 });79 const events = await submitTransactionAsync(alice, tx);80 const result = getCreateCollectionResult(events);8182 const collection = (await getDetailedCollectionInfo(api, result.collectionId))!;83 expect(collection.owner.toString()).to.equal(alice.address);84 expect(collection.mode.asFungible.toNumber()).to.equal(8);85 expect(collection.access.isAllowList).to.be.true;86 expect(collection.name.map(v => v.toNumber())).to.deep.equal([1]);87 expect(collection.description.map(v => v.toNumber())).to.deep.equal([2]);88 expect(collection.tokenPrefix.toString()).to.equal('0x000000');89 expect(collection.offchainSchema.toString()).to.equal('0x111111');90 expect(collection.schemaVersion.isUnique).to.be.true;91 expect(collection.sponsorship.asUnconfirmed.toString()).to.equal(bob.address);92 expect(collection.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.equal(3);93 expect(collection.constOnChainSchema.toString()).to.equal('0x333333');94 expect(collection.metaUpdatePermission.isAdmin).to.be.true;95 });96 });97});9899describe('(!negative test!) integration test: ext. createCollection():', () => {100 it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {101 await createCollectionExpectFailure({name: 'A'.repeat(65), mode: {type: 'NFT'}});102 });103 it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => {104 await createCollectionExpectFailure({description: 'A'.repeat(257), mode: {type: 'NFT'}});105 });106 it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => {107 await createCollectionExpectFailure({tokenPrefix: 'A'.repeat(17), mode: {type: 'NFT'}});108 });109 it('fails when bad limits are set', async () => {110 await usingApi(async api => {111 const alice = privateKey('//Alice');112 const tx = api.tx.unique.createCollectionEx({mode: 'NFT', limits: {tokenLimit: 0}});113 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/^common.CollectionTokenLimitExceeded$/);114 });115 });116117 it('(!negative test!) create collection with incorrect property limit (64 elements)', async () => {118 const props = [];119120 for (let i = 0; i < 65; i++) {121 props.push({key: `key${i}`, value: `value${i}`});122 }123124 await createCollectionWithPropsExpectFailure({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}, properties: props});125 });126127 it('(!negative test!) create collection with incorrect property limit (40 kb)', async () => {128 const props = [];129130 for (let i = 0; i < 32; i++) {131 props.push({key: `key${i}`.repeat(80), value: `value${i}`.repeat(80)});132 }133134 await createCollectionWithPropsExpectFailure({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}, properties: props});135 });136});