difftreelog
Merge pull request #780 from UniqueNetwork/feature/properties-for-ft-collections
in: master
5 files changed
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -1222,7 +1222,8 @@
Ok(())
}
- /// Set scouped collection property.
+ /// Set a scoped collection property, where the scope is a special prefix
+ /// prohibiting a user to change the property.
///
/// * `collection_id` - ID of the collection for which the property is being set.
/// * `scope` - Property scope.
@@ -1240,7 +1241,8 @@
Ok(())
}
- /// Set scouped collection properties.
+ /// Set scoped collection properties, where the scope is a special prefix
+ /// prohibiting a user to change the properties.
///
/// * `collection_id` - ID of the collection for which the properties is being set.
/// * `scope` - Property scope.
pallets/fungible/src/common.rsdiffbeforeafterboth1// 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/>.1617use core::marker::PhantomData;1819use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, traits::Get};20use up_data_structs::{TokenId, CollectionId, CreateItemExData, budget::Budget, CreateItemData};21use pallet_common::{CommonCollectionOperations, CommonWeightInfo, RefungibleExtensions, with_weight};22use pallet_structure::Error as StructureError;23use sp_runtime::ArithmeticError;24use sp_std::{vec::Vec, vec};25use up_data_structs::{Property, PropertyKey, PropertyValue, PropertyKeyPermission};2627use crate::{28 Allowance, TotalSupply, Balance, Config, Error, FungibleHandle, Pallet, SelfWeightOf,29 weights::WeightInfo,30};3132pub struct CommonWeights<T: Config>(PhantomData<T>);33impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {34 fn create_item() -> Weight {35 <SelfWeightOf<T>>::create_item()36 }3738 fn create_multiple_items(_data: &[CreateItemData]) -> Weight {39 // All items minted for the same user, so it works same as create_item40 Self::create_item()41 }4243 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {44 match data {45 CreateItemExData::Fungible(f) => {46 <SelfWeightOf<T>>::create_multiple_items_ex(f.len() as u32)47 }48 _ => Weight::zero(),49 }50 }5152 fn burn_item() -> Weight {53 <SelfWeightOf<T>>::burn_item()54 }5556 fn set_collection_properties(_amount: u32) -> Weight {57 // Error58 Weight::zero()59 }6061 fn delete_collection_properties(_amount: u32) -> Weight {62 // Error63 Weight::zero()64 }6566 fn set_token_properties(_amount: u32) -> Weight {67 // Error68 Weight::zero()69 }7071 fn delete_token_properties(_amount: u32) -> Weight {72 // Error73 Weight::zero()74 }7576 fn set_token_property_permissions(_amount: u32) -> Weight {77 // Error78 Weight::zero()79 }8081 fn transfer() -> Weight {82 <SelfWeightOf<T>>::transfer()83 }8485 fn approve() -> Weight {86 <SelfWeightOf<T>>::approve()87 }8889 fn transfer_from() -> Weight {90 <SelfWeightOf<T>>::transfer_from()91 }9293 fn burn_from() -> Weight {94 <SelfWeightOf<T>>::burn_from()95 }9697 fn burn_recursively_self_raw() -> Weight {98 // Read to get total balance99 Self::burn_item() + T::DbWeight::get().reads(1)100 }101102 fn burn_recursively_breadth_raw(_amount: u32) -> Weight {103 // Fungible tokens can't have children104 Weight::zero()105 }106107 fn token_owner() -> Weight {108 Weight::zero()109 }110111 fn set_allowance_for_all() -> Weight {112 Weight::zero()113 }114115 fn repair_item() -> Weight {116 Weight::zero()117 }118}119120/// Implementation of `CommonCollectionOperations` for `FungibleHandle`. It wraps FungibleHandle Pallete121/// methods and adds weight info.122impl<T: Config> CommonCollectionOperations<T> for FungibleHandle<T> {123 fn create_item(124 &self,125 sender: T::CrossAccountId,126 to: T::CrossAccountId,127 data: up_data_structs::CreateItemData,128 nesting_budget: &dyn Budget,129 ) -> DispatchResultWithPostInfo {130 match data {131 up_data_structs::CreateItemData::Fungible(data) => with_weight(132 <Pallet<T>>::create_item(self, &sender, (to, data.value), nesting_budget),133 <CommonWeights<T>>::create_item(),134 ),135 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),136 }137 }138139 fn create_multiple_items(140 &self,141 sender: T::CrossAccountId,142 to: T::CrossAccountId,143 data: Vec<up_data_structs::CreateItemData>,144 nesting_budget: &dyn Budget,145 ) -> DispatchResultWithPostInfo {146 let mut sum: u128 = 0;147 for data in data {148 match data {149 up_data_structs::CreateItemData::Fungible(data) => {150 sum = sum151 .checked_add(data.value)152 .ok_or(ArithmeticError::Overflow)?;153 }154 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),155 }156 }157158 with_weight(159 <Pallet<T>>::create_item(self, &sender, (to, sum), nesting_budget),160 <CommonWeights<T>>::create_item(),161 )162 }163164 fn create_multiple_items_ex(165 &self,166 sender: <T>::CrossAccountId,167 data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,168 nesting_budget: &dyn Budget,169 ) -> DispatchResultWithPostInfo {170 let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);171 let data = match data {172 up_data_structs::CreateItemExData::Fungible(f) => f,173 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),174 };175176 with_weight(177 <Pallet<T>>::create_multiple_items(self, &sender, data.into_inner(), nesting_budget),178 weight,179 )180 }181182 fn burn_item(183 &self,184 sender: T::CrossAccountId,185 token: TokenId,186 amount: u128,187 ) -> DispatchResultWithPostInfo {188 ensure!(189 token == TokenId::default(),190 <Error<T>>::FungibleItemsHaveNoId191 );192193 with_weight(194 <Pallet<T>>::burn(self, &sender, amount),195 <CommonWeights<T>>::burn_item(),196 )197 }198199 fn burn_item_recursively(200 &self,201 sender: T::CrossAccountId,202 token: TokenId,203 self_budget: &dyn Budget,204 _breadth_budget: &dyn Budget,205 ) -> DispatchResultWithPostInfo {206 // Should not happen?207 ensure!(208 token == TokenId::default(),209 <Error<T>>::FungibleItemsHaveNoId210 );211 ensure!(self_budget.consume(), <StructureError<T>>::DepthLimit,);212213 with_weight(214 <Pallet<T>>::burn(self, &sender, <Balance<T>>::get((self.id, &sender))),215 <CommonWeights<T>>::burn_recursively_self_raw(),216 )217 }218219 fn transfer(220 &self,221 from: T::CrossAccountId,222 to: T::CrossAccountId,223 token: TokenId,224 amount: u128,225 nesting_budget: &dyn Budget,226 ) -> DispatchResultWithPostInfo {227 ensure!(228 token == TokenId::default(),229 <Error<T>>::FungibleItemsHaveNoId230 );231232 with_weight(233 <Pallet<T>>::transfer(self, &from, &to, amount, nesting_budget),234 <CommonWeights<T>>::transfer(),235 )236 }237238 fn approve(239 &self,240 sender: T::CrossAccountId,241 spender: T::CrossAccountId,242 token: TokenId,243 amount: u128,244 ) -> DispatchResultWithPostInfo {245 ensure!(246 token == TokenId::default(),247 <Error<T>>::FungibleItemsHaveNoId248 );249250 with_weight(251 <Pallet<T>>::set_allowance(self, &sender, &spender, amount),252 <CommonWeights<T>>::approve(),253 )254 }255256 fn transfer_from(257 &self,258 sender: T::CrossAccountId,259 from: T::CrossAccountId,260 to: T::CrossAccountId,261 token: TokenId,262 amount: u128,263 nesting_budget: &dyn Budget,264 ) -> DispatchResultWithPostInfo {265 ensure!(266 token == TokenId::default(),267 <Error<T>>::FungibleItemsHaveNoId268 );269270 with_weight(271 <Pallet<T>>::transfer_from(self, &sender, &from, &to, amount, nesting_budget),272 <CommonWeights<T>>::transfer_from(),273 )274 }275276 fn burn_from(277 &self,278 sender: T::CrossAccountId,279 from: T::CrossAccountId,280 token: TokenId,281 amount: u128,282 nesting_budget: &dyn Budget,283 ) -> DispatchResultWithPostInfo {284 ensure!(285 token == TokenId::default(),286 <Error<T>>::FungibleItemsHaveNoId287 );288289 with_weight(290 <Pallet<T>>::burn_from(self, &sender, &from, amount, nesting_budget),291 <CommonWeights<T>>::burn_from(),292 )293 }294295 fn set_collection_properties(296 &self,297 _sender: T::CrossAccountId,298 _property: Vec<Property>,299 ) -> DispatchResultWithPostInfo {300 fail!(<Error<T>>::SettingPropertiesNotAllowed)301 }302303 fn delete_collection_properties(304 &self,305 _sender: &T::CrossAccountId,306 _property_keys: Vec<PropertyKey>,307 ) -> DispatchResultWithPostInfo {308 fail!(<Error<T>>::SettingPropertiesNotAllowed)309 }310311 fn set_token_properties(312 &self,313 _sender: T::CrossAccountId,314 _token_id: TokenId,315 _property: Vec<Property>,316 _nesting_budget: &dyn Budget,317 ) -> DispatchResultWithPostInfo {318 fail!(<Error<T>>::SettingPropertiesNotAllowed)319 }320321 fn set_token_property_permissions(322 &self,323 _sender: &T::CrossAccountId,324 _property_permissions: Vec<PropertyKeyPermission>,325 ) -> DispatchResultWithPostInfo {326 fail!(<Error<T>>::SettingPropertiesNotAllowed)327 }328329 fn delete_token_properties(330 &self,331 _sender: T::CrossAccountId,332 _token_id: TokenId,333 _property_keys: Vec<PropertyKey>,334 _nesting_budget: &dyn Budget,335 ) -> DispatchResultWithPostInfo {336 fail!(<Error<T>>::SettingPropertiesNotAllowed)337 }338339 fn check_nesting(340 &self,341 _sender: <T>::CrossAccountId,342 _from: (CollectionId, TokenId),343 _under: TokenId,344 _nesting_budget: &dyn Budget,345 ) -> sp_runtime::DispatchResult {346 fail!(<Error<T>>::FungibleDisallowsNesting)347 }348349 fn nest(&self, _under: TokenId, _to_nest: (CollectionId, TokenId)) {}350351 fn unnest(&self, _under: TokenId, _to_nest: (CollectionId, TokenId)) {}352353 fn collection_tokens(&self) -> Vec<TokenId> {354 vec![TokenId::default()]355 }356357 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {358 if <Balance<T>>::get((self.id, account)) != 0 {359 vec![TokenId::default()]360 } else {361 vec![]362 }363 }364365 fn token_exists(&self, token: TokenId) -> bool {366 token == TokenId::default()367 }368369 fn last_token_id(&self) -> TokenId {370 TokenId::default()371 }372373 fn token_owner(&self, _token: TokenId) -> Option<T::CrossAccountId> {374 None375 }376377 /// Returns 10 tokens owners in no particular order.378 fn token_owners(&self, token: TokenId) -> Vec<T::CrossAccountId> {379 <Pallet<T>>::token_owners(self.id, token).unwrap_or_default()380 }381382 fn token_property(&self, _token_id: TokenId, _key: &PropertyKey) -> Option<PropertyValue> {383 None384 }385386 fn token_properties(387 &self,388 _token_id: TokenId,389 _keys: Option<Vec<PropertyKey>>,390 ) -> Vec<Property> {391 Vec::new()392 }393394 fn total_supply(&self) -> u32 {395 1396 }397398 fn account_balance(&self, account: T::CrossAccountId) -> u32 {399 if <Balance<T>>::get((self.id, account)) != 0 {400 1401 } else {402 0403 }404 }405406 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {407 if token != TokenId::default() {408 return 0;409 }410 <Balance<T>>::get((self.id, account))411 }412413 fn allowance(414 &self,415 sender: T::CrossAccountId,416 spender: T::CrossAccountId,417 token: TokenId,418 ) -> u128 {419 if token != TokenId::default() {420 return 0;421 }422 <Allowance<T>>::get((self.id, sender, spender))423 }424425 fn refungible_extensions(&self) -> Option<&dyn RefungibleExtensions<T>> {426 None427 }428429 fn total_pieces(&self, token: TokenId) -> Option<u128> {430 if token != TokenId::default() {431 return None;432 }433 <TotalSupply<T>>::try_get(self.id).ok()434 }435436 fn set_allowance_for_all(437 &self,438 _owner: T::CrossAccountId,439 _operator: T::CrossAccountId,440 _approve: bool,441 ) -> DispatchResultWithPostInfo {442 fail!(<Error<T>>::SettingAllowanceForAllNotAllowed)443 }444445 fn allowance_for_all(&self, _owner: T::CrossAccountId, _operator: T::CrossAccountId) -> bool {446 false447 }448449 /// Repairs a possibly broken item.450 fn repair_item(&self, _token: TokenId) -> DispatchResultWithPostInfo {451 fail!(<Error<T>>::FungibleTokensAreAlwaysValid)452 }453}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/>.1617use core::marker::PhantomData;1819use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, traits::Get};20use up_data_structs::{TokenId, CollectionId, CreateItemExData, budget::Budget, CreateItemData};21use pallet_common::{22 CommonCollectionOperations, CommonWeightInfo, RefungibleExtensions, with_weight,23 weights::WeightInfo as _,24};25use pallet_structure::Error as StructureError;26use sp_runtime::ArithmeticError;27use sp_std::{vec::Vec, vec};28use up_data_structs::{Property, PropertyKey, PropertyValue, PropertyKeyPermission};2930use crate::{31 Allowance, TotalSupply, Balance, Config, Error, FungibleHandle, Pallet, SelfWeightOf,32 weights::WeightInfo,33};3435pub struct CommonWeights<T: Config>(PhantomData<T>);36impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {37 fn create_item() -> Weight {38 <SelfWeightOf<T>>::create_item()39 }4041 fn create_multiple_items(_data: &[CreateItemData]) -> Weight {42 // All items minted for the same user, so it works same as create_item43 Self::create_item()44 }4546 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {47 match data {48 CreateItemExData::Fungible(f) => {49 <SelfWeightOf<T>>::create_multiple_items_ex(f.len() as u32)50 }51 _ => Weight::zero(),52 }53 }5455 fn burn_item() -> Weight {56 <SelfWeightOf<T>>::burn_item()57 }5859 fn set_collection_properties(amount: u32) -> Weight {60 <pallet_common::SelfWeightOf<T>>::set_collection_properties(amount)61 }6263 fn delete_collection_properties(amount: u32) -> Weight {64 <pallet_common::SelfWeightOf<T>>::delete_collection_properties(amount)65 }6667 fn set_token_properties(_amount: u32) -> Weight {68 // Error69 Weight::zero()70 }7172 fn delete_token_properties(_amount: u32) -> Weight {73 // Error74 Weight::zero()75 }7677 fn set_token_property_permissions(_amount: u32) -> Weight {78 // Error79 Weight::zero()80 }8182 fn transfer() -> Weight {83 <SelfWeightOf<T>>::transfer()84 }8586 fn approve() -> Weight {87 <SelfWeightOf<T>>::approve()88 }8990 fn transfer_from() -> Weight {91 <SelfWeightOf<T>>::transfer_from()92 }9394 fn burn_from() -> Weight {95 <SelfWeightOf<T>>::burn_from()96 }9798 fn burn_recursively_self_raw() -> Weight {99 // Read to get total balance100 Self::burn_item() + T::DbWeight::get().reads(1)101 }102103 fn burn_recursively_breadth_raw(_amount: u32) -> Weight {104 // Fungible tokens can't have children105 Weight::zero()106 }107108 fn token_owner() -> Weight {109 Weight::zero()110 }111112 fn set_allowance_for_all() -> Weight {113 Weight::zero()114 }115116 fn repair_item() -> Weight {117 Weight::zero()118 }119}120121/// Implementation of `CommonCollectionOperations` for `FungibleHandle`. It wraps FungibleHandle Pallete122/// methods and adds weight info.123impl<T: Config> CommonCollectionOperations<T> for FungibleHandle<T> {124 fn create_item(125 &self,126 sender: T::CrossAccountId,127 to: T::CrossAccountId,128 data: up_data_structs::CreateItemData,129 nesting_budget: &dyn Budget,130 ) -> DispatchResultWithPostInfo {131 match data {132 up_data_structs::CreateItemData::Fungible(data) => with_weight(133 <Pallet<T>>::create_item(self, &sender, (to, data.value), nesting_budget),134 <CommonWeights<T>>::create_item(),135 ),136 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),137 }138 }139140 fn create_multiple_items(141 &self,142 sender: T::CrossAccountId,143 to: T::CrossAccountId,144 data: Vec<up_data_structs::CreateItemData>,145 nesting_budget: &dyn Budget,146 ) -> DispatchResultWithPostInfo {147 let mut sum: u128 = 0;148 for data in data {149 match data {150 up_data_structs::CreateItemData::Fungible(data) => {151 sum = sum152 .checked_add(data.value)153 .ok_or(ArithmeticError::Overflow)?;154 }155 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),156 }157 }158159 with_weight(160 <Pallet<T>>::create_item(self, &sender, (to, sum), nesting_budget),161 <CommonWeights<T>>::create_item(),162 )163 }164165 fn create_multiple_items_ex(166 &self,167 sender: <T>::CrossAccountId,168 data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,169 nesting_budget: &dyn Budget,170 ) -> DispatchResultWithPostInfo {171 let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);172 let data = match data {173 up_data_structs::CreateItemExData::Fungible(f) => f,174 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),175 };176177 with_weight(178 <Pallet<T>>::create_multiple_items(self, &sender, data.into_inner(), nesting_budget),179 weight,180 )181 }182183 fn burn_item(184 &self,185 sender: T::CrossAccountId,186 token: TokenId,187 amount: u128,188 ) -> DispatchResultWithPostInfo {189 ensure!(190 token == TokenId::default(),191 <Error<T>>::FungibleItemsHaveNoId192 );193194 with_weight(195 <Pallet<T>>::burn(self, &sender, amount),196 <CommonWeights<T>>::burn_item(),197 )198 }199200 fn burn_item_recursively(201 &self,202 sender: T::CrossAccountId,203 token: TokenId,204 self_budget: &dyn Budget,205 _breadth_budget: &dyn Budget,206 ) -> DispatchResultWithPostInfo {207 // Should not happen?208 ensure!(209 token == TokenId::default(),210 <Error<T>>::FungibleItemsHaveNoId211 );212 ensure!(self_budget.consume(), <StructureError<T>>::DepthLimit,);213214 with_weight(215 <Pallet<T>>::burn(self, &sender, <Balance<T>>::get((self.id, &sender))),216 <CommonWeights<T>>::burn_recursively_self_raw(),217 )218 }219220 fn transfer(221 &self,222 from: T::CrossAccountId,223 to: T::CrossAccountId,224 token: TokenId,225 amount: u128,226 nesting_budget: &dyn Budget,227 ) -> DispatchResultWithPostInfo {228 ensure!(229 token == TokenId::default(),230 <Error<T>>::FungibleItemsHaveNoId231 );232233 with_weight(234 <Pallet<T>>::transfer(self, &from, &to, amount, nesting_budget),235 <CommonWeights<T>>::transfer(),236 )237 }238239 fn approve(240 &self,241 sender: T::CrossAccountId,242 spender: T::CrossAccountId,243 token: TokenId,244 amount: u128,245 ) -> DispatchResultWithPostInfo {246 ensure!(247 token == TokenId::default(),248 <Error<T>>::FungibleItemsHaveNoId249 );250251 with_weight(252 <Pallet<T>>::set_allowance(self, &sender, &spender, amount),253 <CommonWeights<T>>::approve(),254 )255 }256257 fn transfer_from(258 &self,259 sender: T::CrossAccountId,260 from: T::CrossAccountId,261 to: T::CrossAccountId,262 token: TokenId,263 amount: u128,264 nesting_budget: &dyn Budget,265 ) -> DispatchResultWithPostInfo {266 ensure!(267 token == TokenId::default(),268 <Error<T>>::FungibleItemsHaveNoId269 );270271 with_weight(272 <Pallet<T>>::transfer_from(self, &sender, &from, &to, amount, nesting_budget),273 <CommonWeights<T>>::transfer_from(),274 )275 }276277 fn burn_from(278 &self,279 sender: T::CrossAccountId,280 from: T::CrossAccountId,281 token: TokenId,282 amount: u128,283 nesting_budget: &dyn Budget,284 ) -> DispatchResultWithPostInfo {285 ensure!(286 token == TokenId::default(),287 <Error<T>>::FungibleItemsHaveNoId288 );289290 with_weight(291 <Pallet<T>>::burn_from(self, &sender, &from, amount, nesting_budget),292 <CommonWeights<T>>::burn_from(),293 )294 }295296 fn set_collection_properties(297 &self,298 sender: T::CrossAccountId,299 properties: Vec<Property>,300 ) -> DispatchResultWithPostInfo {301 let weight = <CommonWeights<T>>::set_collection_properties(properties.len() as u32);302303 with_weight(304 <Pallet<T>>::set_collection_properties(self, &sender, properties),305 weight,306 )307 }308309 fn delete_collection_properties(310 &self,311 sender: &T::CrossAccountId,312 property_keys: Vec<PropertyKey>,313 ) -> DispatchResultWithPostInfo {314 let weight = <CommonWeights<T>>::delete_collection_properties(property_keys.len() as u32);315316 with_weight(317 <Pallet<T>>::delete_collection_properties(self, sender, property_keys),318 weight,319 )320 }321322 fn set_token_properties(323 &self,324 _sender: T::CrossAccountId,325 _token_id: TokenId,326 _property: Vec<Property>,327 _nesting_budget: &dyn Budget,328 ) -> DispatchResultWithPostInfo {329 fail!(<Error<T>>::SettingPropertiesNotAllowed)330 }331332 fn set_token_property_permissions(333 &self,334 _sender: &T::CrossAccountId,335 _property_permissions: Vec<PropertyKeyPermission>,336 ) -> DispatchResultWithPostInfo {337 fail!(<Error<T>>::SettingPropertiesNotAllowed)338 }339340 fn delete_token_properties(341 &self,342 _sender: T::CrossAccountId,343 _token_id: TokenId,344 _property_keys: Vec<PropertyKey>,345 _nesting_budget: &dyn Budget,346 ) -> DispatchResultWithPostInfo {347 fail!(<Error<T>>::SettingPropertiesNotAllowed)348 }349350 fn check_nesting(351 &self,352 _sender: <T>::CrossAccountId,353 _from: (CollectionId, TokenId),354 _under: TokenId,355 _nesting_budget: &dyn Budget,356 ) -> sp_runtime::DispatchResult {357 fail!(<Error<T>>::FungibleDisallowsNesting)358 }359360 fn nest(&self, _under: TokenId, _to_nest: (CollectionId, TokenId)) {}361362 fn unnest(&self, _under: TokenId, _to_nest: (CollectionId, TokenId)) {}363364 fn collection_tokens(&self) -> Vec<TokenId> {365 vec![TokenId::default()]366 }367368 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {369 if <Balance<T>>::get((self.id, account)) != 0 {370 vec![TokenId::default()]371 } else {372 vec![]373 }374 }375376 fn token_exists(&self, token: TokenId) -> bool {377 token == TokenId::default()378 }379380 fn last_token_id(&self) -> TokenId {381 TokenId::default()382 }383384 fn token_owner(&self, _token: TokenId) -> Option<T::CrossAccountId> {385 None386 }387388 /// Returns 10 tokens owners in no particular order.389 fn token_owners(&self, token: TokenId) -> Vec<T::CrossAccountId> {390 <Pallet<T>>::token_owners(self.id, token).unwrap_or_default()391 }392393 fn token_property(&self, _token_id: TokenId, _key: &PropertyKey) -> Option<PropertyValue> {394 None395 }396397 fn token_properties(398 &self,399 _token_id: TokenId,400 _keys: Option<Vec<PropertyKey>>,401 ) -> Vec<Property> {402 Vec::new()403 }404405 fn total_supply(&self) -> u32 {406 1407 }408409 fn account_balance(&self, account: T::CrossAccountId) -> u32 {410 if <Balance<T>>::get((self.id, account)) != 0 {411 1412 } else {413 0414 }415 }416417 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {418 if token != TokenId::default() {419 return 0;420 }421 <Balance<T>>::get((self.id, account))422 }423424 fn allowance(425 &self,426 sender: T::CrossAccountId,427 spender: T::CrossAccountId,428 token: TokenId,429 ) -> u128 {430 if token != TokenId::default() {431 return 0;432 }433 <Allowance<T>>::get((self.id, sender, spender))434 }435436 fn refungible_extensions(&self) -> Option<&dyn RefungibleExtensions<T>> {437 None438 }439440 fn total_pieces(&self, token: TokenId) -> Option<u128> {441 if token != TokenId::default() {442 return None;443 }444 <TotalSupply<T>>::try_get(self.id).ok()445 }446447 fn set_allowance_for_all(448 &self,449 _owner: T::CrossAccountId,450 _operator: T::CrossAccountId,451 _approve: bool,452 ) -> DispatchResultWithPostInfo {453 fail!(<Error<T>>::SettingAllowanceForAllNotAllowed)454 }455456 fn allowance_for_all(&self, _owner: T::CrossAccountId, _operator: T::CrossAccountId) -> bool {457 false458 }459460 /// Repairs a possibly broken item.461 fn repair_item(&self, _token: TokenId) -> DispatchResultWithPostInfo {462 fail!(<Error<T>>::FungibleTokensAreAlwaysValid)463 }464}pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -80,11 +80,11 @@
use core::ops::Deref;
use evm_coder::ToLog;
-use frame_support::{ensure};
+use frame_support::ensure;
use pallet_evm::account::CrossAccountId;
use up_data_structs::{
AccessMode, CollectionId, CollectionFlags, TokenId, CreateCollectionData,
- mapping::TokenAddressMapping, budget::Budget,
+ mapping::TokenAddressMapping, budget::Budget, PropertyKey, Property,
};
use pallet_common::{
Error as CommonError, Event as CommonEvent, Pallet as PalletCommon,
@@ -260,7 +260,25 @@
Ok(())
}
- ///Checks if collection has tokens. Return `true` if it has.
+ /// Add properties to the collection.
+ pub fn set_collection_properties(
+ collection: &FungibleHandle<T>,
+ sender: &T::CrossAccountId,
+ properties: Vec<Property>,
+ ) -> DispatchResult {
+ <PalletCommon<T>>::set_collection_properties(collection, sender, properties)
+ }
+
+ /// Delete properties of the collection, associated with the provided keys.
+ pub fn delete_collection_properties(
+ collection: &FungibleHandle<T>,
+ sender: &T::CrossAccountId,
+ property_keys: Vec<PropertyKey>,
+ ) -> DispatchResult {
+ <PalletCommon<T>>::delete_collection_properties(collection, sender, property_keys)
+ }
+
+ /// Checks if collection has tokens. Return `true` if it has.
fn collection_has_tokens(collection_id: CollectionId) -> bool {
<TotalSupply<T>>::get(collection_id) != 0
}
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -45,6 +45,7 @@
"testNesting": "mocha --timeout 9999999 -r ts-node/register ./**/nest.test.ts",
"testUnnesting": "mocha --timeout 9999999 -r ts-node/register ./**/unnest.test.ts",
"testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/collectionProperties.test.ts ./**/tokenProperties.test.ts ./**/getPropertiesRpc.test.ts",
+ "testCollectionProperties": "mocha --timeout 9999999 -r ts-node/register ./**/collectionProperties.test.ts",
"testMigration": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts",
"testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",
"testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",
tests/src/nesting/collectionProperties.test.tsdiffbeforeafterboth--- a/tests/src/nesting/collectionProperties.test.ts
+++ b/tests/src/nesting/collectionProperties.test.ts
@@ -15,8 +15,7 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {IKeyringPair} from '@polkadot/types/types';
-import {itSub, Pallets, usingPlaygrounds, expect} from '../util';
-import {UniqueBaseCollection} from '../util/playgrounds/unique';
+import {itSub, Pallets, usingPlaygrounds, expect, requirePalletsOrSkip} from '../util';
describe('Integration Test: Collection Properties', () => {
let alice: IKeyringPair;
@@ -32,116 +31,98 @@
itSub('Properties are initially empty', async ({helper}) => {
const collection = await helper.nft.mintCollection(alice);
expect(await collection.getProperties()).to.be.empty;
- });
-
- async function testSetsPropertiesForCollection(collection: UniqueBaseCollection) {
- // As owner
- await expect(collection.setProperties(alice, [{key: 'electron', value: 'come bond'}])).to.be.fulfilled;
-
- await collection.addAdmin(alice, {Substrate: bob.address});
-
- // As administrator
- await expect(collection.setProperties(bob, [{key: 'black_hole'}])).to.be.fulfilled;
-
- const properties = await collection.getProperties();
- expect(properties).to.include.deep.members([
- {key: 'electron', value: 'come bond'},
- {key: 'black_hole', value: ''},
- ]);
- }
-
- itSub('Sets properties for a NFT collection', async ({helper}) => {
- await testSetsPropertiesForCollection(await helper.nft.mintCollection(alice));
- });
-
- itSub.ifWithPallets('Sets properties for a ReFungible collection', [Pallets.ReFungible], async ({helper}) => {
- await testSetsPropertiesForCollection(await helper.rft.mintCollection(alice));
});
-
- async function testCheckValidNames(collection: UniqueBaseCollection) {
- // alpha symbols
- await expect(collection.setProperties(alice, [{key: 'answer'}])).to.be.fulfilled;
-
- // numeric symbols
- await expect(collection.setProperties(alice, [{key: '451'}])).to.be.fulfilled;
-
- // underscore symbol
- await expect(collection.setProperties(alice, [{key: 'black_hole'}])).to.be.fulfilled;
-
- // dash symbol
- await expect(collection.setProperties(alice, [{key: '-'}])).to.be.fulfilled;
-
- // dot symbol
- await expect(collection.setProperties(alice, [{key: 'once.in.a.long.long.while...', value: 'you get a little lost'}])).to.be.fulfilled;
-
- const properties = await collection.getProperties();
- expect(properties).to.include.deep.members([
- {key: 'answer', value: ''},
- {key: '451', value: ''},
- {key: 'black_hole', value: ''},
- {key: '-', value: ''},
- {key: 'once.in.a.long.long.while...', value: 'you get a little lost'},
- ]);
- }
-
- itSub('Check valid names for NFT collection properties keys', async ({helper}) => {
- await testCheckValidNames(await helper.nft.mintCollection(alice));
- });
-
- itSub.ifWithPallets('Check valid names for ReFungible collection properties keys', [Pallets.ReFungible], async ({helper}) => {
- await testCheckValidNames(await helper.rft.mintCollection(alice));
- });
-
- async function testChangesProperties(collection: UniqueBaseCollection) {
- await expect(collection.setProperties(alice, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: ''}])).to.be.fulfilled;
-
- // Mutate the properties
- await expect(collection.setProperties(alice, [{key: 'black_hole', value: 'LIGO'}])).to.be.fulfilled;
-
- const properties = await collection.getProperties();
- expect(properties).to.include.deep.members([
- {key: 'electron', value: 'come bond'},
- {key: 'black_hole', value: 'LIGO'},
- ]);
- }
-
- itSub('Changes properties of a NFT collection', async ({helper}) => {
- await testChangesProperties(await helper.nft.mintCollection(alice));
- });
-
- itSub.ifWithPallets('Changes properties of a ReFungible collection', [Pallets.ReFungible], async ({helper}) => {
- await testChangesProperties(await helper.rft.mintCollection(alice));
- });
-
- async function testDeleteProperties(collection: UniqueBaseCollection) {
- await expect(collection.setProperties(alice, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: 'LIGO'}])).to.be.fulfilled;
-
- await expect(collection.deleteProperties(alice, ['electron'])).to.be.fulfilled;
-
- const properties = await collection.getProperties(['black_hole', 'electron']);
- expect(properties).to.be.deep.equal([
- {key: 'black_hole', value: 'LIGO'},
- ]);
- }
-
- itSub('Deletes properties of a NFT collection', async ({helper}) => {
- await testDeleteProperties(await helper.nft.mintCollection(alice));
- });
-
- itSub.ifWithPallets('Deletes properties of a ReFungible collection', [Pallets.ReFungible], async ({helper}) => {
- await testDeleteProperties(await helper.rft.mintCollection(alice));
- });
[
- // TODO enable properties for FT collection in Substrate (release 040)
- // {mode: 'ft' as const, requiredPallets: []},
{mode: 'nft' as const, requiredPallets: []},
+ {mode: 'ft' as const, requiredPallets: []},
{mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
- ].map(testCase =>
- itSub.ifWithPallets(`Allows modifying a collection property multiple times with the same size (${testCase.mode})`, testCase.requiredPallets, async({helper}) => {
+ ].map(testSuite => describe(`${testSuite.mode.toUpperCase()}`, () => {
+ before(async function() {
+ // eslint-disable-next-line require-await
+ await usingPlaygrounds(async helper => {
+ requirePalletsOrSkip(this, helper, testSuite.requiredPallets);
+ });
+ });
+
+ itSub('Sets properties for a collection', async ({helper}) => {
+ const collection = await helper[testSuite.mode].mintCollection(alice);
+
+ // As owner
+ await expect(collection.setProperties(alice, [{key: 'electron', value: 'come bond'}])).to.be.fulfilled;
+
+ await collection.addAdmin(alice, {Substrate: bob.address});
+
+ // As administrator
+ await expect(collection.setProperties(bob, [{key: 'black_hole'}])).to.be.fulfilled;
+
+ const properties = await collection.getProperties();
+ expect(properties).to.include.deep.members([
+ {key: 'electron', value: 'come bond'},
+ {key: 'black_hole', value: ''},
+ ]);
+ });
+
+ itSub('Check valid names for collection properties keys', async ({helper}) => {
+ const collection = await helper[testSuite.mode].mintCollection(alice);
+
+ // alpha symbols
+ await expect(collection.setProperties(alice, [{key: 'answer'}])).to.be.fulfilled;
+
+ // numeric symbols
+ await expect(collection.setProperties(alice, [{key: '451'}])).to.be.fulfilled;
+
+ // underscore symbol
+ await expect(collection.setProperties(alice, [{key: 'black_hole'}])).to.be.fulfilled;
+
+ // dash symbol
+ await expect(collection.setProperties(alice, [{key: '-'}])).to.be.fulfilled;
+
+ // dot symbol
+ await expect(collection.setProperties(alice, [{key: 'once.in.a.long.long.while...', value: 'you get a little lost'}])).to.be.fulfilled;
+
+ const properties = await collection.getProperties();
+ expect(properties).to.include.deep.members([
+ {key: 'answer', value: ''},
+ {key: '451', value: ''},
+ {key: 'black_hole', value: ''},
+ {key: '-', value: ''},
+ {key: 'once.in.a.long.long.while...', value: 'you get a little lost'},
+ ]);
+ });
+
+ itSub('Changes properties of a collection', async ({helper}) => {
+ const collection = await helper[testSuite.mode].mintCollection(alice);
+
+ await expect(collection.setProperties(alice, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: ''}])).to.be.fulfilled;
+
+ // Mutate the properties
+ await expect(collection.setProperties(alice, [{key: 'black_hole', value: 'LIGO'}])).to.be.fulfilled;
+
+ const properties = await collection.getProperties();
+ expect(properties).to.include.deep.members([
+ {key: 'electron', value: 'come bond'},
+ {key: 'black_hole', value: 'LIGO'},
+ ]);
+ });
+
+ itSub('Deletes properties of a collection', async ({helper}) => {
+ const collection = await helper[testSuite.mode].mintCollection(alice);
+
+ await expect(collection.setProperties(alice, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: 'LIGO'}])).to.be.fulfilled;
+
+ await expect(collection.deleteProperties(alice, ['electron'])).to.be.fulfilled;
+
+ const properties = await collection.getProperties(['black_hole', 'electron']);
+ expect(properties).to.be.deep.equal([
+ {key: 'black_hole', value: 'LIGO'},
+ ]);
+ });
+
+ itSub('Allows modifying a collection property multiple times with the same size', async({helper}) => {
const propKey = 'tok-prop';
- const collection = await helper[testCase.mode].mintCollection(alice);
+ const collection = await helper[testSuite.mode].mintCollection(alice);
const maxCollectionPropertiesSize = 40960;
@@ -166,18 +147,12 @@
const consumedSpace = await collection.getPropertiesConsumedSpace();
expect(consumedSpace).to.be.equal(originalSpace);
}
- }));
+ });
- [
- // TODO enable properties for FT collection in Substrate (release 040)
- // {mode: 'ft' as const, requiredPallets: []},
- {mode: 'nft' as const, requiredPallets: []},
- {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
- ].map(testCase =>
- itSub.ifWithPallets(`Adding then removing a collection property doesn't change the consumed space (${testCase.mode})`, testCase.requiredPallets, async({helper}) => {
+ itSub('Adding then removing a collection property doesn\'t change the consumed space', async({helper}) => {
const propKey = 'tok-prop';
- const collection = await helper[testCase.mode].mintCollection(alice);
+ const collection = await helper[testSuite.mode].mintCollection(alice);
const originalSpace = await collection.getPropertiesConsumedSpace();
const propDataSize = 4096;
@@ -190,18 +165,12 @@
await collection.deleteProperties(alice, [propKey]);
consumedSpace = await collection.getPropertiesConsumedSpace();
expect(consumedSpace).to.be.equal(originalSpace);
- }));
+ });
- [
- // TODO enable properties for FT collection in Substrate (release 040)
- // {mode: 'ft' as const, requiredPallets: []},
- {mode: 'nft' as const, requiredPallets: []},
- {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
- ].map(testCase =>
- itSub.ifWithPallets(`Modifying a collection property with different sizes correctly changes the consumed space (${testCase.mode})`, testCase.requiredPallets, async({helper}) => {
+ itSub('Modifying a collection property with different sizes correctly changes the consumed space', async({helper}) => {
const propKey = 'tok-prop';
- const collection = await helper[testCase.mode].mintCollection(alice);
+ const collection = await helper[testSuite.mode].mintCollection(alice);
const originalSpace = await collection.getPropertiesConsumedSpace();
const initPropDataSize = 4096;
@@ -229,7 +198,8 @@
consumedSpace = await collection.getPropertiesConsumedSpace();
expectedConsumedSpaceDiff = biggerPropDataSize - smallerPropDataSize;
expect(consumedSpace).to.be.equal(biggerPropDataSize - expectedConsumedSpaceDiff);
- }));
+ });
+ }));
});
describe('Negative Integration Test: Collection Properties', () => {
@@ -242,119 +212,108 @@
[alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);
});
});
+
+ [
+ {mode: 'nft' as const, requiredPallets: []},
+ {mode: 'ft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ ].map(testSuite => describe(`${testSuite.mode.toUpperCase()}`, () => {
+ before(async function() {
+ // eslint-disable-next-line require-await
+ await usingPlaygrounds(async helper => {
+ requirePalletsOrSkip(this, helper, testSuite.requiredPallets);
+ });
+ });
- async function testFailsSetPropertiesIfNotOwnerOrAdmin(collection: UniqueBaseCollection) {
- await expect(collection.setProperties(bob, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: 'LIGO'}]))
- .to.be.rejectedWith(/common\.NoPermission/);
-
- expect(await collection.getProperties()).to.be.empty;
- }
-
- itSub('Fails to set properties in a NFT collection if not its onwer/administrator', async ({helper}) => {
- await testFailsSetPropertiesIfNotOwnerOrAdmin(await helper.nft.mintCollection(alice));
- });
-
- itSub.ifWithPallets('Fails to set properties in a ReFungible collection if not its onwer/administrator', [Pallets.ReFungible], async ({helper}) => {
- await testFailsSetPropertiesIfNotOwnerOrAdmin(await helper.rft.mintCollection(alice));
- });
+ itSub('Fails to set properties in a collection if not its onwer/administrator', async ({helper}) => {
+ const collection = await helper[testSuite.mode].mintCollection(alice);
+
+ await expect(collection.setProperties(bob, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: 'LIGO'}]))
+ .to.be.rejectedWith(/common\.NoPermission/);
- async function testFailsSetPropertiesThatExeedLimits(collection: UniqueBaseCollection) {
- const spaceLimit = (await (collection.helper!.api! as any).query.common.collectionProperties(collection.collectionId)).spaceLimit.toNumber();
+ expect(await collection.getProperties()).to.be.empty;
+ });
- // Mute the general tx parsing error, too many bytes to process
- {
- console.error = () => {};
+ itSub('Fails to set properties that exceed the limits', async ({helper}) => {
+ const collection = await helper[testSuite.mode].mintCollection(alice);
+
+ const spaceLimit = (await (collection.helper!.api! as any).query.common.collectionProperties(collection.collectionId)).spaceLimit.toNumber();
+
+ // Mute the general tx parsing error, too many bytes to process
+ {
+ console.error = () => {};
+ await expect(collection.setProperties(alice, [
+ {key: 'electron', value: 'low high '.repeat(Math.ceil(spaceLimit! / 9))},
+ ])).to.be.rejected;
+ }
+
+ expect(await collection.getProperties(['electron'])).to.be.empty;
+
await expect(collection.setProperties(alice, [
- {key: 'electron', value: 'low high '.repeat(Math.ceil(spaceLimit! / 9))},
- ])).to.be.rejected;
- }
-
- expect(await collection.getProperties(['electron'])).to.be.empty;
-
- await expect(collection.setProperties(alice, [
- {key: 'electron', value: 'low high '.repeat(Math.ceil(spaceLimit! / 18))},
- {key: 'black_hole', value: '0'.repeat(Math.ceil(spaceLimit! / 2))},
- ])).to.be.rejectedWith(/common\.NoSpaceForProperty/);
-
- expect(await collection.getProperties(['electron', 'black_hole'])).to.be.empty;
- }
-
- itSub('Fails to set properties that exceed the limits (NFT)', async ({helper}) => {
- await testFailsSetPropertiesThatExeedLimits(await helper.nft.mintCollection(alice));
- });
-
- itSub.ifWithPallets('Fails to set properties that exceed the limits (ReFungible)', [Pallets.ReFungible], async ({helper}) => {
- await testFailsSetPropertiesThatExeedLimits(await helper.rft.mintCollection(alice));
- });
+ {key: 'electron', value: 'low high '.repeat(Math.ceil(spaceLimit! / 18))},
+ {key: 'black_hole', value: '0'.repeat(Math.ceil(spaceLimit! / 2))},
+ ])).to.be.rejectedWith(/common\.NoSpaceForProperty/);
- async function testFailsSetMorePropertiesThanAllowed(collection: UniqueBaseCollection) {
- const propertiesToBeSet = [];
- for (let i = 0; i < 65; i++) {
- propertiesToBeSet.push({
- key: 'electron_' + i,
- value: Math.random() > 0.5 ? 'high' : 'low',
- });
- }
-
- await expect(collection.setProperties(alice, propertiesToBeSet)).
- to.be.rejectedWith(/common\.PropertyLimitReached/);
-
- expect(await collection.getProperties()).to.be.empty;
- }
-
- itSub('Fails to set more properties than it is allowed (NFT)', async ({helper}) => {
- await testFailsSetMorePropertiesThanAllowed(await helper.nft.mintCollection(alice));
- });
-
- itSub.ifWithPallets('Fails to set more properties than it is allowed (ReFungible)', [Pallets.ReFungible], async ({helper}) => {
- await testFailsSetMorePropertiesThanAllowed(await helper.rft.mintCollection(alice));
- });
+ expect(await collection.getProperties(['electron', 'black_hole'])).to.be.empty;
+ });
+
+ itSub('Fails to set more properties than it is allowed', async ({helper}) => {
+ const collection = await helper[testSuite.mode].mintCollection(alice);
+
+ const propertiesToBeSet = [];
+ for (let i = 0; i < 65; i++) {
+ propertiesToBeSet.push({
+ key: 'electron_' + i,
+ value: Math.random() > 0.5 ? 'high' : 'low',
+ });
+ }
+
+ await expect(collection.setProperties(alice, propertiesToBeSet)).
+ to.be.rejectedWith(/common\.PropertyLimitReached/);
+
+ expect(await collection.getProperties()).to.be.empty;
+ });
+
+ itSub('Fails to set properties with invalid names', async ({helper}) => {
+ const collection = await helper[testSuite.mode].mintCollection(alice);
+
+ const invalidProperties = [
+ [{key: 'electron', value: 'negative'}, {key: 'string theory', value: 'understandable'}],
+ [{key: 'Mr/Sandman', value: 'Bring me a gene'}],
+ [{key: 'déjà vu', value: 'hmm...'}],
+ ];
- async function testFailsSetPropertiesWithInvalidNames(collection: UniqueBaseCollection) {
- const invalidProperties = [
- [{key: 'electron', value: 'negative'}, {key: 'string theory', value: 'understandable'}],
- [{key: 'Mr/Sandman', value: 'Bring me a gene'}],
- [{key: 'déjà vu', value: 'hmm...'}],
- ];
-
- for (let i = 0; i < invalidProperties.length; i++) {
+ for (let i = 0; i < invalidProperties.length; i++) {
+ await expect(
+ collection.setProperties(alice, invalidProperties[i]),
+ `on rejecting the new badly-named property #${i}`,
+ ).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);
+ }
+
await expect(
- collection.setProperties(alice, invalidProperties[i]),
- `on rejecting the new badly-named property #${i}`,
- ).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);
- }
-
- await expect(
- collection.setProperties(alice, [{key: '', value: 'nothing must not exist'}]),
- 'on rejecting an unnamed property',
- ).to.be.rejectedWith(/common\.EmptyPropertyKey/);
-
- await expect(
- collection.setProperties(alice, [{key: 'CRISPR-Cas9', value: 'rewriting nature!'}]),
- 'on setting the correctly-but-still-badly-named property',
- ).to.be.fulfilled;
-
- const keys = invalidProperties.flatMap(propertySet => propertySet.map(property => property.key)).concat('CRISPR-Cas9').concat('');
-
- const properties = await collection.getProperties(keys);
- expect(properties).to.be.deep.equal([
- {key: 'CRISPR-Cas9', value: 'rewriting nature!'},
- ]);
-
- for (let i = 0; i < invalidProperties.length; i++) {
+ collection.setProperties(alice, [{key: '', value: 'nothing must not exist'}]),
+ 'on rejecting an unnamed property',
+ ).to.be.rejectedWith(/common\.EmptyPropertyKey/);
+
await expect(
- collection.deleteProperties(alice, invalidProperties[i].map(propertySet => propertySet.key)),
- `on trying to delete the non-existent badly-named property #${i}`,
- ).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);
- }
- }
-
- itSub('Fails to set properties with invalid names (NFT)', async ({helper}) => {
- await testFailsSetPropertiesWithInvalidNames(await helper.nft.mintCollection(alice));
- });
-
- itSub.ifWithPallets('Fails to set properties with invalid names (ReFungible)', [Pallets.ReFungible], async ({helper}) => {
- await testFailsSetPropertiesWithInvalidNames(await helper.rft.mintCollection(alice));
- });
+ collection.setProperties(alice, [{key: 'CRISPR-Cas9', value: 'rewriting nature!'}]),
+ 'on setting the correctly-but-still-badly-named property',
+ ).to.be.fulfilled;
+
+ const keys = invalidProperties.flatMap(propertySet => propertySet.map(property => property.key)).concat('CRISPR-Cas9').concat('');
+
+ const properties = await collection.getProperties(keys);
+ expect(properties).to.be.deep.equal([
+ {key: 'CRISPR-Cas9', value: 'rewriting nature!'},
+ ]);
+
+ for (let i = 0; i < invalidProperties.length; i++) {
+ await expect(
+ collection.deleteProperties(alice, invalidProperties[i].map(propertySet => propertySet.key)),
+ `on trying to delete the non-existent badly-named property #${i}`,
+ ).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);
+ }
+ });
+ }));
});
\ No newline at end of file