difftreelog
CORE-410 Set collection properties for exist collection
in: master
3 files changed
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -298,46 +298,72 @@
fn set_collection_properties(
&self,
- _sender: T::CrossAccountId,
- _property: Vec<Property>,
+ sender: T::CrossAccountId,
+ properties: Vec<Property>,
) -> DispatchResultWithPostInfo {
- fail!(<Error<T>>::SettingPropertiesNotAllowed)
+ let weight = <CommonWeights<T>>::set_collection_properties(properties.len() as u32);
+
+ with_weight(
+ <Pallet<T>>::set_collection_properties(self, &sender, properties),
+ weight,
+ )
}
fn delete_collection_properties(
&self,
- _sender: &T::CrossAccountId,
- _property_keys: Vec<PropertyKey>,
+ sender: &T::CrossAccountId,
+ property_keys: Vec<PropertyKey>,
) -> DispatchResultWithPostInfo {
- fail!(<Error<T>>::SettingPropertiesNotAllowed)
+ let weight = <CommonWeights<T>>::delete_collection_properties(property_keys.len() as u32);
+
+ with_weight(
+ <Pallet<T>>::delete_collection_properties(self, sender, property_keys),
+ weight,
+ )
}
fn set_token_properties(
&self,
- _sender: T::CrossAccountId,
- _token_id: TokenId,
- _property: Vec<Property>,
+ sender: T::CrossAccountId,
+ token_id: TokenId,
+ properties: Vec<Property>,
_nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
- fail!(<Error<T>>::SettingPropertiesNotAllowed)
+ let weight = <CommonWeights<T>>::set_token_properties(properties.len() as u32);
+
+ with_weight(
+ <Pallet<T>>::set_token_properties(self, &sender, token_id, properties, false),
+ weight,
+ )
}
fn set_token_property_permissions(
&self,
- _sender: &T::CrossAccountId,
- _property_permissions: Vec<PropertyKeyPermission>,
+ sender: &T::CrossAccountId,
+ property_permissions: Vec<PropertyKeyPermission>,
) -> DispatchResultWithPostInfo {
- fail!(<Error<T>>::SettingPropertiesNotAllowed)
+ let weight =
+ <CommonWeights<T>>::set_token_property_permissions(property_permissions.len() as u32);
+
+ with_weight(
+ <Pallet<T>>::set_token_property_permissions(self, sender, property_permissions),
+ weight,
+ )
}
fn delete_token_properties(
&self,
- _sender: T::CrossAccountId,
- _token_id: TokenId,
- _property_keys: Vec<PropertyKey>,
+ sender: T::CrossAccountId,
+ token_id: TokenId,
+ property_keys: Vec<PropertyKey>,
_nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
- fail!(<Error<T>>::SettingPropertiesNotAllowed)
+ let weight = <CommonWeights<T>>::delete_token_properties(property_keys.len() as u32);
+
+ with_weight(
+ <Pallet<T>>::delete_token_properties(self, &sender, token_id, property_keys),
+ weight,
+ )
}
fn check_nesting(
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -91,7 +91,7 @@
use up_data_structs::{
AccessMode, CollectionId, CustomDataLimit, MAX_REFUNGIBLE_PIECES, TokenId,
CreateCollectionData, CreateRefungibleExData, mapping::TokenAddressMapping, budget::Budget,
- Property, PropertyScope, TrySetProperty, PropertyKey, PropertyPermission
+ Property, PropertyScope, TrySetProperty, PropertyKey, PropertyPermission, PropertyKeyPermission
};
use pallet_evm::account::CrossAccountId;
use pallet_common::{Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, CommonCollectionOperations as _};
@@ -1064,4 +1064,28 @@
fn total_pieces(collection_id: CollectionId, token_id: TokenId) -> Option<u128> {
<TotalSupply<T>>::try_get((collection_id, token_id)).ok()
}
+
+ pub fn set_collection_properties(
+ collection: &RefungibleHandle<T>,
+ sender: &T::CrossAccountId,
+ properties: Vec<Property>,
+ ) -> DispatchResult {
+ <PalletCommon<T>>::set_collection_properties(collection, sender, properties)
+ }
+
+ pub fn delete_collection_properties(
+ collection: &RefungibleHandle<T>,
+ sender: &T::CrossAccountId,
+ property_keys: Vec<PropertyKey>,
+ ) -> DispatchResult {
+ <PalletCommon<T>>::delete_collection_properties(collection, sender, property_keys)
+ }
+
+ pub fn set_token_property_permissions(
+ collection: &RefungibleHandle<T>,
+ sender: &T::CrossAccountId,
+ property_permissions: Vec<PropertyKeyPermission>,
+ ) -> DispatchResult {
+ <PalletCommon<T>>::set_token_property_permissions(collection, sender, property_permissions)
+ }
}
tests/src/refungible.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {default as usingApi, executeTransaction} from './substrate/substrate-api';18import {IKeyringPair} from '@polkadot/types/types';19import {20 createCollectionExpectSuccess,21 getBalance,22 createMultipleItemsExpectSuccess,23 isTokenExists,24 getLastTokenId,25 getAllowance,26 approve,27 transferFrom,28 createCollection,29 createRefungibleToken,30 transfer,31 burnItem,32 repartitionRFT,33 createCollectionWithPropsExpectSuccess,34 getDetailedCollectionInfo,35} from './util/helpers';3637import chai from 'chai';38import chaiAsPromised from 'chai-as-promised';39chai.use(chaiAsPromised);40const expect = chai.expect;4142let alice: IKeyringPair;43let bob: IKeyringPair;4445describe('integration test: Refungible functionality:', () => {46 before(async () => {47 await usingApi(async (api, privateKeyWrapper) => {48 alice = privateKeyWrapper('//Alice');49 bob = privateKeyWrapper('//Bob');50 });51 });5253 it('Create refungible collection and token', async () => {54 await usingApi(async api => {55 const createCollectionResult = await createCollection(api, alice, {mode: {type: 'ReFungible'}});56 expect(createCollectionResult.success).to.be.true; 57 const collectionId = createCollectionResult.collectionId;5859 const itemCountBefore = await getLastTokenId(api, collectionId);60 const result = await createRefungibleToken(api, alice, collectionId, 100n);6162 const itemCountAfter = await getLastTokenId(api, collectionId);6364 // What to expect65 // tslint:disable-next-line:no-unused-expression66 expect(result.success).to.be.true;67 expect(itemCountAfter).to.be.equal(itemCountBefore + 1);68 expect(collectionId).to.be.equal(result.collectionId);69 expect(itemCountAfter.toString()).to.be.equal(result.itemId.toString());70 });71 });7273 it('Transfer token pieces', async () => {74 await usingApi(async api => {75 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;76 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;7778 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);79 expect(await transfer(api, collectionId, tokenId, alice, bob, 60n)).to.be.true;8081 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(40n);82 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(60n);83 await expect(transfer(api, collectionId, tokenId, alice, bob, 41n)).to.eventually.be.rejected;84 });85 });8687 it('Create multiple tokens', async () => {88 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});89 const args = [90 {ReFungible: {pieces: 1}},91 {ReFungible: {pieces: 2}},92 {ReFungible: {pieces: 100}},93 ];94 await createMultipleItemsExpectSuccess(alice, collectionId, args);9596 await usingApi(async api => { 97 const tokenId = await getLastTokenId(api, collectionId);98 expect(tokenId).to.be.equal(3);99 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);100 });101 });102103 it('Burn some pieces', async () => {104 await usingApi(async api => { 105 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;106 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;107 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;108 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);109 expect(await burnItem(api, alice, collectionId, tokenId, 99n)).to.be.true;110 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;111 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(1n);112 });113 });114115 it('Burn all pieces', async () => {116 await usingApi(async api => { 117 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;118 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;119 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;120 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);121 expect(await burnItem(api, alice, collectionId, tokenId, 100n)).to.be.true;122 expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;123 });124 });125126 it('Burn some pieces for multiple users', async () => {127 await usingApi(async api => { 128 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;129 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;130 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;131132 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);133 expect(await transfer(api, collectionId, tokenId, alice, bob, 60n)).to.be.true;134135 136 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(40n);137 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(60n);138 expect(await burnItem(api, alice, collectionId, tokenId, 40n)).to.be.true;139140 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(0n);141 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;142 expect(await burnItem(api, bob, collectionId, tokenId, 59n)).to.be.true;143144 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(1n);145 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;146 expect(await burnItem(api, bob, collectionId, tokenId, 1n)).to.be.true;147 148 expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;149 });150 });151152 it('Set allowance for token', async () => {153 await usingApi(async api => {154 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;155 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;156157 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);158159 expect(await approve(api, collectionId, tokenId, alice, bob, 60n)).to.be.true;160 expect(await getAllowance(api, collectionId, alice, bob, tokenId)).to.be.equal(60n);161162 expect(await transferFrom(api, collectionId, tokenId, bob, alice, bob, 20n)).to.be.true;163 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(80n);164 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(20n);165 expect(await getAllowance(api, collectionId, alice, bob, tokenId)).to.be.equal(40n);166 });167 });168169 it('Repartition', async () => {170 await usingApi(async api => {171 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;172 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;173174 expect(await repartitionRFT(api, collectionId, alice, tokenId, 200n)).to.be.true;175 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(200n);176177 expect(await transfer(api, collectionId, tokenId, alice, bob, 110n)).to.be.true;178 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(90n);179 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(110n);180181 await expect(repartitionRFT(api, collectionId, alice, tokenId, 80n)).to.eventually.be.rejected;182183 expect(await transfer(api, collectionId, tokenId, alice, bob, 90n)).to.be.true;184 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(0n);185 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(200n);186187 expect(await repartitionRFT(api, collectionId, bob, tokenId, 150n)).to.be.true;188 await expect(transfer(api, collectionId, tokenId, bob, alice, 160n)).to.eventually.be.rejected;189 });190 });191});192193describe('Test Refungible properties:', () => {194 before(async () => {195 await usingApi(async (api, privateKeyWrapper) => {196 alice = privateKeyWrapper('//Alice');197 bob = privateKeyWrapper('//Bob');198 });199 });200 201 it('Сreate new collection with properties', async () => {202 await usingApi(async api => {203 const properties = [{key: 'key1', value: 'val1'}];204 const propertyPermissions = [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}];205 const collectionId = await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'ReFungible'},206 properties: properties,207 propPerm: propertyPermissions, 208 });209 const collection = (await getDetailedCollectionInfo(api, collectionId))!;210 expect(collection.properties.toHuman()).to.be.deep.equal(properties);211 expect(collection.tokenPropertyPermissions.toHuman()).to.be.deep.equal(propertyPermissions);212 });213 });214215 it.only('Set properties for exist collection', async () => {216 await usingApi(async api => {217 const collectionId = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'ReFungible'},218 });219220 const properties = [{key: 'key1', value: 'val1'}];221 // await expect(executeTransaction(222 // api, 223 // alice, 224 // api.tx.unique.setCollectionProperties(collectionId, properties), 225 // )).to.not.be.rejected;226227 const propertyPermissions = [228 {key: 'key1', permission: {collectionAdmin: true, mutable: false, tokenOwner: true}},229 {key: 'key2', permission: {collectionAdmin: false, mutable: true, tokenOwner: false}},230 ];231 await expect(executeTransaction(232 api, 233 alice, 234 api.tx.unique.setTokenPropertyPermissions(collectionId, propertyPermissions), 235 )).to.not.be.rejected;236237 const collection = (await getDetailedCollectionInfo(api, collectionId))!;238 expect(collection.properties.toHuman()).to.be.deep.equal(properties);239 expect(collection.tokenPropertyPermissions.toHuman()).to.be.deep.equal(propertyPermissions);240 });241 });242});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {default as usingApi, executeTransaction} from './substrate/substrate-api';18import {IKeyringPair} from '@polkadot/types/types';19import {20 createCollectionExpectSuccess,21 getBalance,22 createMultipleItemsExpectSuccess,23 isTokenExists,24 getLastTokenId,25 getAllowance,26 approve,27 transferFrom,28 createCollection,29 createRefungibleToken,30 transfer,31 burnItem,32 repartitionRFT,33 createCollectionWithPropsExpectSuccess,34 getDetailedCollectionInfo,35} from './util/helpers';3637import chai from 'chai';38import chaiAsPromised from 'chai-as-promised';39chai.use(chaiAsPromised);40const expect = chai.expect;4142let alice: IKeyringPair;43let bob: IKeyringPair;4445describe('integration test: Refungible functionality:', () => {46 before(async () => {47 await usingApi(async (api, privateKeyWrapper) => {48 alice = privateKeyWrapper('//Alice');49 bob = privateKeyWrapper('//Bob');50 });51 });5253 it('Create refungible collection and token', async () => {54 await usingApi(async api => {55 const createCollectionResult = await createCollection(api, alice, {mode: {type: 'ReFungible'}});56 expect(createCollectionResult.success).to.be.true; 57 const collectionId = createCollectionResult.collectionId;5859 const itemCountBefore = await getLastTokenId(api, collectionId);60 const result = await createRefungibleToken(api, alice, collectionId, 100n);6162 const itemCountAfter = await getLastTokenId(api, collectionId);6364 // What to expect65 // tslint:disable-next-line:no-unused-expression66 expect(result.success).to.be.true;67 expect(itemCountAfter).to.be.equal(itemCountBefore + 1);68 expect(collectionId).to.be.equal(result.collectionId);69 expect(itemCountAfter.toString()).to.be.equal(result.itemId.toString());70 });71 });7273 it('Transfer token pieces', async () => {74 await usingApi(async api => {75 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;76 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;7778 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);79 expect(await transfer(api, collectionId, tokenId, alice, bob, 60n)).to.be.true;8081 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(40n);82 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(60n);83 await expect(transfer(api, collectionId, tokenId, alice, bob, 41n)).to.eventually.be.rejected;84 });85 });8687 it('Create multiple tokens', async () => {88 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});89 const args = [90 {ReFungible: {pieces: 1}},91 {ReFungible: {pieces: 2}},92 {ReFungible: {pieces: 100}},93 ];94 await createMultipleItemsExpectSuccess(alice, collectionId, args);9596 await usingApi(async api => { 97 const tokenId = await getLastTokenId(api, collectionId);98 expect(tokenId).to.be.equal(3);99 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);100 });101 });102103 it('Burn some pieces', async () => {104 await usingApi(async api => { 105 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;106 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;107 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;108 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);109 expect(await burnItem(api, alice, collectionId, tokenId, 99n)).to.be.true;110 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;111 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(1n);112 });113 });114115 it('Burn all pieces', async () => {116 await usingApi(async api => { 117 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;118 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;119 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;120 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);121 expect(await burnItem(api, alice, collectionId, tokenId, 100n)).to.be.true;122 expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;123 });124 });125126 it('Burn some pieces for multiple users', async () => {127 await usingApi(async api => { 128 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;129 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;130 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;131132 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);133 expect(await transfer(api, collectionId, tokenId, alice, bob, 60n)).to.be.true;134135 136 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(40n);137 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(60n);138 expect(await burnItem(api, alice, collectionId, tokenId, 40n)).to.be.true;139140 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(0n);141 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;142 expect(await burnItem(api, bob, collectionId, tokenId, 59n)).to.be.true;143144 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(1n);145 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;146 expect(await burnItem(api, bob, collectionId, tokenId, 1n)).to.be.true;147 148 expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;149 });150 });151152 it('Set allowance for token', async () => {153 await usingApi(async api => {154 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;155 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;156157 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);158159 expect(await approve(api, collectionId, tokenId, alice, bob, 60n)).to.be.true;160 expect(await getAllowance(api, collectionId, alice, bob, tokenId)).to.be.equal(60n);161162 expect(await transferFrom(api, collectionId, tokenId, bob, alice, bob, 20n)).to.be.true;163 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(80n);164 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(20n);165 expect(await getAllowance(api, collectionId, alice, bob, tokenId)).to.be.equal(40n);166 });167 });168169 it('Repartition', async () => {170 await usingApi(async api => {171 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;172 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;173174 expect(await repartitionRFT(api, collectionId, alice, tokenId, 200n)).to.be.true;175 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(200n);176177 expect(await transfer(api, collectionId, tokenId, alice, bob, 110n)).to.be.true;178 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(90n);179 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(110n);180181 await expect(repartitionRFT(api, collectionId, alice, tokenId, 80n)).to.eventually.be.rejected;182183 expect(await transfer(api, collectionId, tokenId, alice, bob, 90n)).to.be.true;184 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(0n);185 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(200n);186187 expect(await repartitionRFT(api, collectionId, bob, tokenId, 150n)).to.be.true;188 await expect(transfer(api, collectionId, tokenId, bob, alice, 160n)).to.eventually.be.rejected;189 });190 });191});192193describe('Test Refungible properties:', () => {194 before(async () => {195 await usingApi(async (api, privateKeyWrapper) => {196 alice = privateKeyWrapper('//Alice');197 bob = privateKeyWrapper('//Bob');198 });199 });200 201 it('Сreate new collection with properties', async () => {202 await usingApi(async api => {203 const properties = [{key: 'key1', value: 'val1'}];204 const propertyPermissions = [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}];205 const collectionId = await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'ReFungible'},206 properties: properties,207 propPerm: propertyPermissions, 208 });209 const collection = (await getDetailedCollectionInfo(api, collectionId))!;210 expect(collection.properties.toHuman()).to.be.deep.equal(properties);211 expect(collection.tokenPropertyPermissions.toHuman()).to.be.deep.equal(propertyPermissions);212 });213 });214215 it('Set properties for exist collection', async () => {216 await usingApi(async api => {217 const collectionId = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'ReFungible'},218 });219220 const properties = [221 {key: 'key1', value: 'val1'},222 {key: 'key2', value: 'val2'},223 ];224 await expect(executeTransaction(225 api, 226 alice, 227 api.tx.unique.setCollectionProperties(collectionId, properties), 228 )).to.not.be.rejected;229230 const propertyPermissions = [231 {key: 'key1', permission: {collectionAdmin: true, mutable: false, tokenOwner: true}},232 {key: 'key2', permission: {collectionAdmin: false, mutable: true, tokenOwner: false}},233 ];234 await expect(executeTransaction(235 api, 236 alice, 237 api.tx.unique.setTokenPropertyPermissions(collectionId, propertyPermissions), 238 )).to.not.be.rejected;239240 const collection = (await getDetailedCollectionInfo(api, collectionId))!;241 expect(collection.properties.toHuman()).to.be.deep.equal(properties);242 expect(collection.tokenPropertyPermissions.toHuman()).to.be.deep.equal(propertyPermissions);243 });244 });245});