difftreelog
CreateItem* tests fixes
in: master
4 files changed
tests/src/createItem.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 {default as usingApi, executeTransaction} from './substrate/substrate-api';18import chai from 'chai';19import {Keyring} from '@polkadot/api';20import {IKeyringPair} from '@polkadot/types/types';21import {22 createCollectionExpectSuccess,23 createItemExpectSuccess,24 addCollectionAdminExpectSuccess,25 createCollectionWithPropsExpectSuccess,26} from './util/helpers';2728const expect = chai.expect;29let alice: IKeyringPair;30let bob: IKeyringPair;3132describe('integration test: ext. createItem():', () => {33 before(async () => {34 await usingApi(async () => {35 const keyring = new Keyring({type: 'sr25519'});36 alice = keyring.addFromUri('//Alice');37 bob = keyring.addFromUri('//Bob');38 });39 });4041 it('Create new item in NFT collection', async () => {42 const createMode = 'NFT';43 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});44 await createItemExpectSuccess(alice, newCollectionID, createMode);45 });46 it('Create new item in Fungible collection', async () => {47 const createMode = 'Fungible';48 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});49 await createItemExpectSuccess(alice, newCollectionID, createMode);50 });51 it('Create new item in ReFungible collection', async () => {52 const createMode = 'ReFungible';53 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});54 await createItemExpectSuccess(alice, newCollectionID, createMode);55 });56 it('Create new item in NFT collection with collection admin permissions', async () => {57 const createMode = 'NFT';58 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});59 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);60 await createItemExpectSuccess(bob, newCollectionID, createMode);61 });62 it('Create new item in Fungible collection with collection admin permissions', async () => {63 const createMode = 'Fungible';64 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});65 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);66 await createItemExpectSuccess(bob, newCollectionID, createMode);67 });68 it('Create new item in ReFungible collection with collection admin permissions', async () => {69 const createMode = 'ReFungible';70 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});71 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);72 await createItemExpectSuccess(bob, newCollectionID, createMode);73 });7475 it('Set property Admin', async () => {76 const createMode = 'NFT';77 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 78 properties: [{key: 'key1', value: 'val1'}], 79 propPerm: [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: false}]});80 81 await createItemExpectSuccess(alice, newCollectionID, createMode);82 });8384 it('Set property AdminConst', async () => {85 const createMode = 'NFT';86 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 87 properties: [{key: 'key1', value: 'val1'}], 88 propPerm: [{key: 'key1', mutable: false, collectionAdmin: true, tokenOwner: false}]});89 90 await createItemExpectSuccess(alice, newCollectionID, createMode);91 });9293 it('Set property itemOwnerOrAdmin', async () => {94 const createMode = 'NFT';95 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 96 properties: [{key: 'key1', value: 'val1'}], 97 propPerm: [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: true}]});98 99 await createItemExpectSuccess(alice, newCollectionID, createMode);100 });101});102103describe('Negative integration test: ext. createItem():', () => {104 before(async () => {105 await usingApi(async () => {106 const keyring = new Keyring({type: 'sr25519'});107 alice = keyring.addFromUri('//Alice');108 bob = keyring.addFromUri('//Bob');109 });110 });111112 it('Regular user cannot create new item in NFT collection', async () => {113 const createMode = 'NFT';114 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});115 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;116 });117 it('Regular user cannot create new item in Fungible collection', async () => {118 const createMode = 'Fungible';119 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});120 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;121 });122 it('Regular user cannot create new item in ReFungible collection', async () => {123 const createMode = 'ReFungible';124 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});125 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;126 });127128 it('No editing rights', async () => {129 await usingApi(async api => {130 const createMode = 'NFT';131 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 132 propPerm: [{key: 'key1', mutable: false, collectionAdmin: false, tokenOwner: false}]});133134 const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');135 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);136137 await expect(executeTransaction(138 api, 139 alice, 140 api.tx.unique.setTokenProperties(newCollectionID, token, [{key: 'key1', value: 'v2'}]), 141 )).to.be.rejected;142 });143 });144145 it('User doesnt have editing rights', async () => {146 await usingApi(async api => {147 const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});148 const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');149150 await expect(executeTransaction(151 api, 152 bob, 153 api.tx.unique.setTokenProperties(newCollectionID, token, [{key: 'key1', value: 'v2'}]), 154 )).to.be.rejected;155 });156 });157158 it('Adding property without access rights', async () => {159 await usingApi(async api => {160 const createMode = 'NFT';161 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});162163 const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');164 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);165 166 await expect(executeTransaction(167 api, 168 bob, 169 api.tx.unique.setTokenProperties(newCollectionID, token, [{key: 'key1', value: 'v2'}]), 170 )).to.be.rejected;171 });172 });173174 it('Adding more than 64 prps', async () => {175 await usingApi(async api => {176 const createMode = 'NFT';177178 const prps = [];179180 for (let i = 0; i < 65; i++) {181 prps.push({key: `key${i}`, value: `value${i}`});182 }183184 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});185 186 await expect(executeTransaction(api, alice, api.tx.unique.setCollectionProperties(newCollectionID, prps))).to.be.rejectedWith(/common\.PropertyLimitReached/);187 });188 });189190 it('Trying to add bigger property than allowed', async () => {191 await usingApi(async api => {192 const createMode = 'NFT';193 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});194 195 await expect(executeTransaction(api, alice, api.tx.unique.setCollectionProperties(newCollectionID, [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]))).to.be.rejectedWith(/common\.NoSpaceForProperty/);196 });197 });198});1// 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 {default as usingApi, executeTransaction} from './substrate/substrate-api';18import chai from 'chai';19import {Keyring} from '@polkadot/api';20import {IKeyringPair} from '@polkadot/types/types';21import {22 createCollectionExpectSuccess,23 createItemExpectSuccess,24 addCollectionAdminExpectSuccess,25 createCollectionWithPropsExpectSuccess,26 createItemWithPropsExpectSuccess,27} from './util/helpers';2829const expect = chai.expect;30let alice: IKeyringPair;31let bob: IKeyringPair;3233describe('integration test: ext. ():', () => {34 before(async () => {35 await usingApi(async () => {36 const keyring = new Keyring({type: 'sr25519'});37 alice = keyring.addFromUri('//Alice');38 bob = keyring.addFromUri('//Bob');39 });40 });4142 it('Create new item in NFT collection', async () => {43 const createMode = 'NFT';44 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});45 await createItemExpectSuccess(alice, newCollectionID, createMode);46 });47 it('Create new item in Fungible collection', async () => {48 const createMode = 'Fungible';49 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});50 await createItemExpectSuccess(alice, newCollectionID, createMode);51 });52 it('Create new item in ReFungible collection', async () => {53 const createMode = 'ReFungible';54 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});55 await createItemExpectSuccess(alice, newCollectionID, createMode);56 });57 it('Create new item in NFT collection with collection admin permissions', async () => {58 const createMode = 'NFT';59 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});60 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);61 await createItemExpectSuccess(bob, newCollectionID, createMode);62 });63 it('Create new item in Fungible collection with collection admin permissions', async () => {64 const createMode = 'Fungible';65 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});66 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);67 await createItemExpectSuccess(bob, newCollectionID, createMode);68 });69 it('Create new item in ReFungible collection with collection admin permissions', async () => {70 const createMode = 'ReFungible';71 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});72 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);73 await createItemExpectSuccess(bob, newCollectionID, createMode);74 });7576 it('Set property Admin', async () => {77 const createMode = 'NFT';78 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 79 propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});80 81 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'k', value: 't2'}]);82 });8384 it('Set property AdminConst', async () => {85 const createMode = 'NFT';86 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 87 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});88 89 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);90 });9192 it('Set property itemOwnerOrAdmin', async () => {93 const createMode = 'NFT';94 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},95 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});96 97 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);98 });99});100101describe('Negative integration test: ext. createItem():', () => {102 before(async () => {103 await usingApi(async () => {104 const keyring = new Keyring({type: 'sr25519'});105 alice = keyring.addFromUri('//Alice');106 bob = keyring.addFromUri('//Bob');107 });108 });109110 it('Regular user cannot create new item in NFT collection', async () => {111 const createMode = 'NFT';112 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});113 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;114 });115 it('Regular user cannot create new item in Fungible collection', async () => {116 const createMode = 'Fungible';117 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});118 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;119 });120 it('Regular user cannot create new item in ReFungible collection', async () => {121 const createMode = 'ReFungible';122 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});123 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;124 });125126 it('No editing rights', async () => {127 await usingApi(async api => {128 const createMode = 'NFT';129 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 130 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});131132 const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');133 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);134135 await expect(executeTransaction(136 api, 137 alice, 138 api.tx.unique.setTokenProperties(newCollectionID, token, [{key: 'key1', value: 'v2'}]), 139 )).to.be.rejected;140 });141 });142143 it('User doesnt have editing rights', async () => {144 await usingApi(async api => {145 const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});146 const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');147148 await expect(executeTransaction(149 api, 150 bob, 151 api.tx.unique.setTokenProperties(newCollectionID, token, [{key: 'key1', value: 'v2'}]), 152 )).to.be.rejected;153 });154 });155156 it('Adding property without access rights', async () => {157 await usingApi(async api => {158 const createMode = 'NFT';159 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});160161 const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');162 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);163 164 await expect(executeTransaction(165 api, 166 bob, 167 api.tx.unique.setTokenProperties(newCollectionID, token, [{key: 'key1', value: 'v2'}]), 168 )).to.be.rejected;169 });170 });171172 it('Adding more than 64 prps', async () => {173 await usingApi(async api => {174 const createMode = 'NFT';175176 const prps = [];177178 for (let i = 0; i < 65; i++) {179 prps.push({key: `key${i}`, value: `value${i}`});180 }181182 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});183 184 await expect(executeTransaction(api, alice, api.tx.unique.setCollectionProperties(newCollectionID, prps))).to.be.rejectedWith(/common\.PropertyLimitReached/);185 });186 });187188 it('Trying to add bigger property than allowed', async () => {189 await usingApi(async api => {190 const createMode = 'NFT';191 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});192 193 await expect(executeTransaction(api, alice, api.tx.unique.setCollectionProperties(newCollectionID, [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]))).to.be.rejectedWith(/common\.NoSpaceForProperty/);194 });195 });196});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.tsdiffbeforeafterboth--- a/tests/src/createMultipleItemsEx.test.ts
+++ b/tests/src/createMultipleItemsEx.test.ts
@@ -48,8 +48,8 @@
});
});
- it('createMultipleItemsEx with property Admin', async () => {
- const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ it.only('createMultipleItemsEx with property Admin', async () => {
+ const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
@@ -57,33 +57,30 @@
const data = [
{
owner: {substrate: alice.address},
- constData: '0x0000',
+ constData: '0x1111',
+ properties: [{key: 'k', value: 'v1'}],
}, {
owner: {substrate: bob.address},
constData: '0x2222',
+ properties: [{key: 'k', value: 'v2'}],
}, {
owner: {substrate: charlie.address},
constData: '0x4444',
+ properties: [{key: 'k', value: 'v3'}],
},
];
-
- await expect(executeTransaction(
- api,
- alice,
- api.tx.unique.setPropertyPermissions(collection, [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]),
- )).to.not.be.rejected;
await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {
NFT: data,
}));
- const tokens = await api.query.nonfungible.tokenData.entries(collection);
- const json = tokens.map(([, token]) => token.toJSON());
- expect(json).to.be.deep.equal(data);
+ for (let i = 1; i < 4; i++) {
+ expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;
+ }
});
});
it('createMultipleItemsEx with property AdminConst', async () => {
- const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
@@ -92,33 +89,29 @@
{
owner: {substrate: alice.address},
constData: '0x0000',
+ properties: [{key: 'k', value: 'v1'}],
}, {
owner: {substrate: bob.address},
constData: '0x2222',
+ properties: [{key: 'k', value: 'v2'}],
}, {
owner: {substrate: charlie.address},
constData: '0x4444',
+ properties: [{key: 'k', value: 'v3'}],
},
];
- await expect(executeTransaction(
- api,
- alice,
- api.tx.unique.setPropertyPermissions(collection, [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]),
- )).to.not.be.rejected;
await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {
NFT: data,
}));
-
-
- const tokens = await api.query.nonfungible.tokenData.entries(collection);
- const json = tokens.map(([, token]) => token.toJSON());
- expect(json).to.be.deep.equal(data);
+ for (let i = 1; i < 4; i++) {
+ expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;
+ }
});
});
it('createMultipleItemsEx with property itemOwnerOrAdmin', async () => {
- const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: true}}]});
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
@@ -127,34 +120,30 @@
{
owner: {substrate: alice.address},
constData: '0x0000',
+ properties: [{key: 'k', value: 'v1'}],
}, {
owner: {substrate: bob.address},
constData: '0x2222',
+ properties: [{key: 'k', value: 'v2'}],
}, {
owner: {substrate: charlie.address},
constData: '0x4444',
+ properties: [{key: 'k', value: 'v3'}],
},
];
- await expect(executeTransaction(
- api,
- alice,
- api.tx.unique.setPropertyPermissions(collection, [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]),
- )).to.not.be.rejected;
await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {
NFT: data,
}));
-
-
- const tokens = await api.query.nonfungible.tokenData.entries(collection);
- const json = tokens.map(([, token]) => token.toJSON());
- expect(json).to.be.deep.equal(data);
+ for (let i = 1; i < 4; i++) {
+ expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;
+ }
});
});
it('No editing rights', async () => {
const collection = 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 alice = privateKey('//Alice');
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
@@ -188,7 +177,7 @@
it('User doesnt have editing rights', async () => {
const collection = 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 alice = privateKey('//Alice');
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
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) => {