difftreelog
fix properties have been moved in creation functions
in: master
5 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 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});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 createItemWithPropsExpectFailure,28} from './util/helpers';2930const expect = chai.expect;31let alice: IKeyringPair;32let bob: IKeyringPair;3334describe('integration test: ext. ():', () => {35 before(async () => {36 await usingApi(async () => {37 const keyring = new Keyring({type: 'sr25519'});38 alice = keyring.addFromUri('//Alice');39 bob = keyring.addFromUri('//Bob');40 });41 });4243 it('Create new item in NFT collection', async () => {44 const createMode = 'NFT';45 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});46 await createItemExpectSuccess(alice, newCollectionID, createMode);47 });48 it('Create new item in Fungible collection', async () => {49 const createMode = 'Fungible';50 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});51 await createItemExpectSuccess(alice, newCollectionID, createMode);52 });53 it('Create new item in ReFungible collection', async () => {54 const createMode = 'ReFungible';55 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});56 await createItemExpectSuccess(alice, newCollectionID, createMode);57 });58 it('Create new item in NFT collection with collection admin permissions', async () => {59 const createMode = 'NFT';60 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});61 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);62 await createItemExpectSuccess(bob, newCollectionID, createMode);63 });64 it('Create new item in Fungible collection with collection admin permissions', async () => {65 const createMode = 'Fungible';66 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});67 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);68 await createItemExpectSuccess(bob, newCollectionID, createMode);69 });70 it('Create new item in ReFungible collection with collection admin permissions', async () => {71 const createMode = 'ReFungible';72 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});73 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);74 await createItemExpectSuccess(bob, newCollectionID, createMode);75 });7677 it('Set property Admin', async () => {78 const createMode = 'NFT';79 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 80 propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});81 82 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'k', value: 't2'}]);83 });8485 it('Set property AdminConst', async () => {86 const createMode = 'NFT';87 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 88 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});89 90 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);91 });9293 it('Set property itemOwnerOrAdmin', async () => {94 const createMode = 'NFT';95 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},96 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});97 98 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);99 });100});101102describe('Negative integration test: ext. createItem():', () => {103 before(async () => {104 await usingApi(async () => {105 const keyring = new Keyring({type: 'sr25519'});106 alice = keyring.addFromUri('//Alice');107 bob = keyring.addFromUri('//Bob');108 });109 });110111 it('Regular user cannot create new item in NFT collection', async () => {112 const createMode = 'NFT';113 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});114 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;115 });116 it('Regular user cannot create new item in Fungible collection', async () => {117 const createMode = 'Fungible';118 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});119 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;120 });121 it('Regular user cannot create new item in ReFungible collection', async () => {122 const createMode = 'ReFungible';123 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});124 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;125 });126127 it('No editing rights', async () => {128 await usingApi(async api => {129 const createMode = 'NFT';130 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 131 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});132 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);133134 await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'key1', value: 'v'}]);135 });136 });137138 it('User doesnt have editing rights', async () => {139 await usingApi(async api => {140 const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});141 await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'key1', value: 'v'}]);142 });143 });144145 it('Adding property without access rights', async () => {146 await usingApi(async api => {147 const newCollectionID = await createCollectionWithPropsExpectSuccess();148 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);149150 await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'k', value: 'v'}]);151 });152 });153154 it('Adding more than 64 prps', async () => {155 await usingApi(async api => {156 const prps = [];157158 for (let i = 0; i < 65; i++) {159 prps.push({key: `key${i}`, value: `value${i}`});160 }161162 const newCollectionID = await createCollectionWithPropsExpectSuccess();163 164 createItemWithPropsExpectFailure(alice, newCollectionID, 'NFT', prps);165 });166 });167168 it('Trying to add bigger property than allowed', async () => {169 await usingApi(async api => {170 const newCollectionID = await createCollectionWithPropsExpectSuccess();171 172 createItemWithPropsExpectFailure(alice, newCollectionID, 'NFT', [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]);173 });174 });175});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.tsdiffbeforeafterboth--- a/tests/src/createMultipleItemsEx.test.ts
+++ b/tests/src/createMultipleItemsEx.test.ts
@@ -16,7 +16,7 @@
import {expect} from 'chai';
import privateKey from './substrate/privateKey';
-import usingApi, {executeTransaction, submitTransactionAsync} from './substrate/substrate-api';
+import usingApi, {executeTransaction, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
import {createCollectionExpectSuccess, createCollectionWithPropsExpectSuccess, addCollectionAdminExpectSuccess, getCreateItemsResult} from './util/helpers';
describe('createMultipleItemsEx', () => {
@@ -48,7 +48,7 @@
});
});
- it.only('createMultipleItemsEx with property Admin', async () => {
+ it('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');
@@ -152,26 +152,20 @@
const data = [
{
owner: {substrate: alice.address},
+ properties: [{key: 'key1', value: 'v2'}],
}, {
- owner: {substrate: bob.address},
+ owner: {substrate: alice.address},
+ properties: [{key: 'key1', value: 'v2'}],
}, {
- owner: {substrate: charlie.address},
+ owner: {substrate: alice.address},
+ properties: [{key: 'key1', value: 'v2'}],
},
];
const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});
- await executeTransaction(api, alice, tx);
-
- const events = await submitTransactionAsync(alice, tx);
- const result = getCreateItemsResult(events);
+ // await executeTransaction(api, alice, tx);
- 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 submitTransactionExpectFailAsync(alice, tx);
});
});
@@ -186,26 +180,20 @@
const data = [
{
owner: {substrate: alice.address},
+ properties: [{key: 'key1', value: 'v2'}],
}, {
- owner: {substrate: bob.address},
+ owner: {substrate: alice.address},
+ properties: [{key: 'key1', value: 'v2'}],
}, {
- owner: {substrate: charlie.address},
+ owner: {substrate: alice.address},
+ properties: [{key: 'key1', value: 'v2'}],
},
];
const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});
- await executeTransaction(api, alice, tx);
-
- const events = await submitTransactionAsync(alice, tx);
- const result = getCreateItemsResult(events);
+ // await executeTransaction(api, alice, tx);
- 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 submitTransactionExpectFailAsync(alice, tx);
});
});
@@ -219,31 +207,32 @@
const data = [
{
owner: {substrate: alice.address},
+ properties: [{key: 'key1', value: 'v2'}],
}, {
owner: {substrate: bob.address},
+ properties: [{key: 'key1', value: 'v2'}],
}, {
owner: {substrate: charlie.address},
+ properties: [{key: 'key1', value: 'v2'}],
},
];
const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});
- await executeTransaction(api, alice, tx);
-
- const events = await submitTransactionAsync(alice, tx);
- 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 submitTransactionExpectFailAsync(alice, tx);
});
});
it('Adding more than 64 prps', async () => {
- const collection = await createCollectionWithPropsExpectSuccess();
+ const prps = [{key: 'key', value: 'v'}];
+ const propPerm = [{key: 'key', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}];
+
+ for (let i = 0; i < 65; i++) {
+ prps.push({key: `key${i}`, value: `value${i}`});
+ propPerm.push({key: `key${i}`, permission: {mutable: true, collectionAdmin: true, tokenOwner: true}});
+ }
+
+ const collection = await createCollectionWithPropsExpectSuccess({propPerm: propPerm});
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
@@ -252,40 +241,24 @@
const data = [
{
owner: {substrate: alice.address},
+ properties: prps,
}, {
- owner: {substrate: bob.address},
+ owner: {substrate: alice.address},
+ properties: prps,
}, {
- owner: {substrate: charlie.address},
+ owner: {substrate: alice.address},
+ properties: prps,
},
];
const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});
- await executeTransaction(api, alice, tx);
- const events = await submitTransactionAsync(alice, tx);
- const result = getCreateItemsResult(events);
-
- const prps = [];
-
- for (let i = 0; i < 65; i++) {
- prps.push({key: `key${i}`, value: `value${i}`});
- }
-
- await expect(executeTransaction(api, bob, api.tx.unique.setCollectionProperties(collection, prps))).to.be.rejectedWith(/common\.PropertyLimitReached/);
-
-
- for (const elem of result) {
- await expect(executeTransaction(
- api,
- bob,
- api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, prps),
- )).to.be.rejected;
- }
+ await submitTransactionExpectFailAsync(alice, tx);
});
});
it('Trying to add bigger property than allowed', async () => {
- const collection = await createCollectionWithPropsExpectSuccess();
+ const collection = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
@@ -293,32 +266,17 @@
await usingApi(async (api) => {
const data = [
{
- owner: {substrate: alice.address},
+ owner: {substrate: alice.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}],
}, {
- owner: {substrate: bob.address},
+ owner: {substrate: bob.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}],
}, {
- owner: {substrate: charlie.address},
+ owner: {substrate: charlie.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}],
},
];
const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});
- await executeTransaction(api, alice, tx);
- const events = await submitTransactionAsync(alice, tx);
- const result = getCreateItemsResult(events);
-
- const prps = [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}];
-
- await expect(executeTransaction(api, bob, api.tx.unique.setCollectionProperties(collection, prps))).to.be.rejectedWith(/common\.NoSpaceForProperty/);
-
-
- for (const elem of result) {
- await expect(executeTransaction(
- api,
- bob,
- api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, prps),
- )).to.be.rejected;
- }
+ await submitTransactionExpectFailAsync(alice, tx);
});
});
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) => {