difftreelog
chore code review requests
in: master
8 files changed
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -709,9 +709,6 @@
/// Value "1" ERC721 metadata supported.
pub const ERC721_METADATA_SUPPORTED: &[u8] = b"1";
- /// Value "0" ERC721 metadata supported.
- pub const ERC721_METADATA_UNSUPPORTED: &[u8] = b"0";
-
/// Value for [`ERC721_METADATA`].
pub fn erc721() -> up_data_structs::PropertyValue {
property_value_from_bytes(ERC721_METADATA).expect(EXPECT_CONVERT_ERROR)
pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -104,7 +104,7 @@
.try_push(up_data_structs::PropertyKeyPermission {
key: key::url(),
permission: up_data_structs::PropertyPermission {
- mutable: false,
+ mutable: true,
collection_admin: true,
token_owner: false,
},
@@ -115,17 +115,6 @@
token_property_permissions
.try_push(up_data_structs::PropertyKeyPermission {
key: key::suffix(),
- permission: up_data_structs::PropertyPermission {
- mutable: true,
- collection_admin: true,
- token_owner: false,
- },
- })
- .map_err(|e| Error::Revert(format!("{:?}", e)))?;
-
- token_property_permissions
- .try_push(up_data_structs::PropertyKeyPermission {
- key: key::url(),
permission: up_data_structs::PropertyPermission {
mutable: true,
collection_admin: true,
tests/src/deprecated-helpers/helpers.tsdiffbeforeafterboth--- a/tests/src/deprecated-helpers/helpers.ts
+++ b/tests/src/deprecated-helpers/helpers.ts
@@ -433,7 +433,6 @@
mode: {type: 'NFT'},
name: 'name',
tokenPrefix: 'prefix',
- properties: [{key: 'ERC721Metadata', value: '1'}],
};
export async function
tests/src/eth/base.test.tsdiffbeforeafterboth--- a/tests/src/eth/base.test.ts
+++ b/tests/src/eth/base.test.ts
@@ -80,7 +80,7 @@
await usingEthPlaygrounds(async (helper, privateKey) => {
const donor = privateKey('//Alice');
const [alice] = await helper.arrange.createAccounts([10n], donor);
- ({collectionId: collection} = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}));
+ ({collectionId: collection} = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test', properties: [{key: 'ERC721Metadata', value: '1'}]}));
minter = helper.eth.createAccount();
});
});
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -501,7 +501,7 @@
itEth('Returns collection name', async ({helper}) => {
const caller = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.nft.mintCollection(alice, {name: 'oh River', tokenPrefix: 'CHANGE'});
+ const collection = await helper.nft.mintCollection(alice, {name: 'oh River', tokenPrefix: 'CHANGE', properties: [{key: 'ERC721Metadata', value: '1'}]});
const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);
const name = await contract.methods.name().call();
@@ -510,7 +510,7 @@
itEth('Returns symbol name', async ({helper}) => {
const caller = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.nft.mintCollection(alice, {name: 'oh River', tokenPrefix: 'CHANGE'});
+ const collection = await helper.nft.mintCollection(alice, {name: 'oh River', tokenPrefix: 'CHANGE', properties: [{key: 'ERC721Metadata', value: '1'}]});
const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);
const symbol = await contract.methods.symbol().call();
tests/src/eth/reFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -377,7 +377,7 @@
itEth('Returns collection name', async ({helper}) => {
const caller = helper.eth.createAccount();
- const collection = await helper.rft.mintCollection(alice, {name: 'Leviathan', tokenPrefix: '11'});
+ const collection = await helper.rft.mintCollection(alice, {name: 'Leviathan', tokenPrefix: '11', properties: [{key: 'ERC721Metadata', value: '1'}]});
const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);
const name = await contract.methods.name().call();
@@ -386,7 +386,7 @@
itEth('Returns symbol name', async ({helper}) => {
const caller = await helper.eth.createAccountWithBalance(donor);
- const {collectionId} = await helper.rft.mintCollection(alice, {name: 'Leviathan', tokenPrefix: '12'});
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'Leviathan', tokenPrefix: '12', properties: [{key: 'ERC721Metadata', value: '1'}]});
const contract = helper.ethNativeContract.collectionById(collectionId, 'rft', caller);
const symbol = await contract.methods.symbol().call();
expect(symbol).to.equal('12');
tests/src/nesting/properties.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 {IKeyringPair} from '@polkadot/types/types';18import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from '../util/playgrounds';19import {UniqueHelper, UniqueBaseCollection, UniqueNFTCollection, UniqueNFToken, UniqueRFTCollection, UniqueRFToken} from '../util/playgrounds/unique';202122describe('Composite Properties Test', () => {23 let alice: IKeyringPair;2425 before(async () => {26 await usingPlaygrounds(async (helper, privateKey) => {27 const donor = privateKey('//Alice');28 [alice] = await helper.arrange.createAccounts([50n], donor);29 });30 });3132 async function testMakeSureSuppliesRequired(baseCollection: UniqueNFTCollection | UniqueRFTCollection) {3334 const collectionOption = await baseCollection.getOptions();35 expect(collectionOption).is.not.null;36 let collection = collectionOption;37 expect(collection.tokenPropertyPermissions).to.be.empty;38 expect(collection.properties).to.be.deep.equal([{key: 'ERC721Metadata', value: '1'}]);3940 const propertyPermissions = [41 {key: 'mindgame', permission: {collectionAdmin: true, mutable: false, tokenOwner: true}},42 {key: 'skullduggery', permission: {collectionAdmin: false, mutable: true, tokenOwner: false}},43 ];44 await expect(await baseCollection.setTokenPropertyPermissions(alice, propertyPermissions)).to.be.true;4546 const collectionProperties = [47 {key: 'ERC721Metadata', value: '1'}, 48 {key: 'black_hole', value: 'LIGO'},49 {key: 'electron', value: 'come bond'}, 50 ];51 52 await expect(await baseCollection.setProperties(alice, collectionProperties)).to.be.true;5354 collection = await baseCollection.getOptions();55 expect(collection.tokenPropertyPermissions).to.be.deep.equal(propertyPermissions);56 expect(collection.properties).to.be.deep.equal(collectionProperties);57 }5859 itSub('Makes sure collectionById supplies required fields for NFT', async ({helper}) => {60 await testMakeSureSuppliesRequired(await helper.nft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'}));61 });6263 itSub.ifWithPallets('Makes sure collectionById supplies required fields for ReFungible', [Pallets.ReFungible], async ({helper}) => {64 await testMakeSureSuppliesRequired(await helper.rft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'}));65 });66});67// ---------- COLLECTION PROPERTIES6869describe('Integration Test: Collection Properties', () => {70 let alice: IKeyringPair;71 let bob: IKeyringPair;7273 before(async () => {74 await usingPlaygrounds(async (helper, privateKey) => {75 const donor = privateKey('//Alice');76 [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);77 });78 });7980 itSub('Properties are initially empty', async ({helper}) => {81 const collection = await helper.nft.mintCollection(alice);82 const properties = await collection.getProperties();83 expect(properties).to.be.deep.equal([{84 'key': 'ERC721Metadata',85 'value': '1',86 }]);87 });8889 async function testSetsPropertiesForCollection(collection: UniqueBaseCollection) {90 // As owner91 await expect(collection.setProperties(alice, [{key: 'electron', value: 'come bond'}])).to.be.fulfilled;9293 await collection.addAdmin(alice, {Substrate: bob.address});9495 // As administrator96 await expect(collection.setProperties(bob, [{key: 'black_hole'}])).to.be.fulfilled;9798 const properties = await collection.getProperties();99 expect(properties).to.include.deep.members([100 {key: 'electron', value: 'come bond'},101 {key: 'black_hole', value: ''},102 ]);103 }104105 itSub('Sets properties for a NFT collection', async ({helper}) => {106 await testSetsPropertiesForCollection(await helper.nft.mintCollection(alice));107 });108109 itSub.ifWithPallets('Sets properties for a ReFungible collection', [Pallets.ReFungible], async ({helper}) => {110 await testSetsPropertiesForCollection(await helper.rft.mintCollection(alice));111 });112113 async function testCheckValidNames(collection: UniqueBaseCollection) {114 // alpha symbols115 await expect(collection.setProperties(alice, [{key: 'answer'}])).to.be.fulfilled;116117 // numeric symbols118 await expect(collection.setProperties(alice, [{key: '451'}])).to.be.fulfilled;119120 // underscore symbol121 await expect(collection.setProperties(alice, [{key: 'black_hole'}])).to.be.fulfilled;122123 // dash symbol124 await expect(collection.setProperties(alice, [{key: '-'}])).to.be.fulfilled;125126 // dot symbol127 await expect(collection.setProperties(alice, [{key: 'once.in.a.long.long.while...', value: 'you get a little lost'}])).to.be.fulfilled;128129 const properties = await collection.getProperties();130 expect(properties).to.include.deep.members([131 {key: 'answer', value: ''},132 {key: '451', value: ''},133 {key: 'black_hole', value: ''},134 {key: '-', value: ''},135 {key: 'once.in.a.long.long.while...', value: 'you get a little lost'},136 ]);137 }138139 itSub('Check valid names for NFT collection properties keys', async ({helper}) => {140 await testCheckValidNames(await helper.nft.mintCollection(alice));141 });142143 itSub.ifWithPallets('Check valid names for ReFungible collection properties keys', [Pallets.ReFungible], async ({helper}) => {144 await testCheckValidNames(await helper.rft.mintCollection(alice));145 });146147 async function testChangesProperties(collection: UniqueBaseCollection) {148 await expect(collection.setProperties(alice, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: ''}])).to.be.fulfilled;149150 // Mutate the properties151 await expect(collection.setProperties(alice, [{key: 'black_hole', value: 'LIGO'}])).to.be.fulfilled;152153 const properties = await collection.getProperties();154 expect(properties).to.include.deep.members([155 {key: 'electron', value: 'come bond'},156 {key: 'black_hole', value: 'LIGO'},157 ]);158 }159160 itSub('Changes properties of a NFT collection', async ({helper}) => {161 await testChangesProperties(await helper.nft.mintCollection(alice));162 });163164 itSub.ifWithPallets('Changes properties of a ReFungible collection', [Pallets.ReFungible], async ({helper}) => {165 await testChangesProperties(await helper.rft.mintCollection(alice));166 });167168 async function testDeleteProperties(collection: UniqueBaseCollection) {169 await expect(collection.setProperties(alice, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: 'LIGO'}])).to.be.fulfilled;170171 await expect(collection.deleteProperties(alice, ['electron'])).to.be.fulfilled;172173 const properties = await collection.getProperties(['black_hole', 'electron']);174 expect(properties).to.be.deep.equal([175 {key: 'black_hole', value: 'LIGO'},176 ]);177 }178179 itSub('Deletes properties of a NFT collection', async ({helper}) => {180 await testDeleteProperties(await helper.nft.mintCollection(alice));181 });182183 itSub.ifWithPallets('Deletes properties of a ReFungible collection', [Pallets.ReFungible], async ({helper}) => {184 await testDeleteProperties(await helper.rft.mintCollection(alice));185 });186});187188describe('Negative Integration Test: Collection Properties', () => {189 let alice: IKeyringPair;190 let bob: IKeyringPair;191192 before(async () => {193 await usingPlaygrounds(async (helper, privateKey) => {194 const donor = privateKey('//Alice');195 [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);196 });197 });198 199 async function testFailsSetPropertiesIfNotOwnerOrAdmin(collection: UniqueBaseCollection) { 200 await expect(collection.setProperties(bob, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: 'LIGO'}]))201 .to.be.rejectedWith(/common\.NoPermission/);202203 const properties = await collection.getProperties();204 expect(properties).to.be.deep.equal([{205 'key': 'ERC721Metadata',206 'value': '1',207 }]);208 }209210 itSub('Fails to set properties in a NFT collection if not its onwer/administrator', async ({helper}) => {211 await testFailsSetPropertiesIfNotOwnerOrAdmin(await helper.nft.mintCollection(alice));212 });213214 itSub.ifWithPallets('Fails to set properties in a ReFungible collection if not its onwer/administrator', [Pallets.ReFungible], async ({helper}) => {215 await testFailsSetPropertiesIfNotOwnerOrAdmin(await helper.rft.mintCollection(alice));216 });217 218 async function testFailsSetPropertiesThatExeedLimits(collection: UniqueBaseCollection) {219 const spaceLimit = (await (collection.helper!.api! as any).query.common.collectionProperties(collection.collectionId)).spaceLimit.toNumber();220 221 // Mute the general tx parsing error, too many bytes to process222 {223 console.error = () => {};224 await expect(collection.setProperties(alice, [225 {key: 'electron', value: 'low high '.repeat(Math.ceil(spaceLimit! / 9))},226 ])).to.be.rejected;227 }228229 expect(await collection.getProperties(['electron'])).to.be.empty;230231 await expect(collection.setProperties(alice, [232 {key: 'electron', value: 'low high '.repeat(Math.ceil(spaceLimit! / 18))}, 233 {key: 'black_hole', value: '0'.repeat(Math.ceil(spaceLimit! / 2))}, 234 ])).to.be.rejectedWith(/common\.NoSpaceForProperty/);235236 expect(await collection.getProperties(['electron', 'black_hole'])).to.be.empty;237 }238239 itSub('Fails to set properties that exceed the limits (NFT)', async ({helper}) => {240 await testFailsSetPropertiesThatExeedLimits(await helper.nft.mintCollection(alice));241 });242243 itSub.ifWithPallets('Fails to set properties that exceed the limits (ReFungible)', [Pallets.ReFungible], async ({helper}) => {244 await testFailsSetPropertiesThatExeedLimits(await helper.rft.mintCollection(alice));245 });246 247 async function testFailsSetMorePropertiesThanAllowed(collection: UniqueBaseCollection) {248 const propertiesToBeSet = [];249 for (let i = 0; i < 65; i++) {250 propertiesToBeSet.push({251 key: 'electron_' + i,252 value: Math.random() > 0.5 ? 'high' : 'low',253 });254 }255256 await expect(collection.setProperties(alice, propertiesToBeSet)).257 to.be.rejectedWith(/common\.PropertyLimitReached/);258259 const properties = await collection.getProperties();260 expect(properties).to.be.deep.equal([{261 'key': 'ERC721Metadata',262 'value': '1',263 }]);264 }265266 itSub('Fails to set more properties than it is allowed (NFT)', async ({helper}) => {267 await testFailsSetMorePropertiesThanAllowed(await helper.nft.mintCollection(alice));268 });269270 itSub.ifWithPallets('Fails to set more properties than it is allowed (ReFungible)', [Pallets.ReFungible], async ({helper}) => {271 await testFailsSetMorePropertiesThanAllowed(await helper.rft.mintCollection(alice));272 });273 274 async function testFailsSetPropertiesWithInvalidNames(collection: UniqueBaseCollection) {275 const invalidProperties = [276 [{key: 'electron', value: 'negative'}, {key: 'string theory', value: 'understandable'}],277 [{key: 'Mr/Sandman', value: 'Bring me a gene'}],278 [{key: 'déjà vu', value: 'hmm...'}],279 ];280281 for (let i = 0; i < invalidProperties.length; i++) {282 await expect(283 collection.setProperties(alice, invalidProperties[i]), 284 `on rejecting the new badly-named property #${i}`,285 ).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);286 }287288 await expect(289 collection.setProperties(alice, [{key: '', value: 'nothing must not exist'}]), 290 'on rejecting an unnamed property',291 ).to.be.rejectedWith(/common\.EmptyPropertyKey/);292293 await expect(294 collection.setProperties(alice, [{key: 'CRISPR-Cas9', value: 'rewriting nature!'}]), 295 'on setting the correctly-but-still-badly-named property',296 ).to.be.fulfilled;297298 const keys = invalidProperties.flatMap(propertySet => propertySet.map(property => property.key)).concat('CRISPR-Cas9').concat('');299300 const properties = await collection.getProperties(keys);301 expect(properties).to.be.deep.equal([302 {key: 'CRISPR-Cas9', value: 'rewriting nature!'},303 ]);304305 for (let i = 0; i < invalidProperties.length; i++) {306 await expect(307 collection.deleteProperties(alice, invalidProperties[i].map(propertySet => propertySet.key)), 308 `on trying to delete the non-existent badly-named property #${i}`,309 ).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);310 }311 }312313 itSub('Fails to set properties with invalid names (NFT)', async ({helper}) => {314 await testFailsSetPropertiesWithInvalidNames(await helper.nft.mintCollection(alice));315 });316317 itSub.ifWithPallets('Fails to set properties with invalid names (ReFungible)', [Pallets.ReFungible], async ({helper}) => {318 await testFailsSetPropertiesWithInvalidNames(await helper.rft.mintCollection(alice));319 });320});321322// ---------- ACCESS RIGHTS323324describe('Integration Test: Access Rights to Token Properties', () => {325 let alice: IKeyringPair;326 let bob: IKeyringPair;327328 before(async () => {329 await usingPlaygrounds(async (helper, privateKey) => {330 const donor = privateKey('//Alice');331 [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);332 });333 });334 335 itSub('Reads access rights to properties of a collection', async ({helper}) => {336 const collection = await helper.nft.mintCollection(alice);337 const propertyRights = (await helper.callRpc('api.query.common.collectionPropertyPermissions', [collection.collectionId])).toJSON();338 expect(propertyRights).to.be.empty;339 });340 341 async function testSetsAccessRightsToProperties(collection: UniqueNFTCollection | UniqueRFTCollection) { 342 await expect(collection.setTokenPropertyPermissions(alice, [{key: 'skullduggery', permission: {mutable: true}}]))343 .to.be.fulfilled;344345 await collection.addAdmin(alice, {Substrate: bob.address});346347 await expect(collection.setTokenPropertyPermissions(bob, [{key: 'mindgame', permission: {collectionAdmin: true, tokenOwner: false}}]))348 .to.be.fulfilled;349350 const propertyRights = await collection.getPropertyPermissions(['skullduggery', 'mindgame']);351 expect(propertyRights).to.include.deep.members([352 {key: 'skullduggery', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}},353 {key: 'mindgame', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}},354 ]);355 }356357 itSub('Sets access rights to properties of a collection (NFT)', async ({helper}) => {358 await testSetsAccessRightsToProperties(await helper.nft.mintCollection(alice));359 });360361 itSub.ifWithPallets('Sets access rights to properties of a collection (ReFungible)', [Pallets.ReFungible], async ({helper}) => {362 await testSetsAccessRightsToProperties(await helper.rft.mintCollection(alice));363 });364 365 async function testChangesAccessRightsToProperty(collection: UniqueNFTCollection | UniqueRFTCollection) {366 await expect(collection.setTokenPropertyPermissions(alice, [{key: 'skullduggery', permission: {mutable: true, collectionAdmin: true}}]))367 .to.be.fulfilled;368369 await expect(collection.setTokenPropertyPermissions(alice, [{key: 'skullduggery', permission: {mutable: false, tokenOwner: true}}]))370 .to.be.fulfilled;371372 const propertyRights = await collection.getPropertyPermissions();373 expect(propertyRights).to.be.deep.equal([374 {key: 'skullduggery', permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},375 ]);376 }377378 itSub('Changes access rights to properties of a NFT collection', async ({helper}) => {379 await testChangesAccessRightsToProperty(await helper.nft.mintCollection(alice));380 });381382 itSub.ifWithPallets('Changes access rights to properties of a ReFungible collection', [Pallets.ReFungible], async ({helper}) => {383 await testChangesAccessRightsToProperty(await helper.rft.mintCollection(alice));384 });385});386387describe('Negative Integration Test: Access Rights to Token Properties', () => {388 let alice: IKeyringPair;389 let bob: IKeyringPair;390391 before(async () => {392 await usingPlaygrounds(async (helper, privateKey) => {393 const donor = privateKey('//Alice');394 [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);395 });396 });397398 async function testPreventsFromSettingAccessRightsNotAdminOrOwner(collection: UniqueNFTCollection | UniqueRFTCollection) {399 await expect(collection.setTokenPropertyPermissions(bob, [{key: 'skullduggery', permission: {mutable: true, tokenOwner: true}}]))400 .to.be.rejectedWith(/common\.NoPermission/);401402 const propertyRights = await collection.getPropertyPermissions(['skullduggery']);403 expect(propertyRights).to.be.empty;404 }405406 itSub('Prevents from setting access rights to properties of a NFT collection if not an onwer/admin', async ({helper}) => {407 await testPreventsFromSettingAccessRightsNotAdminOrOwner(await helper.nft.mintCollection(alice));408 });409410 itSub.ifWithPallets('Prevents from setting access rights to properties of a ReFungible collection if not an onwer/admin', [Pallets.ReFungible], async ({helper}) => {411 await testPreventsFromSettingAccessRightsNotAdminOrOwner(await helper.rft.mintCollection(alice));412 });413414 async function testPreventFromAddingTooManyPossibleProperties(collection: UniqueNFTCollection | UniqueRFTCollection) { 415 const constitution = [];416 for (let i = 0; i < 65; i++) {417 constitution.push({418 key: 'property_' + i,419 permission: Math.random() > 0.5 ? {mutable: true, collectionAdmin: true, tokenOwner: true} : {},420 });421 }422423 await expect(collection.setTokenPropertyPermissions(alice, constitution))424 .to.be.rejectedWith(/common\.PropertyLimitReached/);425426 const propertyRights = await collection.getPropertyPermissions();427 expect(propertyRights).to.be.empty;428 }429430 itSub('Prevents from adding too many possible properties (NFT)', async ({helper}) => {431 await testPreventFromAddingTooManyPossibleProperties(await helper.nft.mintCollection(alice));432 });433434 itSub.ifWithPallets('Prevents from adding too many possible properties (ReFungible)', [Pallets.ReFungible], async ({helper}) => {435 await testPreventFromAddingTooManyPossibleProperties(await helper.rft.mintCollection(alice));436 });437438 async function testPreventAccessRightsModifiedIfConstant(collection: UniqueNFTCollection | UniqueRFTCollection) {439 await expect(collection.setTokenPropertyPermissions(alice, [{key: 'skullduggery', permission: {mutable: false, tokenOwner: true}}]))440 .to.be.fulfilled;441442 await expect(collection.setTokenPropertyPermissions(alice, [{key: 'skullduggery', permission: {collectionAdmin: true}}]))443 .to.be.rejectedWith(/common\.NoPermission/);444445 const propertyRights = await collection.getPropertyPermissions(['skullduggery']);446 expect(propertyRights).to.deep.equal([447 {key: 'skullduggery', permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},448 ]);449 }450451 itSub('Prevents access rights to be modified if constant (NFT)', async ({helper}) => {452 await testPreventAccessRightsModifiedIfConstant(await helper.nft.mintCollection(alice));453 });454455 itSub.ifWithPallets('Prevents access rights to be modified if constant (ReFungible)', [Pallets.ReFungible], async ({helper}) => {456 await testPreventAccessRightsModifiedIfConstant(await helper.rft.mintCollection(alice));457 });458459 async function testPreventsAddingPropertiesWithInvalidNames(collection: UniqueNFTCollection | UniqueRFTCollection) {460 const invalidProperties = [461 [{key: 'skullduggery', permission: {tokenOwner: true}}, {key: 'im possible', permission: {collectionAdmin: true}}],462 [{key: 'G#4', permission: {tokenOwner: true}}],463 [{key: 'HÆMILTON', permission: {mutable: false, collectionAdmin: true, tokenOwner: true}}],464 ];465466 for (let i = 0; i < invalidProperties.length; i++) {467 await expect(468 collection.setTokenPropertyPermissions(alice, invalidProperties[i]), 469 `on setting the new badly-named property #${i}`,470 ).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);471 }472473 await expect(474 collection.setTokenPropertyPermissions(alice, [{key: '', permission: {}}]), 475 'on rejecting an unnamed property',476 ).to.be.rejectedWith(/common\.EmptyPropertyKey/);477478 const correctKey = '--0x03116e387820CA05'; // PolkadotJS would parse this as an already encoded hex-string479 await expect(480 collection.setTokenPropertyPermissions(alice, [481 {key: correctKey, permission: {collectionAdmin: true}},482 ]), 483 'on setting the correctly-but-still-badly-named property',484 ).to.be.fulfilled;485486 const keys = invalidProperties.flatMap(propertySet => propertySet.map(property => property.key)).concat(correctKey).concat('');487488 const propertyRights = await collection.getPropertyPermissions(keys);489 expect(propertyRights).to.be.deep.equal([490 {key: correctKey, permission: {mutable: false, collectionAdmin: true, tokenOwner: false}},491 ]);492 }493494 itSub('Prevents adding properties with invalid names (NFT)', async ({helper}) => {495 await testPreventsAddingPropertiesWithInvalidNames(await helper.nft.mintCollection(alice));496 });497498 itSub.ifWithPallets('Prevents adding properties with invalid names (ReFungible)', [Pallets.ReFungible], async ({helper}) => {499 await testPreventsAddingPropertiesWithInvalidNames(await helper.rft.mintCollection(alice));500 });501});502503// ---------- TOKEN PROPERTIES504505describe('Integration Test: Token Properties', () => {506 let alice: IKeyringPair; // collection owner507 let bob: IKeyringPair; // collection admin508 let charlie: IKeyringPair; // token owner509510 let permissions: {permission: any, signers: IKeyringPair[]}[];511512 before(async () => {513 await usingPlaygrounds(async (helper, privateKey) => {514 const donor = privateKey('//Alice');515 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);516 });517518 // todo:playgrounds probably separate these tests later519 permissions = [520 {permission: {mutable: true, collectionAdmin: true}, signers: [alice, bob]},521 {permission: {mutable: false, collectionAdmin: true}, signers: [alice, bob]},522 {permission: {mutable: true, tokenOwner: true}, signers: [charlie]},523 {permission: {mutable: false, tokenOwner: true}, signers: [charlie]},524 {permission: {mutable: true, collectionAdmin: true, tokenOwner: true}, signers: [alice, bob, charlie]},525 {permission: {mutable: false, collectionAdmin: true, tokenOwner: true}, signers: [alice, bob, charlie]},526 ];527 });528 529 async function testReadsYetEmptyProperties(token: UniqueNFToken | UniqueRFToken) {530 const properties = await token.getProperties();531 expect(properties).to.be.empty;532533 const tokenData = await token.getData();534 expect(tokenData!.properties).to.be.empty;535 }536537 itSub('Reads yet empty properties of a token (NFT)', async ({helper}) => {538 const collection = await helper.nft.mintCollection(alice);539 const token = await collection.mintToken(alice);540 await testReadsYetEmptyProperties(token);541 });542543 itSub.ifWithPallets('Reads yet empty properties of a token (ReFungible)', [Pallets.ReFungible], async ({helper}) => {544 const collection = await helper.rft.mintCollection(alice);545 const token = await collection.mintToken(alice);546 await testReadsYetEmptyProperties(token);547 });548549 async function testAssignPropertiesAccordingToPermissions(token: UniqueNFToken | UniqueRFToken, pieces: bigint) {550 await token.collection.addAdmin(alice, {Substrate: bob.address});551 await token.transfer(alice, {Substrate: charlie.address}, pieces);552553 const propertyKeys: string[] = [];554 let i = 0;555 for (const permission of permissions) {556 i++;557 let j = 0;558 for (const signer of permission.signers) {559 j++;560 const key = i + '_' + signer.address;561 propertyKeys.push(key);562563 await expect(564 token.collection.setTokenPropertyPermissions(alice, [{key: key, permission: permission.permission}]), 565 `on setting permission #${i} by alice`,566 ).to.be.fulfilled;567568 await expect(569 token.setProperties(signer, [{key: key, value: 'Serotonin increase'}]), 570 `on adding property #${i} by signer #${j}`,571 ).to.be.fulfilled;572 }573 }574575 const properties = await token.getProperties(propertyKeys);576 const tokenData = await token.getData();577 for (let i = 0; i < properties.length; i++) {578 expect(properties[i].value).to.be.equal('Serotonin increase');579 expect(tokenData!.properties[i].value).to.be.equal('Serotonin increase');580 }581 }582583 itSub('Assigns properties to a token according to permissions (NFT)', async ({helper}) => {584 const collection = await helper.nft.mintCollection(alice);585 const token = await collection.mintToken(alice);586 await testAssignPropertiesAccordingToPermissions(token, 1n);587 });588589 itSub.ifWithPallets('Assigns properties to a token according to permissions (ReFungible)', [Pallets.ReFungible], async ({helper}) => {590 const collection = await helper.rft.mintCollection(alice);591 const token = await collection.mintToken(alice, 100n);592 await testAssignPropertiesAccordingToPermissions(token, 100n);593 });594595 async function testChangesPropertiesAccordingPermission(token: UniqueNFToken | UniqueRFToken, pieces: bigint) {596 await token.collection.addAdmin(alice, {Substrate: bob.address});597 await token.transfer(alice, {Substrate: charlie.address}, pieces);598599 const propertyKeys: string[] = [];600 let i = 0;601 for (const permission of permissions) {602 i++;603 if (!permission.permission.mutable) continue;604 605 let j = 0;606 for (const signer of permission.signers) {607 j++;608 const key = i + '_' + signer.address;609 propertyKeys.push(key);610611 await expect(612 token.collection.setTokenPropertyPermissions(alice, [{key: key, permission: permission.permission}]), 613 `on setting permission #${i} by alice`,614 ).to.be.fulfilled;615616 await expect(617 token.setProperties(signer, [{key, value: 'Serotonin increase'}]), 618 `on adding property #${i} by signer #${j}`,619 ).to.be.fulfilled;620621 await expect(622 token.setProperties(signer, [{key, value: 'Serotonin stable'}]), 623 `on changing property #${i} by signer #${j}`,624 ).to.be.fulfilled;625 }626 }627628 const properties = await token.getProperties(propertyKeys);629 const tokenData = await token.getData();630 for (let i = 0; i < properties.length; i++) {631 expect(properties[i].value).to.be.equal('Serotonin stable');632 expect(tokenData!.properties[i].value).to.be.equal('Serotonin stable');633 }634 }635636 itSub('Changes properties of a token according to permissions (NFT)', async ({helper}) => {637 const collection = await helper.nft.mintCollection(alice);638 const token = await collection.mintToken(alice);639 await testChangesPropertiesAccordingPermission(token, 1n);640 });641642 itSub.ifWithPallets('Changes properties of a token according to permissions (ReFungible)', [Pallets.ReFungible], async ({helper}) => {643 const collection = await helper.rft.mintCollection(alice);644 const token = await collection.mintToken(alice, 100n);645 await testChangesPropertiesAccordingPermission(token, 100n);646 });647648 async function testDeletePropertiesAccordingPermission(token: UniqueNFToken | UniqueRFToken, pieces: bigint) {649 await token.collection.addAdmin(alice, {Substrate: bob.address});650 await token.transfer(alice, {Substrate: charlie.address}, pieces);651652 const propertyKeys: string[] = [];653 let i = 0;654655 for (const permission of permissions) {656 i++;657 if (!permission.permission.mutable) continue;658 659 let j = 0;660 for (const signer of permission.signers) {661 j++;662 const key = i + '_' + signer.address;663 propertyKeys.push(key);664665 await expect(666 token.collection.setTokenPropertyPermissions(alice, [{key: key, permission: permission.permission}]), 667 `on setting permission #${i} by alice`,668 ).to.be.fulfilled;669670 await expect(671 token.setProperties(signer, [{key, value: 'Serotonin increase'}]), 672 `on adding property #${i} by signer #${j}`,673 ).to.be.fulfilled;674675 await expect(676 token.deleteProperties(signer, [key]), 677 `on deleting property #${i} by signer #${j}`,678 ).to.be.fulfilled;679 }680 }681682 expect(await token.getProperties(propertyKeys)).to.be.empty;683 expect((await token.getData())!.properties).to.be.empty;684 }685 686 itSub('Deletes properties of a token according to permissions (NFT)', async ({helper}) => {687 const collection = await helper.nft.mintCollection(alice);688 const token = await collection.mintToken(alice);689 await testDeletePropertiesAccordingPermission(token, 1n);690 });691692 itSub.ifWithPallets('Deletes properties of a token according to permissions (ReFungible)', [Pallets.ReFungible], async ({helper}) => {693 const collection = await helper.rft.mintCollection(alice);694 const token = await collection.mintToken(alice, 100n);695 await testDeletePropertiesAccordingPermission(token, 100n);696 });697698 itSub('Assigns properties to a nested token according to permissions', async ({helper}) => {699 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});700 const collectionB = await helper.nft.mintCollection(alice);701 const targetToken = await collectionA.mintToken(alice);702 const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAccount());703704 await collectionB.addAdmin(alice, {Substrate: bob.address});705 await targetToken.transfer(alice, {Substrate: charlie.address});706707 const propertyKeys: string[] = [];708 let i = 0;709 for (const permission of permissions) {710 i++;711 let j = 0;712 for (const signer of permission.signers) {713 j++;714 const key = i + '_' + signer.address;715 propertyKeys.push(key);716 717 await expect(718 nestedToken.collection.setTokenPropertyPermissions(alice, [{key: key, permission: permission.permission}]), 719 `on setting permission #${i} by alice`,720 ).to.be.fulfilled;721722 await expect(723 nestedToken.setProperties(signer, [{key, value: 'Serotonin increase'}]), 724 `on adding property #${i} by signer #${j}`,725 ).to.be.fulfilled;726 }727 }728729 const properties = await nestedToken.getProperties(propertyKeys);730 const tokenData = await nestedToken.getData();731 for (let i = 0; i < properties.length; i++) {732 expect(properties[i].value).to.be.equal('Serotonin increase');733 expect(tokenData!.properties[i].value).to.be.equal('Serotonin increase');734 }735 expect(await targetToken.getProperties()).to.be.empty;736 });737738 itSub('Changes properties of a nested token according to permissions', async ({helper}) => {739 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});740 const collectionB = await helper.nft.mintCollection(alice);741 const targetToken = await collectionA.mintToken(alice);742 const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAccount());743744 await collectionB.addAdmin(alice, {Substrate: bob.address});745 await targetToken.transfer(alice, {Substrate: charlie.address});746747 const propertyKeys: string[] = [];748 let i = 0;749 for (const permission of permissions) {750 i++;751 if (!permission.permission.mutable) continue;752 753 let j = 0;754 for (const signer of permission.signers) {755 j++;756 const key = i + '_' + signer.address;757 propertyKeys.push(key);758759 await expect(760 nestedToken.collection.setTokenPropertyPermissions(alice, [{key: key, permission: permission.permission}]), 761 `on setting permission #${i} by alice`,762 ).to.be.fulfilled;763764 await expect(765 nestedToken.setProperties(signer, [{key, value: 'Serotonin increase'}]), 766 `on adding property #${i} by signer #${j}`,767 ).to.be.fulfilled;768769 await expect(770 nestedToken.setProperties(signer, [{key, value: 'Serotonin stable'}]), 771 `on changing property #${i} by signer #${j}`,772 ).to.be.fulfilled;773 }774 }775776 const properties = await nestedToken.getProperties(propertyKeys);777 const tokenData = await nestedToken.getData();778 for (let i = 0; i < properties.length; i++) {779 expect(properties[i].value).to.be.equal('Serotonin stable');780 expect(tokenData!.properties[i].value).to.be.equal('Serotonin stable');781 }782 expect(await targetToken.getProperties()).to.be.empty;783 });784785 itSub('Deletes properties of a nested token according to permissions', async ({helper}) => {786 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});787 const collectionB = await helper.nft.mintCollection(alice);788 const targetToken = await collectionA.mintToken(alice);789 const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAccount());790791 await collectionB.addAdmin(alice, {Substrate: bob.address});792 await targetToken.transfer(alice, {Substrate: charlie.address});793794 const propertyKeys: string[] = [];795 let i = 0;796 for (const permission of permissions) {797 i++;798 if (!permission.permission.mutable) continue;799 800 let j = 0;801 for (const signer of permission.signers) {802 j++;803 const key = i + '_' + signer.address;804 propertyKeys.push(key);805806 await expect(807 nestedToken.collection.setTokenPropertyPermissions(alice, [{key: key, permission: permission.permission}]), 808 `on setting permission #${i} by alice`,809 ).to.be.fulfilled;810811 await expect(812 nestedToken.setProperties(signer, [{key, value: 'Serotonin increase'}]), 813 `on adding property #${i} by signer #${j}`,814 ).to.be.fulfilled;815816 await expect(817 nestedToken.deleteProperties(signer, [key]), 818 `on deleting property #${i} by signer #${j}`,819 ).to.be.fulfilled;820 }821 }822823 expect(await nestedToken.getProperties(propertyKeys)).to.be.empty;824 expect((await nestedToken.getData())!.properties).to.be.empty;825 expect(await targetToken.getProperties()).to.be.empty;826 });827});828829describe('Negative Integration Test: Token Properties', () => {830 let alice: IKeyringPair; // collection owner831 let bob: IKeyringPair; // collection admin832 let charlie: IKeyringPair; // token owner833834 let constitution: {permission: any, signers: IKeyringPair[], sinner: IKeyringPair}[];835836 before(async () => {837 await usingPlaygrounds(async (helper, privateKey) => {838 const donor = privateKey('//Alice');839 let dave: IKeyringPair;840 [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);841842 // todo:playgrounds probably separate these tests later843 constitution = [844 {permission: {mutable: true, collectionAdmin: true}, signers: [alice, bob], sinner: charlie},845 {permission: {mutable: false, collectionAdmin: true}, signers: [alice, bob], sinner: charlie},846 {permission: {mutable: true, tokenOwner: true}, signers: [charlie], sinner: alice},847 {permission: {mutable: false, tokenOwner: true}, signers: [charlie], sinner: alice},848 {permission: {mutable: true, collectionAdmin: true, tokenOwner: true}, signers: [alice, bob, charlie], sinner: dave},849 {permission: {mutable: false, collectionAdmin: true, tokenOwner: true}, signers: [alice, bob, charlie], sinner: dave},850 ];851 });852 });853854 async function getConsumedSpace(api: any, collectionId: number, tokenId: number, mode: 'NFT' | 'RFT'): Promise<number> {855 return (await (mode == 'NFT' ? api.query.nonfungible : api.query.refungible).tokenProperties(collectionId, tokenId)).toJSON().consumedSpace;856 }857858 async function prepare(token: UniqueNFToken | UniqueRFToken, pieces: bigint): Promise<number> {859 await token.collection.addAdmin(alice, {Substrate: bob.address});860 await token.transfer(alice, {Substrate: charlie.address}, pieces);861862 let i = 0;863 for (const passage of constitution) {864 i++;865 const signer = passage.signers[0];866 867 await expect(868 token.collection.setTokenPropertyPermissions(alice, [{key: `${i}`, permission: passage.permission}]), 869 `on setting permission ${i} by alice`,870 ).to.be.fulfilled;871872 await expect(873 token.setProperties(signer, [{key: `${i}`, value: 'Serotonin increase'}]), 874 `on adding property ${i} by ${signer.address}`,875 ).to.be.fulfilled;876 }877878 const originalSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT'); 879 return originalSpace;880 }881882 async function testForbidsChangingDeletingPropertiesUserOutsideOfPermissions(token: UniqueNFToken | UniqueRFToken, pieces: bigint) {883 const originalSpace = await prepare(token, pieces);884885 let i = 0;886 for (const forbiddance of constitution) {887 i++;888 if (!forbiddance.permission.mutable) continue;889890 await expect(891 token.setProperties(forbiddance.sinner, [{key: `${i}`, value: 'Serotonin down'}]), 892 `on failing to change property ${i} by the malefactor`,893 ).to.be.rejectedWith(/common\.NoPermission/);894895 await expect(896 token.deleteProperties(forbiddance.sinner, [`${i}`]), 897 `on failing to delete property ${i} by the malefactor`,898 ).to.be.rejectedWith(/common\.NoPermission/);899 }900901 const consumedSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT'); 902 expect(consumedSpace).to.be.equal(originalSpace);903 }904905 itSub('Forbids changing/deleting properties of a token if the user is outside of permissions (NFT)', async ({helper}) => {906 const collection = await helper.nft.mintCollection(alice);907 const token = await collection.mintToken(alice);908 await testForbidsChangingDeletingPropertiesUserOutsideOfPermissions(token, 1n);909 });910911 itSub.ifWithPallets('Forbids changing/deleting properties of a token if the user is outside of permissions (ReFungible)', [Pallets.ReFungible], async ({helper}) => {912 const collection = await helper.rft.mintCollection(alice);913 const token = await collection.mintToken(alice, 100n);914 await testForbidsChangingDeletingPropertiesUserOutsideOfPermissions(token, 100n);915 });916917 async function testForbidsChangingDeletingPropertiesIfPropertyImmutable(token: UniqueNFToken | UniqueRFToken, pieces: bigint) {918 const originalSpace = await prepare(token, pieces);919920 let i = 0;921 for (const permission of constitution) {922 i++;923 if (permission.permission.mutable) continue;924925 await expect(926 token.setProperties(permission.signers[0], [{key: `${i}`, value: 'Serotonin down'}]), 927 `on failing to change property ${i} by signer #0`,928 ).to.be.rejectedWith(/common\.NoPermission/);929930 await expect(931 token.deleteProperties(permission.signers[0], [i.toString()]), 932 `on failing to delete property ${i} by signer #0`,933 ).to.be.rejectedWith(/common\.NoPermission/);934 }935 936 const consumedSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT'); 937 expect(consumedSpace).to.be.equal(originalSpace);938 }939940 itSub('Forbids changing/deleting properties of a token if the property is permanent (immutable) (NFT)', async ({helper}) => {941 const collection = await helper.nft.mintCollection(alice);942 const token = await collection.mintToken(alice);943 await testForbidsChangingDeletingPropertiesIfPropertyImmutable(token, 1n);944 });945946 itSub.ifWithPallets('Forbids changing/deleting properties of a token if the property is permanent (immutable) (ReFungible)', [Pallets.ReFungible], async ({helper}) => {947 const collection = await helper.rft.mintCollection(alice);948 const token = await collection.mintToken(alice, 100n);949 await testForbidsChangingDeletingPropertiesIfPropertyImmutable(token, 100n);950 });951952 async function testForbidsAddingPropertiesIfPropertyNotDeclared(token: UniqueNFToken | UniqueRFToken, pieces: bigint) {953 const originalSpace = await prepare(token, pieces);954955 await expect(956 token.setProperties(alice, [{key: 'non-existent', value: 'I exist!'}]), 957 'on failing to add a previously non-existent property',958 ).to.be.rejectedWith(/common\.NoPermission/);959 960 await expect(961 token.collection.setTokenPropertyPermissions(alice, [{key: 'now-existent', permission: {}}]), 962 'on setting a new non-permitted property',963 ).to.be.fulfilled;964965 await expect(966 token.setProperties(alice, [{key: 'now-existent', value: 'I exist!'}]), 967 'on failing to add a property forbidden by the \'None\' permission',968 ).to.be.rejectedWith(/common\.NoPermission/);969970 expect(await token.getProperties(['non-existent', 'now-existent'])).to.be.empty;971 972 const consumedSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT'); 973 expect(consumedSpace).to.be.equal(originalSpace);974 }975976 itSub('Forbids adding properties to a token if the property is not declared / forbidden with the \'None\' permission (NFT)', async ({helper}) => {977 const collection = await helper.nft.mintCollection(alice);978 const token = await collection.mintToken(alice);979 await testForbidsAddingPropertiesIfPropertyNotDeclared(token, 1n);980 });981982 itSub.ifWithPallets('Forbids adding properties to a token if the property is not declared / forbidden with the \'None\' permission (ReFungible)', [Pallets.ReFungible], async ({helper}) => {983 const collection = await helper.rft.mintCollection(alice);984 const token = await collection.mintToken(alice, 100n);985 await testForbidsAddingPropertiesIfPropertyNotDeclared(token, 100n);986 });987988 async function testForbidsAddingTooManyProperties(token: UniqueNFToken | UniqueRFToken, pieces: bigint) {989 const originalSpace = await prepare(token, pieces);990991 await expect(992 token.collection.setTokenPropertyPermissions(alice, [993 {key: 'a_holy_book', permission: {collectionAdmin: true, tokenOwner: true}}, 994 {key: 'young_years', permission: {collectionAdmin: true, tokenOwner: true}},995 ]), 996 'on setting new permissions for properties',997 ).to.be.fulfilled;998999 // Mute the general tx parsing error1000 {1001 console.error = () => {};1002 await expect(token.setProperties(alice, [{key: 'a_holy_book', value: 'word '.repeat(6554)}]))1003 .to.be.rejected;1004 }10051006 await expect(token.setProperties(alice, [1007 {key: 'a_holy_book', value: 'word '.repeat(3277)}, 1008 {key: 'young_years', value: 'neverending'.repeat(1490)},1009 ])).to.be.rejectedWith(/common\.NoSpaceForProperty/);1010 1011 expect(await token.getProperties(['a_holy_book', 'young_years'])).to.be.empty;1012 const consumedSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT'); 1013 expect(consumedSpace).to.be.equal(originalSpace);1014 }10151016 itSub('Forbids adding too many properties to a token (NFT)', async ({helper}) => {1017 const collection = await helper.nft.mintCollection(alice);1018 const token = await collection.mintToken(alice);1019 await testForbidsAddingTooManyProperties(token, 1n);1020 });10211022 itSub.ifWithPallets('Forbids adding too many properties to a token (ReFungible)', [Pallets.ReFungible], async ({helper}) => {1023 const collection = await helper.rft.mintCollection(alice);1024 const token = await collection.mintToken(alice, 100n);1025 await testForbidsAddingTooManyProperties(token, 100n);1026 });1027});10281029describe('ReFungible token properties permissions tests', () => {1030 let alice: IKeyringPair;1031 let bob: IKeyringPair;1032 let charlie: IKeyringPair;10331034 before(async function() {1035 await usingPlaygrounds(async (helper, privateKey) => {1036 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);10371038 const donor = privateKey('//Alice');1039 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);1040 });1041 });10421043 async function prepare(helper: UniqueHelper): Promise<UniqueRFToken> {1044 const collection = await helper.rft.mintCollection(alice);1045 const token = await collection.mintToken(alice, 100n);1046 1047 await collection.addAdmin(alice, {Substrate: bob.address});1048 await collection.setTokenPropertyPermissions(alice, [{key: 'fractals', permission: {mutable: true, tokenOwner: true}}]);1049 1050 return token;1051 }10521053 itSub('Forbids adding token property with tokenOwner==true when signer doesn\'t have all pieces', async ({helper}) => {1054 const token = await prepare(helper);10551056 await token.transfer(alice, {Substrate: charlie.address}, 33n);10571058 await expect(token.setProperties(alice, [1059 {key: 'fractals', value: 'multiverse'}, 1060 ])).to.be.rejectedWith(/common\.NoPermission/);1061 });10621063 itSub('Forbids mutating token property with tokenOwher==true when signer doesn\'t have all pieces', async ({helper}) => {1064 const token = await prepare(helper);10651066 await expect(token.collection.setTokenPropertyPermissions(alice, [{key: 'fractals', permission: {mutable:true, tokenOwner: true}}]))1067 .to.be.fulfilled;10681069 await expect(token.setProperties(alice, [1070 {key: 'fractals', value: 'multiverse'}, 1071 ])).to.be.fulfilled;10721073 await token.transfer(alice, {Substrate: charlie.address}, 33n);10741075 await expect(token.setProperties(alice, [1076 {key: 'fractals', value: 'want to rule the world'}, 1077 ])).to.be.rejectedWith(/common\.NoPermission/);1078 });10791080 itSub('Forbids deleting token property with tokenOwner==true when signer doesn\'t have all pieces', async ({helper}) => {1081 const token = await prepare(helper);10821083 await expect(token.setProperties(alice, [1084 {key: 'fractals', value: 'one headline - why believe it'}, 1085 ])).to.be.fulfilled;10861087 await token.transfer(alice, {Substrate: charlie.address}, 33n);10881089 await expect(token.deleteProperties(alice, ['fractals'])).1090 to.be.rejectedWith(/common\.NoPermission/);1091 });10921093 itSub('Allows token property mutation with collectionOwner==true when admin doesn\'t have all pieces', async ({helper}) => {1094 const token = await prepare(helper);10951096 await token.transfer(alice, {Substrate: charlie.address}, 33n);10971098 await expect(token.collection.setTokenPropertyPermissions(alice, [{key: 'fractals', permission: {mutable:true, collectionAdmin: true}}]))1099 .to.be.fulfilled;11001101 await expect(token.setProperties(alice, [1102 {key: 'fractals', value: 'multiverse'}, 1103 ])).to.be.fulfilled;1104 });1105});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 {IKeyringPair} from '@polkadot/types/types';18import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from '../util/playgrounds';19import {UniqueHelper, UniqueBaseCollection, UniqueNFTCollection, UniqueNFToken, UniqueRFTCollection, UniqueRFToken} from '../util/playgrounds/unique';202122describe('Composite Properties Test', () => {23 let alice: IKeyringPair;2425 before(async () => {26 await usingPlaygrounds(async (helper, privateKey) => {27 const donor = privateKey('//Alice');28 [alice] = await helper.arrange.createAccounts([50n], donor);29 });30 });3132 async function testMakeSureSuppliesRequired(baseCollection: UniqueNFTCollection | UniqueRFTCollection) {3334 const collectionOption = await baseCollection.getOptions();35 expect(collectionOption).is.not.null;36 let collection = collectionOption;37 expect(collection.tokenPropertyPermissions).to.be.empty;38 expect(collection.properties).to.be.empty;3940 const propertyPermissions = [41 {key: 'mindgame', permission: {collectionAdmin: true, mutable: false, tokenOwner: true}},42 {key: 'skullduggery', permission: {collectionAdmin: false, mutable: true, tokenOwner: false}},43 ];44 await expect(await baseCollection.setTokenPropertyPermissions(alice, propertyPermissions)).to.be.true;4546 const collectionProperties = [47 {key: 'black_hole', value: 'LIGO'},48 {key: 'electron', value: 'come bond'}, 49 ];50 51 await expect(await baseCollection.setProperties(alice, collectionProperties)).to.be.true;5253 collection = await baseCollection.getOptions();54 expect(collection.tokenPropertyPermissions).to.be.deep.equal(propertyPermissions);55 expect(collection.properties).to.be.deep.equal(collectionProperties);56 }5758 itSub('Makes sure collectionById supplies required fields for NFT', async ({helper}) => {59 await testMakeSureSuppliesRequired(await helper.nft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'}));60 });6162 itSub.ifWithPallets('Makes sure collectionById supplies required fields for ReFungible', [Pallets.ReFungible], async ({helper}) => {63 await testMakeSureSuppliesRequired(await helper.rft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'}));64 });65});66// ---------- COLLECTION PROPERTIES6768describe('Integration Test: Collection Properties', () => {69 let alice: IKeyringPair;70 let bob: IKeyringPair;7172 before(async () => {73 await usingPlaygrounds(async (helper, privateKey) => {74 const donor = privateKey('//Alice');75 [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);76 });77 });7879 itSub('Properties are initially empty', async ({helper}) => {80 const collection = await helper.nft.mintCollection(alice);81 const properties = await collection.getProperties();82 expect(properties).to.be.empty;83 });8485 async function testSetsPropertiesForCollection(collection: UniqueBaseCollection) {86 // As owner87 await expect(collection.setProperties(alice, [{key: 'electron', value: 'come bond'}])).to.be.fulfilled;8889 await collection.addAdmin(alice, {Substrate: bob.address});9091 // As administrator92 await expect(collection.setProperties(bob, [{key: 'black_hole'}])).to.be.fulfilled;9394 const properties = await collection.getProperties();95 expect(properties).to.include.deep.members([96 {key: 'electron', value: 'come bond'},97 {key: 'black_hole', value: ''},98 ]);99 }100101 itSub('Sets properties for a NFT collection', async ({helper}) => {102 await testSetsPropertiesForCollection(await helper.nft.mintCollection(alice));103 });104105 itSub.ifWithPallets('Sets properties for a ReFungible collection', [Pallets.ReFungible], async ({helper}) => {106 await testSetsPropertiesForCollection(await helper.rft.mintCollection(alice));107 });108109 async function testCheckValidNames(collection: UniqueBaseCollection) {110 // alpha symbols111 await expect(collection.setProperties(alice, [{key: 'answer'}])).to.be.fulfilled;112113 // numeric symbols114 await expect(collection.setProperties(alice, [{key: '451'}])).to.be.fulfilled;115116 // underscore symbol117 await expect(collection.setProperties(alice, [{key: 'black_hole'}])).to.be.fulfilled;118119 // dash symbol120 await expect(collection.setProperties(alice, [{key: '-'}])).to.be.fulfilled;121122 // dot symbol123 await expect(collection.setProperties(alice, [{key: 'once.in.a.long.long.while...', value: 'you get a little lost'}])).to.be.fulfilled;124125 const properties = await collection.getProperties();126 expect(properties).to.include.deep.members([127 {key: 'answer', value: ''},128 {key: '451', value: ''},129 {key: 'black_hole', value: ''},130 {key: '-', value: ''},131 {key: 'once.in.a.long.long.while...', value: 'you get a little lost'},132 ]);133 }134135 itSub('Check valid names for NFT collection properties keys', async ({helper}) => {136 await testCheckValidNames(await helper.nft.mintCollection(alice));137 });138139 itSub.ifWithPallets('Check valid names for ReFungible collection properties keys', [Pallets.ReFungible], async ({helper}) => {140 await testCheckValidNames(await helper.rft.mintCollection(alice));141 });142143 async function testChangesProperties(collection: UniqueBaseCollection) {144 await expect(collection.setProperties(alice, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: ''}])).to.be.fulfilled;145146 // Mutate the properties147 await expect(collection.setProperties(alice, [{key: 'black_hole', value: 'LIGO'}])).to.be.fulfilled;148149 const properties = await collection.getProperties();150 expect(properties).to.include.deep.members([151 {key: 'electron', value: 'come bond'},152 {key: 'black_hole', value: 'LIGO'},153 ]);154 }155156 itSub('Changes properties of a NFT collection', async ({helper}) => {157 await testChangesProperties(await helper.nft.mintCollection(alice));158 });159160 itSub.ifWithPallets('Changes properties of a ReFungible collection', [Pallets.ReFungible], async ({helper}) => {161 await testChangesProperties(await helper.rft.mintCollection(alice));162 });163164 async function testDeleteProperties(collection: UniqueBaseCollection) {165 await expect(collection.setProperties(alice, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: 'LIGO'}])).to.be.fulfilled;166167 await expect(collection.deleteProperties(alice, ['electron'])).to.be.fulfilled;168169 const properties = await collection.getProperties(['black_hole', 'electron']);170 expect(properties).to.be.deep.equal([171 {key: 'black_hole', value: 'LIGO'},172 ]);173 }174175 itSub('Deletes properties of a NFT collection', async ({helper}) => {176 await testDeleteProperties(await helper.nft.mintCollection(alice));177 });178179 itSub.ifWithPallets('Deletes properties of a ReFungible collection', [Pallets.ReFungible], async ({helper}) => {180 await testDeleteProperties(await helper.rft.mintCollection(alice));181 });182});183184describe('Negative Integration Test: Collection Properties', () => {185 let alice: IKeyringPair;186 let bob: IKeyringPair;187188 before(async () => {189 await usingPlaygrounds(async (helper, privateKey) => {190 const donor = privateKey('//Alice');191 [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);192 });193 });194 195 async function testFailsSetPropertiesIfNotOwnerOrAdmin(collection: UniqueBaseCollection) { 196 await expect(collection.setProperties(bob, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: 'LIGO'}]))197 .to.be.rejectedWith(/common\.NoPermission/);198199 const properties = await collection.getProperties();200 expect(properties).to.be.empty;201 }202203 itSub('Fails to set properties in a NFT collection if not its onwer/administrator', async ({helper}) => {204 await testFailsSetPropertiesIfNotOwnerOrAdmin(await helper.nft.mintCollection(alice));205 });206207 itSub.ifWithPallets('Fails to set properties in a ReFungible collection if not its onwer/administrator', [Pallets.ReFungible], async ({helper}) => {208 await testFailsSetPropertiesIfNotOwnerOrAdmin(await helper.rft.mintCollection(alice));209 });210 211 async function testFailsSetPropertiesThatExeedLimits(collection: UniqueBaseCollection) {212 const spaceLimit = (await (collection.helper!.api! as any).query.common.collectionProperties(collection.collectionId)).spaceLimit.toNumber();213 214 // Mute the general tx parsing error, too many bytes to process215 {216 console.error = () => {};217 await expect(collection.setProperties(alice, [218 {key: 'electron', value: 'low high '.repeat(Math.ceil(spaceLimit! / 9))},219 ])).to.be.rejected;220 }221222 expect(await collection.getProperties(['electron'])).to.be.empty;223224 await expect(collection.setProperties(alice, [225 {key: 'electron', value: 'low high '.repeat(Math.ceil(spaceLimit! / 18))}, 226 {key: 'black_hole', value: '0'.repeat(Math.ceil(spaceLimit! / 2))}, 227 ])).to.be.rejectedWith(/common\.NoSpaceForProperty/);228229 expect(await collection.getProperties(['electron', 'black_hole'])).to.be.empty;230 }231232 itSub('Fails to set properties that exceed the limits (NFT)', async ({helper}) => {233 await testFailsSetPropertiesThatExeedLimits(await helper.nft.mintCollection(alice));234 });235236 itSub.ifWithPallets('Fails to set properties that exceed the limits (ReFungible)', [Pallets.ReFungible], async ({helper}) => {237 await testFailsSetPropertiesThatExeedLimits(await helper.rft.mintCollection(alice));238 });239 240 async function testFailsSetMorePropertiesThanAllowed(collection: UniqueBaseCollection) {241 const propertiesToBeSet = [];242 for (let i = 0; i < 65; i++) {243 propertiesToBeSet.push({244 key: 'electron_' + i,245 value: Math.random() > 0.5 ? 'high' : 'low',246 });247 }248249 await expect(collection.setProperties(alice, propertiesToBeSet)).250 to.be.rejectedWith(/common\.PropertyLimitReached/);251252 const properties = await collection.getProperties();253 expect(properties).to.be.empty;254 }255256 itSub('Fails to set more properties than it is allowed (NFT)', async ({helper}) => {257 await testFailsSetMorePropertiesThanAllowed(await helper.nft.mintCollection(alice));258 });259260 itSub.ifWithPallets('Fails to set more properties than it is allowed (ReFungible)', [Pallets.ReFungible], async ({helper}) => {261 await testFailsSetMorePropertiesThanAllowed(await helper.rft.mintCollection(alice));262 });263 264 async function testFailsSetPropertiesWithInvalidNames(collection: UniqueBaseCollection) {265 const invalidProperties = [266 [{key: 'electron', value: 'negative'}, {key: 'string theory', value: 'understandable'}],267 [{key: 'Mr/Sandman', value: 'Bring me a gene'}],268 [{key: 'déjà vu', value: 'hmm...'}],269 ];270271 for (let i = 0; i < invalidProperties.length; i++) {272 await expect(273 collection.setProperties(alice, invalidProperties[i]), 274 `on rejecting the new badly-named property #${i}`,275 ).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);276 }277278 await expect(279 collection.setProperties(alice, [{key: '', value: 'nothing must not exist'}]), 280 'on rejecting an unnamed property',281 ).to.be.rejectedWith(/common\.EmptyPropertyKey/);282283 await expect(284 collection.setProperties(alice, [{key: 'CRISPR-Cas9', value: 'rewriting nature!'}]), 285 'on setting the correctly-but-still-badly-named property',286 ).to.be.fulfilled;287288 const keys = invalidProperties.flatMap(propertySet => propertySet.map(property => property.key)).concat('CRISPR-Cas9').concat('');289290 const properties = await collection.getProperties(keys);291 expect(properties).to.be.deep.equal([292 {key: 'CRISPR-Cas9', value: 'rewriting nature!'},293 ]);294295 for (let i = 0; i < invalidProperties.length; i++) {296 await expect(297 collection.deleteProperties(alice, invalidProperties[i].map(propertySet => propertySet.key)), 298 `on trying to delete the non-existent badly-named property #${i}`,299 ).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);300 }301 }302303 itSub('Fails to set properties with invalid names (NFT)', async ({helper}) => {304 await testFailsSetPropertiesWithInvalidNames(await helper.nft.mintCollection(alice));305 });306307 itSub.ifWithPallets('Fails to set properties with invalid names (ReFungible)', [Pallets.ReFungible], async ({helper}) => {308 await testFailsSetPropertiesWithInvalidNames(await helper.rft.mintCollection(alice));309 });310});311312// ---------- ACCESS RIGHTS313314describe('Integration Test: Access Rights to Token Properties', () => {315 let alice: IKeyringPair;316 let bob: IKeyringPair;317318 before(async () => {319 await usingPlaygrounds(async (helper, privateKey) => {320 const donor = privateKey('//Alice');321 [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);322 });323 });324 325 itSub('Reads access rights to properties of a collection', async ({helper}) => {326 const collection = await helper.nft.mintCollection(alice);327 const propertyRights = (await helper.callRpc('api.query.common.collectionPropertyPermissions', [collection.collectionId])).toJSON();328 expect(propertyRights).to.be.empty;329 });330 331 async function testSetsAccessRightsToProperties(collection: UniqueNFTCollection | UniqueRFTCollection) { 332 await expect(collection.setTokenPropertyPermissions(alice, [{key: 'skullduggery', permission: {mutable: true}}]))333 .to.be.fulfilled;334335 await collection.addAdmin(alice, {Substrate: bob.address});336337 await expect(collection.setTokenPropertyPermissions(bob, [{key: 'mindgame', permission: {collectionAdmin: true, tokenOwner: false}}]))338 .to.be.fulfilled;339340 const propertyRights = await collection.getPropertyPermissions(['skullduggery', 'mindgame']);341 expect(propertyRights).to.include.deep.members([342 {key: 'skullduggery', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}},343 {key: 'mindgame', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}},344 ]);345 }346347 itSub('Sets access rights to properties of a collection (NFT)', async ({helper}) => {348 await testSetsAccessRightsToProperties(await helper.nft.mintCollection(alice));349 });350351 itSub.ifWithPallets('Sets access rights to properties of a collection (ReFungible)', [Pallets.ReFungible], async ({helper}) => {352 await testSetsAccessRightsToProperties(await helper.rft.mintCollection(alice));353 });354 355 async function testChangesAccessRightsToProperty(collection: UniqueNFTCollection | UniqueRFTCollection) {356 await expect(collection.setTokenPropertyPermissions(alice, [{key: 'skullduggery', permission: {mutable: true, collectionAdmin: true}}]))357 .to.be.fulfilled;358359 await expect(collection.setTokenPropertyPermissions(alice, [{key: 'skullduggery', permission: {mutable: false, tokenOwner: true}}]))360 .to.be.fulfilled;361362 const propertyRights = await collection.getPropertyPermissions();363 expect(propertyRights).to.be.deep.equal([364 {key: 'skullduggery', permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},365 ]);366 }367368 itSub('Changes access rights to properties of a NFT collection', async ({helper}) => {369 await testChangesAccessRightsToProperty(await helper.nft.mintCollection(alice));370 });371372 itSub.ifWithPallets('Changes access rights to properties of a ReFungible collection', [Pallets.ReFungible], async ({helper}) => {373 await testChangesAccessRightsToProperty(await helper.rft.mintCollection(alice));374 });375});376377describe('Negative Integration Test: Access Rights to Token Properties', () => {378 let alice: IKeyringPair;379 let bob: IKeyringPair;380381 before(async () => {382 await usingPlaygrounds(async (helper, privateKey) => {383 const donor = privateKey('//Alice');384 [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);385 });386 });387388 async function testPreventsFromSettingAccessRightsNotAdminOrOwner(collection: UniqueNFTCollection | UniqueRFTCollection) {389 await expect(collection.setTokenPropertyPermissions(bob, [{key: 'skullduggery', permission: {mutable: true, tokenOwner: true}}]))390 .to.be.rejectedWith(/common\.NoPermission/);391392 const propertyRights = await collection.getPropertyPermissions(['skullduggery']);393 expect(propertyRights).to.be.empty;394 }395396 itSub('Prevents from setting access rights to properties of a NFT collection if not an onwer/admin', async ({helper}) => {397 await testPreventsFromSettingAccessRightsNotAdminOrOwner(await helper.nft.mintCollection(alice));398 });399400 itSub.ifWithPallets('Prevents from setting access rights to properties of a ReFungible collection if not an onwer/admin', [Pallets.ReFungible], async ({helper}) => {401 await testPreventsFromSettingAccessRightsNotAdminOrOwner(await helper.rft.mintCollection(alice));402 });403404 async function testPreventFromAddingTooManyPossibleProperties(collection: UniqueNFTCollection | UniqueRFTCollection) { 405 const constitution = [];406 for (let i = 0; i < 65; i++) {407 constitution.push({408 key: 'property_' + i,409 permission: Math.random() > 0.5 ? {mutable: true, collectionAdmin: true, tokenOwner: true} : {},410 });411 }412413 await expect(collection.setTokenPropertyPermissions(alice, constitution))414 .to.be.rejectedWith(/common\.PropertyLimitReached/);415416 const propertyRights = await collection.getPropertyPermissions();417 expect(propertyRights).to.be.empty;418 }419420 itSub('Prevents from adding too many possible properties (NFT)', async ({helper}) => {421 await testPreventFromAddingTooManyPossibleProperties(await helper.nft.mintCollection(alice));422 });423424 itSub.ifWithPallets('Prevents from adding too many possible properties (ReFungible)', [Pallets.ReFungible], async ({helper}) => {425 await testPreventFromAddingTooManyPossibleProperties(await helper.rft.mintCollection(alice));426 });427428 async function testPreventAccessRightsModifiedIfConstant(collection: UniqueNFTCollection | UniqueRFTCollection) {429 await expect(collection.setTokenPropertyPermissions(alice, [{key: 'skullduggery', permission: {mutable: false, tokenOwner: true}}]))430 .to.be.fulfilled;431432 await expect(collection.setTokenPropertyPermissions(alice, [{key: 'skullduggery', permission: {collectionAdmin: true}}]))433 .to.be.rejectedWith(/common\.NoPermission/);434435 const propertyRights = await collection.getPropertyPermissions(['skullduggery']);436 expect(propertyRights).to.deep.equal([437 {key: 'skullduggery', permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},438 ]);439 }440441 itSub('Prevents access rights to be modified if constant (NFT)', async ({helper}) => {442 await testPreventAccessRightsModifiedIfConstant(await helper.nft.mintCollection(alice));443 });444445 itSub.ifWithPallets('Prevents access rights to be modified if constant (ReFungible)', [Pallets.ReFungible], async ({helper}) => {446 await testPreventAccessRightsModifiedIfConstant(await helper.rft.mintCollection(alice));447 });448449 async function testPreventsAddingPropertiesWithInvalidNames(collection: UniqueNFTCollection | UniqueRFTCollection) {450 const invalidProperties = [451 [{key: 'skullduggery', permission: {tokenOwner: true}}, {key: 'im possible', permission: {collectionAdmin: true}}],452 [{key: 'G#4', permission: {tokenOwner: true}}],453 [{key: 'HÆMILTON', permission: {mutable: false, collectionAdmin: true, tokenOwner: true}}],454 ];455456 for (let i = 0; i < invalidProperties.length; i++) {457 await expect(458 collection.setTokenPropertyPermissions(alice, invalidProperties[i]), 459 `on setting the new badly-named property #${i}`,460 ).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);461 }462463 await expect(464 collection.setTokenPropertyPermissions(alice, [{key: '', permission: {}}]), 465 'on rejecting an unnamed property',466 ).to.be.rejectedWith(/common\.EmptyPropertyKey/);467468 const correctKey = '--0x03116e387820CA05'; // PolkadotJS would parse this as an already encoded hex-string469 await expect(470 collection.setTokenPropertyPermissions(alice, [471 {key: correctKey, permission: {collectionAdmin: true}},472 ]), 473 'on setting the correctly-but-still-badly-named property',474 ).to.be.fulfilled;475476 const keys = invalidProperties.flatMap(propertySet => propertySet.map(property => property.key)).concat(correctKey).concat('');477478 const propertyRights = await collection.getPropertyPermissions(keys);479 expect(propertyRights).to.be.deep.equal([480 {key: correctKey, permission: {mutable: false, collectionAdmin: true, tokenOwner: false}},481 ]);482 }483484 itSub('Prevents adding properties with invalid names (NFT)', async ({helper}) => {485 await testPreventsAddingPropertiesWithInvalidNames(await helper.nft.mintCollection(alice));486 });487488 itSub.ifWithPallets('Prevents adding properties with invalid names (ReFungible)', [Pallets.ReFungible], async ({helper}) => {489 await testPreventsAddingPropertiesWithInvalidNames(await helper.rft.mintCollection(alice));490 });491});492493// ---------- TOKEN PROPERTIES494495describe('Integration Test: Token Properties', () => {496 let alice: IKeyringPair; // collection owner497 let bob: IKeyringPair; // collection admin498 let charlie: IKeyringPair; // token owner499500 let permissions: {permission: any, signers: IKeyringPair[]}[];501502 before(async () => {503 await usingPlaygrounds(async (helper, privateKey) => {504 const donor = privateKey('//Alice');505 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);506 });507508 // todo:playgrounds probably separate these tests later509 permissions = [510 {permission: {mutable: true, collectionAdmin: true}, signers: [alice, bob]},511 {permission: {mutable: false, collectionAdmin: true}, signers: [alice, bob]},512 {permission: {mutable: true, tokenOwner: true}, signers: [charlie]},513 {permission: {mutable: false, tokenOwner: true}, signers: [charlie]},514 {permission: {mutable: true, collectionAdmin: true, tokenOwner: true}, signers: [alice, bob, charlie]},515 {permission: {mutable: false, collectionAdmin: true, tokenOwner: true}, signers: [alice, bob, charlie]},516 ];517 });518 519 async function testReadsYetEmptyProperties(token: UniqueNFToken | UniqueRFToken) {520 const properties = await token.getProperties();521 expect(properties).to.be.empty;522523 const tokenData = await token.getData();524 expect(tokenData!.properties).to.be.empty;525 }526527 itSub('Reads yet empty properties of a token (NFT)', async ({helper}) => {528 const collection = await helper.nft.mintCollection(alice);529 const token = await collection.mintToken(alice);530 await testReadsYetEmptyProperties(token);531 });532533 itSub.ifWithPallets('Reads yet empty properties of a token (ReFungible)', [Pallets.ReFungible], async ({helper}) => {534 const collection = await helper.rft.mintCollection(alice);535 const token = await collection.mintToken(alice);536 await testReadsYetEmptyProperties(token);537 });538539 async function testAssignPropertiesAccordingToPermissions(token: UniqueNFToken | UniqueRFToken, pieces: bigint) {540 await token.collection.addAdmin(alice, {Substrate: bob.address});541 await token.transfer(alice, {Substrate: charlie.address}, pieces);542543 const propertyKeys: string[] = [];544 let i = 0;545 for (const permission of permissions) {546 i++;547 let j = 0;548 for (const signer of permission.signers) {549 j++;550 const key = i + '_' + signer.address;551 propertyKeys.push(key);552553 await expect(554 token.collection.setTokenPropertyPermissions(alice, [{key: key, permission: permission.permission}]), 555 `on setting permission #${i} by alice`,556 ).to.be.fulfilled;557558 await expect(559 token.setProperties(signer, [{key: key, value: 'Serotonin increase'}]), 560 `on adding property #${i} by signer #${j}`,561 ).to.be.fulfilled;562 }563 }564565 const properties = await token.getProperties(propertyKeys);566 const tokenData = await token.getData();567 for (let i = 0; i < properties.length; i++) {568 expect(properties[i].value).to.be.equal('Serotonin increase');569 expect(tokenData!.properties[i].value).to.be.equal('Serotonin increase');570 }571 }572573 itSub('Assigns properties to a token according to permissions (NFT)', async ({helper}) => {574 const collection = await helper.nft.mintCollection(alice);575 const token = await collection.mintToken(alice);576 await testAssignPropertiesAccordingToPermissions(token, 1n);577 });578579 itSub.ifWithPallets('Assigns properties to a token according to permissions (ReFungible)', [Pallets.ReFungible], async ({helper}) => {580 const collection = await helper.rft.mintCollection(alice);581 const token = await collection.mintToken(alice, 100n);582 await testAssignPropertiesAccordingToPermissions(token, 100n);583 });584585 async function testChangesPropertiesAccordingPermission(token: UniqueNFToken | UniqueRFToken, pieces: bigint) {586 await token.collection.addAdmin(alice, {Substrate: bob.address});587 await token.transfer(alice, {Substrate: charlie.address}, pieces);588589 const propertyKeys: string[] = [];590 let i = 0;591 for (const permission of permissions) {592 i++;593 if (!permission.permission.mutable) continue;594 595 let j = 0;596 for (const signer of permission.signers) {597 j++;598 const key = i + '_' + signer.address;599 propertyKeys.push(key);600601 await expect(602 token.collection.setTokenPropertyPermissions(alice, [{key: key, permission: permission.permission}]), 603 `on setting permission #${i} by alice`,604 ).to.be.fulfilled;605606 await expect(607 token.setProperties(signer, [{key, value: 'Serotonin increase'}]), 608 `on adding property #${i} by signer #${j}`,609 ).to.be.fulfilled;610611 await expect(612 token.setProperties(signer, [{key, value: 'Serotonin stable'}]), 613 `on changing property #${i} by signer #${j}`,614 ).to.be.fulfilled;615 }616 }617618 const properties = await token.getProperties(propertyKeys);619 const tokenData = await token.getData();620 for (let i = 0; i < properties.length; i++) {621 expect(properties[i].value).to.be.equal('Serotonin stable');622 expect(tokenData!.properties[i].value).to.be.equal('Serotonin stable');623 }624 }625626 itSub('Changes properties of a token according to permissions (NFT)', async ({helper}) => {627 const collection = await helper.nft.mintCollection(alice);628 const token = await collection.mintToken(alice);629 await testChangesPropertiesAccordingPermission(token, 1n);630 });631632 itSub.ifWithPallets('Changes properties of a token according to permissions (ReFungible)', [Pallets.ReFungible], async ({helper}) => {633 const collection = await helper.rft.mintCollection(alice);634 const token = await collection.mintToken(alice, 100n);635 await testChangesPropertiesAccordingPermission(token, 100n);636 });637638 async function testDeletePropertiesAccordingPermission(token: UniqueNFToken | UniqueRFToken, pieces: bigint) {639 await token.collection.addAdmin(alice, {Substrate: bob.address});640 await token.transfer(alice, {Substrate: charlie.address}, pieces);641642 const propertyKeys: string[] = [];643 let i = 0;644645 for (const permission of permissions) {646 i++;647 if (!permission.permission.mutable) continue;648 649 let j = 0;650 for (const signer of permission.signers) {651 j++;652 const key = i + '_' + signer.address;653 propertyKeys.push(key);654655 await expect(656 token.collection.setTokenPropertyPermissions(alice, [{key: key, permission: permission.permission}]), 657 `on setting permission #${i} by alice`,658 ).to.be.fulfilled;659660 await expect(661 token.setProperties(signer, [{key, value: 'Serotonin increase'}]), 662 `on adding property #${i} by signer #${j}`,663 ).to.be.fulfilled;664665 await expect(666 token.deleteProperties(signer, [key]), 667 `on deleting property #${i} by signer #${j}`,668 ).to.be.fulfilled;669 }670 }671672 expect(await token.getProperties(propertyKeys)).to.be.empty;673 expect((await token.getData())!.properties).to.be.empty;674 }675 676 itSub('Deletes properties of a token according to permissions (NFT)', async ({helper}) => {677 const collection = await helper.nft.mintCollection(alice);678 const token = await collection.mintToken(alice);679 await testDeletePropertiesAccordingPermission(token, 1n);680 });681682 itSub.ifWithPallets('Deletes properties of a token according to permissions (ReFungible)', [Pallets.ReFungible], async ({helper}) => {683 const collection = await helper.rft.mintCollection(alice);684 const token = await collection.mintToken(alice, 100n);685 await testDeletePropertiesAccordingPermission(token, 100n);686 });687688 itSub('Assigns properties to a nested token according to permissions', async ({helper}) => {689 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});690 const collectionB = await helper.nft.mintCollection(alice);691 const targetToken = await collectionA.mintToken(alice);692 const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAccount());693694 await collectionB.addAdmin(alice, {Substrate: bob.address});695 await targetToken.transfer(alice, {Substrate: charlie.address});696697 const propertyKeys: string[] = [];698 let i = 0;699 for (const permission of permissions) {700 i++;701 let j = 0;702 for (const signer of permission.signers) {703 j++;704 const key = i + '_' + signer.address;705 propertyKeys.push(key);706 707 await expect(708 nestedToken.collection.setTokenPropertyPermissions(alice, [{key: key, permission: permission.permission}]), 709 `on setting permission #${i} by alice`,710 ).to.be.fulfilled;711712 await expect(713 nestedToken.setProperties(signer, [{key, value: 'Serotonin increase'}]), 714 `on adding property #${i} by signer #${j}`,715 ).to.be.fulfilled;716 }717 }718719 const properties = await nestedToken.getProperties(propertyKeys);720 const tokenData = await nestedToken.getData();721 for (let i = 0; i < properties.length; i++) {722 expect(properties[i].value).to.be.equal('Serotonin increase');723 expect(tokenData!.properties[i].value).to.be.equal('Serotonin increase');724 }725 expect(await targetToken.getProperties()).to.be.empty;726 });727728 itSub('Changes properties of a nested token according to permissions', async ({helper}) => {729 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});730 const collectionB = await helper.nft.mintCollection(alice);731 const targetToken = await collectionA.mintToken(alice);732 const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAccount());733734 await collectionB.addAdmin(alice, {Substrate: bob.address});735 await targetToken.transfer(alice, {Substrate: charlie.address});736737 const propertyKeys: string[] = [];738 let i = 0;739 for (const permission of permissions) {740 i++;741 if (!permission.permission.mutable) continue;742 743 let j = 0;744 for (const signer of permission.signers) {745 j++;746 const key = i + '_' + signer.address;747 propertyKeys.push(key);748749 await expect(750 nestedToken.collection.setTokenPropertyPermissions(alice, [{key: key, permission: permission.permission}]), 751 `on setting permission #${i} by alice`,752 ).to.be.fulfilled;753754 await expect(755 nestedToken.setProperties(signer, [{key, value: 'Serotonin increase'}]), 756 `on adding property #${i} by signer #${j}`,757 ).to.be.fulfilled;758759 await expect(760 nestedToken.setProperties(signer, [{key, value: 'Serotonin stable'}]), 761 `on changing property #${i} by signer #${j}`,762 ).to.be.fulfilled;763 }764 }765766 const properties = await nestedToken.getProperties(propertyKeys);767 const tokenData = await nestedToken.getData();768 for (let i = 0; i < properties.length; i++) {769 expect(properties[i].value).to.be.equal('Serotonin stable');770 expect(tokenData!.properties[i].value).to.be.equal('Serotonin stable');771 }772 expect(await targetToken.getProperties()).to.be.empty;773 });774775 itSub('Deletes properties of a nested token according to permissions', async ({helper}) => {776 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});777 const collectionB = await helper.nft.mintCollection(alice);778 const targetToken = await collectionA.mintToken(alice);779 const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAccount());780781 await collectionB.addAdmin(alice, {Substrate: bob.address});782 await targetToken.transfer(alice, {Substrate: charlie.address});783784 const propertyKeys: string[] = [];785 let i = 0;786 for (const permission of permissions) {787 i++;788 if (!permission.permission.mutable) continue;789 790 let j = 0;791 for (const signer of permission.signers) {792 j++;793 const key = i + '_' + signer.address;794 propertyKeys.push(key);795796 await expect(797 nestedToken.collection.setTokenPropertyPermissions(alice, [{key: key, permission: permission.permission}]), 798 `on setting permission #${i} by alice`,799 ).to.be.fulfilled;800801 await expect(802 nestedToken.setProperties(signer, [{key, value: 'Serotonin increase'}]), 803 `on adding property #${i} by signer #${j}`,804 ).to.be.fulfilled;805806 await expect(807 nestedToken.deleteProperties(signer, [key]), 808 `on deleting property #${i} by signer #${j}`,809 ).to.be.fulfilled;810 }811 }812813 expect(await nestedToken.getProperties(propertyKeys)).to.be.empty;814 expect((await nestedToken.getData())!.properties).to.be.empty;815 expect(await targetToken.getProperties()).to.be.empty;816 });817});818819describe('Negative Integration Test: Token Properties', () => {820 let alice: IKeyringPair; // collection owner821 let bob: IKeyringPair; // collection admin822 let charlie: IKeyringPair; // token owner823824 let constitution: {permission: any, signers: IKeyringPair[], sinner: IKeyringPair}[];825826 before(async () => {827 await usingPlaygrounds(async (helper, privateKey) => {828 const donor = privateKey('//Alice');829 let dave: IKeyringPair;830 [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);831832 // todo:playgrounds probably separate these tests later833 constitution = [834 {permission: {mutable: true, collectionAdmin: true}, signers: [alice, bob], sinner: charlie},835 {permission: {mutable: false, collectionAdmin: true}, signers: [alice, bob], sinner: charlie},836 {permission: {mutable: true, tokenOwner: true}, signers: [charlie], sinner: alice},837 {permission: {mutable: false, tokenOwner: true}, signers: [charlie], sinner: alice},838 {permission: {mutable: true, collectionAdmin: true, tokenOwner: true}, signers: [alice, bob, charlie], sinner: dave},839 {permission: {mutable: false, collectionAdmin: true, tokenOwner: true}, signers: [alice, bob, charlie], sinner: dave},840 ];841 });842 });843844 async function getConsumedSpace(api: any, collectionId: number, tokenId: number, mode: 'NFT' | 'RFT'): Promise<number> {845 return (await (mode == 'NFT' ? api.query.nonfungible : api.query.refungible).tokenProperties(collectionId, tokenId)).toJSON().consumedSpace;846 }847848 async function prepare(token: UniqueNFToken | UniqueRFToken, pieces: bigint): Promise<number> {849 await token.collection.addAdmin(alice, {Substrate: bob.address});850 await token.transfer(alice, {Substrate: charlie.address}, pieces);851852 let i = 0;853 for (const passage of constitution) {854 i++;855 const signer = passage.signers[0];856 857 await expect(858 token.collection.setTokenPropertyPermissions(alice, [{key: `${i}`, permission: passage.permission}]), 859 `on setting permission ${i} by alice`,860 ).to.be.fulfilled;861862 await expect(863 token.setProperties(signer, [{key: `${i}`, value: 'Serotonin increase'}]), 864 `on adding property ${i} by ${signer.address}`,865 ).to.be.fulfilled;866 }867868 const originalSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT'); 869 return originalSpace;870 }871872 async function testForbidsChangingDeletingPropertiesUserOutsideOfPermissions(token: UniqueNFToken | UniqueRFToken, pieces: bigint) {873 const originalSpace = await prepare(token, pieces);874875 let i = 0;876 for (const forbiddance of constitution) {877 i++;878 if (!forbiddance.permission.mutable) continue;879880 await expect(881 token.setProperties(forbiddance.sinner, [{key: `${i}`, value: 'Serotonin down'}]), 882 `on failing to change property ${i} by the malefactor`,883 ).to.be.rejectedWith(/common\.NoPermission/);884885 await expect(886 token.deleteProperties(forbiddance.sinner, [`${i}`]), 887 `on failing to delete property ${i} by the malefactor`,888 ).to.be.rejectedWith(/common\.NoPermission/);889 }890891 const consumedSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT'); 892 expect(consumedSpace).to.be.equal(originalSpace);893 }894895 itSub('Forbids changing/deleting properties of a token if the user is outside of permissions (NFT)', async ({helper}) => {896 const collection = await helper.nft.mintCollection(alice);897 const token = await collection.mintToken(alice);898 await testForbidsChangingDeletingPropertiesUserOutsideOfPermissions(token, 1n);899 });900901 itSub.ifWithPallets('Forbids changing/deleting properties of a token if the user is outside of permissions (ReFungible)', [Pallets.ReFungible], async ({helper}) => {902 const collection = await helper.rft.mintCollection(alice);903 const token = await collection.mintToken(alice, 100n);904 await testForbidsChangingDeletingPropertiesUserOutsideOfPermissions(token, 100n);905 });906907 async function testForbidsChangingDeletingPropertiesIfPropertyImmutable(token: UniqueNFToken | UniqueRFToken, pieces: bigint) {908 const originalSpace = await prepare(token, pieces);909910 let i = 0;911 for (const permission of constitution) {912 i++;913 if (permission.permission.mutable) continue;914915 await expect(916 token.setProperties(permission.signers[0], [{key: `${i}`, value: 'Serotonin down'}]), 917 `on failing to change property ${i} by signer #0`,918 ).to.be.rejectedWith(/common\.NoPermission/);919920 await expect(921 token.deleteProperties(permission.signers[0], [i.toString()]), 922 `on failing to delete property ${i} by signer #0`,923 ).to.be.rejectedWith(/common\.NoPermission/);924 }925 926 const consumedSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT'); 927 expect(consumedSpace).to.be.equal(originalSpace);928 }929930 itSub('Forbids changing/deleting properties of a token if the property is permanent (immutable) (NFT)', async ({helper}) => {931 const collection = await helper.nft.mintCollection(alice);932 const token = await collection.mintToken(alice);933 await testForbidsChangingDeletingPropertiesIfPropertyImmutable(token, 1n);934 });935936 itSub.ifWithPallets('Forbids changing/deleting properties of a token if the property is permanent (immutable) (ReFungible)', [Pallets.ReFungible], async ({helper}) => {937 const collection = await helper.rft.mintCollection(alice);938 const token = await collection.mintToken(alice, 100n);939 await testForbidsChangingDeletingPropertiesIfPropertyImmutable(token, 100n);940 });941942 async function testForbidsAddingPropertiesIfPropertyNotDeclared(token: UniqueNFToken | UniqueRFToken, pieces: bigint) {943 const originalSpace = await prepare(token, pieces);944945 await expect(946 token.setProperties(alice, [{key: 'non-existent', value: 'I exist!'}]), 947 'on failing to add a previously non-existent property',948 ).to.be.rejectedWith(/common\.NoPermission/);949 950 await expect(951 token.collection.setTokenPropertyPermissions(alice, [{key: 'now-existent', permission: {}}]), 952 'on setting a new non-permitted property',953 ).to.be.fulfilled;954955 await expect(956 token.setProperties(alice, [{key: 'now-existent', value: 'I exist!'}]), 957 'on failing to add a property forbidden by the \'None\' permission',958 ).to.be.rejectedWith(/common\.NoPermission/);959960 expect(await token.getProperties(['non-existent', 'now-existent'])).to.be.empty;961 962 const consumedSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT'); 963 expect(consumedSpace).to.be.equal(originalSpace);964 }965966 itSub('Forbids adding properties to a token if the property is not declared / forbidden with the \'None\' permission (NFT)', async ({helper}) => {967 const collection = await helper.nft.mintCollection(alice);968 const token = await collection.mintToken(alice);969 await testForbidsAddingPropertiesIfPropertyNotDeclared(token, 1n);970 });971972 itSub.ifWithPallets('Forbids adding properties to a token if the property is not declared / forbidden with the \'None\' permission (ReFungible)', [Pallets.ReFungible], async ({helper}) => {973 const collection = await helper.rft.mintCollection(alice);974 const token = await collection.mintToken(alice, 100n);975 await testForbidsAddingPropertiesIfPropertyNotDeclared(token, 100n);976 });977978 async function testForbidsAddingTooManyProperties(token: UniqueNFToken | UniqueRFToken, pieces: bigint) {979 const originalSpace = await prepare(token, pieces);980981 await expect(982 token.collection.setTokenPropertyPermissions(alice, [983 {key: 'a_holy_book', permission: {collectionAdmin: true, tokenOwner: true}}, 984 {key: 'young_years', permission: {collectionAdmin: true, tokenOwner: true}},985 ]), 986 'on setting new permissions for properties',987 ).to.be.fulfilled;988989 // Mute the general tx parsing error990 {991 console.error = () => {};992 await expect(token.setProperties(alice, [{key: 'a_holy_book', value: 'word '.repeat(6554)}]))993 .to.be.rejected;994 }995996 await expect(token.setProperties(alice, [997 {key: 'a_holy_book', value: 'word '.repeat(3277)}, 998 {key: 'young_years', value: 'neverending'.repeat(1490)},999 ])).to.be.rejectedWith(/common\.NoSpaceForProperty/);1000 1001 expect(await token.getProperties(['a_holy_book', 'young_years'])).to.be.empty;1002 const consumedSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT'); 1003 expect(consumedSpace).to.be.equal(originalSpace);1004 }10051006 itSub('Forbids adding too many properties to a token (NFT)', async ({helper}) => {1007 const collection = await helper.nft.mintCollection(alice);1008 const token = await collection.mintToken(alice);1009 await testForbidsAddingTooManyProperties(token, 1n);1010 });10111012 itSub.ifWithPallets('Forbids adding too many properties to a token (ReFungible)', [Pallets.ReFungible], async ({helper}) => {1013 const collection = await helper.rft.mintCollection(alice);1014 const token = await collection.mintToken(alice, 100n);1015 await testForbidsAddingTooManyProperties(token, 100n);1016 });1017});10181019describe('ReFungible token properties permissions tests', () => {1020 let alice: IKeyringPair;1021 let bob: IKeyringPair;1022 let charlie: IKeyringPair;10231024 before(async function() {1025 await usingPlaygrounds(async (helper, privateKey) => {1026 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);10271028 const donor = privateKey('//Alice');1029 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);1030 });1031 });10321033 async function prepare(helper: UniqueHelper): Promise<UniqueRFToken> {1034 const collection = await helper.rft.mintCollection(alice);1035 const token = await collection.mintToken(alice, 100n);1036 1037 await collection.addAdmin(alice, {Substrate: bob.address});1038 await collection.setTokenPropertyPermissions(alice, [{key: 'fractals', permission: {mutable: true, tokenOwner: true}}]);1039 1040 return token;1041 }10421043 itSub('Forbids adding token property with tokenOwner==true when signer doesn\'t have all pieces', async ({helper}) => {1044 const token = await prepare(helper);10451046 await token.transfer(alice, {Substrate: charlie.address}, 33n);10471048 await expect(token.setProperties(alice, [1049 {key: 'fractals', value: 'multiverse'}, 1050 ])).to.be.rejectedWith(/common\.NoPermission/);1051 });10521053 itSub('Forbids mutating token property with tokenOwher==true when signer doesn\'t have all pieces', async ({helper}) => {1054 const token = await prepare(helper);10551056 await expect(token.collection.setTokenPropertyPermissions(alice, [{key: 'fractals', permission: {mutable:true, tokenOwner: true}}]))1057 .to.be.fulfilled;10581059 await expect(token.setProperties(alice, [1060 {key: 'fractals', value: 'multiverse'}, 1061 ])).to.be.fulfilled;10621063 await token.transfer(alice, {Substrate: charlie.address}, 33n);10641065 await expect(token.setProperties(alice, [1066 {key: 'fractals', value: 'want to rule the world'}, 1067 ])).to.be.rejectedWith(/common\.NoPermission/);1068 });10691070 itSub('Forbids deleting token property with tokenOwner==true when signer doesn\'t have all pieces', async ({helper}) => {1071 const token = await prepare(helper);10721073 await expect(token.setProperties(alice, [1074 {key: 'fractals', value: 'one headline - why believe it'}, 1075 ])).to.be.fulfilled;10761077 await token.transfer(alice, {Substrate: charlie.address}, 33n);10781079 await expect(token.deleteProperties(alice, ['fractals'])).1080 to.be.rejectedWith(/common\.NoPermission/);1081 });10821083 itSub('Allows token property mutation with collectionOwner==true when admin doesn\'t have all pieces', async ({helper}) => {1084 const token = await prepare(helper);10851086 await token.transfer(alice, {Substrate: charlie.address}, 33n);10871088 await expect(token.collection.setTokenPropertyPermissions(alice, [{key: 'fractals', permission: {mutable:true, collectionAdmin: true}}]))1089 .to.be.fulfilled;10901091 await expect(token.setProperties(alice, [1092 {key: 'fractals', value: 'multiverse'}, 1093 ])).to.be.fulfilled;1094 });1095});tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -1297,7 +1297,6 @@
async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, mode: 'NFT' | 'RFT'): Promise<UniqueBaseCollection> {
collectionOptions = JSON.parse(JSON.stringify(collectionOptions)) as ICollectionCreationOptions; // Clone object
collectionOptions.mode = (mode === 'NFT') ? {nft: null} : {refungible: null};
- collectionOptions.properties = collectionOptions.properties || [{key: 'ERC721Metadata', value: '1'}];
for (const key of ['name', 'description', 'tokenPrefix']) {
if (typeof collectionOptions[key as 'name' | 'description' | 'tokenPrefix'] === 'string') collectionOptions[key as 'name' | 'description' | 'tokenPrefix'] = this.helper.util.str2vec(collectionOptions[key as 'name' | 'description' | 'tokenPrefix'] as string);
}