difftreelog
fix properties have been moved in creation functions
in: master
5 files changed
tests/src/createItem.test.tsdiffbeforeafterboth--- a/tests/src/createItem.test.ts
+++ b/tests/src/createItem.test.ts
@@ -24,6 +24,7 @@
addCollectionAdminExpectSuccess,
createCollectionWithPropsExpectSuccess,
createItemWithPropsExpectSuccess,
+ createItemWithPropsExpectFailure,
} from './util/helpers';
const expect = chai.expect;
@@ -128,69 +129,47 @@
const createMode = 'NFT';
const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},
propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});
-
- const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');
await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);
- await expect(executeTransaction(
- api,
- alice,
- api.tx.unique.setTokenProperties(newCollectionID, token, [{key: 'key1', value: 'v2'}]),
- )).to.be.rejected;
+ await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'key1', value: 'v'}]);
});
});
it('User doesnt have editing rights', async () => {
await usingApi(async api => {
const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});
- const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');
-
- await expect(executeTransaction(
- api,
- bob,
- api.tx.unique.setTokenProperties(newCollectionID, token, [{key: 'key1', value: 'v2'}]),
- )).to.be.rejected;
+ await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'key1', value: 'v'}]);
});
});
it('Adding property without access rights', async () => {
await usingApi(async api => {
- const createMode = 'NFT';
- const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
-
- const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');
+ const newCollectionID = await createCollectionWithPropsExpectSuccess();
await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);
-
- await expect(executeTransaction(
- api,
- bob,
- api.tx.unique.setTokenProperties(newCollectionID, token, [{key: 'key1', value: 'v2'}]),
- )).to.be.rejected;
+
+ await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'k', value: 'v'}]);
});
});
it('Adding more than 64 prps', async () => {
await usingApi(async api => {
- const createMode = 'NFT';
-
const prps = [];
for (let i = 0; i < 65; i++) {
prps.push({key: `key${i}`, value: `value${i}`});
}
- const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
+ const newCollectionID = await createCollectionWithPropsExpectSuccess();
- await expect(executeTransaction(api, alice, api.tx.unique.setCollectionProperties(newCollectionID, prps))).to.be.rejectedWith(/common\.PropertyLimitReached/);
+ createItemWithPropsExpectFailure(alice, newCollectionID, 'NFT', prps);
});
});
it('Trying to add bigger property than allowed', async () => {
await usingApi(async api => {
- const createMode = 'NFT';
- const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
+ const newCollectionID = await createCollectionWithPropsExpectSuccess();
- 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/);
+ createItemWithPropsExpectFailure(alice, newCollectionID, 'NFT', [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]);
});
});
});
tests/src/createMultipleItems.test.tsdiffbeforeafterboth--- a/tests/src/createMultipleItems.test.ts
+++ b/tests/src/createMultipleItems.test.ts
@@ -34,7 +34,8 @@
getCreatedCollectionCount,
createCollectionWithPropsExpectSuccess,
getCreateItemsResult,
- createMultipleItemsWithPropsExpectSuccess
+ createMultipleItemsWithPropsExpectSuccess,
+ createMultipleItemsWithPropsExpectFailure,
} from './util/helpers';
chai.use(chaiAsPromised);
@@ -432,79 +433,44 @@
it('No editing rights', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],
- propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});
+ propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: true}}]});
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- const args = [{Nft: {const_data: '0x31'}},
+ const args = [{Nft: {const_data: '0x31', properties: [{key: 'key1', value: 'v2'}]}},
{Nft: {const_data: '0x32'}},
{Nft: {const_data: '0x33'}}];
- const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
-
- const events = await submitTransactionAsync(alice, createMultipleItemsTx);
- const result = getCreateItemsResult(events);
-
- for (const elem of result) {
- await expect(executeTransaction(
- api,
- bob,
- api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, [{key: 'key1', value: 'v2'}]),
- )).to.be.rejected;
- }
-
- // await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;
+ await createMultipleItemsWithPropsExpectFailure(bob, collectionId, args);
});
});
it('User doesnt have editing rights', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],
- propPerm: [{key: 'key1', permission: {mutable: false, 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);
- const args = [{Nft: {const_data: '0x31'}},
+ const args = [{Nft: {const_data: '0x31', properties: [{key: 'key1', value: 'v2'}]}},
{Nft: {const_data: '0x32'}},
{Nft: {const_data: '0x33'}}];
- const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
-
- const events = await submitTransactionAsync(alice, createMultipleItemsTx);
- const result = getCreateItemsResult(events);
-
- for (const elem of result) {
- await expect(executeTransaction(
- api,
- bob,
- api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, [{key: 'key1', value: 'v2'}]),
- )).to.be.rejected;
- }
+ await createMultipleItemsWithPropsExpectFailure(bob, collectionId, args);
});
});
it('Adding property without access rights', async () => {
await usingApi(async (api: ApiPromise) => {
- const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}]});
+ const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'k', value: 'v1'}]});
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
expect(itemsListIndexBefore).to.be.equal(0);
- const args = [{Nft: {const_data: '0x31'}},
+ const args = [{Nft: {const_data: '0x31', properties: [{key: 'k', value: 'v'}]}},
{Nft: {const_data: '0x32'}},
{Nft: {const_data: '0x33'}}];
- const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
-
- const events = await submitTransactionAsync(alice, createMultipleItemsTx);
- const result = getCreateItemsResult(events);
-
- for (const elem of result) {
- await expect(executeTransaction(
- api,
- bob,
- api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, [{key: 'key1', value: 'v2'}]),
- )).to.be.rejected;
- }
+ await createMultipleItemsWithPropsExpectFailure(bob, collectionId, args);
});
});
@@ -515,15 +481,6 @@
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
-
- 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);
- const events = await submitTransactionAsync(alice, createMultipleItemsTx);
-
- const result = getCreateItemsResult(events);
const prps = [];
@@ -531,43 +488,24 @@
prps.push({key: `key${i}`, value: `value${i}`});
}
- await expect(executeTransaction(api, bob, api.tx.unique.setCollectionProperties(collectionId, prps))).to.be.rejectedWith(/common\.PropertyLimitReached/);
+ const args = [{Nft: {const_data: '0x31', properties: prps}},
+ {Nft: {const_data: '0x32', properties: prps}},
+ {Nft: {const_data: '0x33', properties: prps}}];
- for (const elem of result) {
- await expect(executeTransaction(
- api,
- bob,
- api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, prps),
- )).to.be.rejected;
- }
+ createMultipleItemsWithPropsExpectFailure(alice, collectionId, args);
});
});
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', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});
+ 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 args = [{Nft: {const_data: '0x31'}},
- {Nft: {const_data: '0x32'}},
- {Nft: {const_data: '0x33'}}];
-
- const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
-
- const events = await submitTransactionAsync(alice, createMultipleItemsTx);
- const result = getCreateItemsResult(events);
-
-
- await expect(executeTransaction(api, alice, api.tx.unique.setCollectionProperties(collectionId, [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]))).to.be.rejectedWith(/common\.NoSpaceForProperty/);
+ const args = [{Nft: {const_data: '0x31', properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]}},
+ {Nft: {const_data: '0x32', properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]}},
+ {Nft: {const_data: '0x33', properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]}}];
- for (const elem of result) {
- await expect(executeTransaction(
- api,
- bob,
- api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]),
- )).to.be.rejected;
- }
+ createMultipleItemsWithPropsExpectFailure(alice, collectionId, args);
});
});
});
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.only('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 constData: '0x1111',61 properties: [{key: 'k', value: 'v1'}],62 }, {63 owner: {substrate: bob.address},64 constData: '0x2222',65 properties: [{key: 'k', value: 'v2'}],66 }, {67 owner: {substrate: charlie.address},68 constData: '0x4444',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 constData: '0x0000',92 properties: [{key: 'k', value: 'v1'}],93 }, {94 owner: {substrate: bob.address},95 constData: '0x2222',96 properties: [{key: 'k', value: 'v2'}],97 }, {98 owner: {substrate: charlie.address},99 constData: '0x4444',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 constData: '0x0000',123 properties: [{key: 'k', value: 'v1'}],124 }, {125 owner: {substrate: bob.address},126 constData: '0x2222',127 properties: [{key: 'k', value: 'v2'}],128 }, {129 owner: {substrate: charlie.address},130 constData: '0x4444',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 }, {156 owner: {substrate: bob.address},157 }, {158 owner: {substrate: charlie.address},159 },160 ];161162 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});163 await executeTransaction(api, alice, tx);164165 const events = await submitTransactionAsync(alice, tx);166 const result = getCreateItemsResult(events);167168 for (const elem of result) {169 await expect(executeTransaction(170 api,171 bob,172 api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, [{key: 'key1', value: 'v2'}]),173 )).to.be.rejected;174 }175 });176 });177178 it('User doesnt have editing rights', async () => {179 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],180 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});181 const alice = privateKey('//Alice');182 const bob = privateKey('//Bob');183 const charlie = privateKey('//Charlie');184 await addCollectionAdminExpectSuccess(alice, collection, bob.address);185 await usingApi(async (api) => {186 const data = [187 {188 owner: {substrate: alice.address},189 }, {190 owner: {substrate: bob.address},191 }, {192 owner: {substrate: charlie.address},193 },194 ];195196 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});197 await executeTransaction(api, alice, tx);198199 const events = await submitTransactionAsync(alice, tx);200 const result = getCreateItemsResult(events);201202 for (const elem of result) {203 await expect(executeTransaction(204 api,205 bob,206 api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, [{key: 'key1', value: 'v2'}]),207 )).to.be.rejected;208 }209 });210 });211212 it('Adding property without access rights', async () => {213 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}]});214 const alice = privateKey('//Alice');215 const bob = privateKey('//Bob');216 const charlie = privateKey('//Charlie');217 await addCollectionAdminExpectSuccess(alice, collection, bob.address);218 await usingApi(async (api) => {219 const data = [220 {221 owner: {substrate: alice.address},222 }, {223 owner: {substrate: bob.address},224 }, {225 owner: {substrate: charlie.address},226 },227 ];228229 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});230 await executeTransaction(api, alice, tx);231232 const events = await submitTransactionAsync(alice, tx);233 const result = getCreateItemsResult(events);234235 for (const elem of result) {236 await expect(executeTransaction(237 api,238 bob,239 api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, [{key: 'key1', value: 'v2'}]),240 )).to.be.rejected;241 }242 });243 });244245 it('Adding more than 64 prps', async () => {246 const collection = await createCollectionWithPropsExpectSuccess();247 const alice = privateKey('//Alice');248 const bob = privateKey('//Bob');249 const charlie = privateKey('//Charlie');250 await addCollectionAdminExpectSuccess(alice, collection, bob.address);251 await usingApi(async (api) => {252 const data = [253 {254 owner: {substrate: alice.address},255 }, {256 owner: {substrate: bob.address},257 }, {258 owner: {substrate: charlie.address},259 },260 ];261262 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});263 await executeTransaction(api, alice, tx);264265 const events = await submitTransactionAsync(alice, tx);266 const result = getCreateItemsResult(events);267268 const prps = [];269270 for (let i = 0; i < 65; i++) {271 prps.push({key: `key${i}`, value: `value${i}`});272 }273274 await expect(executeTransaction(api, bob, api.tx.unique.setCollectionProperties(collection, prps))).to.be.rejectedWith(/common\.PropertyLimitReached/);275276277 for (const elem of result) {278 await expect(executeTransaction(279 api,280 bob,281 api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, prps),282 )).to.be.rejected;283 }284 });285 });286287 it('Trying to add bigger property than allowed', async () => {288 const collection = await createCollectionWithPropsExpectSuccess();289 const alice = privateKey('//Alice');290 const bob = privateKey('//Bob');291 const charlie = privateKey('//Charlie');292 await addCollectionAdminExpectSuccess(alice, collection, bob.address);293 await usingApi(async (api) => {294 const data = [295 {296 owner: {substrate: alice.address},297 }, {298 owner: {substrate: bob.address},299 }, {300 owner: {substrate: charlie.address},301 },302 ];303304 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});305 await executeTransaction(api, alice, tx);306307 const events = await submitTransactionAsync(alice, tx);308 const result = getCreateItemsResult(events);309310 const prps = [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}];311312 await expect(executeTransaction(api, bob, api.tx.unique.setCollectionProperties(collection, prps))).to.be.rejectedWith(/common\.NoSpaceForProperty/);313314315 for (const elem of result) {316 await expect(executeTransaction(317 api,318 bob,319 api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, prps),320 )).to.be.rejected;321 }322 });323 });324325 it('can initialize multiple NFT with different owners', async () => {326 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});327 const alice = privateKey('//Alice');328 const bob = privateKey('//Bob');329 const charlie = privateKey('//Charlie');330 await usingApi(async (api) => {331 const data = [332 {333 owner: {substrate: alice.address},334 constData: '0x0000',335 }, {336 owner: {substrate: bob.address},337 constData: '0x2222',338 }, {339 owner: {substrate: charlie.address},340 constData: '0x4444',341 },342 ];343344 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {345 NFT: data,346 }));347 const tokens = await api.query.nonfungible.tokenData.entries(collection);348 const json = tokens.map(([, token]) => token.toJSON());349 expect(json).to.be.deep.equal(data);350 });351 });352353 it('can initialize multiple NFT with different owners', async () => {354 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});355 const alice = privateKey('//Alice');356 const bob = privateKey('//Bob');357 const charlie = privateKey('//Charlie');358 await usingApi(async (api) => {359 const data = [360 {361 owner: {substrate: alice.address},362 constData: '0x0000',363 }, {364 owner: {substrate: bob.address},365 constData: '0x2222',366 }, {367 owner: {substrate: charlie.address},368 constData: '0x4444',369 },370 ];371372 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {373 NFT: data,374 }));375 const tokens = await api.query.nonfungible.tokenData.entries(collection);376 const json = tokens.map(([, token]) => token.toJSON());377 expect(json).to.be.deep.equal(data);378 });379 });380381 it('fails when trying to set multiple owners when creating multiple refungibles', async () => {382 const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});383 const alice = privateKey('//Alice');384 const bob = privateKey('//Bob');385386 await usingApi(async (api) => {387 // Polkadot requires map, and yet requires keys to be JSON encoded388 const users = new Map();389 users.set(JSON.stringify({substrate: alice.address}), 1);390 users.set(JSON.stringify({substrate: bob.address}), 1);391392 // TODO: better error message?393 await expect(executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {394 RefungibleMultipleItems: [395 {users},396 {users},397 ],398 }))).to.be.rejectedWith(/^refungible\.NotRefungibleDataUsedToMintFungibleCollectionToken$/);399 });400 });401});402'';tests/src/interfaces/rmrk/definitions.tsdiffbeforeafterboth--- a/tests/src/interfaces/rmrk/definitions.ts
+++ b/tests/src/interfaces/rmrk/definitions.ts
@@ -24,92 +24,92 @@
const atParam = {name: 'at', type: 'Hash', isOptional: true};
const fn = (description: string, params: RpcParam[], type: string) => ({
- description,
- params: [...params, atParam],
- type,
+ description,
+ params: [...params, atParam],
+ type,
});
export default {
- types,
- rpc: {
- lastCollectionIdx: fn('Get the latest created collection id', [], 'u32'),
- collectionById: fn('Get collection by id', [{name: 'id', type: 'u32'}], 'Option<RmrkTypesCollectionInfo>'),
- nftById: fn(
- 'Get NFT by collection id and NFT id',
- [
- {name: 'collectionId', type: 'u32'},
- {name: 'nftId', type: 'u32'},
- ],
- 'Option<RmrkTypesNftInfo>'
- ),
- accountTokens: fn(
- 'Get tokens owned by an account in a collection',
- [
- {name: 'accountId', type: 'AccountId32'},
- {name: 'collectionId', type: 'u32'}
- ],
- 'Vec<u32>'
- ),
- nftChildren: fn(
- 'Get NFT children',
- [
- {name: 'collectionId', type: 'u32'},
- {name: 'nftId', type: 'u32'},
- ],
- 'Vec<RmrkTypesNftChild>'
- ),
- collectionProperties: fn(
- 'Get collection properties',
- [{name: 'collectionId', type: 'u32'}],
- 'Vec<RmrkTypesPropertyInfo>'
- ),
- nftProperties: fn(
- 'Get NFT properties',
- [
- {name: 'collectionId', type: 'u32'},
- {name: 'nftId', type: 'u32'}
- ],
- 'Vec<RmrkTypesPropertyInfo>'
- ),
- nftResources: fn(
- 'Get NFT resources',
- [
- {name: 'collectionId', type: 'u32'},
- {name: 'nftId', type: 'u32'}
- ],
- 'Vec<RmrkTypesResourceInfo>'
- ),
- nftResourcePriorities: fn(
- 'Get NFT resource priorities',
- [
- {name: 'collectionId', type: 'u32'},
- {name: 'nftId', type: 'u32'}
- ],
- 'Vec<Bytes>'
- ),
- base: fn(
- 'Get base info',
- [{name: 'baseId', type: 'u32'}],
- 'Option<RmrkTypesBaseInfo>'
- ),
- baseParts: fn(
- 'Get all Base\'s parts',
- [{name: 'baseId', type: 'u32'}],
- 'Vec<RmrkTypesPartType>'
- ),
- themeNames: fn(
- 'Get Base\'s theme names',
- [{name: 'baseId', type: 'u32'}],
- 'Vec<Bytes>'
- ),
- themes: fn(
- 'Get Theme\'s keys values',
- [
- {name: 'baseId', type: 'u32'},
- {name: 'themeName', type: 'String'},
- {name: 'keys', type: 'Option<Vec<String>>'}
- ],
- 'Option<RmrkTypesTheme>'
- )
- }
+ types,
+ rpc: {
+ lastCollectionIdx: fn('Get the latest created collection id', [], 'u32'),
+ collectionById: fn('Get collection by id', [{name: 'id', type: 'u32'}], 'Option<RmrkTypesCollectionInfo>'),
+ nftById: fn(
+ 'Get NFT by collection id and NFT id',
+ [
+ {name: 'collectionId', type: 'u32'},
+ {name: 'nftId', type: 'u32'},
+ ],
+ 'Option<RmrkTypesNftInfo>',
+ ),
+ accountTokens: fn(
+ 'Get tokens owned by an account in a collection',
+ [
+ {name: 'accountId', type: 'AccountId32'},
+ {name: 'collectionId', type: 'u32'},
+ ],
+ 'Vec<u32>',
+ ),
+ nftChildren: fn(
+ 'Get NFT children',
+ [
+ {name: 'collectionId', type: 'u32'},
+ {name: 'nftId', type: 'u32'},
+ ],
+ 'Vec<RmrkTypesNftChild>',
+ ),
+ collectionProperties: fn(
+ 'Get collection properties',
+ [{name: 'collectionId', type: 'u32'}],
+ 'Vec<RmrkTypesPropertyInfo>',
+ ),
+ nftProperties: fn(
+ 'Get NFT properties',
+ [
+ {name: 'collectionId', type: 'u32'},
+ {name: 'nftId', type: 'u32'},
+ ],
+ 'Vec<RmrkTypesPropertyInfo>',
+ ),
+ nftResources: fn(
+ 'Get NFT resources',
+ [
+ {name: 'collectionId', type: 'u32'},
+ {name: 'nftId', type: 'u32'},
+ ],
+ 'Vec<RmrkTypesResourceInfo>',
+ ),
+ nftResourcePriorities: fn(
+ 'Get NFT resource priorities',
+ [
+ {name: 'collectionId', type: 'u32'},
+ {name: 'nftId', type: 'u32'},
+ ],
+ 'Vec<Bytes>',
+ ),
+ base: fn(
+ 'Get base info',
+ [{name: 'baseId', type: 'u32'}],
+ 'Option<RmrkTypesBaseInfo>',
+ ),
+ baseParts: fn(
+ 'Get all Base\'s parts',
+ [{name: 'baseId', type: 'u32'}],
+ 'Vec<RmrkTypesPartType>',
+ ),
+ themeNames: fn(
+ 'Get Base\'s theme names',
+ [{name: 'baseId', type: 'u32'}],
+ 'Vec<Bytes>',
+ ),
+ themes: fn(
+ 'Get Theme\'s keys values',
+ [
+ {name: 'baseId', type: 'u32'},
+ {name: 'themeName', type: 'String'},
+ {name: 'keys', type: 'Option<Vec<String>>'},
+ ],
+ 'Option<RmrkTypesTheme>',
+ ),
+ },
};
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -1135,7 +1135,32 @@
const events = await submitTransactionAsync(sender, tx);
const result = getCreateItemsResult(events);
- for (let res of result) {
+ for (const res of result) {
+ expect(await api.rpc.unique.tokenProperties(collectionId, res.itemId)).not.to.be.empty;
+ }
+ });
+}
+
+export async function createMultipleItemsWithPropsExpectFailure(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 expect(await submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
+ const result = getCreateItemsResult(events);
+
+ expect(result).to.be.equal(false);
+ });
+}
+
+export async function createMultipleItemsExWithPropsExpectSuccess(sender: IKeyringPair, collectionId: number, itemsData: any) {
+ await usingApi(async (api) => {
+ const tx = api.tx.unique.createMultipleItemsEx(collectionId, itemsData);
+
+ const events = await submitTransactionAsync(sender, tx);
+ const result = getCreateItemsResult(events);
+
+ for (const res of result) {
expect(await api.rpc.unique.tokenProperties(collectionId, res.itemId)).not.to.be.empty;
}
});
@@ -1156,7 +1181,7 @@
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}});
+ const data = api.createType('UpDataStructsCreateItemData', {NFT: {constData: 'test', properties: props}});
tx = api.tx.unique.createItem(collectionId, to, data as UpDataStructsCreateItemData);
}
@@ -1186,6 +1211,25 @@
return newItemId;
}
+export async function createItemWithPropsExpectFailure(sender: IKeyringPair, collectionId: number, createMode: string, props: Array<Property>, owner: CrossAccountId | string = sender.address) {
+ await usingApi(async (api) => {
+
+ let tx;
+ if (createMode === 'NFT') {
+ const data = api.createType('UpDataStructsCreateItemData', {NFT: {constData: 'test', properties: props}});
+ tx = api.tx.unique.createItem(collectionId, normalizeAccountId(owner), data);
+ } else {
+ tx = api.tx.unique.createItem(collectionId, normalizeAccountId(owner), createMode);
+ }
+
+
+ const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
+ const result = getCreateItemResult(events);
+
+ expect(result.success).to.be.false;
+ });
+}
+
export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: CrossAccountId | string = sender.address) {
let newItemId = 0;
await usingApi(async (api) => {