git.delta.rocks / unique-network / refs/commits / 0660dd124ff7

difftreelog

source

tests/src/createCollection.test.ts4.3 KiBsourcehistory
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import {expect} from 'chai';7import privateKey from './substrate/privateKey';8import usingApi, {executeTransaction, submitTransactionAsync} from './substrate/substrate-api';9import {createCollectionExpectFailure, createCollectionExpectSuccess, getCreateCollectionResult, getDetailedCollectionInfo} from './util/helpers';1011describe('integration test: ext. createCollection():', () => {12  it('Create new NFT collection', async () => {13    await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});14  });15  it('Create new NFT collection whith collection_name of maximum length (64 bytes)', async () => {16    await createCollectionExpectSuccess({name: 'A'.repeat(64)});17  });18  it('Create new NFT collection whith collection_description of maximum length (256 bytes)', async () => {19    await createCollectionExpectSuccess({description: 'A'.repeat(256)});20  });21  it('Create new NFT collection whith token_prefix of maximum length (16 bytes)', async () => {22    await createCollectionExpectSuccess({tokenPrefix: 'A'.repeat(16)});23  });24  it('Create new Fungible collection', async () => {25    await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});26  });27  it('Create new ReFungible collection', async () => {28    await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});29  });30  it('Create new collection with extra fields', async () => {31    await usingApi(async api => {32      const alice = privateKey('//Alice');33      const bob = privateKey('//Bob');34      const tx = api.tx.unique.createCollectionEx({35        mode: {Fungible: 8},36        access: 'AllowList',37        name: [1],38        description: [2],39        tokenPrefix: '0x000000',40        offchainSchema: '0x111111',41        schemaVersion: 'Unique',42        pendingSponsor: bob.address,43        limits: {44          accountTokenOwnershipLimit: 3,45        },46        variableOnChainSchema: '0x222222',47        constOnChainSchema: '0x333333',48        metaUpdatePermission: 'Admin',49      });50      const events = await submitTransactionAsync(alice, tx);51      const result = getCreateCollectionResult(events);5253      const collection = (await getDetailedCollectionInfo(api, result.collectionId))!;54      expect(collection.owner.toString()).to.equal(alice.address);55      expect(collection.mode.asFungible.toNumber()).to.equal(8);56      expect(collection.access.isAllowList).to.be.true;57      expect(collection.name.map(v => v.toNumber())).to.deep.equal([1]);58      expect(collection.description.map(v => v.toNumber())).to.deep.equal([2]);59      expect(collection.tokenPrefix.toString()).to.equal('0x000000');60      expect(collection.offchainSchema.toString()).to.equal('0x111111');61      expect(collection.schemaVersion.isUnique).to.be.true;62      expect(collection.sponsorship.asUnconfirmed.toString()).to.equal(bob.address);63      expect(collection.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.equal(3);64      expect(collection.variableOnChainSchema.toString()).to.equal('0x222222');65      expect(collection.constOnChainSchema.toString()).to.equal('0x333333');66      expect(collection.metaUpdatePermission.isAdmin).to.be.true;67    });68  });69});7071describe('(!negative test!) integration test: ext. createCollection():', () => {72  it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {73    await createCollectionExpectFailure({name: 'A'.repeat(65), mode: {type: 'NFT'}});74  });75  it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => {76    await createCollectionExpectFailure({description: 'A'.repeat(257), mode: {type: 'NFT'}});77  });78  it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => {79    await createCollectionExpectFailure({tokenPrefix: 'A'.repeat(17), mode: {type: 'NFT'}});80  });81  it('fails when bad limits are set', async () => {82    await usingApi(async api => {83      const alice = privateKey('//Alice');84      const tx = api.tx.unique.createCollectionEx({mode: 'NFT', limits: {tokenLimit: 0}});85      await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/^common.CollectionTokenLimitExceeded$/);86    });87  });88});