diff --git a/.gitignore b/.gitignore index b386776c..7e172432 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ gcloud-md5-ingress.yml collator-data relay-data .vscode/settings.json +lcov.info diff --git a/pallets/fruniques/Cargo.toml b/pallets/fruniques/Cargo.toml index dd4bcbd9..1b2c6154 100644 --- a/pallets/fruniques/Cargo.toml +++ b/pallets/fruniques/Cargo.toml @@ -43,6 +43,7 @@ std = [ "frame-system/std", "frame-benchmarking/std", "sp-runtime/std", + "pallet-rbac/std", ] runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] diff --git a/pallets/fruniques/src/functions.rs b/pallets/fruniques/src/functions.rs index 4e4c001b..8ed643da 100644 --- a/pallets/fruniques/src/functions.rs +++ b/pallets/fruniques/src/functions.rs @@ -1,9 +1,9 @@ use super::*; use crate::types::*; -use frame_system::pallet_prelude::*; - +use frame_support::sp_io::hashing::blake2_256; use frame_support::traits::tokens::nonfungibles::Inspect; +use frame_system::pallet_prelude::*; use scale_info::prelude::string::String; use pallet_rbac::types::*; @@ -82,7 +82,63 @@ impl Pallet { } pub fn do_initial_setup() -> DispatchResult { - let _pallet_id = Self::pallet_id(); + + let pallet: IdOrVec = Self::pallet_id(); + + let owner_role_ids = T::Rbac::create_and_set_roles( + pallet.clone(), + FruniqueRole::get_owner_roles())?; + + for owner_role in owner_role_ids { + T::Rbac::create_and_set_permissions( + pallet.clone(), + owner_role, + Permission::owner_permissions())?; + } + + let admin_role_ids = T::Rbac::create_and_set_roles( + pallet.clone(), + FruniqueRole::get_admin_roles())?; + + for admin_role in admin_role_ids { + T::Rbac::create_and_set_permissions( + pallet.clone(), + admin_role, + Permission::admin_permissions())?; + } + + let collaborator_role_ids = T::Rbac::create_and_set_roles( + pallet.clone(), + FruniqueRole::get_collaborator_roles())?; + + for collaborator_role in collaborator_role_ids { + T::Rbac::create_and_set_permissions( + pallet.clone(), + collaborator_role, + Permission::collaborator_permissions())?; + } + + let collector_role_ids = T::Rbac::create_and_set_roles( + pallet.clone(), + FruniqueRole::get_collector_roles())?; + + for collector_role in collector_role_ids { + T::Rbac::create_and_set_permissions( + pallet.clone(), + collector_role, + Permission::collector_permissions())?; + } + + let holder_role_ids = T::Rbac::create_and_set_roles( + pallet.clone(), + FruniqueRole::get_holder_roles())?; + + for holder_role in holder_role_ids { + T::Rbac::create_and_set_permissions( + pallet.clone(), + holder_role, + Permission::holder_permissions())?; + } Ok(()) } @@ -150,6 +206,11 @@ impl Pallet { ) -> DispatchResult { let owner = T::CreateOrigin::ensure_origin(origin.clone(), &class_id)?; + let scope_id = class_id.using_encoded(blake2_256); + T::Rbac::create_scope(Self::pallet_id(), scope_id)?; + + Self::insert_auth_in_frunique_collection(owner.clone(), class_id, FruniqueRole::Owner)?; + pallet_uniques::Pallet::::do_create_collection( class_id, owner.clone(), @@ -197,12 +258,18 @@ impl Pallet { origin: OriginFor, collection: T::CollectionId, item: T::ItemId, - owner: ::Source, + owner: T::AccountId, metadata: CollectionDescription, attributes: Option>, ) -> DispatchResult { ensure!(Self::collection_exists(&collection), >::CollectionNotFound); - pallet_uniques::Pallet::::mint(origin.clone(), collection, item, owner)?; + let user: T::AccountId = ensure_signed(origin.clone())?; + Self::is_authorized(user, collection, Permission::Mint)?; + + // pallet_uniques::Pallet::::do_mint(collection, item, owner, |_| Ok(()))?; + pallet_uniques::Pallet::::do_mint(collection, item, owner, |_| { + Ok(()) + })?; pallet_uniques::Pallet::::set_metadata( origin.clone(), @@ -227,7 +294,37 @@ impl Pallet { Ok(()) } + /// Helper functions to interact with the RBAC module pub fn pallet_id() -> IdOrVec { IdOrVec::Vec(Self::module_name().as_bytes().to_vec()) } + + pub fn insert_auth_in_frunique_collection( + user: T::AccountId, + class_id: T::CollectionId, + role: FruniqueRole, + ) -> DispatchResult { + T::Rbac::assign_role_to_user( + user, + Self::pallet_id(), + &class_id.using_encoded(blake2_256), + role.id(), + )?; + + Ok(()) + } + + fn is_authorized( + user: T::AccountId, + collection_id: T::CollectionId, + permission: Permission, + ) -> DispatchResult { + let scope_id = collection_id.using_encoded(blake2_256); + ::Rbac::is_authorized( + user, + Self::pallet_id(), + &scope_id, + &permission.id(), + ) + } } diff --git a/pallets/fruniques/src/lib.rs b/pallets/fruniques/src/lib.rs index d62e87c2..e90dfcee 100644 --- a/pallets/fruniques/src/lib.rs +++ b/pallets/fruniques/src/lib.rs @@ -20,6 +20,8 @@ pub mod pallet { use crate::types::*; use frame_support::{pallet_prelude::*, transactional}; use frame_system::pallet_prelude::*; + + use pallet_rbac::types::RoleBasedAccessControl; /// Configure the pallet by specifying the parameters and types on which it depends. #[pallet::config] pub trait Config: frame_system::Config + pallet_uniques::Config { @@ -30,6 +32,8 @@ pub mod pallet { /// Maximum number of children a Frunique can have #[pallet::constant] type ChildMaxLen: Get; + + type Rbac : RoleBasedAccessControl; } #[pallet::pallet] @@ -47,6 +51,8 @@ pub mod pallet { FruniqueDivided(T::AccountId, T::AccountId, T::CollectionId, T::ItemId), // A frunique has been verified. FruniqueVerified(T::AccountId, CollectionId, ItemId), + // A user has been invited to collaborate on a collection. + InvitedToCollaborate(T::AccountId, T::AccountId, T::CollectionId), // Counter should work? NextFrunique(u32), } @@ -158,7 +164,7 @@ pub mod pallet { #[pallet::weight(10_000 + T::DbWeight::get().writes(10))] pub fn initial_setup(origin: OriginFor) -> DispatchResult { T::RemoveOrigin::ensure_origin(origin.clone())?; - // Self::do_initial_setup()?; + Self::do_initial_setup()?; Ok(()) } @@ -263,7 +269,6 @@ pub mod pallet { } let owner: T::AccountId = ensure_signed(origin.clone())?; - let account_id = Self::account_id_to_lookup_source(&owner); let instance_id: ItemId = >::try_get(class_id).unwrap_or(0); >::insert(class_id, instance_id + 1); @@ -282,7 +287,7 @@ pub mod pallet { >::insert(class_id, instance_id, Some(child_info)); } - Self::do_spawn(origin, class_id, instance_id, account_id, metadata, attributes)?; + Self::do_spawn(origin, class_id, instance_id, owner.clone(), metadata, attributes)?; Self::deposit_event(Event::FruniqueCreated( owner.clone(), @@ -317,6 +322,30 @@ pub mod pallet { Ok(()) } + /// ## Invite a user to become a collaborator in a collection. + /// ### Parameters: + /// - `origin` must be signed by the owner of the frunique. + /// - `class_id` must be a valid class of the asset class. + /// - `invitee` must be a valid user. + /// ### Considerations: + /// This functions enables the owner of a collection to invite a user to become a collaborator. + /// The user will be able to create NFTs in the collection. + /// The user will be able to add attributes to the NFTs in the collection. + + #[pallet::weight(10_000 + T::DbWeight::get().writes(1))] + pub fn invite( + origin: OriginFor, + class_id: CollectionId, + invitee: T::AccountId, + ) -> DispatchResult { + + let owner: T::AccountId = ensure_signed(origin.clone())?; + Self::insert_auth_in_frunique_collection(invitee.clone(), class_id, FruniqueRole::Collaborator)?; + + Self::deposit_event(Event::InvitedToCollaborate(owner, invitee, class_id)); + Ok(()) + } + /// ## Force set counter /// ### Parameters: /// `origin` must be signed by the Root origin. @@ -391,7 +420,7 @@ pub mod pallet { let _ = >::clear(1000, None); let _ = >::clear(1000, None); let _ = >::clear(1000, None); - + T::Rbac::remove_pallet_storage(Self::pallet_id())?; Ok(()) } } diff --git a/pallets/fruniques/src/mock.rs b/pallets/fruniques/src/mock.rs index ddb59b34..59901fdf 100644 --- a/pallets/fruniques/src/mock.rs +++ b/pallets/fruniques/src/mock.rs @@ -22,6 +22,7 @@ construct_runtime!( Uniques: pallet_uniques::{Pallet, Call, Storage, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, Fruniques: pallet_fruniques::{Pallet, Call, Storage, Event}, + RBAC: pallet_rbac::{Pallet, Call, Storage, Event}, } ); parameter_types! { @@ -60,6 +61,7 @@ impl pallet_fruniques::Config for Test { type Event = Event; type RemoveOrigin = EnsureRoot; type ChildMaxLen = ChildMaxLen; + type Rbac = RBAC; } parameter_types! { @@ -112,7 +114,39 @@ impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; } +parameter_types! { + pub const MaxScopesPerPallet: u32 = 2; + pub const MaxRolesPerPallet: u32 = 6; + pub const RoleMaxLen: u32 = 25; + pub const PermissionMaxLen: u32 = 25; + pub const MaxPermissionsPerRole: u32 = 11; + pub const MaxRolesPerUser: u32 = 2; + pub const MaxUsersPerRole: u32 = 2; +} +impl pallet_rbac::Config for Test { + type Event = Event; + type MaxScopesPerPallet = MaxScopesPerPallet; + type MaxRolesPerPallet = MaxRolesPerPallet; + type RoleMaxLen = RoleMaxLen; + type PermissionMaxLen = PermissionMaxLen; + type MaxPermissionsPerRole = MaxPermissionsPerRole; + type MaxRolesPerUser = MaxRolesPerUser; + type MaxUsersPerRole = MaxUsersPerRole; +} // Build genesis storage according to the mock runtime. // pub(crate) fn new_test_ext() -> sp_io::TestExternalities { // frame_system::GenesisConfig::default().build_storage::().unwrap().into() // } +// Build genesis storage according to the mock runtime. + + +pub fn new_test_ext() -> sp_io::TestExternalities { + let balance_amount = 1_000_000 as u64; + let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + pallet_balances::GenesisConfig:: { + balances: vec![(1, balance_amount), (2, balance_amount), (3, balance_amount)], + }.assimilate_storage(&mut t).expect("assimilate_storage failed"); + let mut t: sp_io::TestExternalities = t.into(); + t.execute_with(|| Fruniques::do_initial_setup().expect("Error on configuring initial setup")); + t +} diff --git a/pallets/fruniques/src/tests.rs b/pallets/fruniques/src/tests.rs index a201bd1c..08ed8570 100644 --- a/pallets/fruniques/src/tests.rs +++ b/pallets/fruniques/src/tests.rs @@ -1,6 +1,6 @@ use crate::{mock::*, Error}; +use codec::Encode; use core::convert::TryFrom; -use codec::{Encode}; use frame_support::{assert_noop, assert_ok, BoundedVec}; @@ -40,16 +40,17 @@ fn dummy_description() -> BoundedVec { fn dummy_attributes() -> Vec<(BoundedVec, BoundedVec)> { vec![( - BoundedVec::::try_from(b"dummy key".encode()).expect("Error on encoding key to BoundedVec"), - BoundedVec::::try_from(b"dummy value".encode()).expect("Error on encoding value to BoundedVec"), - )] + BoundedVec::::try_from(b"dummy key".encode()) + .expect("Error on encoding key to BoundedVec"), + BoundedVec::::try_from(b"dummy value".encode()) + .expect("Error on encoding value to BoundedVec"), + )] } fn dummy_empty_attributes() -> Vec<(BoundedVec, BoundedVec)> { vec![] } - #[test] fn create_collection_works() { ExtBuilder::default().build().execute_with(|| { @@ -61,23 +62,49 @@ fn create_collection_works() { fn spawn_extrinsic_works() { ExtBuilder::default().build().execute_with(|| { // A collection must be created before spawning an NFT - assert_noop!(Fruniques::spawn(Origin::signed(1), 0, None, dummy_description(), None), Error::::CollectionNotFound); + assert_noop!( + Fruniques::spawn(Origin::signed(1), 0, None, dummy_description(), None), + Error::::CollectionNotFound + ); // Create a collection assert_ok!(Fruniques::create_collection(Origin::signed(1), dummy_description())); // The first item can not be a child - assert_noop!(Fruniques::spawn(Origin::signed(1), 0, Some((0, false, 10)), dummy_description(), None), Error::::ParentNotFound); + assert_noop!( + Fruniques::spawn(Origin::signed(1), 0, Some((0, false, 10)), dummy_description(), None), + Error::::ParentNotFound + ); // A NFT can be created with empty data assert_ok!(Fruniques::spawn(Origin::signed(1), 0, None, dummy_description(), None)); // A NFT can be created with attributes - assert_ok!(Fruniques::spawn(Origin::signed(1), 0, None, dummy_description(), Some(dummy_attributes()))); + assert_ok!(Fruniques::spawn( + Origin::signed(1), + 0, + None, + dummy_description(), + Some(dummy_attributes()) + )); // A NFT can be hierarchical - assert_ok!(Fruniques::spawn(Origin::signed(1), 0, Some((0, false, 10)), dummy_description(), None)); + assert_ok!(Fruniques::spawn( + Origin::signed(1), + 0, + Some((0, false, 10)), + dummy_description(), + None + )); // The parent must exist - assert_noop!(Fruniques::spawn(Origin::signed(1), 0, Some((100, false, 10)), dummy_description(), None), Error::::ParentNotFound); - + assert_noop!( + Fruniques::spawn( + Origin::signed(1), + 0, + Some((100, false, 10)), + dummy_description(), + None + ), + Error::::ParentNotFound + ); }) } @@ -85,16 +112,37 @@ fn spawn_extrinsic_works() { fn set_attributes_works() { ExtBuilder::default().build().execute_with(|| { // A collection must be created before spawning an NFT - assert_noop!(Fruniques::spawn(Origin::signed(1), 0, None, dummy_description(), None), Error::::CollectionNotFound); + assert_noop!( + Fruniques::spawn(Origin::signed(1), 0, None, dummy_description(), None), + Error::::CollectionNotFound + ); // Create a collection assert_ok!(Fruniques::create_collection(Origin::signed(1), dummy_description())); // Attributes can be added only to existing NFTs - assert_noop!(Fruniques::set_attributes(Origin::signed(1), 0, 0, dummy_attributes()), Error::::FruniqueNotFound); + assert_noop!( + Fruniques::set_attributes(Origin::signed(1), 0, 0, dummy_attributes()), + Error::::FruniqueNotFound + ); // A NFT can be created with empty data assert_ok!(Fruniques::spawn(Origin::signed(1), 0, None, dummy_description(), None)); // Attributes can not be empty - assert_noop!(Fruniques::set_attributes(Origin::signed(1), 0, 0, dummy_empty_attributes()), Error::::AttributesEmpty); - + assert_noop!( + Fruniques::set_attributes(Origin::signed(1), 0, 0, dummy_empty_attributes()), + Error::::AttributesEmpty + ); }) } + +#[test] +fn invite_collaborator_works() { + new_test_ext().execute_with(|| { + // Create a collection + assert_ok!(Fruniques::create_collection(Origin::signed(1), dummy_description())); + assert_ok!(Fruniques::invite( + Origin::signed(1), + 0, + 2 + )); + }); +} diff --git a/pallets/fruniques/src/types.rs b/pallets/fruniques/src/types.rs index d8ef186a..60ab39a0 100644 --- a/pallets/fruniques/src/types.rs +++ b/pallets/fruniques/src/types.rs @@ -3,8 +3,8 @@ use super::*; use frame_support::pallet_prelude::*; use frame_support::sp_io::hashing::blake2_256; -use sp_runtime::Permill; use sp_runtime::sp_std::vec::Vec; +use sp_runtime::Permill; pub type AttributeKey = BoundedVec::KeyLimit>; pub type AttributeValue = BoundedVec::ValueLimit>; @@ -20,6 +20,10 @@ pub type CollectionDescription = StringLimit; // (ParentId, Hierarchical, Percentage) pub type HierarchicalInfo = (ItemId, bool, u8); +// pub type RoleId = + +// pub type RoleIds = BoundedVec<[u8; 32], <::Rbac as RoleBasedAccessControl<::AccountId>>::MaxRolesPerPallet>; + #[derive(CloneNoBound, Encode, Decode, RuntimeDebugNoBound, Default, TypeInfo, MaxEncodedLen)] pub struct ChildInfo { pub collection_id: CollectionId, @@ -44,6 +48,7 @@ pub enum FruniqueRole { Admin, Collaborator, Collector, + Holder, } impl Default for FruniqueRole { @@ -59,6 +64,7 @@ impl FruniqueRole { Self::Admin => "Admin".as_bytes().to_vec(), Self::Collaborator => "Collaborator".as_bytes().to_vec(), Self::Collector => "Collector".as_bytes().to_vec(), + Self::Holder => "Holder".as_bytes().to_vec(), } } @@ -66,9 +72,31 @@ impl FruniqueRole { self.to_vec().using_encoded(blake2_256) } + pub fn get_owner_roles() -> Vec> { + [Self::Owner.to_vec()].to_vec() + } + + pub fn get_admin_roles() -> Vec> { + [Self::Admin.to_vec()].to_vec() + } + + pub fn get_collaborator_roles() -> Vec> { + [Self::Collaborator.to_vec()] + .to_vec() + } + + pub fn get_collector_roles() -> Vec> { + [Self::Collector.to_vec()].to_vec() + } + + pub fn get_holder_roles() -> Vec> { + [Self::Holder.to_vec()].to_vec() + } + pub fn enum_to_vec() -> Vec> { use crate::types::FruniqueRole::*; - [Owner.to_vec(), Admin.to_vec(), Collaborator.to_vec(), Collector.to_vec()].to_vec() + [Owner.to_vec(), Admin.to_vec(), Collaborator.to_vec(), Collector.to_vec(), Holder.to_vec()] + .to_vec() } } @@ -77,26 +105,23 @@ impl FruniqueRole { Encode, Decode, Clone, Eq, PartialEq, RuntimeDebugNoBound, MaxEncodedLen, TypeInfo, Copy, )] pub enum Permission { - /// No authorization required + /// Not a permission None, - /// Authorization required - Required, /// Authorization required and must be approved by the owner Mint, /// Authorization required and must be approved by a holder / collector Transfer, /// Allow a user to collaborate on a collection - Collaborate, + InviteCollaborator, } impl Permission { pub fn to_vec(self) -> Vec { match self { Self::None => "None".as_bytes().to_vec(), - Self::Required => "Required".as_bytes().to_vec(), Self::Mint => "Mint".as_bytes().to_vec(), Self::Transfer => "Transfer".as_bytes().to_vec(), - Self::Collaborate => "Collaborate".as_bytes().to_vec(), + Self::InviteCollaborator => "InviteCollaborator".as_bytes().to_vec(), } } @@ -104,21 +129,21 @@ impl Permission { self.to_vec().using_encoded(blake2_256) } + pub fn get_permissions() -> Vec> { + use crate::types::Permission::*; + [None.to_vec(), Mint.to_vec(), Transfer.to_vec(), InviteCollaborator.to_vec()] + .to_vec() + } + pub fn owner_permissions() -> Vec> { use crate::types::Permission::*; - [None.to_vec(), Required.to_vec(), Mint.to_vec(), Transfer.to_vec()].to_vec() + [Mint.to_vec(), Transfer.to_vec(), InviteCollaborator.to_vec()].to_vec() } pub fn admin_permissions() -> Vec> { use crate::types::Permission::*; - let mut admin_permissions = [ - None.to_vec(), - Required.to_vec(), - Mint.to_vec(), - Transfer.to_vec(), - Collaborate.to_vec(), - ] - .to_vec(); + let mut admin_permissions = + [Mint.to_vec(), InviteCollaborator.to_vec()].to_vec(); admin_permissions.append(&mut Permission::holder_permissions()); admin_permissions } @@ -128,8 +153,13 @@ impl Permission { [Mint.to_vec()].to_vec() } + pub fn collector_permissions() -> Vec> { + use crate::types::Permission::*; + [None.to_vec()].to_vec() + } + pub fn holder_permissions() -> Vec> { use crate::types::Permission::*; - [None.to_vec(), Required.to_vec(), Transfer.to_vec()].to_vec() + [Transfer.to_vec()].to_vec() } } diff --git a/pallets/gated-marketplace/src/functions.rs b/pallets/gated-marketplace/src/functions.rs index b4e67c81..ed5cc522 100644 --- a/pallets/gated-marketplace/src/functions.rs +++ b/pallets/gated-marketplace/src/functions.rs @@ -16,17 +16,17 @@ impl Pallet { pub fn do_initial_setup()->DispatchResult{ let pallet_id = Self::pallet_id(); let super_roles = vec![MarketplaceRole::Owner.to_vec(), MarketplaceRole::Admin.to_vec()]; - let super_role_ids = T::Rbac::create_and_set_roles(pallet_id.clone(), super_roles)?; + let super_role_ids = ::Rbac::create_and_set_roles(pallet_id.clone(), super_roles)?; for super_role in super_role_ids{ - T::Rbac::create_and_set_permissions(pallet_id.clone(), super_role, Permission::admin_permissions())?; + ::Rbac::create_and_set_permissions(pallet_id.clone(), super_role, Permission::admin_permissions())?; } // participant role and permissions - let participant_role_id = T::Rbac::create_and_set_roles(pallet_id.clone(), [MarketplaceRole::Participant.to_vec()].to_vec())?; - T::Rbac::create_and_set_permissions(pallet_id.clone(), participant_role_id[0], Permission::participant_permissions() )?; + let participant_role_id = ::Rbac::create_and_set_roles(pallet_id.clone(), [MarketplaceRole::Participant.to_vec()].to_vec())?; + ::Rbac::create_and_set_permissions(pallet_id.clone(), participant_role_id[0], Permission::participant_permissions() )?; // appraiser role and permissions - let _appraiser_role_id = T::Rbac::create_and_set_roles(pallet_id.clone(), [MarketplaceRole::Appraiser.to_vec()].to_vec())?; + let _appraiser_role_id = ::Rbac::create_and_set_roles(pallet_id.clone(), [MarketplaceRole::Appraiser.to_vec()].to_vec())?; // redemption specialist role and permissions - let _redemption_role_id = T::Rbac::create_and_set_roles(pallet_id, [MarketplaceRole::RedemptionSpecialist.to_vec()].to_vec())?; + let _redemption_role_id = ::Rbac::create_and_set_roles(pallet_id, [MarketplaceRole::RedemptionSpecialist.to_vec()].to_vec())?; Self::deposit_event(Event::MarketplaceSetupCompleted); Ok(()) @@ -38,7 +38,7 @@ impl Pallet { // ensure the generated id is unique ensure!(!>::contains_key(marketplace_id), Error::::MarketplaceAlreadyExists); //Insert on marketplaces and marketplaces by auth - T::Rbac::create_scope(Self::pallet_id(), marketplace_id)?; + ::Rbac::create_scope(Self::pallet_id(), marketplace_id)?; Self::insert_in_auth_market_lists(owner.clone(), MarketplaceRole::Owner, marketplace_id)?; Self::insert_in_auth_market_lists(admin.clone(), MarketplaceRole::Admin, marketplace_id)?; >::insert(marketplace_id, marketplace); @@ -125,7 +125,7 @@ impl Pallet { //Self::can_enroll(authority, marketplace_id)?; Self::is_authorized(authority, &marketplace_id,Permission::AddAuth)?; //ensure the account is not already an authority - // handled by T::Rbac::assign_role_to_user + // handled by ::Rbac::assign_role_to_user //ensure!(!Self::does_exist_authority(account.clone(), marketplace_id, authority_type), Error::::AlreadyApplied); match authority_type{ MarketplaceRole::Owner => { @@ -148,7 +148,7 @@ impl Pallet { //Self::can_enroll(authority.clone(), marketplace_id)?; Self::is_authorized(authority.clone(), &marketplace_id,Permission::RemoveAuth)?; //ensure the account has the selected authority before to try to remove - // T::Rbac handles the if role doesnt hasnt been asigned to the user + // ::Rbac handles the if role doesnt hasnt been asigned to the user //ensure!(Self::does_exist_authority(account.clone(), marketplace_id, authority_type), Error::::AuthorityNotFoundForUser); match authority_type{ @@ -494,7 +494,7 @@ impl Pallet { fn insert_in_auth_market_lists(authority: T::AccountId, role: MarketplaceRole, marketplace_id: [u8;32])->DispatchResult{ - T::Rbac::assign_role_to_user(authority, Self::pallet_id(), + ::Rbac::assign_role_to_user(authority, Self::pallet_id(), &marketplace_id, role.id())?; Ok(()) @@ -529,7 +529,7 @@ impl Pallet { fn remove_from_market_lists(account: T::AccountId, author_type: MarketplaceRole , marketplace_id : [u8;32])->DispatchResult{ - T::Rbac::remove_role_from_user(account, Self::pallet_id(), + ::Rbac::remove_role_from_user(account, Self::pallet_id(), &marketplace_id, author_type.id())?; Ok(()) @@ -557,17 +557,17 @@ impl Pallet { Self::insert_in_applicants_lists(applicant.clone(), next_status,marketplace_id)?; if prev_status == ApplicationStatus::Approved{ - T::Rbac::remove_role_from_user(applicant.clone(), Self::pallet_id(), &marketplace_id, MarketplaceRole::Participant.id())?; + ::Rbac::remove_role_from_user(applicant.clone(), Self::pallet_id(), &marketplace_id, MarketplaceRole::Participant.id())?; } if next_status == ApplicationStatus::Approved{ - T::Rbac::assign_role_to_user(applicant, Self::pallet_id(), &marketplace_id, MarketplaceRole::Participant.id())? + ::Rbac::assign_role_to_user(applicant, Self::pallet_id(), &marketplace_id, MarketplaceRole::Participant.id())? } Ok(()) } fn is_authorized( authority: T::AccountId, marketplace_id: &[u8;32], permission: Permission ) -> DispatchResult{ - T::Rbac::is_authorized( + ::Rbac::is_authorized( authority, Self::pallet_id(), marketplace_id, @@ -579,7 +579,7 @@ impl Pallet { ///Lets us know if the selected user is an admin. /// It returns true if the user is an admin, false otherwise. fn is_admin(account: T::AccountId, marketplace_id: [u8;32]) -> bool{ - T::Rbac::has_role(account, Self::pallet_id(), + ::Rbac::has_role(account, Self::pallet_id(), &marketplace_id, [MarketplaceRole::Admin.id()].to_vec()).is_ok() } @@ -604,7 +604,7 @@ impl Pallet { // }; //owners.len() == 1 - T::Rbac::get_role_users_len(Self::pallet_id(), + ::Rbac::get_role_users_len(Self::pallet_id(), &marketplace_id, &MarketplaceRole::Owner.id()) == 1 } @@ -657,7 +657,7 @@ impl Pallet { // remove from Marketplaces list >::remove(marketplace_id); - T::Rbac::remove_scope(Self::pallet_id(), marketplace_id)?; + ::Rbac::remove_scope(Self::pallet_id(), marketplace_id)?; Ok(()) } diff --git a/pallets/gated-marketplace/src/lib.rs b/pallets/gated-marketplace/src/lib.rs index 725ca5de..0c8b8c6d 100644 --- a/pallets/gated-marketplace/src/lib.rs +++ b/pallets/gated-marketplace/src/lib.rs @@ -670,7 +670,7 @@ pub mod pallet { let _ = >::clear(1000, None); let _ = >::clear(1000, None); let _ = >::clear(1000, None); - T::Rbac::remove_pallet_storage(Self::pallet_id())?; + // T::Rbac::remove_pallet_storage(Self::pallet_id())?; Ok(()) } diff --git a/pallets/gated-marketplace/src/mock.rs b/pallets/gated-marketplace/src/mock.rs index f22786e9..931d54b3 100644 --- a/pallets/gated-marketplace/src/mock.rs +++ b/pallets/gated-marketplace/src/mock.rs @@ -100,6 +100,7 @@ impl pallet_fruniques::Config for Test { type Event = Event; type RemoveOrigin = EnsureRoot; type ChildMaxLen = ChildMaxLen; + type Rbac = RBAC; } parameter_types! { diff --git a/pallets/gated-marketplace/src/tests.rs b/pallets/gated-marketplace/src/tests.rs index 2e252042..2e0397ff 100644 --- a/pallets/gated-marketplace/src/tests.rs +++ b/pallets/gated-marketplace/src/tests.rs @@ -52,7 +52,7 @@ fn _create_file(name: &str, cid: &str, create_custodian_file: bool) -> Applicati } // due to encoding problems with polkadot-js, the custodians_cid generation will be done in another function -fn create_application_fields( n_files: u32) -> +fn create_application_fields( n_files: u32) -> BoundedVec<(BoundedVec >,BoundedVec> ), MaxFiles> { let mut files = Vec::<(BoundedVec >,BoundedVec> )>::default(); for i in 0..n_files{ @@ -63,7 +63,7 @@ fn create_application_fields( n_files: u32) -> BoundedVec::<(BoundedVec >,BoundedVec> ), MaxFiles>::try_from( files).unwrap_or_default() } -fn create_custiodian_fields( custodian_account: u64, n_files: u32, ) -> +fn create_custodian_fields( custodian_account: u64, n_files: u32, ) -> Option<( u64,BoundedVec>, MaxFiles>) >{ let cids: Vec>> = (0..n_files).map(|n|{ let cid = format!("cid_custodian{}",n.to_string()); @@ -71,7 +71,7 @@ fn create_custiodian_fields( custodian_account: u64, n_files: u32, ) -> }).collect(); - Some( + Some( (custodian_account,BoundedVec::>, MaxFiles>::try_from(cids).unwrap_or_default()) ) } @@ -83,7 +83,7 @@ fn create_marketplace_works() { // Dispatch a signed extrinsic. assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1),2, create_label("my marketplace") )); let m_id = create_label("my marketplace").using_encoded(blake2_256); - assert!(GatedMarketplace::marketplaces(m_id).is_some() ); + assert!(GatedMarketplace::marketplaces(m_id).is_some() ); }); } @@ -103,8 +103,8 @@ fn exceeding_max_roles_per_auth_shouldnt_work() { assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1),2, m_label.clone() )); assert_ok!(GatedMarketplace::add_authority(Origin::signed(1), 2, MarketplaceRole::Appraiser, m_label.using_encoded(blake2_256))); assert_noop!( - GatedMarketplace::add_authority(Origin::signed(1), 2, MarketplaceRole::RedemptionSpecialist, m_label.using_encoded(blake2_256) ), - RbacErr::ExceedMaxRolesPerUser + GatedMarketplace::add_authority(Origin::signed(1), 2, MarketplaceRole::RedemptionSpecialist, m_label.using_encoded(blake2_256) ), + RbacErr::ExceedMaxRolesPerUser ); }); @@ -128,7 +128,7 @@ fn apply_with_custodian_works() { // Dispatch a signed extrinsic. assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1),2, create_label("my marketplace") )); let m_id = create_label("my marketplace").using_encoded(blake2_256); - assert_ok!(GatedMarketplace::apply(Origin::signed(3),m_id, create_application_fields(2), create_custiodian_fields(4,2) )); + assert_ok!(GatedMarketplace::apply(Origin::signed(3),m_id, create_application_fields(2), create_custodian_fields(4,2) )); assert!( GatedMarketplace::applicants_by_marketplace(m_id, ApplicationStatus::Pending).len() ==1); assert!(GatedMarketplace::custodians(4, m_id).pop().is_some() ); @@ -142,7 +142,7 @@ fn apply_with_same_account_as_custodian_shouldnt_work() { assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1),2, create_label("my marketplace") )); let m_id = create_label("my marketplace").using_encoded(blake2_256); assert_noop!( - GatedMarketplace::apply(Origin::signed(3),m_id, create_application_fields(2), create_custiodian_fields(3,2) ), + GatedMarketplace::apply(Origin::signed(3),m_id, create_application_fields(2), create_custodian_fields(3,2) ), Error::::ApplicantCannotBeCustodian ); }); @@ -154,10 +154,10 @@ fn exceeding_max_applications_per_custodian_shouldnt_work() { // Dispatch a signed extrinsic. assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1),2, create_label("my marketplace") )); let m_id = create_label("my marketplace").using_encoded(blake2_256); - assert_ok!(GatedMarketplace::apply(Origin::signed(3),m_id, create_application_fields(2), create_custiodian_fields(6,2) )); - assert_ok!(GatedMarketplace::apply(Origin::signed(4),m_id, create_application_fields(2), create_custiodian_fields(6,2) )); + assert_ok!(GatedMarketplace::apply(Origin::signed(3),m_id, create_application_fields(2), create_custodian_fields(6,2) )); + assert_ok!(GatedMarketplace::apply(Origin::signed(4),m_id, create_application_fields(2), create_custodian_fields(6,2) )); assert_noop!( - GatedMarketplace::apply(Origin::signed(5),m_id, create_application_fields(2), create_custiodian_fields(6,2) ), + GatedMarketplace::apply(Origin::signed(5),m_id, create_application_fields(2), create_custodian_fields(6,2) ), Error::::ExceedMaxApplicationsPerCustodian ); }); @@ -464,10 +464,10 @@ fn update_marketplace_marketplace_not_found_shouldnt_work(){ assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1),2, create_label("my marketplace") )); let m_id = create_label("my marketplace").using_encoded(blake2_256); assert!(GatedMarketplace::marketplaces(m_id).is_some()); - let m_id_2 = create_label("not the first marketplace").using_encoded(blake2_256); + let m_id_2 = create_label("not the first marketplace").using_encoded(blake2_256); assert_noop!(GatedMarketplace::update_label_marketplace(Origin::signed(1), m_id_2, create_label("my marketplace 2")), Error::::MarketplaceNotFound); }); - + } #[test] @@ -486,9 +486,9 @@ fn update_label_marketplace_works(){ new_test_ext().execute_with(|| { assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1),2, create_label("my marketplace") )); let m_id = create_label("my marketplace").using_encoded(blake2_256); - assert!(GatedMarketplace::marketplaces(m_id).is_some()); + assert!(GatedMarketplace::marketplaces(m_id).is_some()); assert_ok!(GatedMarketplace::update_label_marketplace(Origin::signed(1), m_id, create_label("my marketplace 2"))); - assert!(GatedMarketplace::marketplaces(m_id).is_some() ); + assert!(GatedMarketplace::marketplaces(m_id).is_some() ); }); } @@ -504,7 +504,7 @@ fn remove_marketplace_marketplace_not_found_shouldnt_work(){ let m_id_2 = create_label("not the first marketplace").using_encoded(blake2_256); assert_noop!(GatedMarketplace::remove_marketplace(Origin::signed(1), m_id_2), Error::::MarketplaceNotFound); }); - + } @@ -538,7 +538,7 @@ fn remove_marketplace_deletes_storage_from_marketplaces_by_authority_works(){ assert_ok!(GatedMarketplace::add_authority(Origin::signed(1), 3, MarketplaceRole::Appraiser, m_id)); assert_ok!(GatedMarketplace::add_authority(Origin::signed(1), 4, MarketplaceRole::RedemptionSpecialist, m_id)); - + //assert!(GatedMarketplace::marketplaces_by_authority(1, m_id) == vec![MarketplaceRole::Owner]); assert_ok!(::Rbac::has_role(1, GatedMarketplace::pallet_id(), &m_id, vec![MarketplaceRole::Owner.id()])); //assert!(GatedMarketplace::marketplaces_by_authority(2, m_id) == vec![MarketplaceRole::Admin]); @@ -602,7 +602,7 @@ fn remove_marketplace_deletes_storage_from_custodians_works(){ let m_id = create_label("my marketplace").using_encoded(blake2_256); assert!(GatedMarketplace::marketplaces(m_id).is_some()); - assert_ok!(GatedMarketplace::apply(Origin::signed(3),m_id, create_application_fields(2), create_custiodian_fields(4,2) )); + assert_ok!(GatedMarketplace::apply(Origin::signed(3),m_id, create_application_fields(2), create_custodian_fields(4,2) )); assert!(GatedMarketplace::custodians(4, m_id) == vec![3]); assert_ok!(GatedMarketplace::remove_marketplace(Origin::signed(1), m_id)); @@ -804,12 +804,12 @@ fn enlist_sell_offer_works() { assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 10000)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 10000)); let offer_id = GatedMarketplace::offers_by_item(0, 0).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id).is_some()); assert_eq!(GatedMarketplace::offers_info(offer_id).unwrap().offer_type, OfferType::SellOrder); @@ -842,12 +842,12 @@ fn enlist_sell_offer_item_already_enlisted_shouldnt_work() { assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 10000)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 10000)); let offer_id = GatedMarketplace::offers_by_item(0, 0).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id).is_some()); assert_noop!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 10000), Error::::OfferAlreadyExists); @@ -862,11 +862,11 @@ fn enlist_sell_offer_not_owner_tries_to_enlist_shouldnt_work() { assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - + assert_noop!(GatedMarketplace::enlist_sell_offer(Origin::signed(2), m_id, 0, 0, 10000), Error::::NotOwner); }); } @@ -878,11 +878,11 @@ fn enlist_sell_offer_price_must_greater_than_zero_shouldnt_work() { assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - + assert_noop!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 0), Error::::PriceMustBeGreaterThanZero); }); } @@ -894,12 +894,12 @@ fn enlist_sell_offer_price_must_greater_than_minimun_amount_works() { assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - let minimum_amount = 1001; + + let minimum_amount = 1001; assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, minimum_amount)); let offer_id = GatedMarketplace::offers_by_item(0, 0).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id).is_some()); @@ -913,11 +913,11 @@ fn enlist_sell_offer_is_properly_stored_works() { assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 10000)); let offer_id = GatedMarketplace::offers_by_item(0, 0).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id).is_some()); @@ -938,13 +938,13 @@ fn enlist_sell_offer_two_marketplaces(){ assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace2"))); let m_id2 = create_label("my marketplace2").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 10000)); - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id2, 0, 0, 11000)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 10000)); + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id2, 0, 0, 11000)); assert_eq!(GatedMarketplace::offers_by_item(0, 0).len(), 2); assert_eq!(GatedMarketplace::offers_by_account(1).len(), 2); @@ -962,12 +962,12 @@ fn enlist_buy_offer_works() { assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); let offer_id = GatedMarketplace::offers_by_account(1).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id).is_some()); @@ -986,12 +986,12 @@ fn enlist_buy_offer_item_is_not_for_sale_shouldnt_work() { assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); let offer_id = GatedMarketplace::offers_by_account(1).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id).is_some()); @@ -1008,20 +1008,20 @@ fn enlist_buy_offer_owner_cannnot_create_buy_offers_for_their_own_items_shouldnt assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); let offer_id = GatedMarketplace::offers_by_account(1).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id).is_some()); - + assert_noop!(GatedMarketplace::enlist_buy_offer(Origin::signed(1), m_id, 0, 0, 1100), Error::::CannotCreateOffer); }); } -#[test] +#[test] fn enlist_buy_offer_user_does_not_have_enough_balance_shouldnt_work() { new_test_ext().execute_with(|| { Balances::make_free_balance_be(&1, 100); @@ -1030,12 +1030,12 @@ fn enlist_buy_offer_user_does_not_have_enough_balance_shouldnt_work() { assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 10000)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 10000)); let offer_id = GatedMarketplace::offers_by_account(1).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id).is_some()); @@ -1052,12 +1052,12 @@ fn enlist_buy_offer_price_must_greater_than_zero_shouldnt_work() { assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 10000)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 10000)); let offer_id = GatedMarketplace::offers_by_account(1).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id).is_some()); @@ -1076,12 +1076,12 @@ fn enlist_buy_offer_an_item_can_receive_multiple_buy_offers(){ assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 10000)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 10000)); let offer_id = GatedMarketplace::offers_by_account(1).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id).is_some()); @@ -1107,15 +1107,15 @@ fn take_sell_offer_works(){ new_test_ext().execute_with(|| { Balances::make_free_balance_be(&1, 100); Balances::make_free_balance_be(&2, 1300); - + assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1200)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1200)); let offer_id = GatedMarketplace::offers_by_item(0, 0).iter().next().unwrap().clone(); assert_ok!(GatedMarketplace::take_sell_offer(Origin::signed(2), offer_id)); @@ -1130,15 +1130,15 @@ fn take_sell_offer_owner_cannnot_be_the_buyer_shouldnt_work() { new_test_ext().execute_with(|| { Balances::make_free_balance_be(&1, 100); Balances::make_free_balance_be(&2, 1300); - + assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1200)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1200)); let offer_id = GatedMarketplace::offers_by_item(0, 0).iter().next().unwrap().clone(); assert_noop!(GatedMarketplace::take_sell_offer(Origin::signed(1), offer_id), Error::::CannotTakeOffer); @@ -1150,15 +1150,15 @@ fn take_sell_offer_id_does_not_exist_shouldnt_work(){ new_test_ext().execute_with(|| { Balances::make_free_balance_be(&1, 100); Balances::make_free_balance_be(&2, 1300); - + assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1200)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1200)); let offer_id = GatedMarketplace::offers_by_item(0, 0).iter().next().unwrap().clone(); let offer_id2 = offer_id.using_encoded(blake2_256); @@ -1172,15 +1172,15 @@ fn take_sell_offer_buyer_does_not_have_enough_balance_shouldnt_work(){ new_test_ext().execute_with(|| { Balances::make_free_balance_be(&1, 100); Balances::make_free_balance_be(&2, 1100); - + assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1200)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1200)); let offer_id = GatedMarketplace::offers_by_item(0, 0).iter().next().unwrap().clone(); assert_noop!(GatedMarketplace::take_sell_offer(Origin::signed(2), offer_id), Error::::NotEnoughBalance); @@ -1192,22 +1192,22 @@ fn take_buy_offer_works(){ new_test_ext().execute_with(|| { Balances::make_free_balance_be(&1, 100); Balances::make_free_balance_be(&2, 1300); - + assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); let offer_id = GatedMarketplace::offers_by_account(1).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id).is_some()); - - assert_ok!(GatedMarketplace::enlist_buy_offer(Origin::signed(2), m_id, 0, 0, 1200)); + + assert_ok!(GatedMarketplace::enlist_buy_offer(Origin::signed(2), m_id, 0, 0, 1200)); let offer_id2 = GatedMarketplace::offers_by_account(2).iter().next().unwrap().clone(); assert_eq!(GatedMarketplace::offers_info(offer_id2).unwrap().offer_type, OfferType::BuyOrder); - + assert_ok!(GatedMarketplace::take_buy_offer(Origin::signed(1), offer_id2)); assert_eq!(GatedMarketplace::offers_by_item(0, 0).len(), 0); assert_eq!(GatedMarketplace::offers_info(offer_id).unwrap().status, OfferStatus::Closed); @@ -1219,20 +1219,20 @@ fn take_buy_offer_only_owner_can_accept_buy_offers_shouldnt_work(){ new_test_ext().execute_with(|| { Balances::make_free_balance_be(&1, 100); Balances::make_free_balance_be(&2, 1300); - + assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); let offer_id = GatedMarketplace::offers_by_account(1).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id).is_some()); - - assert_ok!(GatedMarketplace::enlist_buy_offer(Origin::signed(2), m_id, 0, 0, 1200)); + + assert_ok!(GatedMarketplace::enlist_buy_offer(Origin::signed(2), m_id, 0, 0, 1200)); let offer_id2 = GatedMarketplace::offers_by_account(2).iter().next().unwrap().clone(); assert_eq!(GatedMarketplace::offers_info(offer_id2).unwrap().offer_type, OfferType::BuyOrder); @@ -1245,19 +1245,19 @@ fn take_buy_offer_id_does_not_exist_shouldnt_work(){ new_test_ext().execute_with(|| { Balances::make_free_balance_be(&1, 100); Balances::make_free_balance_be(&2, 1300); - + assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); let offer_id = GatedMarketplace::offers_by_account(1).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id).is_some()); - - assert_ok!(GatedMarketplace::enlist_buy_offer(Origin::signed(2), m_id, 0, 0, 1200)); + + assert_ok!(GatedMarketplace::enlist_buy_offer(Origin::signed(2), m_id, 0, 0, 1200)); let offer_id2 = GatedMarketplace::offers_by_account(2).iter().next().unwrap().clone(); assert_eq!(GatedMarketplace::offers_info(offer_id2).unwrap().offer_type, OfferType::BuyOrder); @@ -1272,22 +1272,22 @@ fn take_buy_offer_user_does_not_have_enough_balance_shouldnt_work(){ new_test_ext().execute_with(|| { Balances::make_free_balance_be(&1, 100); Balances::make_free_balance_be(&2, 1300); - + assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); let offer_id = GatedMarketplace::offers_by_account(1).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id).is_some()); - - assert_ok!(GatedMarketplace::enlist_buy_offer(Origin::signed(2), m_id, 0, 0, 1200)); + + assert_ok!(GatedMarketplace::enlist_buy_offer(Origin::signed(2), m_id, 0, 0, 1200)); let offer_id2 = GatedMarketplace::offers_by_account(2).iter().next().unwrap().clone(); assert_eq!(GatedMarketplace::offers_info(offer_id2).unwrap().offer_type, OfferType::BuyOrder); - + Balances::make_free_balance_be(&2, 0); assert_noop!(GatedMarketplace::take_buy_offer(Origin::signed(1), offer_id2), Error::::NotEnoughBalance); }); @@ -1298,18 +1298,18 @@ fn remove_sell_offer_works(){ new_test_ext().execute_with(|| { Balances::make_free_balance_be(&1, 100); Balances::make_free_balance_be(&2, 1300); - + assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); let offer_id = GatedMarketplace::offers_by_account(1).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id).is_some()); - + assert_ok!(GatedMarketplace::remove_offer(Origin::signed(1), offer_id)); assert_eq!(GatedMarketplace::offers_by_account(1).len(), 0); assert!(GatedMarketplace::offers_info(offer_id).is_none()); @@ -1321,22 +1321,22 @@ fn remove_buy_offer_works(){ new_test_ext().execute_with(|| { Balances::make_free_balance_be(&1, 100); Balances::make_free_balance_be(&2, 1300); - + assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); let offer_id = GatedMarketplace::offers_by_account(1).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id).is_some()); - assert_ok!(GatedMarketplace::enlist_buy_offer(Origin::signed(2), m_id, 0, 0, 1001)); + assert_ok!(GatedMarketplace::enlist_buy_offer(Origin::signed(2), m_id, 0, 0, 1001)); let offer_id2 = GatedMarketplace::offers_by_account(2).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id2).is_some()); - + assert_ok!(GatedMarketplace::remove_offer(Origin::signed(2), offer_id2)); assert_eq!(GatedMarketplace::offers_by_account(2).len(), 0); assert!(GatedMarketplace::offers_info(offer_id2).is_none()); @@ -1348,18 +1348,18 @@ fn remove_offer_id_does_not_exist_sholdnt_work(){ new_test_ext().execute_with(|| { Balances::make_free_balance_be(&1, 100); Balances::make_free_balance_be(&2, 1300); - + assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); let offer_id = GatedMarketplace::offers_by_account(1).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id).is_some()); - + let offer_id2 = offer_id.using_encoded(blake2_256); assert_noop!(GatedMarketplace::remove_offer(Origin::signed(2), offer_id2), Error::::OfferNotFound); }); @@ -1370,18 +1370,18 @@ fn remove_offer_creator_doesnt_match_sholdnt_work(){ new_test_ext().execute_with(|| { Balances::make_free_balance_be(&1, 100); Balances::make_free_balance_be(&2, 1300); - + assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); + + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); let offer_id = GatedMarketplace::offers_by_account(1).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id).is_some()); - + assert_noop!(GatedMarketplace::remove_offer(Origin::signed(2), offer_id), Error::::CannotRemoveOffer); }); } @@ -1391,27 +1391,27 @@ fn remove_offer_status_is_closed_shouldnt_work(){ new_test_ext().execute_with(|| { Balances::make_free_balance_be(&1, 100); Balances::make_free_balance_be(&2, 1300); - + assert_ok!(GatedMarketplace::create_marketplace(Origin::signed(1), 2, create_label("my marketplace"))); let m_id = create_label("my marketplace").using_encoded(blake2_256); - + assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 0, 1)); assert_eq!(Uniques::owner(0, 0).unwrap(), 1); - assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); + assert_ok!(GatedMarketplace::enlist_sell_offer(Origin::signed(1), m_id, 0, 0, 1001)); let offer_id = GatedMarketplace::offers_by_account(1).iter().next().unwrap().clone(); assert!(GatedMarketplace::offers_info(offer_id).is_some()); - - assert_ok!(GatedMarketplace::enlist_buy_offer(Origin::signed(2), m_id, 0, 0, 1200)); + + assert_ok!(GatedMarketplace::enlist_buy_offer(Origin::signed(2), m_id, 0, 0, 1200)); let offer_id2 = GatedMarketplace::offers_by_account(2).iter().next().unwrap().clone(); assert_eq!(GatedMarketplace::offers_info(offer_id2).unwrap().offer_type, OfferType::BuyOrder); - + assert_ok!(GatedMarketplace::take_buy_offer(Origin::signed(1), offer_id2)); assert_eq!(GatedMarketplace::offers_by_item(0, 0).len(), 0); assert_eq!(GatedMarketplace::offers_info(offer_id).unwrap().status, OfferStatus::Closed); assert_noop!(GatedMarketplace::remove_offer(Origin::signed(2), offer_id2), Error::::CannotDeleteOffer); }); - -} \ No newline at end of file + +} diff --git a/pallets/rbac/src/functions.rs b/pallets/rbac/src/functions.rs index bc21c4b5..d08a0c5e 100644 --- a/pallets/rbac/src/functions.rs +++ b/pallets/rbac/src/functions.rs @@ -10,7 +10,7 @@ use crate::types::*; impl RoleBasedAccessControl for Pallet{ /*---- Basic Insertion of individual storage maps ---*/ /// Scope creation - /// + /// /// Creates a scope within a external pallet using the pallet index. /// ### Parameters: /// - `pallet_id`: The unique pallet identifier. @@ -25,7 +25,7 @@ impl RoleBasedAccessControl for Pallet{ } /// Scope removal - /// + /// /// Removes a scope within a external pallet using the pallet index. /// Executing this function will delete all registered role users. /// ### Parameters: @@ -53,14 +53,14 @@ impl RoleBasedAccessControl for Pallet{ }); // remove on users by scope let _ = >::clear_prefix((pallet_id, scope_id),1000 ,None); - + Ok(()) } /// External pallet storage removal - /// + /// /// Removes all storage associated to a external pallet. - /// + /// /// Executing this function will delete all role lists and permissions linked /// to that pallet. /// ### Parameters: @@ -90,13 +90,13 @@ impl RoleBasedAccessControl for Pallet{ } /// Role creation and coupling with pallet. - /// + /// /// Creates the specified roles if needed and adds them to the pallet. /// Recommended first step to enable RBAC on a external pallet. /// ### Parameters: /// - `pallet_id`: The unique pallet identifier. /// - `roles`: A list of roles to create, encoded in bytes. - fn create_and_set_roles(pallet: IdOrVec, roles: Vec>) -> + fn create_and_set_roles(pallet: IdOrVec, roles: Vec>) -> Result, DispatchError>{ let mut role_ids= Vec::<[u8;32]>::new(); for role in roles{ @@ -109,7 +109,7 @@ impl RoleBasedAccessControl for Pallet{ } /// Role creation. - /// + /// /// Creates a role and returns its identifier, if its already created, /// the function will return the preexisting one. /// ### Parameters: @@ -124,12 +124,12 @@ impl RoleBasedAccessControl for Pallet{ } /// Role coupling with pallet. - /// + /// /// Assigns a previously created role to a pallet. - /// + /// /// ### Parameters: /// - `pallet_id`: The unique pallet identifier. - /// - `role_id`: The unique role identifier. + /// - `role_id`: The unique role identifier. fn set_role_to_pallet(pallet: IdOrVec, role_id: RoleId )-> DispatchResult{ ensure!(>::contains_key(role_id), Error::::RoleNotFound); >::try_mutate(pallet.to_id(), |roles|{ @@ -140,11 +140,11 @@ impl RoleBasedAccessControl for Pallet{ } /// Multiple role coupling with pallet. - /// + /// /// Assigns multiple, previously created roles to a pallet. /// ### Parameters: /// - `pallet_id`: The unique pallet identifier. - /// - `roles`: A list of unique role identifiers. + /// - `roles`: A list of unique role identifiers. fn set_multiple_pallet_roles(pallet: IdOrVec, roles: Vec)->DispatchResult{ let pallet_id = pallet.to_id(); // checks for duplicates: @@ -161,7 +161,7 @@ impl RoleBasedAccessControl for Pallet{ } /// Role assignation to a user - /// + /// /// Assigns a role to a user in a scope context. /// ### Parameters: /// - `user`: The account which the role will be granted. @@ -186,7 +186,7 @@ impl RoleBasedAccessControl for Pallet{ } /// Role removal from the user. - /// + /// /// Removes the specified role from a user in a scope context. the user will no longer /// be able to enforce the removed role and its permissions. /// ### Parameters: @@ -218,13 +218,13 @@ impl RoleBasedAccessControl for Pallet{ } /// Permission creation and coupling with a role. - /// + /// /// Creates the specified permissions if needed and assigns them to a role. /// ### Parameters: /// - `pallet_id`: The unique pallet identifier. /// - `role_id`: The role identifier to which the permissions will /// be linked to. - /// - `permissions`: A list of permissions to create and link, + /// - `permissions`: A list of permissions to create and link, /// encoded in bytes. fn create_and_set_permissions(pallet: IdOrVec, role_id: RoleId, permissions: Vec>)-> Result, DispatchError> { @@ -241,7 +241,7 @@ impl RoleBasedAccessControl for Pallet{ } /// Permission creation - /// + /// /// Creates the specified permission in the specified pallet.. /// ### Parameters: /// - `pallet_id`: The unique pallet identifier. @@ -260,7 +260,7 @@ impl RoleBasedAccessControl for Pallet{ } /// Permission linking to role. - /// + /// /// Assigns a previously created permission to a role. /// ### Parameters: /// - `pallet_id`: The unique pallet identifier. @@ -281,8 +281,8 @@ impl RoleBasedAccessControl for Pallet{ } /// Multiple permissions assignation to a role - /// - /// Assigns multiple, previously created permissions + /// + /// Assigns multiple, previously created permissions /// to a role in a pallet context. /// ### Parameters: /// - `pallet_id`: The unique pallet identifier. @@ -294,7 +294,7 @@ impl RoleBasedAccessControl for Pallet{ let pallet_id_enum = pallet.to_id_enum(); let pallet_id = pallet_id_enum.to_id(); Self::is_role_linked_to_pallet(pallet_id_enum, &role_id )?; - + let role_permissions = >::get(&pallet_id, role_id); for id in permissions.clone(){ ensure!(!role_permissions.contains(&id), Error::::PermissionAlreadyLinkedToRole ); @@ -308,7 +308,7 @@ impl RoleBasedAccessControl for Pallet{ /*---- Helper functions ----*/ /// Authorization function - /// + /// /// Checks if the user has a role that includes the specified permission. /// ### Parameters: /// - `user`: The account to validate. @@ -329,7 +329,7 @@ impl RoleBasedAccessControl for Pallet{ } /// User role validation function - /// + /// /// Checks if the user has at least one of the specified roles. /// ### Parameters: /// - `user`: The account to validate. @@ -346,9 +346,9 @@ impl RoleBasedAccessControl for Pallet{ ); Ok(()) } - + /// Scope validation - /// + /// /// Checks if the scope exists in that pallet. /// ### Parameters: /// - `pallet_id`: The unique pallet identifier. @@ -359,18 +359,18 @@ impl RoleBasedAccessControl for Pallet{ } /// Permission validation. - /// - /// Checks if the permission exists in a pallet context. + /// + /// Checks if the permission exists in a pallet context. /// ### Parameters: /// - `pallet_id`: The unique pallet identifier. /// - `permission_id`: The permission to validate. fn permission_exists(pallet: IdOrVec, permission_id: &PermissionId)->DispatchResult{ ensure!(>::contains_key(pallet.to_id(), permission_id), Error::::PermissionNotFound); - Ok(()) + Ok(()) } /// Role validation - /// + /// /// Checks if the role is linked to the pallet. /// ### Parameters: /// - `pallet_id`: The unique pallet identifier. @@ -383,7 +383,7 @@ impl RoleBasedAccessControl for Pallet{ } /// Permission linking validation - /// + /// /// Checks if the permission is linked to the role in the pallet context. /// ### Parameters: /// - `pallet_id`: The unique pallet identifier. @@ -396,7 +396,7 @@ impl RoleBasedAccessControl for Pallet{ } /// Role list length - /// + /// /// Returns the number of user that have the specified role in a scope context. /// ### Parameters: /// - `pallet_id`: The unique pallet identifier. @@ -431,4 +431,4 @@ impl Pallet{ filtered_vec.dedup(); vec.len() == filtered_vec.len() } -} \ No newline at end of file +} diff --git a/parachain-runtime/src/lib.rs b/parachain-runtime/src/lib.rs index b4113974..71627e84 100644 --- a/parachain-runtime/src/lib.rs +++ b/parachain-runtime/src/lib.rs @@ -973,6 +973,7 @@ impl pallet_fruniques::Config for Runtime { type Event = Event; type RemoveOrigin = RootOrThreeFifthsOfCouncil; type ChildMaxLen = ChildMaxLen; + type Rbac = RBAC; } parameter_types! { diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 09ce3d65..159edd47 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -549,7 +549,7 @@ impl pallet_fruniques::Config for Runtime { EnsureRoot, pallet_collective::EnsureProportionAtLeast, >; - + type Rbac = RBAC; type ChildMaxLen = ChildMaxLen; }