difftreelog
CreateItem* tests fixes
in: master
4 files changed
tests/src/createItem.test.tsdiffbeforeafterboth--- a/tests/src/createItem.test.ts
+++ b/tests/src/createItem.test.ts
@@ -23,13 +23,14 @@
createItemExpectSuccess,
addCollectionAdminExpectSuccess,
createCollectionWithPropsExpectSuccess,
+ createItemWithPropsExpectSuccess,
} from './util/helpers';
const expect = chai.expect;
let alice: IKeyringPair;
let bob: IKeyringPair;
-describe('integration test: ext. createItem():', () => {
+describe('integration test: ext. ():', () => {
before(async () => {
await usingApi(async () => {
const keyring = new Keyring({type: 'sr25519'});
@@ -75,28 +76,25 @@
it('Set property Admin', async () => {
const createMode = 'NFT';
const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},
- properties: [{key: 'key1', value: 'val1'}],
- propPerm: [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: false}]});
+ propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});
- await createItemExpectSuccess(alice, newCollectionID, createMode);
+ await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'k', value: 't2'}]);
});
it('Set property AdminConst', async () => {
const createMode = 'NFT';
const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},
- properties: [{key: 'key1', value: 'val1'}],
- propPerm: [{key: 'key1', mutable: false, collectionAdmin: true, tokenOwner: false}]});
+ propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});
- await createItemExpectSuccess(alice, newCollectionID, createMode);
+ await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);
});
it('Set property itemOwnerOrAdmin', async () => {
const createMode = 'NFT';
- const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},
- properties: [{key: 'key1', value: 'val1'}],
- propPerm: [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: true}]});
+ const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},
+ propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});
- await createItemExpectSuccess(alice, newCollectionID, createMode);
+ await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);
});
});
@@ -129,7 +127,7 @@
await usingApi(async api => {
const createMode = 'NFT';
const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},
- propPerm: [{key: 'key1', mutable: false, collectionAdmin: false, tokenOwner: false}]});
+ propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});
const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');
await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);
@@ -144,7 +142,7 @@
it('User doesnt have editing rights', async () => {
await usingApi(async api => {
- const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});
+ const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});
const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');
await expect(executeTransaction(
tests/src/createMultipleItems.test.tsdiffbeforeafterboth--- a/tests/src/createMultipleItems.test.ts
+++ b/tests/src/createMultipleItems.test.ts
@@ -34,6 +34,7 @@
getCreatedCollectionCount,
createCollectionWithPropsExpectSuccess,
getCreateItemsResult,
+ createMultipleItemsWithPropsExpectSuccess
} from './util/helpers';
chai.use(chaiAsPromised);
@@ -133,25 +134,18 @@
it('Create 0x31, 0x32, 0x33 items in active NFT with property Admin', async () => {
await usingApi(async (api: ApiPromise) => {
- const collectionId = await createCollectionExpectSuccess();
+ const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
- const args = [{Nft: {const_data: '0x31'}},
- {Nft: {const_data: '0x32'}},
- {Nft: {const_data: '0x33'}}];
- const createMultipleItemsTx = api.tx.unique
- .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
- await submitTransactionAsync(alice, createMultipleItemsTx);
+ const args = [{Nft: {const_data: '0x31', properties: [{key: 'k', value: 'v1'}]}},
+ {Nft: {const_data: '0x32', properties: [{key: 'k', value: 'v2'}]}},
+ {Nft: {const_data: '0x33', properties: [{key: 'k', value: 'v3'}]}}];
+
+ await createMultipleItemsWithPropsExpectSuccess(alice, collectionId, args);
const itemsListIndexAfter = await getLastTokenId(api, collectionId);
expect(itemsListIndexAfter).to.be.equal(3);
-
- await expect(executeTransaction(
- api,
- alice,
- api.tx.unique.setPropertyPermissions(collectionId, [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]),
- )).to.not.be.rejected;
expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));
expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));
@@ -165,26 +159,20 @@
it('Create 0x31, 0x32, 0x33 items in active NFT with property AdminConst', async () => {
await usingApi(async (api: ApiPromise) => {
- const collectionId = await createCollectionExpectSuccess();
+ const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
- const args = [{Nft: {const_data: '0x31'}},
- {Nft: {const_data: '0x32'}},
- {Nft: {const_data: '0x33'}}];
- const createMultipleItemsTx = api.tx.unique
- .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
- await submitTransactionAsync(alice, createMultipleItemsTx);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ const args = [{Nft: {const_data: '0x31', properties: [{key: 'k', value: 'v1'}]}},
+ {Nft: {const_data: '0x32', properties: [{key: 'k', value: 'v2'}]}},
+ {Nft: {const_data: '0x33', properties: [{key: 'k', value: 'v3'}]}}];
+
+ await createMultipleItemsWithPropsExpectSuccess(alice, collectionId, args);
const itemsListIndexAfter = await getLastTokenId(api, collectionId);
expect(itemsListIndexAfter).to.be.equal(3);
- await expect(executeTransaction(
- api,
- alice,
- api.tx.unique.setPropertyPermissions(collectionId, [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]),
- )).to.not.be.rejected;
-
expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));
expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));
expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));
@@ -197,25 +185,18 @@
it('Create 0x31, 0x32, 0x33 items in active NFT with property itemOwnerOrAdmin', async () => {
await usingApi(async (api: ApiPromise) => {
- const collectionId = await createCollectionExpectSuccess();
+ const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
- const args = [{Nft: {const_data: '0x31'}},
- {Nft: {const_data: '0x32'}},
- {Nft: {const_data: '0x33'}}];
- const createMultipleItemsTx = api.tx.unique
- .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
- await submitTransactionAsync(alice, createMultipleItemsTx);
+ const args = [{Nft: {const_data: '0x31', properties: [{key: 'k', value: 'v1'}]}},
+ {Nft: {const_data: '0x32', properties: [{key: 'k', value: 'v2'}]}},
+ {Nft: {const_data: '0x33', properties: [{key: 'k', value: 'v3'}]}}];
+
+ await createMultipleItemsWithPropsExpectSuccess(alice, collectionId, args);
const itemsListIndexAfter = await getLastTokenId(api, collectionId);
expect(itemsListIndexAfter).to.be.equal(3);
-
- await expect(executeTransaction(
- api,
- alice,
- api.tx.unique.setPropertyPermissions(collectionId, [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]),
- )).to.not.be.rejected;
expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));
expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));
@@ -451,7 +432,7 @@
it('No editing rights', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],
- propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});
+ propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
@@ -479,7 +460,7 @@
it('User doesnt have editing rights', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],
- propPerm: [{key: 'key1', mutable: false, collectionAdmin: false, tokenOwner: false}]});
+ propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
@@ -530,7 +511,7 @@
it('Adding more than 64 prps', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],
- propPerm: [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: false}]});
+ propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
@@ -565,7 +546,7 @@
it('Trying to add bigger property than allowed', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],
- propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});
+ propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
const args = [{Nft: {const_data: '0x31'}},
tests/src/createMultipleItemsEx.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {expect} from 'chai';18import privateKey from './substrate/privateKey';19import usingApi, {executeTransaction, submitTransactionAsync} from './substrate/substrate-api';20import {createCollectionExpectSuccess, createCollectionWithPropsExpectSuccess, addCollectionAdminExpectSuccess, getCreateItemsResult} 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 constData: '0x0000',33 }, {34 owner: {substrate: bob.address},35 constData: '0x2222',36 }, {37 owner: {substrate: charlie.address},38 constData: '0x4444',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 createCollectionExpectSuccess({mode: {type: 'NFT'}});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 constData: '0x0000',61 }, {62 owner: {substrate: bob.address},63 constData: '0x2222',64 }, {65 owner: {substrate: charlie.address},66 constData: '0x4444',67 },68 ];6970 await expect(executeTransaction(71 api,72 alice,73 api.tx.unique.setPropertyPermissions(collection, [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]),74 )).to.not.be.rejected;7576 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {77 NFT: data,78 }));79 const tokens = await api.query.nonfungible.tokenData.entries(collection);80 const json = tokens.map(([, token]) => token.toJSON());81 expect(json).to.be.deep.equal(data);82 });83 });8485 it('createMultipleItemsEx with property AdminConst', async () => {86 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});87 const alice = privateKey('//Alice');88 const bob = privateKey('//Bob');89 const charlie = privateKey('//Charlie');90 await usingApi(async (api) => {91 const data = [92 {93 owner: {substrate: alice.address},94 constData: '0x0000',95 }, {96 owner: {substrate: bob.address},97 constData: '0x2222',98 }, {99 owner: {substrate: charlie.address},100 constData: '0x4444',101 },102 ];103 await expect(executeTransaction(104 api,105 alice,106 api.tx.unique.setPropertyPermissions(collection, [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]),107 )).to.not.be.rejected;108109 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {110 NFT: data,111 }));112113114 const tokens = await api.query.nonfungible.tokenData.entries(collection);115 const json = tokens.map(([, token]) => token.toJSON());116 expect(json).to.be.deep.equal(data);117 });118 });119120 it('createMultipleItemsEx with property itemOwnerOrAdmin', async () => {121 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});122 const alice = privateKey('//Alice');123 const bob = privateKey('//Bob');124 const charlie = privateKey('//Charlie');125 await usingApi(async (api) => {126 const data = [127 {128 owner: {substrate: alice.address},129 constData: '0x0000',130 }, {131 owner: {substrate: bob.address},132 constData: '0x2222',133 }, {134 owner: {substrate: charlie.address},135 constData: '0x4444',136 },137 ];138 await expect(executeTransaction(139 api,140 alice,141 api.tx.unique.setPropertyPermissions(collection, [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]),142 )).to.not.be.rejected;143144 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {145 NFT: data,146 }));147148149 const tokens = await api.query.nonfungible.tokenData.entries(collection);150 const json = tokens.map(([, token]) => token.toJSON());151 expect(json).to.be.deep.equal(data);152 });153 });154155 it('No editing rights', async () => {156 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],157 propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});158 const alice = privateKey('//Alice');159 const bob = privateKey('//Bob');160 const charlie = privateKey('//Charlie');161 await addCollectionAdminExpectSuccess(alice, collection, bob.address);162 await usingApi(async (api) => {163 const data = [164 {165 owner: {substrate: alice.address},166 }, {167 owner: {substrate: bob.address},168 }, {169 owner: {substrate: charlie.address},170 },171 ];172173 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});174 await executeTransaction(api, alice, tx);175176 const events = await submitTransactionAsync(alice, tx);177 const result = getCreateItemsResult(events);178179 for (const elem of result) {180 await expect(executeTransaction(181 api,182 bob,183 api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, [{key: 'key1', value: 'v2'}]),184 )).to.be.rejected;185 }186 });187 });188189 it('User doesnt have editing rights', async () => {190 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],191 propPerm: [{key: 'key1', mutable: false, collectionAdmin: false, tokenOwner: false}]});192 const alice = privateKey('//Alice');193 const bob = privateKey('//Bob');194 const charlie = privateKey('//Charlie');195 await addCollectionAdminExpectSuccess(alice, collection, bob.address);196 await usingApi(async (api) => {197 const data = [198 {199 owner: {substrate: alice.address},200 }, {201 owner: {substrate: bob.address},202 }, {203 owner: {substrate: charlie.address},204 },205 ];206207 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});208 await executeTransaction(api, alice, tx);209210 const events = await submitTransactionAsync(alice, tx);211 const result = getCreateItemsResult(events);212213 for (const elem of result) {214 await expect(executeTransaction(215 api,216 bob,217 api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, [{key: 'key1', value: 'v2'}]),218 )).to.be.rejected;219 }220 });221 });222223 it('Adding property without access rights', async () => {224 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}]});225 const alice = privateKey('//Alice');226 const bob = privateKey('//Bob');227 const charlie = privateKey('//Charlie');228 await addCollectionAdminExpectSuccess(alice, collection, bob.address);229 await usingApi(async (api) => {230 const data = [231 {232 owner: {substrate: alice.address},233 }, {234 owner: {substrate: bob.address},235 }, {236 owner: {substrate: charlie.address},237 },238 ];239240 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});241 await executeTransaction(api, alice, tx);242243 const events = await submitTransactionAsync(alice, tx);244 const result = getCreateItemsResult(events);245246 for (const elem of result) {247 await expect(executeTransaction(248 api,249 bob,250 api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, [{key: 'key1', value: 'v2'}]),251 )).to.be.rejected;252 }253 });254 });255256 it('Adding more than 64 prps', async () => {257 const collection = await createCollectionWithPropsExpectSuccess();258 const alice = privateKey('//Alice');259 const bob = privateKey('//Bob');260 const charlie = privateKey('//Charlie');261 await addCollectionAdminExpectSuccess(alice, collection, bob.address);262 await usingApi(async (api) => {263 const data = [264 {265 owner: {substrate: alice.address},266 }, {267 owner: {substrate: bob.address},268 }, {269 owner: {substrate: charlie.address},270 },271 ];272273 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});274 await executeTransaction(api, alice, tx);275276 const events = await submitTransactionAsync(alice, tx);277 const result = getCreateItemsResult(events);278279 const prps = [];280281 for (let i = 0; i < 65; i++) {282 prps.push({key: `key${i}`, value: `value${i}`});283 }284285 await expect(executeTransaction(api, bob, api.tx.unique.setCollectionProperties(collection, prps))).to.be.rejectedWith(/common\.PropertyLimitReached/);286287288 for (const elem of result) {289 await expect(executeTransaction(290 api,291 bob,292 api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, prps),293 )).to.be.rejected;294 }295 });296 });297298 it('Trying to add bigger property than allowed', async () => {299 const collection = await createCollectionWithPropsExpectSuccess();300 const alice = privateKey('//Alice');301 const bob = privateKey('//Bob');302 const charlie = privateKey('//Charlie');303 await addCollectionAdminExpectSuccess(alice, collection, bob.address);304 await usingApi(async (api) => {305 const data = [306 {307 owner: {substrate: alice.address},308 }, {309 owner: {substrate: bob.address},310 }, {311 owner: {substrate: charlie.address},312 },313 ];314315 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});316 await executeTransaction(api, alice, tx);317318 const events = await submitTransactionAsync(alice, tx);319 const result = getCreateItemsResult(events);320321 const prps = [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}];322323 await expect(executeTransaction(api, bob, api.tx.unique.setCollectionProperties(collection, prps))).to.be.rejectedWith(/common\.NoSpaceForProperty/);324325326 for (const elem of result) {327 await expect(executeTransaction(328 api,329 bob,330 api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, prps),331 )).to.be.rejected;332 }333 });334 });335336 it('can initialize multiple NFT with different owners', async () => {337 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});338 const alice = privateKey('//Alice');339 const bob = privateKey('//Bob');340 const charlie = privateKey('//Charlie');341 await usingApi(async (api) => {342 const data = [343 {344 owner: {substrate: alice.address},345 constData: '0x0000',346 }, {347 owner: {substrate: bob.address},348 constData: '0x2222',349 }, {350 owner: {substrate: charlie.address},351 constData: '0x4444',352 },353 ];354355 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {356 NFT: data,357 }));358 const tokens = await api.query.nonfungible.tokenData.entries(collection);359 const json = tokens.map(([, token]) => token.toJSON());360 expect(json).to.be.deep.equal(data);361 });362 });363364 it('can initialize multiple NFT with different owners', async () => {365 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});366 const alice = privateKey('//Alice');367 const bob = privateKey('//Bob');368 const charlie = privateKey('//Charlie');369 await usingApi(async (api) => {370 const data = [371 {372 owner: {substrate: alice.address},373 constData: '0x0000',374 }, {375 owner: {substrate: bob.address},376 constData: '0x2222',377 }, {378 owner: {substrate: charlie.address},379 constData: '0x4444',380 },381 ];382383 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {384 NFT: data,385 }));386 const tokens = await api.query.nonfungible.tokenData.entries(collection);387 const json = tokens.map(([, token]) => token.toJSON());388 expect(json).to.be.deep.equal(data);389 });390 });391392 it('fails when trying to set multiple owners when creating multiple refungibles', async () => {393 const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});394 const alice = privateKey('//Alice');395 const bob = privateKey('//Bob');396397 await usingApi(async (api) => {398 // Polkadot requires map, and yet requires keys to be JSON encoded399 const users = new Map();400 users.set(JSON.stringify({substrate: alice.address}), 1);401 users.set(JSON.stringify({substrate: bob.address}), 1);402403 // TODO: better error message?404 await expect(executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {405 RefungibleMultipleItems: [406 {users},407 {users},408 ],409 }))).to.be.rejectedWith(/^refungible\.NotRefungibleDataUsedToMintFungibleCollectionToken$/);410 });411 });412});413'';tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -27,7 +27,7 @@
import privateKey from '../substrate/privateKey';
import {default as usingApi, executeTransaction, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';
import {hexToStr, strToUTF16, utf16ToStr} from './util';
-import {UpDataStructsRpcCollection} from '@polkadot/types/lookup';
+import {UpDataStructsRpcCollection, UpDataStructsCreateItemData} from '@polkadot/types/lookup';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -295,13 +295,17 @@
value: any,
};
-type PropertyPermission = {
- key: any,
+type Permission = {
mutable: boolean;
collectionAdmin: boolean;
tokenOwner: boolean;
}
+type PropertyPermission = {
+ key: any;
+ permission: Permission;
+}
+
export type CreateCollectionParams = {
mode: CollectionMode,
name: string,
@@ -1123,6 +1127,65 @@
});
}
+export async function createMultipleItemsWithPropsExpectSuccess(sender: IKeyringPair, collectionId: number, itemsData: any, owner: CrossAccountId | string = sender.address) {
+ await usingApi(async (api) => {
+ const to = normalizeAccountId(owner);
+ const tx = api.tx.unique.createMultipleItems(collectionId, to, itemsData);
+
+ const events = await submitTransactionAsync(sender, tx);
+ const result = getCreateItemsResult(events);
+
+ for (let res of result) {
+ expect(await api.rpc.unique.tokenProperties(collectionId, res.itemId)).not.to.be.empty;
+ }
+ });
+}
+
+export async function createItemWithPropsExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, props: Array<Property>, owner: CrossAccountId | string = sender.address) {
+ let newItemId = 0;
+ await usingApi(async (api) => {
+ const to = normalizeAccountId(owner);
+ const itemCountBefore = await getLastTokenId(api, collectionId);
+ const itemBalanceBefore = await getBalance(api, collectionId, to, newItemId);
+
+ let tx;
+ if (createMode === 'Fungible') {
+ const createData = {fungible: {value: 10}};
+ tx = api.tx.unique.createItem(collectionId, to, createData as any);
+ } else if (createMode === 'ReFungible') {
+ const createData = {refungible: {const_data: [], pieces: 100}};
+ tx = api.tx.unique.createItem(collectionId, to, createData as any);
+ } else {
+ const data = api.createType('UpDataStructsCreateItemData', { NFT: { constData: 'test', properties: props}});
+ tx = api.tx.unique.createItem(collectionId, to, data as UpDataStructsCreateItemData);
+ }
+
+ const events = await submitTransactionAsync(sender, tx);
+ const result = getCreateItemResult(events);
+
+ const itemCountAfter = await getLastTokenId(api, collectionId);
+ const itemBalanceAfter = await getBalance(api, collectionId, to, newItemId);
+
+ if (createMode === 'NFT') {
+ expect(await api.rpc.unique.tokenProperties(collectionId, result.itemId)).not.to.be.empty;
+ }
+
+ // What to expect
+ // tslint:disable-next-line:no-unused-expression
+ expect(result.success).to.be.true;
+ if (createMode === 'Fungible') {
+ expect(itemBalanceAfter - itemBalanceBefore).to.be.equal(10n);
+ } else {
+ expect(itemCountAfter).to.be.equal(itemCountBefore + 1);
+ }
+ expect(collectionId).to.be.equal(result.collectionId);
+ expect(itemCountAfter.toString()).to.be.equal(result.itemId.toString());
+ expect(to).to.be.deep.equal(result.recipient);
+ newItemId = result.itemId;
+ });
+ return newItemId;
+}
+
export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: CrossAccountId | string = sender.address) {
let newItemId = 0;
await usingApi(async (api) => {