1234567891011121314151617import {expect} from 'chai';18import usingApi, {executeTransaction} from './substrate/substrate-api';19import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, createCollectionWithPropsExpectSuccess} from './util/helpers';2021describe('createMultipleItemsEx', () => {22 it('can initialize multiple NFT with different owners', async () => {23 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});24 await usingApi(async (api, privateKeyWrapper) => {25 const alice = privateKeyWrapper('//Alice');26 const bob = privateKeyWrapper('//Bob');27 const charlie = privateKeyWrapper('//Charlie');28 const data = [29 {30 owner: {substrate: alice.address},31 }, {32 owner: {substrate: bob.address},33 }, {34 owner: {substrate: charlie.address},35 },36 ];3738 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {39 NFT: data,40 }));41 const tokens = await api.query.nonfungible.tokenData.entries(collection);42 const json = tokens.map(([, token]) => token.toJSON());43 expect(json).to.be.deep.equal(data);44 });45 });4647 it('createMultipleItemsEx with property Admin', async () => {48 const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});49 await usingApi(async (api, privateKeyWrapper) => {50 const alice = privateKeyWrapper('//Alice');51 const bob = privateKeyWrapper('//Bob');52 const charlie = privateKeyWrapper('//Charlie');53 const data = [54 {55 owner: {substrate: alice.address},56 properties: [{key: 'k', value: 'v1'}],57 }, {58 owner: {substrate: bob.address},59 properties: [{key: 'k', value: 'v2'}],60 }, {61 owner: {substrate: charlie.address},62 properties: [{key: 'k', value: 'v3'}],63 },64 ];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 });73 });7475 it('createMultipleItemsEx with property AdminConst', async () => {76 const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});77 await usingApi(async (api, privateKeyWrapper) => {78 const alice = privateKeyWrapper('//Alice');79 const bob = privateKeyWrapper('//Bob');80 const charlie = privateKeyWrapper('//Charlie');81 const data = [82 {83 owner: {substrate: alice.address},84 properties: [{key: 'k', value: 'v1'}],85 }, {86 owner: {substrate: bob.address},87 properties: [{key: 'k', value: 'v2'}],88 }, {89 owner: {substrate: charlie.address},90 properties: [{key: 'k', value: 'v3'}],91 },92 ];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 });101 });102103 it('createMultipleItemsEx with property itemOwnerOrAdmin', async () => {104 const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: true}}]});105 await usingApi(async (api, privateKeyWrapper) => {106 const alice = privateKeyWrapper('//Alice');107 const bob = privateKeyWrapper('//Bob');108 const charlie = privateKeyWrapper('//Charlie');109 const data = [110 {111 owner: {substrate: alice.address},112 properties: [{key: 'k', value: 'v1'}],113 }, {114 owner: {substrate: bob.address},115 properties: [{key: 'k', value: 'v2'}],116 }, {117 owner: {substrate: charlie.address},118 properties: [{key: 'k', value: 'v3'}],119 },120 ];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 });129 });130131 it('No editing rights', async () => {132 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],133 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});134 await usingApi(async (api, privateKeyWrapper) => {135 const alice = privateKeyWrapper('//Alice');136 const bob = privateKeyWrapper('//Bob');137 const charlie = privateKeyWrapper('//Charlie');138 await addCollectionAdminExpectSuccess(alice, collection, bob.address);139 const data = [140 {141 owner: {substrate: alice.address},142 properties: [{key: 'key1', value: 'v2'}],143 }, {144 owner: {substrate: bob.address},145 properties: [{key: 'key1', value: 'v2'}],146 }, {147 owner: {substrate: charlie.address},148 properties: [{key: 'key1', value: 'v2'}],149 },150 ];151152 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});153 154155 156 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);157 });158 });159160 it('User doesnt have editing rights', async () => {161 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],162 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});163 await usingApi(async (api, privateKeyWrapper) => {164 const alice = privateKeyWrapper('//Alice');165 const bob = privateKeyWrapper('//Bob');166 await addCollectionAdminExpectSuccess(alice, collection, bob.address);167 const data = [168 {169 owner: {substrate: alice.address},170 properties: [{key: 'key1', value: 'v2'}],171 }, {172 owner: {substrate: alice.address},173 properties: [{key: 'key1', value: 'v2'}],174 }, {175 owner: {substrate: alice.address},176 properties: [{key: 'key1', value: 'v2'}],177 },178 ];179180 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});181 182183 184 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);185 });186 });187188 it('Adding property without access rights', async () => {189 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}]});190 await usingApi(async (api, privateKeyWrapper) => {191 const alice = privateKeyWrapper('//Alice');192 const bob = privateKeyWrapper('//Bob');193 const charlie = privateKeyWrapper('//Charlie');194 await addCollectionAdminExpectSuccess(alice, collection, bob.address);195 const data = [196 {197 owner: {substrate: alice.address},198 properties: [{key: 'key1', value: 'v2'}],199 }, {200 owner: {substrate: bob.address},201 properties: [{key: 'key1', value: 'v2'}],202 }, {203 owner: {substrate: charlie.address},204 properties: [{key: 'key1', value: 'v2'}],205 },206 ];207208 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});209210 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);211 212 });213 });214215 it('Adding more than 64 properties', async () => {216 const propPerms = [{key: 'key', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}];217218 for (let i = 0; i < 65; i++) {219 propPerms.push({key: `key${i}`, permission: {mutable: true, collectionAdmin: true, tokenOwner: true}});220 }221222 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});223 await usingApi(async (api, privateKeyWrapper) => {224 const alice = privateKeyWrapper('//Alice');225 await expect(executeTransaction(api, alice, api.tx.unique.setPropertyPermissions(collection, propPerms))).to.be.rejectedWith(/common\.PropertyLimitReached/);226 });227 });228229 it('Trying to add bigger property than allowed', async () => {230 const collection = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});231 await usingApi(async (api, privateKeyWrapper) => {232 const alice = privateKeyWrapper('//Alice');233 const bob = privateKeyWrapper('//Bob');234 const charlie = privateKeyWrapper('//Charlie');235 await addCollectionAdminExpectSuccess(alice, collection, bob.address);236 const data = [237 {238 owner: {substrate: alice.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}],239 }, {240 owner: {substrate: bob.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}],241 }, {242 owner: {substrate: charlie.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}],243 },244 ];245246 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});247248 249 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);250 });251 });252253 it('can initialize multiple NFT with different owners', async () => {254 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});255 await usingApi(async (api, privateKeyWrapper) => {256 const alice = privateKeyWrapper('//Alice');257 const bob = privateKeyWrapper('//Bob');258 const charlie = privateKeyWrapper('//Charlie');259 const data = [260 {261 owner: {substrate: alice.address},262 }, {263 owner: {substrate: bob.address},264 }, {265 owner: {substrate: charlie.address},266 },267 ];268269 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {270 NFT: data,271 }));272 const tokens = await api.query.nonfungible.tokenData.entries(collection);273 const json = tokens.map(([, token]) => token.toJSON());274 expect(json).to.be.deep.equal(data);275 });276 });277278 it('can initialize multiple NFT with different owners', async () => {279 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});280 await usingApi(async (api, privateKeyWrapper) => {281 const alice = privateKeyWrapper('//Alice');282 const bob = privateKeyWrapper('//Bob');283 const charlie = privateKeyWrapper('//Charlie');284 const data = [285 {286 owner: {substrate: alice.address},287 }, {288 owner: {substrate: bob.address},289 }, {290 owner: {substrate: charlie.address},291 },292 ];293294 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {295 NFT: data,296 }));297 const tokens = await api.query.nonfungible.tokenData.entries(collection);298 const json = tokens.map(([, token]) => token.toJSON());299 expect(json).to.be.deep.equal(data);300 });301 });302303 it('fails when trying to set multiple owners when creating multiple refungibles', async () => {304 const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});305 306 await usingApi(async (api, privateKeyWrapper) => {307 const alice = privateKeyWrapper('//Alice');308 const bob = privateKeyWrapper('//Bob');309 310 const users = new Map();311 users.set(JSON.stringify({substrate: alice.address}), 1);312 users.set(JSON.stringify({substrate: bob.address}), 1);313314 315 await expect(executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {316 RefungibleMultipleItems: [317 {users},318 {users},319 ],320 }))).to.be.rejectedWith(/^refungible\.NotRefungibleDataUsedToMintFungibleCollectionToken$/);321 });322 });323});324'';