1234567891011121314151617import {expect} from 'chai';18import privateKey from './substrate/privateKey';19import usingApi, {executeTransaction} from './substrate/substrate-api';20import {createCollectionExpectSuccess, createCollectionWithPropsExpectSuccess, addCollectionAdminExpectSuccess} from './util/helpers';2122describe('createMultipleItemsEx', () => {23 it('can initialize multiple NFT with different owners', async () => {24 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});25 const alice = privateKey('//Alice');26 const bob = privateKey('//Bob');27 const charlie = privateKey('//Charlie');28 await usingApi(async (api) => {29 const data = [30 {31 owner: {substrate: alice.address},32 }, {33 owner: {substrate: bob.address},34 }, {35 owner: {substrate: charlie.address},36 },37 ];3839 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {40 NFT: data,41 }));42 const tokens = await api.query.nonfungible.tokenData.entries(collection);43 const json = tokens.map(([, token]) => token.toJSON());44 expect(json).to.be.deep.equal(data);45 });46 });4748 it('createMultipleItemsEx with property Admin', async () => {49 const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});50 const alice = privateKey('//Alice');51 const bob = privateKey('//Bob');52 const charlie = privateKey('//Charlie');53 await usingApi(async (api) => {54 const data = [55 {56 owner: {substrate: alice.address},57 properties: [{key: 'k', value: 'v1'}],58 }, {59 owner: {substrate: bob.address},60 properties: [{key: 'k', value: 'v2'}],61 }, {62 owner: {substrate: charlie.address},63 properties: [{key: 'k', value: 'v3'}],64 },65 ];6667 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {68 NFT: data,69 }));70 for (let i = 1; i < 4; i++) {71 expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;72 }73 });74 });7576 it('createMultipleItemsEx with property AdminConst', async () => {77 const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});78 const alice = privateKey('//Alice');79 const bob = privateKey('//Bob');80 const charlie = privateKey('//Charlie');81 await usingApi(async (api) => {82 const data = [83 {84 owner: {substrate: alice.address},85 properties: [{key: 'k', value: 'v1'}],86 }, {87 owner: {substrate: bob.address},88 properties: [{key: 'k', value: 'v2'}],89 }, {90 owner: {substrate: charlie.address},91 properties: [{key: 'k', value: 'v3'}],92 },93 ];9495 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {96 NFT: data,97 }));98 for (let i = 1; i < 4; i++) {99 expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;100 }101 });102 });103104 it('createMultipleItemsEx with property itemOwnerOrAdmin', async () => {105 const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: true}}]});106 const alice = privateKey('//Alice');107 const bob = privateKey('//Bob');108 const charlie = privateKey('//Charlie');109 await usingApi(async (api) => {110 const data = [111 {112 owner: {substrate: alice.address},113 properties: [{key: 'k', value: 'v1'}],114 }, {115 owner: {substrate: bob.address},116 properties: [{key: 'k', value: 'v2'}],117 }, {118 owner: {substrate: charlie.address},119 properties: [{key: 'k', value: 'v3'}],120 },121 ];122123 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {124 NFT: data,125 }));126 for (let i = 1; i < 4; i++) {127 expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;128 }129 });130 });131132 it('No editing rights', async () => {133 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],134 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});135 const alice = privateKey('//Alice');136 const bob = privateKey('//Bob');137 const charlie = privateKey('//Charlie');138 await addCollectionAdminExpectSuccess(alice, collection, bob.address);139 await usingApi(async (api) => {140 const data = [141 {142 owner: {substrate: alice.address},143 properties: [{key: 'key1', value: 'v2'}],144 }, {145 owner: {substrate: bob.address},146 properties: [{key: 'key1', value: 'v2'}],147 }, {148 owner: {substrate: charlie.address},149 properties: [{key: 'key1', value: 'v2'}],150 },151 ];152153 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});154 155156 157 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);158 });159 });160161 it('User doesnt have editing rights', async () => {162 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],163 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});164 const alice = privateKey('//Alice');165 const bob = privateKey('//Bob');166 await addCollectionAdminExpectSuccess(alice, collection, bob.address);167 await usingApi(async (api) => {168 const data = [169 {170 owner: {substrate: alice.address},171 properties: [{key: 'key1', value: 'v2'}],172 }, {173 owner: {substrate: alice.address},174 properties: [{key: 'key1', value: 'v2'}],175 }, {176 owner: {substrate: alice.address},177 properties: [{key: 'key1', value: 'v2'}],178 },179 ];180181 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});182 183184 185 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);186 });187 });188189 it('Adding property without access rights', async () => {190 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}]});191 const alice = privateKey('//Alice');192 const bob = privateKey('//Bob');193 const charlie = privateKey('//Charlie');194 await addCollectionAdminExpectSuccess(alice, collection, bob.address);195 await usingApi(async (api) => {196 const data = [197 {198 owner: {substrate: alice.address},199 properties: [{key: 'key1', value: 'v2'}],200 }, {201 owner: {substrate: bob.address},202 properties: [{key: 'key1', value: 'v2'}],203 }, {204 owner: {substrate: charlie.address},205 properties: [{key: 'key1', value: 'v2'}],206 },207 ];208209 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});210211 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);212 213 });214 });215216 it('Adding more than 64 properties', async () => {217 const propPerms = [{key: 'key', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}];218219 for (let i = 0; i < 65; i++) {220 propPerms.push({key: `key${i}`, permission: {mutable: true, collectionAdmin: true, tokenOwner: true}});221 }222223 const alice = privateKey('//Alice');224 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});225 await usingApi(async (api) => {226 await expect(executeTransaction(api, alice, api.tx.unique.setPropertyPermissions(collection, propPerms))).to.be.rejectedWith(/common\.PropertyLimitReached/);227 });228 });229230 it('Trying to add bigger property than allowed', async () => {231 const collection = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});232 const alice = privateKey('//Alice');233 const bob = privateKey('//Bob');234 const charlie = privateKey('//Charlie');235 await addCollectionAdminExpectSuccess(alice, collection, bob.address);236 await usingApi(async (api) => {237 const data = [238 {239 owner: {substrate: alice.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}],240 }, {241 owner: {substrate: bob.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}],242 }, {243 owner: {substrate: charlie.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}],244 },245 ];246247 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});248249 250 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);251 });252 });253254 it('can initialize multiple NFT with different owners', async () => {255 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});256 const alice = privateKey('//Alice');257 const bob = privateKey('//Bob');258 const charlie = privateKey('//Charlie');259 await usingApi(async (api) => {260 const data = [261 {262 owner: {substrate: alice.address},263 }, {264 owner: {substrate: bob.address},265 }, {266 owner: {substrate: charlie.address},267 },268 ];269270 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {271 NFT: data,272 }));273 const tokens = await api.query.nonfungible.tokenData.entries(collection);274 const json = tokens.map(([, token]) => token.toJSON());275 expect(json).to.be.deep.equal(data);276 });277 });278279 it('can initialize multiple NFT with different owners', async () => {280 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});281 const alice = privateKey('//Alice');282 const bob = privateKey('//Bob');283 const charlie = privateKey('//Charlie');284 await usingApi(async (api) => {285 const data = [286 {287 owner: {substrate: alice.address},288 }, {289 owner: {substrate: bob.address},290 }, {291 owner: {substrate: charlie.address},292 },293 ];294295 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {296 NFT: data,297 }));298 const tokens = await api.query.nonfungible.tokenData.entries(collection);299 const json = tokens.map(([, token]) => token.toJSON());300 expect(json).to.be.deep.equal(data);301 });302 });303304 it('fails when trying to set multiple owners when creating multiple refungibles', async () => {305 const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});306 const alice = privateKey('//Alice');307 const bob = privateKey('//Bob');308309 await usingApi(async (api) => {310 311 const users = new Map();312 users.set(JSON.stringify({substrate: alice.address}), 1);313 users.set(JSON.stringify({substrate: bob.address}), 1);314315 316 await expect(executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {317 RefungibleMultipleItems: [318 {users},319 {users},320 ],321 }))).to.be.rejectedWith(/^refungible\.NotRefungibleDataUsedToMintFungibleCollectionToken$/);322 });323 });324});325'';