difftreelog
CreateItem* tests fixes
in: master
4 files changed
tests/src/createItem.test.tsdiffbeforeafterboth23 createItemExpectSuccess,23 createItemExpectSuccess,24 addCollectionAdminExpectSuccess,24 addCollectionAdminExpectSuccess,25 createCollectionWithPropsExpectSuccess,25 createCollectionWithPropsExpectSuccess,26 createItemWithPropsExpectSuccess,26} from './util/helpers';27} from './util/helpers';272828const expect = chai.expect;29const expect = chai.expect;29let alice: IKeyringPair;30let alice: IKeyringPair;30let bob: IKeyringPair;31let bob: IKeyringPair;313232describe('integration test: ext. createItem():', () => {33describe('integration test: ext. ():', () => {33 before(async () => {34 before(async () => {34 await usingApi(async () => {35 await usingApi(async () => {35 const keyring = new Keyring({type: 'sr25519'});36 const keyring = new Keyring({type: 'sr25519'});75 it('Set property Admin', async () => {76 it('Set property Admin', async () => {76 const createMode = 'NFT';77 const createMode = 'NFT';77 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 78 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 78 properties: [{key: 'key1', value: 'val1'}], 79 propPerm: [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: false}]});79 propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});80 80 81 await createItemExpectSuccess(alice, newCollectionID, createMode);81 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'k', value: 't2'}]);82 });82 });838384 it('Set property AdminConst', async () => {84 it('Set property AdminConst', async () => {85 const createMode = 'NFT';85 const createMode = 'NFT';86 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 86 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 87 properties: [{key: 'key1', value: 'val1'}], 88 propPerm: [{key: 'key1', mutable: false, collectionAdmin: true, tokenOwner: false}]});87 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});89 88 90 await createItemExpectSuccess(alice, newCollectionID, createMode);89 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);91 });90 });929193 it('Set property itemOwnerOrAdmin', async () => {92 it('Set property itemOwnerOrAdmin', async () => {94 const createMode = 'NFT';93 const createMode = 'NFT';95 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 94 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},96 properties: [{key: 'key1', value: 'val1'}], 97 propPerm: [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: true}]});95 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});98 96 99 await createItemExpectSuccess(alice, newCollectionID, createMode);97 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);100 });98 });101});99});102100129 await usingApi(async api => {127 await usingApi(async api => {130 const createMode = 'NFT';128 const createMode = 'NFT';131 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 129 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 132 propPerm: [{key: 'key1', mutable: false, collectionAdmin: false, tokenOwner: false}]});130 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});133131134 const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');132 const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');135 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);133 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);144142145 it('User doesnt have editing rights', async () => {143 it('User doesnt have editing rights', async () => {146 await usingApi(async api => {144 await usingApi(async api => {147 const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});145 const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});148 const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');146 const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');149147150 await expect(executeTransaction(148 await expect(executeTransaction(tests/src/createMultipleItems.test.tsdiffbeforeafterboth34 getCreatedCollectionCount,34 getCreatedCollectionCount,35 createCollectionWithPropsExpectSuccess,35 createCollectionWithPropsExpectSuccess,36 getCreateItemsResult,36 getCreateItemsResult,37 createMultipleItemsWithPropsExpectSuccess37} from './util/helpers';38} from './util/helpers';383939chai.use(chaiAsPromised);40chai.use(chaiAsPromised);133134134 it('Create 0x31, 0x32, 0x33 items in active NFT with property Admin', async () => {135 it('Create 0x31, 0x32, 0x33 items in active NFT with property Admin', async () => {135 await usingApi(async (api: ApiPromise) => {136 await usingApi(async (api: ApiPromise) => {136 const collectionId = await createCollectionExpectSuccess();137 const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});137 const itemsListIndexBefore = await getLastTokenId(api, collectionId);138 const itemsListIndexBefore = await getLastTokenId(api, collectionId);138 expect(itemsListIndexBefore).to.be.equal(0);139 expect(itemsListIndexBefore).to.be.equal(0);139 const alice = privateKey('//Alice');140 const alice = privateKey('//Alice');140 const bob = privateKey('//Bob');141 const bob = privateKey('//Bob');141 const args = [{Nft: {const_data: '0x31'}},142 const args = [{Nft: {const_data: '0x31', properties: [{key: 'k', value: 'v1'}]}},142 {Nft: {const_data: '0x32'}},143 {Nft: {const_data: '0x32', properties: [{key: 'k', value: 'v2'}]}},143 {Nft: {const_data: '0x33'}}];144 {Nft: {const_data: '0x33', properties: [{key: 'k', value: 'v3'}]}}];144 const createMultipleItemsTx = api.tx.unique145145 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);146 await createMultipleItemsWithPropsExpectSuccess(alice, collectionId, args);146 await submitTransactionAsync(alice, createMultipleItemsTx);147 const itemsListIndexAfter = await getLastTokenId(api, collectionId);147 const itemsListIndexAfter = await getLastTokenId(api, collectionId);148 expect(itemsListIndexAfter).to.be.equal(3);148 expect(itemsListIndexAfter).to.be.equal(3);149150 await expect(executeTransaction(151 api,152 alice,153 api.tx.unique.setPropertyPermissions(collectionId, [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]),154 )).to.not.be.rejected;155149156 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));150 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));157 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));151 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));165159166 it('Create 0x31, 0x32, 0x33 items in active NFT with property AdminConst', async () => {160 it('Create 0x31, 0x32, 0x33 items in active NFT with property AdminConst', async () => {167 await usingApi(async (api: ApiPromise) => {161 await usingApi(async (api: ApiPromise) => {168 const collectionId = await createCollectionExpectSuccess();162 const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});169 const itemsListIndexBefore = await getLastTokenId(api, collectionId);163 const itemsListIndexBefore = await getLastTokenId(api, collectionId);170 expect(itemsListIndexBefore).to.be.equal(0);164 expect(itemsListIndexBefore).to.be.equal(0);171 const alice = privateKey('//Alice');165 const alice = privateKey('//Alice');172 const bob = privateKey('//Bob');166 const bob = privateKey('//Bob');167 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);173 const args = [{Nft: {const_data: '0x31'}},168 const args = [{Nft: {const_data: '0x31', properties: [{key: 'k', value: 'v1'}]}},174 {Nft: {const_data: '0x32'}},169 {Nft: {const_data: '0x32', properties: [{key: 'k', value: 'v2'}]}},175 {Nft: {const_data: '0x33'}}];170 {Nft: {const_data: '0x33', properties: [{key: 'k', value: 'v3'}]}}];176 const createMultipleItemsTx = api.tx.unique171177 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);172 await createMultipleItemsWithPropsExpectSuccess(alice, collectionId, args);178 await submitTransactionAsync(alice, createMultipleItemsTx);179 const itemsListIndexAfter = await getLastTokenId(api, collectionId);173 const itemsListIndexAfter = await getLastTokenId(api, collectionId);180 expect(itemsListIndexAfter).to.be.equal(3);174 expect(itemsListIndexAfter).to.be.equal(3);181182 await expect(executeTransaction(183 api,184 alice,185 api.tx.unique.setPropertyPermissions(collectionId, [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]),186 )).to.not.be.rejected;187175188 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));176 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));189 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));177 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));197185198 it('Create 0x31, 0x32, 0x33 items in active NFT with property itemOwnerOrAdmin', async () => {186 it('Create 0x31, 0x32, 0x33 items in active NFT with property itemOwnerOrAdmin', async () => {199 await usingApi(async (api: ApiPromise) => {187 await usingApi(async (api: ApiPromise) => {200 const collectionId = await createCollectionExpectSuccess();188 const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});201 const itemsListIndexBefore = await getLastTokenId(api, collectionId);189 const itemsListIndexBefore = await getLastTokenId(api, collectionId);202 expect(itemsListIndexBefore).to.be.equal(0);190 expect(itemsListIndexBefore).to.be.equal(0);203 const alice = privateKey('//Alice');191 const alice = privateKey('//Alice');204 const bob = privateKey('//Bob');192 const bob = privateKey('//Bob');205 const args = [{Nft: {const_data: '0x31'}},193 const args = [{Nft: {const_data: '0x31', properties: [{key: 'k', value: 'v1'}]}},206 {Nft: {const_data: '0x32'}},194 {Nft: {const_data: '0x32', properties: [{key: 'k', value: 'v2'}]}},207 {Nft: {const_data: '0x33'}}];195 {Nft: {const_data: '0x33', properties: [{key: 'k', value: 'v3'}]}}];208 const createMultipleItemsTx = api.tx.unique196209 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);197 await createMultipleItemsWithPropsExpectSuccess(alice, collectionId, args);210 await submitTransactionAsync(alice, createMultipleItemsTx);211 const itemsListIndexAfter = await getLastTokenId(api, collectionId);198 const itemsListIndexAfter = await getLastTokenId(api, collectionId);212 expect(itemsListIndexAfter).to.be.equal(3);199 expect(itemsListIndexAfter).to.be.equal(3);213214 await expect(executeTransaction(215 api,216 alice,217 api.tx.unique.setPropertyPermissions(collectionId, [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]),218 )).to.not.be.rejected;219200220 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));201 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));221 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));202 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));451 it('No editing rights', async () => {432 it('No editing rights', async () => {452 await usingApi(async (api: ApiPromise) => {433 await usingApi(async (api: ApiPromise) => {453 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],434 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],454 propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});435 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});455 const itemsListIndexBefore = await getLastTokenId(api, collectionId);436 const itemsListIndexBefore = await getLastTokenId(api, collectionId);456 expect(itemsListIndexBefore).to.be.equal(0);437 expect(itemsListIndexBefore).to.be.equal(0);457 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);438 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);479 it('User doesnt have editing rights', async () => {460 it('User doesnt have editing rights', async () => {480 await usingApi(async (api: ApiPromise) => {461 await usingApi(async (api: ApiPromise) => {481 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],462 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],482 propPerm: [{key: 'key1', mutable: false, collectionAdmin: false, tokenOwner: false}]});463 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});483 const itemsListIndexBefore = await getLastTokenId(api, collectionId);464 const itemsListIndexBefore = await getLastTokenId(api, collectionId);484 expect(itemsListIndexBefore).to.be.equal(0);465 expect(itemsListIndexBefore).to.be.equal(0);485 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);466 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);530 it('Adding more than 64 prps', async () => {511 it('Adding more than 64 prps', async () => {531 await usingApi(async (api: ApiPromise) => {512 await usingApi(async (api: ApiPromise) => {532 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],513 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],533 propPerm: [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: false}]});514 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});534 const itemsListIndexBefore = await getLastTokenId(api, collectionId);515 const itemsListIndexBefore = await getLastTokenId(api, collectionId);535 expect(itemsListIndexBefore).to.be.equal(0);516 expect(itemsListIndexBefore).to.be.equal(0);536 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);517 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);565 it('Trying to add bigger property than allowed', async () => {546 it('Trying to add bigger property than allowed', async () => {566 await usingApi(async (api: ApiPromise) => {547 await usingApi(async (api: ApiPromise) => {567 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],548 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],568 propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});549 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});569 const itemsListIndexBefore = await getLastTokenId(api, collectionId);550 const itemsListIndexBefore = await getLastTokenId(api, collectionId);570 expect(itemsListIndexBefore).to.be.equal(0);551 expect(itemsListIndexBefore).to.be.equal(0);571 const args = [{Nft: {const_data: '0x31'}},552 const args = [{Nft: {const_data: '0x31'}},tests/src/createMultipleItemsEx.test.tsdiffbeforeafterboth48 });48 });49 });49 });505051 it('createMultipleItemsEx with property Admin', async () => {51 it.only('createMultipleItemsEx with property Admin', async () => {52 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});52 const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});53 const alice = privateKey('//Alice');53 const alice = privateKey('//Alice');54 const bob = privateKey('//Bob');54 const bob = privateKey('//Bob');55 const charlie = privateKey('//Charlie');55 const charlie = privateKey('//Charlie');56 await usingApi(async (api) => {56 await usingApi(async (api) => {57 const data = [57 const data = [58 {58 {59 owner: {substrate: alice.address},59 owner: {substrate: alice.address},60 constData: '0x0000',60 constData: '0x1111',61 properties: [{key: 'k', value: 'v1'}],61 }, {62 }, {62 owner: {substrate: bob.address},63 owner: {substrate: bob.address},63 constData: '0x2222',64 constData: '0x2222',65 properties: [{key: 'k', value: 'v2'}],64 }, {66 }, {65 owner: {substrate: charlie.address},67 owner: {substrate: charlie.address},66 constData: '0x4444',68 constData: '0x4444',69 properties: [{key: 'k', value: 'v3'}],67 },70 },68 ];71 ];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;757276 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {73 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {77 NFT: data,74 NFT: data,78 }));75 }));79 const tokens = await api.query.nonfungible.tokenData.entries(collection);76 for (let i = 1; i < 4; i++) {80 const json = tokens.map(([, token]) => token.toJSON());81 expect(json).to.be.deep.equal(data);77 expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;78 }82 });79 });83 });80 });848185 it('createMultipleItemsEx with property AdminConst', async () => {82 it('createMultipleItemsEx with property AdminConst', async () => {86 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});83 const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});87 const alice = privateKey('//Alice');84 const alice = privateKey('//Alice');88 const bob = privateKey('//Bob');85 const bob = privateKey('//Bob');89 const charlie = privateKey('//Charlie');86 const charlie = privateKey('//Charlie');92 {89 {93 owner: {substrate: alice.address},90 owner: {substrate: alice.address},94 constData: '0x0000',91 constData: '0x0000',92 properties: [{key: 'k', value: 'v1'}],95 }, {93 }, {96 owner: {substrate: bob.address},94 owner: {substrate: bob.address},97 constData: '0x2222',95 constData: '0x2222',96 properties: [{key: 'k', value: 'v2'}],98 }, {97 }, {99 owner: {substrate: charlie.address},98 owner: {substrate: charlie.address},100 constData: '0x4444',99 constData: '0x4444',100 properties: [{key: 'k', value: 'v3'}],101 },101 },102 ];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;108103109 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {104 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {110 NFT: data,105 NFT: data,111 }));106 }));112113114 const tokens = await api.query.nonfungible.tokenData.entries(collection);107 for (let i = 1; i < 4; i++) {115 const json = tokens.map(([, token]) => token.toJSON());116 expect(json).to.be.deep.equal(data);108 expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;109 }117 });110 });118 });111 });119112120 it('createMultipleItemsEx with property itemOwnerOrAdmin', async () => {113 it('createMultipleItemsEx with property itemOwnerOrAdmin', async () => {121 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});114 const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: true}}]});122 const alice = privateKey('//Alice');115 const alice = privateKey('//Alice');123 const bob = privateKey('//Bob');116 const bob = privateKey('//Bob');124 const charlie = privateKey('//Charlie');117 const charlie = privateKey('//Charlie');127 {120 {128 owner: {substrate: alice.address},121 owner: {substrate: alice.address},129 constData: '0x0000',122 constData: '0x0000',123 properties: [{key: 'k', value: 'v1'}],130 }, {124 }, {131 owner: {substrate: bob.address},125 owner: {substrate: bob.address},132 constData: '0x2222',126 constData: '0x2222',127 properties: [{key: 'k', value: 'v2'}],133 }, {128 }, {134 owner: {substrate: charlie.address},129 owner: {substrate: charlie.address},135 constData: '0x4444',130 constData: '0x4444',131 properties: [{key: 'k', value: 'v3'}],136 },132 },137 ];133 ];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;143134144 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {135 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {145 NFT: data,136 NFT: data,146 }));137 }));147148149 const tokens = await api.query.nonfungible.tokenData.entries(collection);138 for (let i = 1; i < 4; i++) {150 const json = tokens.map(([, token]) => token.toJSON());151 expect(json).to.be.deep.equal(data);139 expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;140 }152 });141 });153 });142 });154143155 it('No editing rights', async () => {144 it('No editing rights', async () => {156 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],145 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],157 propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});146 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});158 const alice = privateKey('//Alice');147 const alice = privateKey('//Alice');159 const bob = privateKey('//Bob');148 const bob = privateKey('//Bob');160 const charlie = privateKey('//Charlie');149 const charlie = privateKey('//Charlie');188177189 it('User doesnt have editing rights', async () => {178 it('User doesnt have editing rights', async () => {190 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],179 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],191 propPerm: [{key: 'key1', mutable: false, collectionAdmin: false, tokenOwner: false}]});180 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});192 const alice = privateKey('//Alice');181 const alice = privateKey('//Alice');193 const bob = privateKey('//Bob');182 const bob = privateKey('//Bob');194 const charlie = privateKey('//Charlie');183 const charlie = privateKey('//Charlie');tests/src/util/helpers.tsdiffbeforeafterboth27import privateKey from '../substrate/privateKey';27import privateKey from '../substrate/privateKey';28import {default as usingApi, executeTransaction, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';28import {default as usingApi, executeTransaction, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';29import {hexToStr, strToUTF16, utf16ToStr} from './util';29import {hexToStr, strToUTF16, utf16ToStr} from './util';30import {UpDataStructsRpcCollection} from '@polkadot/types/lookup';30import {UpDataStructsRpcCollection, UpDataStructsCreateItemData} from '@polkadot/types/lookup';313132chai.use(chaiAsPromised);32chai.use(chaiAsPromised);33const expect = chai.expect;33const expect = chai.expect;295 value: any,295 value: any,296};296};297297298type PropertyPermission = {298type Permission = {299 key: any,300 mutable: boolean;299 mutable: boolean;301 collectionAdmin: boolean;300 collectionAdmin: boolean;302 tokenOwner: boolean;301 tokenOwner: boolean;303}302}303304type PropertyPermission = {305 key: any;306 permission: Permission;307}304308305export type CreateCollectionParams = {309export type CreateCollectionParams = {306 mode: CollectionMode,310 mode: CollectionMode,1123 });1127 });1124}1128}11291130export async function createMultipleItemsWithPropsExpectSuccess(sender: IKeyringPair, collectionId: number, itemsData: any, owner: CrossAccountId | string = sender.address) {1131 await usingApi(async (api) => {1132 const to = normalizeAccountId(owner);1133 const tx = api.tx.unique.createMultipleItems(collectionId, to, itemsData);11341135 const events = await submitTransactionAsync(sender, tx);1136 const result = getCreateItemsResult(events);11371138 for (let res of result) {1139 expect(await api.rpc.unique.tokenProperties(collectionId, res.itemId)).not.to.be.empty;1140 }1141 });1142}11431144export async function createItemWithPropsExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, props: Array<Property>, owner: CrossAccountId | string = sender.address) {1145 let newItemId = 0;1146 await usingApi(async (api) => {1147 const to = normalizeAccountId(owner);1148 const itemCountBefore = await getLastTokenId(api, collectionId);1149 const itemBalanceBefore = await getBalance(api, collectionId, to, newItemId);11501151 let tx;1152 if (createMode === 'Fungible') {1153 const createData = {fungible: {value: 10}};1154 tx = api.tx.unique.createItem(collectionId, to, createData as any);1155 } else if (createMode === 'ReFungible') {1156 const createData = {refungible: {const_data: [], pieces: 100}};1157 tx = api.tx.unique.createItem(collectionId, to, createData as any);1158 } else {1159 const data = api.createType('UpDataStructsCreateItemData', { NFT: { constData: 'test', properties: props}});1160 tx = api.tx.unique.createItem(collectionId, to, data as UpDataStructsCreateItemData);1161 }11621163 const events = await submitTransactionAsync(sender, tx);1164 const result = getCreateItemResult(events);11651166 const itemCountAfter = await getLastTokenId(api, collectionId);1167 const itemBalanceAfter = await getBalance(api, collectionId, to, newItemId);11681169 if (createMode === 'NFT') {1170 expect(await api.rpc.unique.tokenProperties(collectionId, result.itemId)).not.to.be.empty;1171 }11721173 // What to expect1174 // tslint:disable-next-line:no-unused-expression1175 expect(result.success).to.be.true;1176 if (createMode === 'Fungible') {1177 expect(itemBalanceAfter - itemBalanceBefore).to.be.equal(10n);1178 } else {1179 expect(itemCountAfter).to.be.equal(itemCountBefore + 1);1180 }1181 expect(collectionId).to.be.equal(result.collectionId);1182 expect(itemCountAfter.toString()).to.be.equal(result.itemId.toString());1183 expect(to).to.be.deep.equal(result.recipient);1184 newItemId = result.itemId;1185 });1186 return newItemId;1187}112511881126export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: CrossAccountId | string = sender.address) {1189export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: CrossAccountId | string = sender.address) {1127 let newItemId = 0;1190 let newItemId = 0;