difftreelog
createMultipleItemsEx migrated
in: master
1 file changed
tests/src/createMultipleItemsEx.test.tsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {expect} from 'chai';17import {IKeyringPair} from '@polkadot/types/types';18import {usingPlaygrounds, expect, Pallets, itSub} from './util/playgrounds';18import usingApi, {executeTransaction} from './substrate/substrate-api';19import usingApi, {executeTransaction} from './substrate/substrate-api';19import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, createCollectionWithPropsExpectSuccess, getBalance, getLastTokenId, getTokenProperties, requirePallets, Pallets} from './util/helpers';20import {createCollectionExpectSuccess, getBalance, getLastTokenId, getTokenProperties, requirePallets} from './util/helpers';21import {IProperty} from './util/playgrounds/types';202221describe('Integration Test: createMultipleItemsEx', () => {23describe('Integration Test: createMultipleItemsEx', () => {22 it('can initialize multiple NFT with different owners', async () => {24 let alice: IKeyringPair;23 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});24 await usingApi(async (api, privateKeyWrapper) => {25 let bob: IKeyringPair;25 const alice = privateKeyWrapper('//Alice');26 const bob = privateKeyWrapper('//Bob');27 const charlie = privateKeyWrapper('//Charlie');26 let charlie: IKeyringPair;28 const data = [29 {30 owner: {substrate: alice.address},31 }, {32 owner: {substrate: bob.address},33 }, {34 owner: {substrate: charlie.address},35 },36 ];372738 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {28 before(async () => {39 NFT: data,29 await usingPlaygrounds(async (helper, privateKey) => {40 }));41 const tokens = await api.query.nonfungible.tokenData.entries(collection);30 const donor = privateKey('//Alice');42 const json = tokens.map(([, token]) => token.toJSON());31 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);43 expect(json).to.be.deep.equal(data);44 });32 });45 });33 });463447 it('createMultipleItemsEx with property Admin', async () => {35 itSub('can initialize multiple NFT with different owners', async ({helper}) => {48 const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});36 const collection = await helper.nft.mintCollection(alice, {37 name: 'name',38 description: 'descr',39 tokenPrefix: 'COL',40 });41 const args = [42 {43 owner: {Substrate: alice.address},44 },45 {46 owner: {Substrate: bob.address},47 },48 {49 owner: {Substrate: charlie.address},50 },51 ];5249 await usingApi(async (api, privateKeyWrapper) => {53 const tokens = await collection.mintMultipleTokens(alice, args);54 for (const [i, token] of tokens.entries()) {50 const alice = privateKeyWrapper('//Alice');55 expect(await token.getOwner()).to.be.deep.equal(args[i].owner);56 }57 });5851 const bob = privateKeyWrapper('//Bob');59 itSub('createMultipleItemsEx with property Admin', async ({helper}) => {60 const collection = await helper.nft.mintCollection(alice, {61 name: 'name',52 const charlie = privateKeyWrapper('//Charlie');62 description: 'descr',63 tokenPrefix: 'COL',53 const data = [64 tokenPropertyPermissions: [54 {65 {55 owner: {substrate: alice.address},66 key: 'k',56 properties: [{key: 'k', value: 'v1'}],67 permission: {57 }, {58 owner: {substrate: bob.address},68 mutable: true,59 properties: [{key: 'k', value: 'v2'}],69 collectionAdmin: true,60 }, {70 tokenOwner: false,61 owner: {substrate: charlie.address},62 properties: [{key: 'k', value: 'v3'}],71 },63 },72 },64 ];73 ],6566 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {67 NFT: data,68 }));69 for (let i = 1; i < 4; i++) {70 expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;71 }72 });74 });7576 const args = [77 {78 owner: {Substrate: alice.address},79 properties: [{key: 'k', value: 'v1'}],80 },81 {82 owner: {Substrate: bob.address},83 properties: [{key: 'k', value: 'v2'}],84 },85 {86 owner: {Substrate: charlie.address},87 properties: [{key: 'k', value: 'v3'}],88 },89 ];9091 const tokens = await collection.mintMultipleTokens(alice, args);92 for (const [i, token] of tokens.entries()) {93 expect(await token.getOwner()).to.be.deep.equal(args[i].owner);94 expect(await token.getData()).to.not.be.empty;95 }73 });96 });749775 it('createMultipleItemsEx with property AdminConst', async () => {98 itSub('createMultipleItemsEx with property AdminConst', async ({helper}) => {76 const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});99 const collection = await helper.nft.mintCollection(alice, {77 await usingApi(async (api, privateKeyWrapper) => {78 const alice = privateKeyWrapper('//Alice');100 name: 'name',79 const bob = privateKeyWrapper('//Bob');101 description: 'descr',80 const charlie = privateKeyWrapper('//Charlie');102 tokenPrefix: 'COL',81 const data = [103 tokenPropertyPermissions: [82 {104 {83 owner: {substrate: alice.address},105 key: 'k',84 properties: [{key: 'k', value: 'v1'}],106 permission: {85 }, {86 owner: {substrate: bob.address},107 mutable: false,87 properties: [{key: 'k', value: 'v2'}],108 collectionAdmin: true,88 }, {109 tokenOwner: false,89 owner: {substrate: charlie.address},90 properties: [{key: 'k', value: 'v3'}],110 },91 },111 },92 ];112 ],9394 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {95 NFT: data,96 }));97 for (let i = 1; i < 4; i++) {98 expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;99 }100 });113 });114115 const args = [116 {117 owner: {Substrate: alice.address},118 properties: [{key: 'k', value: 'v1'}],119 },120 {121 owner: {Substrate: bob.address},122 properties: [{key: 'k', value: 'v2'}],123 },124 {125 owner: {Substrate: charlie.address},126 properties: [{key: 'k', value: 'v3'}],127 },128 ];129130 const tokens = await collection.mintMultipleTokens(alice, args);131 for (const [i, token] of tokens.entries()) {132 expect(await token.getOwner()).to.be.deep.equal(args[i].owner);133 expect(await token.getData()).to.not.be.empty;134 }101 });135 });102136103 it('createMultipleItemsEx with property itemOwnerOrAdmin', async () => {137 itSub('createMultipleItemsEx with property itemOwnerOrAdmin', async ({helper}) => {104 const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: true}}]});138 const collection = await helper.nft.mintCollection(alice, {105 await usingApi(async (api, privateKeyWrapper) => {106 const alice = privateKeyWrapper('//Alice');139 name: 'name',107 const bob = privateKeyWrapper('//Bob');140 description: 'descr',108 const charlie = privateKeyWrapper('//Charlie');141 tokenPrefix: 'COL',109 const data = [142 tokenPropertyPermissions: [110 {143 {111 owner: {substrate: alice.address},144 key: 'k',112 properties: [{key: 'k', value: 'v1'}],145 permission: {113 }, {114 owner: {substrate: bob.address},146 mutable: false,115 properties: [{key: 'k', value: 'v2'}],147 collectionAdmin: true,116 }, {148 tokenOwner: true,117 owner: {substrate: charlie.address},118 properties: [{key: 'k', value: 'v3'}],149 },119 },150 },120 ];151 ],121122 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {123 NFT: data,124 }));125 for (let i = 1; i < 4; i++) {126 expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;127 }128 });152 });153154 const args = [155 {156 owner: {Substrate: alice.address},157 properties: [{key: 'k', value: 'v1'}],158 },159 {160 owner: {Substrate: bob.address},161 properties: [{key: 'k', value: 'v2'}],162 },163 {164 owner: {Substrate: charlie.address},165 properties: [{key: 'k', value: 'v3'}],166 },167 ];168169 const tokens = await collection.mintMultipleTokens(alice, args);170 for (const [i, token] of tokens.entries()) {171 expect(await token.getOwner()).to.be.deep.equal(args[i].owner);172 expect(await token.getData()).to.not.be.empty;173 }129 });174 });130175131 it('can initialize fungible with multiple owners', async () => {176 it.skip('can initialize fungible with multiple owners', async () => {132 const collection = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});177 const collection = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});133 await usingApi(async (api, privateKeyWrapper) => {178 await usingApi(async (api, privateKeyWrapper) => {134 const alice = privateKeyWrapper('//Alice');179 const alice = privateKeyWrapper('//Alice');146 });191 });147 });192 });148193149 it('can initialize an RFT with multiple owners', async function() {194 it.skip('can initialize an RFT with multiple owners', async function() {150 await requirePallets(this, [Pallets.ReFungible]);195 await requirePallets(this, [Pallets.ReFungible]);151196152 await usingApi(async (api, privateKeyWrapper) => {197 await usingApi(async (api, privateKeyWrapper) => {180 });225 });181 });226 });182227183 it('can initialize multiple RFTs with the same owner', async function() {228 it.skip('can initialize multiple RFTs with the same owner', async function() {184 await requirePallets(this, [Pallets.ReFungible]);229 await requirePallets(this, [Pallets.ReFungible]);185230186 await usingApi(async (api, privateKeyWrapper) => {231 await usingApi(async (api, privateKeyWrapper) => {221});266});222267223describe('Negative test: createMultipleItemsEx', () => {268describe('Negative test: createMultipleItemsEx', () => {224 it('No editing rights', async () => {269 let alice: IKeyringPair;225 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],226 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});227 await usingApi(async (api, privateKeyWrapper) => {270 let bob: IKeyringPair;228 const alice = privateKeyWrapper('//Alice');229 const bob = privateKeyWrapper('//Bob');230 const charlie = privateKeyWrapper('//Charlie');271 let charlie: IKeyringPair;231 await addCollectionAdminExpectSuccess(alice, collection, bob.address);232 const data = [233 {234 owner: {substrate: alice.address},235 properties: [{key: 'key1', value: 'v2'}],236 }, {237 owner: {substrate: bob.address},238 properties: [{key: 'key1', value: 'v2'}],239 }, {240 owner: {substrate: charlie.address},241 properties: [{key: 'key1', value: 'v2'}],242 },243 ];244272245 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});273 before(async () => {246 // await executeTransaction(api, alice, tx);274 await usingPlaygrounds(async (helper, privateKey) => {247275 const donor = privateKey('//Alice');248 //await submitTransactionExpectFailAsync(alice, tx);276 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);249 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);250 });277 });251 });278 });252279253 it('User doesnt have editing rights', async () => {280 itSub('No editing rights', async ({helper}) => {254 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],281 const collection = await helper.nft.mintCollection(alice, {255 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});282 name: 'name',256 await usingApi(async (api, privateKeyWrapper) => {257 const alice = privateKeyWrapper('//Alice');283 description: 'descr',258 const bob = privateKeyWrapper('//Bob');284 tokenPrefix: 'COL',259 await addCollectionAdminExpectSuccess(alice, collection, bob.address);260 const data = [285 tokenPropertyPermissions: [261 {286 {262 owner: {substrate: alice.address},287 key: 'k',263 properties: [{key: 'key1', value: 'v2'}],288 permission: {264 }, {289 mutable: true,265 owner: {substrate: alice.address},266 properties: [{key: 'key1', value: 'v2'}],290 collectionAdmin: false,267 }, {291 tokenOwner: false,268 owner: {substrate: alice.address},269 properties: [{key: 'key1', value: 'v2'}],292 },270 },293 },271 ];294 ],295 });272296273 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});297 const args = [298 {299 owner: {Substrate: alice.address},300 properties: [{key: 'k', value: 'v1'}],301 },302 {303 owner: {Substrate: bob.address},304 properties: [{key: 'k', value: 'v2'}],274 // await executeTransaction(api, alice, tx);305 },306 {307 owner: {Substrate: charlie.address},308 properties: [{key: 'k', value: 'v3'}],309 },310 ];275311276 //await submitTransactionExpectFailAsync(alice, tx);312 await expect(collection.mintMultipleTokens(alice, args)).to.be.rejectedWith(/common\.NoPermission/);277 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);278 });279 });313 });280314281 it('Adding property without access rights', async () => {315 itSub('User doesnt have editing rights', async ({helper}) => {282 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}]});316 const collection = await helper.nft.mintCollection(alice, {283 await usingApi(async (api, privateKeyWrapper) => {284 const alice = privateKeyWrapper('//Alice');317 name: 'name',285 const bob = privateKeyWrapper('//Bob');318 description: 'descr',286 const charlie = privateKeyWrapper('//Charlie');319 tokenPrefix: 'COL',287 await addCollectionAdminExpectSuccess(alice, collection, bob.address);288 const data = [320 tokenPropertyPermissions: [289 {321 {290 owner: {substrate: alice.address},322 key: 'k',291 properties: [{key: 'key1', value: 'v2'}],323 permission: {292 }, {324 mutable: false,293 owner: {substrate: bob.address},294 properties: [{key: 'key1', value: 'v2'}],325 collectionAdmin: false,295 }, {326 tokenOwner: false,296 owner: {substrate: charlie.address},297 properties: [{key: 'key1', value: 'v2'}],327 },298 },328 },299 ];329 ],330 });300331301 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});332 const args = [333 {334 owner: {Substrate: alice.address},335 properties: [{key: 'k', value: 'v1'}],336 },337 {338 owner: {Substrate: bob.address},339 properties: [{key: 'k', value: 'v2'}],340 },341 {342 owner: {Substrate: charlie.address},343 properties: [{key: 'k', value: 'v3'}],344 },345 ];302346303 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);347 await expect(collection.mintMultipleTokens(alice, args)).to.be.rejectedWith(/common\.NoPermission/);304 //await submitTransactionExpectFailAsync(alice, tx);305 });306 });348 });307349308 it('Adding more than 64 properties', async () => {350 itSub('Adding property without access rights', async ({helper}) => {309 const propPerms = [{key: 'key', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}];351 const collection = await helper.nft.mintCollection(alice, {352 name: 'name',353 description: 'descr',354 tokenPrefix: 'COL',355 });310356311 for (let i = 0; i < 65; i++) {357 const args = [358 {312 propPerms.push({key: `key${i}`, permission: {mutable: true, collectionAdmin: true, tokenOwner: true}});359 owner: {Substrate: alice.address},360 properties: [{key: 'k', value: 'v1'}],361 },362 {363 owner: {Substrate: bob.address},364 properties: [{key: 'k', value: 'v2'}],365 },366 {367 owner: {Substrate: charlie.address},368 properties: [{key: 'k', value: 'v3'}],313 }369 },370 ];314371315 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});372 await expect(collection.mintMultipleTokens(alice, args)).to.be.rejectedWith(/common\.NoPermission/);316 await usingApi(async (api, privateKeyWrapper) => {317 const alice = privateKeyWrapper('//Alice');318 await expect(executeTransaction(api, alice, api.tx.unique.setTokenPropertyPermissions(collection, propPerms))).to.be.rejectedWith(/common\.PropertyLimitReached/);319 });320 });373 });321374322 it('Trying to add bigger property than allowed', async () => {375 itSub('Adding more than 64 properties', async ({helper}) => {323 const collection = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});376 const collection = await helper.nft.mintCollection(alice, {324 await usingApi(async (api, privateKeyWrapper) => {377 name: 'name',325 const alice = privateKeyWrapper('//Alice');326 const bob = privateKeyWrapper('//Bob');378 description: 'descr',327 const charlie = privateKeyWrapper('//Charlie');379 tokenPrefix: 'COL',328 await addCollectionAdminExpectSuccess(alice, collection, bob.address);329 const data = [380 tokenPropertyPermissions: [330 {381 {331 owner: {substrate: alice.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}],382 key: 'k',332 }, {383 permission: {333 owner: {substrate: bob.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}],384 mutable: true,334 }, {385 collectionAdmin: true,335 owner: {substrate: charlie.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}],386 tokenOwner: true,387 },336 },388 },337 ];389 ],390 });338391339 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});392 const properties: IProperty[] = [];340393341 //await submitTransactionExpectFailAsync(alice, tx);394 for (let i = 0; i < 65; i++) {342 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);395 properties.push({key: `k${i}`, value: `v${i}`});343 });344 });396 }345397346 it('can initialize multiple NFT with different owners', async () => {398 const args = [399 {347 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});400 owner: {Substrate: alice.address},348 await usingApi(async (api, privateKeyWrapper) => {349 const alice = privateKeyWrapper('//Alice');401 properties: properties,350 const bob = privateKeyWrapper('//Bob');402 },351 const charlie = privateKeyWrapper('//Charlie');403 {352 const data = [353 {354 owner: {substrate: alice.address},404 owner: {Substrate: bob.address},355 }, {405 properties: properties,356 owner: {substrate: bob.address},406 },357 }, {407 {358 owner: {substrate: charlie.address},408 owner: {Substrate: charlie.address},359 },409 properties: properties,360 ];410 },411 ];361412362 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {413 await expect(collection.mintMultipleTokens(alice, args)).to.be.rejectedWith('Verification Error');363 NFT: data,364 }));365 const tokens = await api.query.nonfungible.tokenData.entries(collection);366 const json = tokens.map(([, token]) => token.toJSON());367 expect(json).to.be.deep.equal(data);368 });369 });414 });370415371 it('can initialize multiple NFT with different owners', async () => {416 itSub('Trying to add bigger property than allowed', async ({helper}) => {372 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});417 const collection = await helper.nft.mintCollection(alice, {373 await usingApi(async (api, privateKeyWrapper) => {374 const alice = privateKeyWrapper('//Alice');418 name: 'name',375 const bob = privateKeyWrapper('//Bob');419 description: 'descr',376 const charlie = privateKeyWrapper('//Charlie');420 tokenPrefix: 'COL',377 const data = [421 tokenPropertyPermissions: [378 {422 {379 owner: {substrate: alice.address},423 key: 'k',380 }, {424 permission: {381 owner: {substrate: bob.address},425 mutable: true,382 }, {426 collectionAdmin: true,383 owner: {substrate: charlie.address},427 tokenOwner: true,428 },384 },429 },385 ];430 ],386387 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {388 NFT: data,389 }));390 const tokens = await api.query.nonfungible.tokenData.entries(collection);391 const json = tokens.map(([, token]) => token.toJSON());392 expect(json).to.be.deep.equal(data);393 });431 });432433 const args = [434 {435 owner: {Substrate: alice.address},436 properties: [{key: 'k', value: 'A'.repeat(32769)}],437 },438 {439 owner: {Substrate: bob.address},440 properties: [{key: 'k', value: 'A'.repeat(32769)}],441 },442 {443 owner: {Substrate: charlie.address},444 properties: [{key: 'k', value: 'A'.repeat(32769)}],445 },446 ];447448 await expect(collection.mintMultipleTokens(alice, args)).to.be.rejectedWith('Verification Error');394 });449 });395});450});396451