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 }, {34 owner: {substrate: bob.address},35 36 }, {37 owner: {substrate: charlie.address},38 39 },40 ];4142 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {43 NFT: data,44 }));45 const tokens = await api.query.nonfungible.tokenData.entries(collection);46 const json = tokens.map(([, token]) => token.toJSON());47 expect(json).to.be.deep.equal(data);48 });49 });5051 it('createMultipleItemsEx with property Admin', async () => {52 const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});53 const alice = privateKey('//Alice');54 const bob = privateKey('//Bob');55 const charlie = privateKey('//Charlie');56 await usingApi(async (api) => {57 const data = [58 {59 owner: {substrate: alice.address},60 61 properties: [{key: 'k', value: 'v1'}],62 }, {63 owner: {substrate: bob.address},64 65 properties: [{key: 'k', value: 'v2'}],66 }, {67 owner: {substrate: charlie.address},68 69 properties: [{key: 'k', value: 'v3'}],70 },71 ];7273 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {74 NFT: data,75 }));76 for (let i = 1; i < 4; i++) {77 expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;78 }79 });80 });8182 it('createMultipleItemsEx with property AdminConst', async () => {83 const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});84 const alice = privateKey('//Alice');85 const bob = privateKey('//Bob');86 const charlie = privateKey('//Charlie');87 await usingApi(async (api) => {88 const data = [89 {90 owner: {substrate: alice.address},91 92 properties: [{key: 'k', value: 'v1'}],93 }, {94 owner: {substrate: bob.address},95 96 properties: [{key: 'k', value: 'v2'}],97 }, {98 owner: {substrate: charlie.address},99 100 properties: [{key: 'k', value: 'v3'}],101 },102 ];103104 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {105 NFT: data,106 }));107 for (let i = 1; i < 4; i++) {108 expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;109 }110 });111 });112113 it('createMultipleItemsEx with property itemOwnerOrAdmin', async () => {114 const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: true}}]});115 const alice = privateKey('//Alice');116 const bob = privateKey('//Bob');117 const charlie = privateKey('//Charlie');118 await usingApi(async (api) => {119 const data = [120 {121 owner: {substrate: alice.address},122 123 properties: [{key: 'k', value: 'v1'}],124 }, {125 owner: {substrate: bob.address},126 127 properties: [{key: 'k', value: 'v2'}],128 }, {129 owner: {substrate: charlie.address},130 131 properties: [{key: 'k', value: 'v3'}],132 },133 ];134135 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {136 NFT: data,137 }));138 for (let i = 1; i < 4; i++) {139 expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;140 }141 });142 });143144 it('No editing rights', async () => {145 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],146 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});147 const alice = privateKey('//Alice');148 const bob = privateKey('//Bob');149 const charlie = privateKey('//Charlie');150 await addCollectionAdminExpectSuccess(alice, collection, bob.address);151 await usingApi(async (api) => {152 const data = [153 {154 owner: {substrate: alice.address},155 properties: [{key: 'key1', value: 'v2'}],156 }, {157 owner: {substrate: bob.address},158 properties: [{key: 'key1', value: 'v2'}],159 }, {160 owner: {substrate: charlie.address},161 properties: [{key: 'key1', value: 'v2'}],162 },163 ];164165 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});166 167168 169 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);170 });171 });172173 it('User doesnt have editing rights', async () => {174 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],175 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});176 const alice = privateKey('//Alice');177 const bob = privateKey('//Bob');178 await addCollectionAdminExpectSuccess(alice, collection, bob.address);179 await usingApi(async (api) => {180 const data = [181 {182 owner: {substrate: alice.address},183 properties: [{key: 'key1', value: 'v2'}],184 }, {185 owner: {substrate: alice.address},186 properties: [{key: 'key1', value: 'v2'}],187 }, {188 owner: {substrate: alice.address},189 properties: [{key: 'key1', value: 'v2'}],190 },191 ];192193 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});194 195196 197 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);198 });199 });200201 it('Adding property without access rights', async () => {202 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}]});203 const alice = privateKey('//Alice');204 const bob = privateKey('//Bob');205 const charlie = privateKey('//Charlie');206 await addCollectionAdminExpectSuccess(alice, collection, bob.address);207 await usingApi(async (api) => {208 const data = [209 {210 owner: {substrate: alice.address},211 properties: [{key: 'key1', value: 'v2'}],212 }, {213 owner: {substrate: bob.address},214 properties: [{key: 'key1', value: 'v2'}],215 }, {216 owner: {substrate: charlie.address},217 properties: [{key: 'key1', value: 'v2'}],218 },219 ];220221 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});222223 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);224 225 });226 });227228 it('Adding more than 64 properties', async () => {229 const propPerms = [{key: 'key', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}];230231 for (let i = 0; i < 65; i++) {232 propPerms.push({key: `key${i}`, permission: {mutable: true, collectionAdmin: true, tokenOwner: true}});233 }234235 const alice = privateKey('//Alice');236 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});237 await usingApi(async (api) => {238 await expect(executeTransaction(api, alice, api.tx.unique.setPropertyPermissions(collection, propPerms))).to.be.rejectedWith(/common\.PropertyLimitReached/);239 });240 });241242 it('Trying to add bigger property than allowed', async () => {243 const collection = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});244 const alice = privateKey('//Alice');245 const bob = privateKey('//Bob');246 const charlie = privateKey('//Charlie');247 await addCollectionAdminExpectSuccess(alice, collection, bob.address);248 await usingApi(async (api) => {249 const data = [250 {251 owner: {substrate: alice.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}],252 }, {253 owner: {substrate: bob.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}],254 }, {255 owner: {substrate: charlie.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}],256 },257 ];258259 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});260261 262 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);263 });264 });265266 it('can initialize multiple NFT with different owners', async () => {267 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});268 const alice = privateKey('//Alice');269 const bob = privateKey('//Bob');270 const charlie = privateKey('//Charlie');271 await usingApi(async (api) => {272 const data = [273 {274 owner: {substrate: alice.address},275 276 }, {277 owner: {substrate: bob.address},278 279 }, {280 owner: {substrate: charlie.address},281 282 },283 ];284285 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {286 NFT: data,287 }));288 const tokens = await api.query.nonfungible.tokenData.entries(collection);289 const json = tokens.map(([, token]) => token.toJSON());290 expect(json).to.be.deep.equal(data);291 });292 });293294 it('can initialize multiple NFT with different owners', async () => {295 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});296 const alice = privateKey('//Alice');297 const bob = privateKey('//Bob');298 const charlie = privateKey('//Charlie');299 await usingApi(async (api) => {300 const data = [301 {302 owner: {substrate: alice.address},303 304 }, {305 owner: {substrate: bob.address},306 307 }, {308 owner: {substrate: charlie.address},309 310 },311 ];312313 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {314 NFT: data,315 }));316 const tokens = await api.query.nonfungible.tokenData.entries(collection);317 const json = tokens.map(([, token]) => token.toJSON());318 expect(json).to.be.deep.equal(data);319 });320 });321322 it('fails when trying to set multiple owners when creating multiple refungibles', async () => {323 const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});324 const alice = privateKey('//Alice');325 const bob = privateKey('//Bob');326327 await usingApi(async (api) => {328 329 const users = new Map();330 users.set(JSON.stringify({substrate: alice.address}), 1);331 users.set(JSON.stringify({substrate: bob.address}), 1);332333 334 await expect(executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {335 RefungibleMultipleItems: [336 {users},337 {users},338 ],339 }))).to.be.rejectedWith(/^refungible\.NotRefungibleDataUsedToMintFungibleCollectionToken$/);340 });341 });342});343'';