--- a/tests/src/createCollection.test.ts +++ b/tests/src/createCollection.test.ts @@ -14,130 +14,145 @@ // You should have received a copy of the GNU General Public License // along with Unique Network. If not, see . -import {expect} from 'chai'; -import usingApi, {executeTransaction, submitTransactionAsync} from './substrate/substrate-api'; -import {createCollectionWithPropsExpectFailure, createCollectionExpectFailure, createCollectionExpectSuccess, getCreateCollectionResult, getDetailedCollectionInfo, createCollectionWithPropsExpectSuccess, requirePallets, Pallets} from './util/helpers'; +import chai from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +import {usingPlaygrounds} from './util/playgrounds'; +import {IKeyringPair} from '@polkadot/types/types'; +import {IProperty} from './util/playgrounds/types'; + +chai.use(chaiAsPromised); +const expect = chai.expect; + +let donor: IKeyringPair; + +before(async () => { + await usingPlaygrounds(async (_, privateKey) => { + donor = privateKey('//Alice'); + }); +}); + +let alice: IKeyringPair; describe('integration test: ext. createCollection():', () => { + before(async () => { + await usingPlaygrounds(async (helper) => { + [alice] = await helper.arrange.createAccounts([100n], donor); + }); + }); it('Create new NFT collection', async () => { - await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}}); + await usingPlaygrounds(async (helper) => { + await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}); + }); }); it('Create new NFT collection whith collection_name of maximum length (64 bytes)', async () => { - await createCollectionExpectSuccess({name: 'A'.repeat(64)}); + await usingPlaygrounds(async (helper) => { + await helper.nft.mintCollection(alice, {name: 'A'.repeat(64), description: 'descr', tokenPrefix: 'COL'}); + }); }); it('Create new NFT collection whith collection_description of maximum length (256 bytes)', async () => { - await createCollectionExpectSuccess({description: 'A'.repeat(256)}); + await usingPlaygrounds(async (helper) => { + await helper.nft.mintCollection(alice, {name: 'name', description: 'A'.repeat(256), tokenPrefix: 'COL'}); + }); }); it('Create new NFT collection whith token_prefix of maximum length (16 bytes)', async () => { - await createCollectionExpectSuccess({tokenPrefix: 'A'.repeat(16)}); + await usingPlaygrounds(async (helper) => { + await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'A'.repeat(16)}); + }); }); it('Create new Fungible collection', async () => { - await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}}); + await usingPlaygrounds(async (helper) => { + await helper.ft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'}, 0); + }); }); it('Create new ReFungible collection', async function() { - await requirePallets(this, [Pallets.ReFungible]); - - await createCollectionExpectSuccess({mode: {type: 'ReFungible'}}); + await usingPlaygrounds(async (helper) => { + await helper.rft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'}); + }); }); - it('create new collection with properties #1', async () => { - await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}, - properties: [{key: 'key1', value: 'val1'}], - propPerm: [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}]}); + it('create new collection with properties', async () => { + await usingPlaygrounds(async (helper) => { + await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', + properties: [{key: 'key1', value: 'val1'}], + tokenPropertyPermissions: [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}], + }); + }); }); - it('create new collection with properties #2', async () => { - await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}, - properties: [{key: 'key1', value: 'val1'}], - propPerm: [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}]}); - }); - - it('create new collection with properties #3', async () => { - await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}, - properties: [{key: 'key1', value: 'val1'}], - propPerm: [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}]}); - }); - it('Create new collection with extra fields', async () => { - await usingApi(async (api, privateKeyWrapper) => { - const alice = privateKeyWrapper('//Alice'); - const bob = privateKeyWrapper('//Bob'); - const tx = api.tx.unique.createCollectionEx({ - mode: {Fungible: 8}, - permissions: { - access: 'AllowList', - }, - name: [1], - description: [2], - tokenPrefix: '0x000000', - pendingSponsor: bob.address, - limits: { - accountTokenOwnershipLimit: 3, - }, - }); - const events = await submitTransactionAsync(alice, tx); - const result = getCreateCollectionResult(events); + await usingPlaygrounds(async (helper) => { + const collection = await helper.ft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'}, 8); + await collection.setPermissions(alice, {access: 'AllowList'}); + await collection.setLimits(alice, {accountTokenOwnershipLimit: 3}); + const data = await collection.getData(); + const limits = await collection.getEffectiveLimits(); + const raw = data?.raw; - const collection = (await getDetailedCollectionInfo(api, result.collectionId))!; - expect(collection.owner.toString()).to.equal(alice.address); - expect(collection.mode.asFungible.toNumber()).to.equal(8); - expect(collection.permissions.access.toHuman()).to.equal('AllowList'); - expect(collection.name.map(v => v.toNumber())).to.deep.equal([1]); - expect(collection.description.map(v => v.toNumber())).to.deep.equal([2]); - expect(collection.tokenPrefix.toString()).to.equal('0x000000'); - expect(collection.sponsorship.asUnconfirmed.toString()).to.equal(bob.address); - expect(collection.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.equal(3); + expect(data?.normalizedOwner).to.be.equal(alice.address); + expect(data?.name).to.be.equal('name'); + expect(data?.description).to.be.equal('descr'); + expect(raw.permissions.access).to.be.equal('AllowList'); + expect(raw.mode).to.be.deep.equal({Fungible: '8'}); + expect(limits.accountTokenOwnershipLimit).to.be.equal(3); }); }); it('New collection is not external', async () => { - await usingApi(async (api, privateKeyWrapper) => { - const alice = privateKeyWrapper('//Alice'); - const tx = api.tx.unique.createCollectionEx({ }); - const events = await submitTransactionAsync(alice, tx); - const result = getCreateCollectionResult(events); - - const collection = (await getDetailedCollectionInfo(api, result.collectionId))!; - expect(collection.readOnly.toHuman()).to.be.false; + await usingPlaygrounds(async (helper) => { + const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'}); + const data = await collection.getData(); + expect(data?.raw.readOnly).to.be.false; }); }); }); describe('(!negative test!) integration test: ext. createCollection():', () => { it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => { - await createCollectionExpectFailure({name: 'A'.repeat(65), mode: {type: 'NFT'}}); + await usingPlaygrounds(async (helper) => { + const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'A'.repeat(65), description: 'descr', tokenPrefix: 'COL'}); + await expect(mintCollectionTx()).to.be.rejected; + }); }); it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => { - await createCollectionExpectFailure({description: 'A'.repeat(257), mode: {type: 'NFT'}}); + await usingPlaygrounds(async (helper) => { + const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'A'.repeat(257), tokenPrefix: 'COL'}); + await expect(mintCollectionTx()).to.be.rejected; + }); }); it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => { - await createCollectionExpectFailure({tokenPrefix: 'A'.repeat(17), mode: {type: 'NFT'}}); + await usingPlaygrounds(async (helper) => { + const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'A'.repeat(17)}); + await expect(mintCollectionTx()).to.be.rejected; + }); }); - it('fails when bad limits are set', async () => { - await usingApi(async (api, privateKeyWrapper) => { - const alice = privateKeyWrapper('//Alice'); - const tx = api.tx.unique.createCollectionEx({mode: 'NFT', limits: {tokenLimit: 0}}); - await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/^common.CollectionTokenLimitExceeded$/); + it('(!negative test!) fails when bad limits are set', async () => { + await usingPlaygrounds(async (helper) => { + const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', limits: {tokenLimit: 0}}); + await expect(mintCollectionTx()).to.be.rejected; }); }); it('(!negative test!) create collection with incorrect property limit (64 elements)', async () => { - const props = []; + const props: IProperty[] = []; for (let i = 0; i < 65; i++) { props.push({key: `key${i}`, value: `value${i}`}); } - - await createCollectionWithPropsExpectFailure({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}, properties: props}); + await usingPlaygrounds(async (helper) => { + const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', properties: props}); + await expect(mintCollectionTx()).to.be.rejected; + }); }); it('(!negative test!) create collection with incorrect property limit (40 kb)', async () => { - const props = []; + const props: IProperty[] = []; for (let i = 0; i < 32; i++) { props.push({key: `key${i}`.repeat(80), value: `value${i}`.repeat(80)}); } - - await createCollectionWithPropsExpectFailure({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}, properties: props}); + await usingPlaygrounds(async (helper) => { + const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', properties: props}); + await expect(mintCollectionTx()).to.be.rejected; + }); }); });