--- a/tests/src/createMultipleItemsEx.test.ts +++ b/tests/src/createMultipleItemsEx.test.ts @@ -14,121 +14,166 @@ // You should have received a copy of the GNU General Public License // along with Unique Network. If not, see . -import {expect} from 'chai'; +import {IKeyringPair} from '@polkadot/types/types'; +import {usingPlaygrounds, expect, Pallets, itSub} from './util/playgrounds'; import usingApi, {executeTransaction} from './substrate/substrate-api'; -import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, createCollectionWithPropsExpectSuccess, getBalance, getLastTokenId, getTokenProperties, requirePallets, Pallets} from './util/helpers'; +import {createCollectionExpectSuccess, getBalance, getLastTokenId, getTokenProperties, requirePallets} from './util/helpers'; +import {IProperty} from './util/playgrounds/types'; describe('Integration Test: createMultipleItemsEx', () => { - it('can initialize multiple NFT with different owners', async () => { - const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await usingApi(async (api, privateKeyWrapper) => { - const alice = privateKeyWrapper('//Alice'); - const bob = privateKeyWrapper('//Bob'); - const charlie = privateKeyWrapper('//Charlie'); - const data = [ - { - owner: {substrate: alice.address}, - }, { - owner: {substrate: bob.address}, - }, { - owner: {substrate: charlie.address}, - }, - ]; + let alice: IKeyringPair; + let bob: IKeyringPair; + let charlie: IKeyringPair; + + before(async () => { + await usingPlaygrounds(async (helper, privateKey) => { + const donor = privateKey('//Alice'); + [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor); + }); + }); - await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, { - NFT: data, - })); - const tokens = await api.query.nonfungible.tokenData.entries(collection); - const json = tokens.map(([, token]) => token.toJSON()); - expect(json).to.be.deep.equal(data); + itSub('can initialize multiple NFT with different owners', async ({helper}) => { + const collection = await helper.nft.mintCollection(alice, { + name: 'name', + description: 'descr', + tokenPrefix: 'COL', }); + const args = [ + { + owner: {Substrate: alice.address}, + }, + { + owner: {Substrate: bob.address}, + }, + { + owner: {Substrate: charlie.address}, + }, + ]; + + const tokens = await collection.mintMultipleTokens(alice, args); + for (const [i, token] of tokens.entries()) { + expect(await token.getOwner()).to.be.deep.equal(args[i].owner); + } }); - it('createMultipleItemsEx with property Admin', async () => { - const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]}); - await usingApi(async (api, privateKeyWrapper) => { - const alice = privateKeyWrapper('//Alice'); - const bob = privateKeyWrapper('//Bob'); - const charlie = privateKeyWrapper('//Charlie'); - const data = [ + itSub('createMultipleItemsEx with property Admin', async ({helper}) => { + const collection = await helper.nft.mintCollection(alice, { + name: 'name', + description: 'descr', + tokenPrefix: 'COL', + tokenPropertyPermissions: [ { - owner: {substrate: alice.address}, - properties: [{key: 'k', value: 'v1'}], - }, { - owner: {substrate: bob.address}, - properties: [{key: 'k', value: 'v2'}], - }, { - owner: {substrate: charlie.address}, - properties: [{key: 'k', value: 'v3'}], + key: 'k', + permission: { + mutable: true, + collectionAdmin: true, + tokenOwner: false, + }, }, - ]; + ], + }); - await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, { - NFT: data, - })); - for (let i = 1; i < 4; i++) { - expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty; - } - }); + const args = [ + { + owner: {Substrate: alice.address}, + properties: [{key: 'k', value: 'v1'}], + }, + { + owner: {Substrate: bob.address}, + properties: [{key: 'k', value: 'v2'}], + }, + { + owner: {Substrate: charlie.address}, + properties: [{key: 'k', value: 'v3'}], + }, + ]; + + const tokens = await collection.mintMultipleTokens(alice, args); + for (const [i, token] of tokens.entries()) { + expect(await token.getOwner()).to.be.deep.equal(args[i].owner); + expect(await token.getData()).to.not.be.empty; + } }); - it('createMultipleItemsEx with property AdminConst', async () => { - const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]}); - await usingApi(async (api, privateKeyWrapper) => { - const alice = privateKeyWrapper('//Alice'); - const bob = privateKeyWrapper('//Bob'); - const charlie = privateKeyWrapper('//Charlie'); - const data = [ + itSub('createMultipleItemsEx with property AdminConst', async ({helper}) => { + const collection = await helper.nft.mintCollection(alice, { + name: 'name', + description: 'descr', + tokenPrefix: 'COL', + tokenPropertyPermissions: [ { - owner: {substrate: alice.address}, - properties: [{key: 'k', value: 'v1'}], - }, { - owner: {substrate: bob.address}, - properties: [{key: 'k', value: 'v2'}], - }, { - owner: {substrate: charlie.address}, - properties: [{key: 'k', value: 'v3'}], + key: 'k', + permission: { + mutable: false, + collectionAdmin: true, + tokenOwner: false, + }, }, - ]; + ], + }); - await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, { - NFT: data, - })); - for (let i = 1; i < 4; i++) { - expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty; - } - }); + const args = [ + { + owner: {Substrate: alice.address}, + properties: [{key: 'k', value: 'v1'}], + }, + { + owner: {Substrate: bob.address}, + properties: [{key: 'k', value: 'v2'}], + }, + { + owner: {Substrate: charlie.address}, + properties: [{key: 'k', value: 'v3'}], + }, + ]; + + const tokens = await collection.mintMultipleTokens(alice, args); + for (const [i, token] of tokens.entries()) { + expect(await token.getOwner()).to.be.deep.equal(args[i].owner); + expect(await token.getData()).to.not.be.empty; + } }); - it('createMultipleItemsEx with property itemOwnerOrAdmin', async () => { - const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: true}}]}); - await usingApi(async (api, privateKeyWrapper) => { - const alice = privateKeyWrapper('//Alice'); - const bob = privateKeyWrapper('//Bob'); - const charlie = privateKeyWrapper('//Charlie'); - const data = [ + itSub('createMultipleItemsEx with property itemOwnerOrAdmin', async ({helper}) => { + const collection = await helper.nft.mintCollection(alice, { + name: 'name', + description: 'descr', + tokenPrefix: 'COL', + tokenPropertyPermissions: [ { - owner: {substrate: alice.address}, - properties: [{key: 'k', value: 'v1'}], - }, { - owner: {substrate: bob.address}, - properties: [{key: 'k', value: 'v2'}], - }, { - owner: {substrate: charlie.address}, - properties: [{key: 'k', value: 'v3'}], + key: 'k', + permission: { + mutable: false, + collectionAdmin: true, + tokenOwner: true, + }, }, - ]; - - await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, { - NFT: data, - })); - for (let i = 1; i < 4; i++) { - expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty; - } + ], }); + + const args = [ + { + owner: {Substrate: alice.address}, + properties: [{key: 'k', value: 'v1'}], + }, + { + owner: {Substrate: bob.address}, + properties: [{key: 'k', value: 'v2'}], + }, + { + owner: {Substrate: charlie.address}, + properties: [{key: 'k', value: 'v3'}], + }, + ]; + + const tokens = await collection.mintMultipleTokens(alice, args); + for (const [i, token] of tokens.entries()) { + expect(await token.getOwner()).to.be.deep.equal(args[i].owner); + expect(await token.getData()).to.not.be.empty; + } }); - it('can initialize fungible with multiple owners', async () => { + it.skip('can initialize fungible with multiple owners', async () => { const collection = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}}); await usingApi(async (api, privateKeyWrapper) => { const alice = privateKeyWrapper('//Alice'); @@ -146,7 +191,7 @@ }); }); - it('can initialize an RFT with multiple owners', async function() { + it.skip('can initialize an RFT with multiple owners', async function() { await requirePallets(this, [Pallets.ReFungible]); await usingApi(async (api, privateKeyWrapper) => { @@ -180,7 +225,7 @@ }); }); - it('can initialize multiple RFTs with the same owner', async function() { + it.skip('can initialize multiple RFTs with the same owner', async function() { await requirePallets(this, [Pallets.ReFungible]); await usingApi(async (api, privateKeyWrapper) => { @@ -221,175 +266,185 @@ }); describe('Negative test: createMultipleItemsEx', () => { - it('No editing rights', async () => { - const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}], - propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]}); - await usingApi(async (api, privateKeyWrapper) => { - const alice = privateKeyWrapper('//Alice'); - const bob = privateKeyWrapper('//Bob'); - const charlie = privateKeyWrapper('//Charlie'); - await addCollectionAdminExpectSuccess(alice, collection, bob.address); - const data = [ - { - owner: {substrate: alice.address}, - properties: [{key: 'key1', value: 'v2'}], - }, { - owner: {substrate: bob.address}, - properties: [{key: 'key1', value: 'v2'}], - }, { - owner: {substrate: charlie.address}, - properties: [{key: 'key1', value: 'v2'}], - }, - ]; + let alice: IKeyringPair; + let bob: IKeyringPair; + let charlie: IKeyringPair; - const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data}); - // await executeTransaction(api, alice, tx); - - //await submitTransactionExpectFailAsync(alice, tx); - await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/); + before(async () => { + await usingPlaygrounds(async (helper, privateKey) => { + const donor = privateKey('//Alice'); + [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor); }); }); - it('User doesnt have editing rights', async () => { - const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}], - propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]}); - await usingApi(async (api, privateKeyWrapper) => { - const alice = privateKeyWrapper('//Alice'); - const bob = privateKeyWrapper('//Bob'); - await addCollectionAdminExpectSuccess(alice, collection, bob.address); - const data = [ + itSub('No editing rights', async ({helper}) => { + const collection = await helper.nft.mintCollection(alice, { + name: 'name', + description: 'descr', + tokenPrefix: 'COL', + tokenPropertyPermissions: [ { - owner: {substrate: alice.address}, - properties: [{key: 'key1', value: 'v2'}], - }, { - owner: {substrate: alice.address}, - properties: [{key: 'key1', value: 'v2'}], - }, { - owner: {substrate: alice.address}, - properties: [{key: 'key1', value: 'v2'}], + key: 'k', + permission: { + mutable: true, + collectionAdmin: false, + tokenOwner: false, + }, }, - ]; + ], + }); - const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data}); - // await executeTransaction(api, alice, tx); + const args = [ + { + owner: {Substrate: alice.address}, + properties: [{key: 'k', value: 'v1'}], + }, + { + owner: {Substrate: bob.address}, + properties: [{key: 'k', value: 'v2'}], + }, + { + owner: {Substrate: charlie.address}, + properties: [{key: 'k', value: 'v3'}], + }, + ]; - //await submitTransactionExpectFailAsync(alice, tx); - await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/); - }); + await expect(collection.mintMultipleTokens(alice, args)).to.be.rejectedWith(/common\.NoPermission/); }); - it('Adding property without access rights', async () => { - const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}]}); - await usingApi(async (api, privateKeyWrapper) => { - const alice = privateKeyWrapper('//Alice'); - const bob = privateKeyWrapper('//Bob'); - const charlie = privateKeyWrapper('//Charlie'); - await addCollectionAdminExpectSuccess(alice, collection, bob.address); - const data = [ + itSub('User doesnt have editing rights', async ({helper}) => { + const collection = await helper.nft.mintCollection(alice, { + name: 'name', + description: 'descr', + tokenPrefix: 'COL', + tokenPropertyPermissions: [ { - owner: {substrate: alice.address}, - properties: [{key: 'key1', value: 'v2'}], - }, { - owner: {substrate: bob.address}, - properties: [{key: 'key1', value: 'v2'}], - }, { - owner: {substrate: charlie.address}, - properties: [{key: 'key1', value: 'v2'}], + key: 'k', + permission: { + mutable: false, + collectionAdmin: false, + tokenOwner: false, + }, }, - ]; + ], + }); - const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data}); + const args = [ + { + owner: {Substrate: alice.address}, + properties: [{key: 'k', value: 'v1'}], + }, + { + owner: {Substrate: bob.address}, + properties: [{key: 'k', value: 'v2'}], + }, + { + owner: {Substrate: charlie.address}, + properties: [{key: 'k', value: 'v3'}], + }, + ]; - await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/); - //await submitTransactionExpectFailAsync(alice, tx); - }); + await expect(collection.mintMultipleTokens(alice, args)).to.be.rejectedWith(/common\.NoPermission/); }); - it('Adding more than 64 properties', async () => { - const propPerms = [{key: 'key', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]; + itSub('Adding property without access rights', async ({helper}) => { + const collection = await helper.nft.mintCollection(alice, { + name: 'name', + description: 'descr', + tokenPrefix: 'COL', + }); - for (let i = 0; i < 65; i++) { - propPerms.push({key: `key${i}`, permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}); - } + const args = [ + { + owner: {Substrate: alice.address}, + properties: [{key: 'k', value: 'v1'}], + }, + { + owner: {Substrate: bob.address}, + properties: [{key: 'k', value: 'v2'}], + }, + { + owner: {Substrate: charlie.address}, + properties: [{key: 'k', value: 'v3'}], + }, + ]; - const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await usingApi(async (api, privateKeyWrapper) => { - const alice = privateKeyWrapper('//Alice'); - await expect(executeTransaction(api, alice, api.tx.unique.setTokenPropertyPermissions(collection, propPerms))).to.be.rejectedWith(/common\.PropertyLimitReached/); - }); + await expect(collection.mintMultipleTokens(alice, args)).to.be.rejectedWith(/common\.NoPermission/); }); - it('Trying to add bigger property than allowed', async () => { - const collection = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]}); - await usingApi(async (api, privateKeyWrapper) => { - const alice = privateKeyWrapper('//Alice'); - const bob = privateKeyWrapper('//Bob'); - const charlie = privateKeyWrapper('//Charlie'); - await addCollectionAdminExpectSuccess(alice, collection, bob.address); - const data = [ + itSub('Adding more than 64 properties', async ({helper}) => { + const collection = await helper.nft.mintCollection(alice, { + name: 'name', + description: 'descr', + tokenPrefix: 'COL', + tokenPropertyPermissions: [ { - owner: {substrate: alice.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}], - }, { - owner: {substrate: bob.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}], - }, { - owner: {substrate: charlie.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}], + key: 'k', + permission: { + mutable: true, + collectionAdmin: true, + tokenOwner: true, + }, }, - ]; + ], + }); + + const properties: IProperty[] = []; + + for (let i = 0; i < 65; i++) { + properties.push({key: `k${i}`, value: `v${i}`}); + } - const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data}); + const args = [ + { + owner: {Substrate: alice.address}, + properties: properties, + }, + { + owner: {Substrate: bob.address}, + properties: properties, + }, + { + owner: {Substrate: charlie.address}, + properties: properties, + }, + ]; - //await submitTransactionExpectFailAsync(alice, tx); - await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/); - }); + await expect(collection.mintMultipleTokens(alice, args)).to.be.rejectedWith('Verification Error'); }); - it('can initialize multiple NFT with different owners', async () => { - const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await usingApi(async (api, privateKeyWrapper) => { - const alice = privateKeyWrapper('//Alice'); - const bob = privateKeyWrapper('//Bob'); - const charlie = privateKeyWrapper('//Charlie'); - const data = [ + itSub('Trying to add bigger property than allowed', async ({helper}) => { + const collection = await helper.nft.mintCollection(alice, { + name: 'name', + description: 'descr', + tokenPrefix: 'COL', + tokenPropertyPermissions: [ { - owner: {substrate: alice.address}, - }, { - owner: {substrate: bob.address}, - }, { - owner: {substrate: charlie.address}, + key: 'k', + permission: { + mutable: true, + collectionAdmin: true, + tokenOwner: true, + }, }, - ]; - - await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, { - NFT: data, - })); - const tokens = await api.query.nonfungible.tokenData.entries(collection); - const json = tokens.map(([, token]) => token.toJSON()); - expect(json).to.be.deep.equal(data); + ], }); - }); - it('can initialize multiple NFT with different owners', async () => { - const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await usingApi(async (api, privateKeyWrapper) => { - const alice = privateKeyWrapper('//Alice'); - const bob = privateKeyWrapper('//Bob'); - const charlie = privateKeyWrapper('//Charlie'); - const data = [ - { - owner: {substrate: alice.address}, - }, { - owner: {substrate: bob.address}, - }, { - owner: {substrate: charlie.address}, - }, - ]; + const args = [ + { + owner: {Substrate: alice.address}, + properties: [{key: 'k', value: 'A'.repeat(32769)}], + }, + { + owner: {Substrate: bob.address}, + properties: [{key: 'k', value: 'A'.repeat(32769)}], + }, + { + owner: {Substrate: charlie.address}, + properties: [{key: 'k', value: 'A'.repeat(32769)}], + }, + ]; - await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, { - NFT: data, - })); - const tokens = await api.query.nonfungible.tokenData.entries(collection); - const json = tokens.map(([, token]) => token.toJSON()); - expect(json).to.be.deep.equal(data); - }); + await expect(collection.mintMultipleTokens(alice, args)).to.be.rejectedWith('Verification Error'); }); });