From 73d9a3eafd0edc83c9f3220da7c582092c265abd Mon Sep 17 00:00:00 2001 From: Trubnikov Sergey Date: Tue, 28 Jun 2022 07:30:30 +0000 Subject: [PATCH] CORE-410 Set collection properties for exist collection --- --- 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, + sender: T::CrossAccountId, + properties: Vec, ) -> DispatchResultWithPostInfo { - fail!(>::SettingPropertiesNotAllowed) + let weight = >::set_collection_properties(properties.len() as u32); + + with_weight( + >::set_collection_properties(self, &sender, properties), + weight, + ) } fn delete_collection_properties( &self, - _sender: &T::CrossAccountId, - _property_keys: Vec, + sender: &T::CrossAccountId, + property_keys: Vec, ) -> DispatchResultWithPostInfo { - fail!(>::SettingPropertiesNotAllowed) + let weight = >::delete_collection_properties(property_keys.len() as u32); + + with_weight( + >::delete_collection_properties(self, sender, property_keys), + weight, + ) } fn set_token_properties( &self, - _sender: T::CrossAccountId, - _token_id: TokenId, - _property: Vec, + sender: T::CrossAccountId, + token_id: TokenId, + properties: Vec, _nesting_budget: &dyn Budget, ) -> DispatchResultWithPostInfo { - fail!(>::SettingPropertiesNotAllowed) + let weight = >::set_token_properties(properties.len() as u32); + + with_weight( + >::set_token_properties(self, &sender, token_id, properties, false), + weight, + ) } fn set_token_property_permissions( &self, - _sender: &T::CrossAccountId, - _property_permissions: Vec, + sender: &T::CrossAccountId, + property_permissions: Vec, ) -> DispatchResultWithPostInfo { - fail!(>::SettingPropertiesNotAllowed) + let weight = + >::set_token_property_permissions(property_permissions.len() as u32); + + with_weight( + >::set_token_property_permissions(self, sender, property_permissions), + weight, + ) } fn delete_token_properties( &self, - _sender: T::CrossAccountId, - _token_id: TokenId, - _property_keys: Vec, + sender: T::CrossAccountId, + token_id: TokenId, + property_keys: Vec, _nesting_budget: &dyn Budget, ) -> DispatchResultWithPostInfo { - fail!(>::SettingPropertiesNotAllowed) + let weight = >::delete_token_properties(property_keys.len() as u32); + + with_weight( + >::delete_token_properties(self, &sender, token_id, property_keys), + weight, + ) } fn check_nesting( --- 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 { >::try_get((collection_id, token_id)).ok() } + + pub fn set_collection_properties( + collection: &RefungibleHandle, + sender: &T::CrossAccountId, + properties: Vec, + ) -> DispatchResult { + >::set_collection_properties(collection, sender, properties) + } + + pub fn delete_collection_properties( + collection: &RefungibleHandle, + sender: &T::CrossAccountId, + property_keys: Vec, + ) -> DispatchResult { + >::delete_collection_properties(collection, sender, property_keys) + } + + pub fn set_token_property_permissions( + collection: &RefungibleHandle, + sender: &T::CrossAccountId, + property_permissions: Vec, + ) -> DispatchResult { + >::set_token_property_permissions(collection, sender, property_permissions) + } } --- a/tests/src/refungible.test.ts +++ b/tests/src/refungible.test.ts @@ -212,17 +212,20 @@ }); }); - it.only('Set properties for exist collection', async () => { + it('Set properties for exist collection', async () => { await usingApi(async api => { const collectionId = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'ReFungible'}, }); - const properties = [{key: 'key1', value: 'val1'}]; - // await expect(executeTransaction( - // api, - // alice, - // api.tx.unique.setCollectionProperties(collectionId, properties), - // )).to.not.be.rejected; + const properties = [ + {key: 'key1', value: 'val1'}, + {key: 'key2', value: 'val2'}, + ]; + await expect(executeTransaction( + api, + alice, + api.tx.unique.setCollectionProperties(collectionId, properties), + )).to.not.be.rejected; const propertyPermissions = [ {key: 'key1', permission: {collectionAdmin: true, mutable: false, tokenOwner: true}}, -- gitstuff