Browse Source

runtime: Upgrade the ‘versioned-store-permissions’ pallet.

Shamil Gadelshin 4 years ago
parent
commit
14970f376d

+ 16 - 0
Cargo.lock

@@ -1015,6 +1015,22 @@ dependencies = [
  "sp-std",
 ]
 
+[[package]]
+name = "pallet-versioned-store-permissions"
+version = "3.0.0"
+dependencies = [
+ "frame-support",
+ "frame-system",
+ "pallet-timestamp",
+ "pallet-versioned-store",
+ "parity-scale-codec",
+ "sp-arithmetic",
+ "sp-core",
+ "sp-io",
+ "sp-runtime",
+ "sp-std",
+]
+
 [[package]]
 name = "parity-scale-codec"
 version = "1.3.1"

+ 1 - 1
Cargo.toml

@@ -17,7 +17,7 @@ members = [
 #	"runtime-modules/storage",
 	"runtime-modules/token-minting",
 	"runtime-modules/versioned-store",
-#	"runtime-modules/versioned-store-permissions",
+	"runtime-modules/versioned-store-permissions",
 #	"runtime-modules/working-group",
 #	"node",
 #	"utils/chain-spec-builder/"

+ 17 - 30
runtime-modules/versioned-store-permissions/Cargo.toml

@@ -1,44 +1,31 @@
 [package]
-name = 'substrate-versioned-store-permissions-module'
-version = '1.0.1'
+name = 'pallet-versioned-store-permissions'
+version = '3.0.0'
 authors = ['Joystream contributors']
 edition = '2018'
 
 [dependencies]
-hex-literal = '0.1.0'
-serde = { version = '1.0', optional = true }
-serde_derive = { version = '1.0', optional = true }
-codec = { package = 'parity-scale-codec', version = '1.0.0', default-features = false, features = ['derive'] }
-rstd = { package = 'sr-std', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-runtime-primitives = { package = 'sr-primitives', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-srml-support = { package = 'srml-support', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-srml-support-procedural = { package = 'srml-support-procedural', git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-system = { package = 'srml-system', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-timestamp = { package = 'srml-timestamp', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-runtime-io = { package = 'sr-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-# https://users.rust-lang.org/t/failure-derive-compilation-error/39062
-quote = '<=1.0.2'
-
-[dependencies.versioned-store]
-default_features = false
-package ='substrate-versioned-store'
-path = '../versioned-store'
+codec = { package = 'parity-scale-codec', version = '1.3.1', default-features = false, features = ['derive'] }
+rstd = { package = 'sp-std', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+frame-support = { package = 'frame-support', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+system = { package = 'frame-system', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+sp-arithmetic = { package = 'sp-arithmetic', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+sp-runtime = { package = 'sp-runtime', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+versioned-store = { package = 'pallet-versioned-store', default-features = false, path = '../versioned-store'}
 
 [dev-dependencies]
-runtime-io = { package = 'sr-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-primitives = { package = 'substrate-primitives', git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
+sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+timestamp = { package = 'pallet-timestamp', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
 
 [features]
 default = ['std']
 std = [
-	'serde',
-	'serde_derive',
 	'codec/std',
 	'rstd/std',
-	'runtime-io/std',
-	'runtime-primitives/std',
-	'srml-support/std',
+	'frame-support/std',
 	'system/std',
-	'timestamp/std',
-	'versioned-store/std',
-]
+	'sp-arithmetic/std',
+	'sp-runtime/std',
+    'versioned-store/std',
+]

+ 0 - 1
runtime-modules/versioned-store-permissions/src/credentials.rs

@@ -1,6 +1,5 @@
 use codec::{Decode, Encode};
 use rstd::collections::btree_set::BTreeSet;
-use rstd::prelude::*;
 
 #[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)]
 pub struct CredentialSet<Credential>(BTreeSet<Credential>);

+ 50 - 38
runtime-modules/versioned-store-permissions/src/lib.rs

@@ -2,10 +2,14 @@
 #![cfg_attr(not(feature = "std"), no_std)]
 
 use codec::Codec;
+use frame_support::{decl_module, decl_storage, ensure, Parameter};
 use rstd::collections::btree_map::BTreeMap;
-use rstd::prelude::*;
-use runtime_primitives::traits::{MaybeSerialize, Member, SimpleArithmetic};
-use srml_support::{decl_module, decl_storage, dispatch, ensure, Parameter};
+use sp_arithmetic::traits::BaseArithmetic;
+use sp_runtime::traits::{MaybeSerialize, Member};
+
+//TODO: Convert errors to the Substrate decl_error! macro.
+/// Result with string error message. This exists for backward compatibility purpose.
+pub type DispatchResult = Result<(), &'static str>;
 
 // EntityId, ClassId -> should be configured on versioned_store::Trait
 pub use versioned_store::{ClassId, ClassPropertyValue, EntityId, Property, PropertyValue};
@@ -60,13 +64,10 @@ pub type ClassPermissionsType<T> =
     ClassPermissions<ClassId, <T as Trait>::Credential, u16, <T as system::Trait>::BlockNumber>;
 
 pub trait Trait: system::Trait + versioned_store::Trait {
-    // type Event: ...
-    // Do we need Events?
-
     /// Type that represents an actor or group of actors in the system.
     type Credential: Parameter
         + Member
-        + SimpleArithmetic
+        + BaseArithmetic
         + Codec
         + Default
         + Copy
@@ -86,10 +87,12 @@ pub trait Trait: system::Trait + versioned_store::Trait {
 decl_storage! {
     trait Store for Module<T: Trait> as VersionedStorePermissions {
       /// ClassPermissions of corresponding Classes in the versioned store
-      pub ClassPermissionsByClassId get(class_permissions_by_class_id): linked_map ClassId => ClassPermissionsType<T>;
+      pub ClassPermissionsByClassId get(fn class_permissions_by_class_id): map hasher(blake2_128_concat)
+        ClassId => ClassPermissionsType<T>;
 
       /// Owner of an entity in the versioned store. If it is None then it is owned by the system.
-      pub EntityMaintainerByEntityId get(entity_maintainer_by_entity_id): linked_map EntityId => Option<T::Credential>;
+      pub EntityMaintainerByEntityId get(fn entity_maintainer_by_entity_id): map hasher(blake2_128_concat)
+        EntityId => Option<T::Credential>;
     }
 }
 
@@ -97,11 +100,12 @@ decl_module! {
     pub struct Module<T: Trait> for enum Call where origin: T::Origin {
 
         /// Sets the admins for a class
+        #[weight = 10_000_000] // TODO: adjust weight
         fn set_class_admins(
             origin,
             class_id: ClassId,
             admins: CredentialSet<T::Credential>
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
             let raw_origin = Self::ensure_root_or_signed(origin)?;
 
             Self::mutate_class_permissions(
@@ -117,13 +121,13 @@ decl_module! {
         }
 
         // Methods for updating concrete permissions
-
+        #[weight = 10_000_000] // TODO: adjust weight
         fn set_class_entity_permissions(
             origin,
             with_credential: Option<T::Credential>,
             class_id: ClassId,
             entity_permissions: EntityPermissions<T::Credential>
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
             let raw_origin = Self::ensure_root_or_signed(origin)?;
 
             Self::mutate_class_permissions(
@@ -138,12 +142,13 @@ decl_module! {
             )
         }
 
+        #[weight = 10_000_000] // TODO: adjust weight
         fn set_class_entities_can_be_created(
             origin,
             with_credential: Option<T::Credential>,
             class_id: ClassId,
             can_be_created: bool
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
             let raw_origin = Self::ensure_root_or_signed(origin)?;
 
             Self::mutate_class_permissions(
@@ -158,12 +163,13 @@ decl_module! {
             )
         }
 
+        #[weight = 10_000_000] // TODO: adjust weight
         fn set_class_add_schemas_set(
             origin,
             with_credential: Option<T::Credential>,
             class_id: ClassId,
             credential_set: CredentialSet<T::Credential>
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
             let raw_origin = Self::ensure_root_or_signed(origin)?;
 
             Self::mutate_class_permissions(
@@ -178,12 +184,13 @@ decl_module! {
             )
         }
 
+        #[weight = 10_000_000] // TODO: adjust weight
         fn set_class_create_entities_set(
             origin,
             with_credential: Option<T::Credential>,
             class_id: ClassId,
             credential_set: CredentialSet<T::Credential>
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
             let raw_origin = Self::ensure_root_or_signed(origin)?;
 
             Self::mutate_class_permissions(
@@ -198,12 +205,13 @@ decl_module! {
             )
         }
 
+        #[weight = 10_000_000] // TODO: adjust weight
         fn set_class_reference_constraint(
             origin,
             with_credential: Option<T::Credential>,
             class_id: ClassId,
             constraint: ReferenceConstraint<ClassId, u16>
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
             let raw_origin = Self::ensure_root_or_signed(origin)?;
 
             Self::mutate_class_permissions(
@@ -224,7 +232,7 @@ decl_module! {
         //     origin,
         //     entity_id: EntityId,
         //     new_maintainer: Option<T::Credential>
-        // ) -> dispatch::Result {
+        // ) -> DispatchResult {
         //     ensure_root(origin)?;
 
         //     // ensure entity exists in the versioned store
@@ -238,13 +246,13 @@ decl_module! {
         // }
 
         // Permissioned proxy calls to versioned store
-
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn create_class(
             origin,
             name: Vec<u8>,
             description: Vec<u8>,
             class_permissions: ClassPermissionsType<T>
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
             let raw_origin = Self::ensure_root_or_signed(origin)?;
 
             let can_create_class = match raw_origin {
@@ -268,21 +276,23 @@ decl_module! {
             }
         }
 
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn create_class_with_default_permissions(
             origin,
             name: Vec<u8>,
             description: Vec<u8>
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
             Self::create_class(origin, name, description, ClassPermissions::default())
         }
 
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn add_class_schema(
             origin,
             with_credential: Option<T::Credential>,
             class_id: ClassId,
             existing_properties: Vec<u16>,
             new_properties: Vec<Property>
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
             let raw_origin = Self::ensure_root_or_signed(origin)?;
 
             Self::if_class_permissions_satisfied(
@@ -304,16 +314,18 @@ decl_module! {
 
         /// Creates a new entity of type class_id. The maintainer is set to be either None if the origin is root, or the provided credential
         /// associated with signer.
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn create_entity(
             origin,
             with_credential: Option<T::Credential>,
             class_id: ClassId
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
             let raw_origin = Self::ensure_root_or_signed(origin)?;
             let _entity_id = Self::do_create_entity(&raw_origin, with_credential, class_id)?;
             Ok(())
         }
 
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn add_schema_support_to_entity(
             origin,
             with_credential: Option<T::Credential>,
@@ -321,23 +333,25 @@ decl_module! {
             entity_id: EntityId,
             schema_id: u16, // Do not type alias u16!! - u16,
             property_values: Vec<ClassPropertyValue>
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
             let raw_origin = Self::ensure_root_or_signed(origin)?;
             Self::do_add_schema_support_to_entity(&raw_origin, with_credential, as_entity_maintainer, entity_id, schema_id, property_values)
         }
 
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn update_entity_property_values(
             origin,
             with_credential: Option<T::Credential>,
             as_entity_maintainer: bool,
             entity_id: EntityId,
             property_values: Vec<ClassPropertyValue>
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
             let raw_origin = Self::ensure_root_or_signed(origin)?;
             Self::do_update_entity_property_values(&raw_origin, with_credential, as_entity_maintainer, entity_id, property_values)
         }
 
-        pub fn transaction(origin, operations: Vec<Operation<T::Credential>>) -> dispatch::Result {
+        #[weight = 10_000_000] // TODO: adjust weight
+        pub fn transaction(origin, operations: Vec<Operation<T::Credential>>) -> DispatchResult {
             // This map holds the EntityId of the entity created as a result of executing a CreateEntity Operation
             // keyed by the indexed of the operation, in the operations vector.
             let mut entity_created_in_operation: BTreeMap<usize, EntityId> = BTreeMap::new();
@@ -415,7 +429,7 @@ impl<T: Trait> Module<T> {
         as_entity_maintainer: bool,
         entity_id: EntityId,
         property_values: Vec<ClassPropertyValue>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         let class_id = Self::get_class_id_by_entity_id(entity_id)?;
 
         Self::ensure_internal_property_values_permitted(class_id, &property_values)?;
@@ -448,7 +462,7 @@ impl<T: Trait> Module<T> {
         entity_id: EntityId,
         schema_id: u16,
         property_values: Vec<ClassPropertyValue>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         // class id of the entity being updated
         let class_id = Self::get_class_id_by_entity_id(entity_id)?;
 
@@ -491,7 +505,7 @@ impl<T: Trait> Module<T> {
                         if let Some(entity_id) = as_entity_maintainer {
                             // is entity maintained by system
                             ensure!(
-                                <EntityMaintainerByEntityId<T>>::exists(entity_id),
+                                <EntityMaintainerByEntityId<T>>::contains_key(entity_id),
                                 "NotEnityMaintainer"
                             );
                             // ensure entity maintainer matches
@@ -522,7 +536,7 @@ impl<T: Trait> Module<T> {
         class_id: ClassId,
     ) -> Result<ClassPermissionsType<T>, &'static str> {
         ensure!(
-            <ClassPermissionsByClassId<T>>::exists(class_id),
+            <ClassPermissionsByClassId<T>>::contains_key(class_id),
             "ClassPermissionsNotFoundByClassId"
         );
         Ok(Self::class_permissions_by_class_id(class_id))
@@ -539,11 +553,10 @@ impl<T: Trait> Module<T> {
         class_id: ClassId,
         // actual mutation to apply.
         mutate: Mutate,
-    ) -> dispatch::Result
+    ) -> DispatchResult
     where
-        Predicate:
-            FnOnce(&ClassPermissionsType<T>, &AccessLevel<T::Credential>) -> dispatch::Result,
-        Mutate: FnOnce(&mut ClassPermissionsType<T>) -> dispatch::Result,
+        Predicate: FnOnce(&ClassPermissionsType<T>, &AccessLevel<T::Credential>) -> DispatchResult,
+        Mutate: FnOnce(&mut ClassPermissionsType<T>) -> DispatchResult,
     {
         let access_level = Self::derive_access_level(raw_origin, with_credential, None)?;
         let mut class_permissions = Self::ensure_class_permissions(class_id)?;
@@ -558,7 +571,7 @@ impl<T: Trait> Module<T> {
     fn is_system(
         _: &ClassPermissionsType<T>,
         access_level: &AccessLevel<T::Credential>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         if *access_level == AccessLevel::System {
             Ok(())
         } else {
@@ -581,8 +594,7 @@ impl<T: Trait> Module<T> {
         callback: Callback,
     ) -> Result<R, &'static str>
     where
-        Predicate:
-            FnOnce(&ClassPermissionsType<T>, &AccessLevel<T::Credential>) -> dispatch::Result,
+        Predicate: FnOnce(&ClassPermissionsType<T>, &AccessLevel<T::Credential>) -> DispatchResult,
         Callback: FnOnce(
             &ClassPermissionsType<T>,
             &AccessLevel<T::Credential>,
@@ -599,7 +611,7 @@ impl<T: Trait> Module<T> {
     fn get_class_id_by_entity_id(entity_id: EntityId) -> Result<ClassId, &'static str> {
         // use a utility method on versioned_store module
         ensure!(
-            versioned_store::EntityById::exists(entity_id),
+            versioned_store::EntityById::contains_key(entity_id),
             "EntityNotFound"
         );
         let entity = <versioned_store::Module<T>>::entity_by_id(entity_id);
@@ -611,7 +623,7 @@ impl<T: Trait> Module<T> {
     fn ensure_internal_property_values_permitted(
         source_class_id: ClassId,
         property_values: &[ClassPropertyValue],
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         for property_value in property_values.iter() {
             if let PropertyValue::Internal(ref target_entity_id) = property_value.value {
                 // get the class permissions for target class

+ 14 - 7
runtime-modules/versioned-store-permissions/src/mock.rs

@@ -3,13 +3,13 @@
 use crate::*;
 use crate::{Module, Trait};
 
-use primitives::H256;
-use runtime_primitives::{
+use frame_support::{impl_outer_origin, parameter_types};
+use sp_core::H256;
+use sp_runtime::{
     testing::Header,
     traits::{BlakeTwo256, IdentityLookup},
     Perbill,
 };
-use srml_support::{impl_outer_origin, parameter_types};
 use versioned_store::InputValidationLengthConstraint;
 
 impl_outer_origin! {
@@ -28,10 +28,11 @@ parameter_types! {
 }
 
 impl system::Trait for Runtime {
+    type BaseCallFilter = ();
     type Origin = Origin;
+    type Call = ();
     type Index = u64;
     type BlockNumber = u64;
-    type Call = ();
     type Hash = H256;
     type Hashing = BlakeTwo256;
     type AccountId = u64;
@@ -40,9 +41,17 @@ impl system::Trait for Runtime {
     type Event = ();
     type BlockHashCount = BlockHashCount;
     type MaximumBlockWeight = MaximumBlockWeight;
+    type DbWeight = ();
+    type BlockExecutionWeight = ();
+    type ExtrinsicBaseWeight = ();
+    type MaximumExtrinsicWeight = ();
     type MaximumBlockLength = MaximumBlockLength;
     type AvailableBlockRatio = AvailableBlockRatio;
     type Version = ();
+    type ModuleToIndex = ();
+    type AccountData = ();
+    type OnNewAccount = ();
+    type OnKilledAccount = ();
 }
 
 impl timestamp::Trait for Runtime {
@@ -141,9 +150,7 @@ fn default_versioned_store_genesis_config() -> versioned_store::GenesisConfig {
     }
 }
 
-fn build_test_externalities(
-    config: versioned_store::GenesisConfig,
-) -> runtime_io::TestExternalities {
+fn build_test_externalities(config: versioned_store::GenesisConfig) -> sp_io::TestExternalities {
     let mut t = system::GenesisConfig::default()
         .build_storage::<Runtime>()
         .unwrap();

+ 0 - 1
runtime-modules/versioned-store-permissions/src/operations.rs

@@ -1,6 +1,5 @@
 use codec::{Decode, Encode};
 use rstd::collections::btree_map::BTreeMap;
-use rstd::prelude::*;
 use versioned_store::{ClassId, ClassPropertyValue, EntityId, PropertyValue};
 
 #[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)]

+ 5 - 5
runtime-modules/versioned-store-permissions/src/permissions.rs

@@ -1,8 +1,8 @@
 use codec::{Decode, Encode};
-use srml_support::dispatch;
 
 use crate::constraint::*;
 use crate::credentials::*;
+use crate::DispatchResult;
 
 /// Permissions for an instance of a Class in the versioned store.
 #[derive(Encode, Decode, Default, Eq, PartialEq, Clone, Debug)]
@@ -48,7 +48,7 @@ where
     pub fn is_admin(
         class_permissions: &Self,
         access_level: &AccessLevel<Credential>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         match access_level {
             AccessLevel::System => Ok(()),
             AccessLevel::Credential(credential) => {
@@ -66,7 +66,7 @@ where
     pub fn can_add_class_schema(
         class_permissions: &Self,
         access_level: &AccessLevel<Credential>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         match access_level {
             AccessLevel::System => Ok(()),
             AccessLevel::Credential(credential) => {
@@ -84,7 +84,7 @@ where
     pub fn can_create_entity(
         class_permissions: &Self,
         access_level: &AccessLevel<Credential>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         match access_level {
             AccessLevel::System => Ok(()),
             AccessLevel::Credential(credential) => {
@@ -104,7 +104,7 @@ where
     pub fn can_update_entity(
         class_permissions: &Self,
         access_level: &AccessLevel<Credential>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         match access_level {
             AccessLevel::System => Ok(()),
             AccessLevel::Credential(credential) => {

+ 30 - 22
runtime-modules/versioned-store-permissions/src/tests.rs

@@ -5,7 +5,7 @@ use crate::mock::*;
 use rstd::collections::btree_set::BTreeSet;
 use versioned_store::PropertyType;
 
-use srml_support::{assert_err, assert_ok};
+use frame_support::{assert_err, assert_ok};
 
 fn simple_test_schema() -> Vec<Property> {
     vec![Property {
@@ -77,7 +77,7 @@ fn create_class_then_entity_with_default_class_permissions() {
 
         let class_id = create_simple_class_with_default_permissions();
 
-        assert!(<ClassPermissionsByClassId<Runtime>>::exists(class_id));
+        assert!(<ClassPermissionsByClassId<Runtime>>::contains_key(class_id));
 
         // default class permissions have empty add_schema acl
         assert_err!(
@@ -94,7 +94,7 @@ fn create_class_then_entity_with_default_class_permissions() {
         // give members of GROUP_ZERO permission to add schemas
         let add_schema_set = CredentialSet::from(vec![0]);
         assert_ok!(Permissions::set_class_add_schemas_set(
-            Origin::ROOT,
+            system::RawOrigin::Root.into(),
             None,
             class_id,
             add_schema_set
@@ -111,9 +111,15 @@ fn create_class_then_entity_with_default_class_permissions() {
 
         // System can always create entities (provided class exists) bypassing any permissions
         let entity_id_1 = next_entity_id();
-        assert_ok!(Permissions::create_entity(Origin::ROOT, None, class_id,));
+        assert_ok!(Permissions::create_entity(
+            system::RawOrigin::Root.into(),
+            None,
+            class_id,
+        ));
         // entities created by system are "un-owned"
-        assert!(!<EntityMaintainerByEntityId<Runtime>>::exists(entity_id_1));
+        assert!(!<EntityMaintainerByEntityId<Runtime>>::contains_key(
+            entity_id_1
+        ));
         assert_eq!(
             Permissions::entity_maintainer_by_entity_id(entity_id_1),
             None
@@ -130,7 +136,7 @@ fn create_class_then_entity_with_default_class_permissions() {
         );
 
         assert_ok!(Permissions::set_class_entities_can_be_created(
-            Origin::ROOT,
+            system::RawOrigin::Root.into(),
             None,
             class_id,
             true
@@ -148,7 +154,7 @@ fn create_class_then_entity_with_default_class_permissions() {
         // give members of GROUP_ONE permission to create entities
         let create_entities_set = CredentialSet::from(vec![1]);
         assert_ok!(Permissions::set_class_create_entities_set(
-            Origin::ROOT,
+            system::RawOrigin::Root.into(),
             None,
             class_id,
             create_entities_set
@@ -160,7 +166,9 @@ fn create_class_then_entity_with_default_class_permissions() {
             Some(1),
             class_id,
         ));
-        assert!(<EntityMaintainerByEntityId<Runtime>>::exists(entity_id_2));
+        assert!(<EntityMaintainerByEntityId<Runtime>>::contains_key(
+            entity_id_2
+        ));
         assert_eq!(
             Permissions::entity_maintainer_by_entity_id(entity_id_2),
             Some(1)
@@ -216,7 +224,7 @@ fn class_permissions_set_admins() {
         );
         assert_err!(
             Permissions::set_class_admins(
-                Origin::NONE, //unsigned inherent?
+                system::RawOrigin::None.into(), //unsigned inherent?
                 class_id,
                 credential_set.clone()
             ),
@@ -225,7 +233,7 @@ fn class_permissions_set_admins() {
 
         // root origin can set admins
         assert_ok!(Permissions::set_class_admins(
-            Origin::ROOT,
+            system::RawOrigin::Root.into(),
             class_id,
             credential_set.clone()
         ));
@@ -250,7 +258,7 @@ fn class_permissions_set_add_schemas_set() {
 
         // root
         assert_ok!(Permissions::set_class_add_schemas_set(
-            Origin::ROOT,
+            system::RawOrigin::Root.into(),
             None,
             class_id,
             credential_set1.clone()
@@ -296,7 +304,7 @@ fn class_permissions_set_class_create_entities_set() {
 
         // root
         assert_ok!(Permissions::set_class_create_entities_set(
-            Origin::ROOT,
+            system::RawOrigin::Root.into(),
             None,
             class_id,
             credential_set1.clone()
@@ -339,7 +347,7 @@ fn class_permissions_set_class_entities_can_be_created() {
 
         // root
         assert_ok!(Permissions::set_class_entities_can_be_created(
-            Origin::ROOT,
+            system::RawOrigin::Root.into(),
             None,
             class_id,
             true
@@ -387,7 +395,7 @@ fn class_permissions_set_class_entity_permissions() {
 
         //root
         assert_ok!(Permissions::set_class_entity_permissions(
-            Origin::ROOT,
+            system::RawOrigin::Root.into(),
             None,
             class_id,
             entity_permissions1.clone()
@@ -441,7 +449,7 @@ fn class_permissions_set_class_reference_constraint() {
 
         //root
         assert_ok!(Permissions::set_class_reference_constraint(
-            Origin::ROOT,
+            system::RawOrigin::Root.into(),
             None,
             class_id,
             reference_constraint1.clone()
@@ -505,7 +513,7 @@ fn batch_transaction_simple() {
         }];
 
         assert_ok!(Permissions::add_class_schema(
-            Origin::ROOT,
+            system::RawOrigin::Root.into(),
             None,
             new_class_id,
             vec![],
@@ -564,8 +572,8 @@ fn batch_transaction_simple() {
         ));
 
         // two entities created
-        assert!(versioned_store::EntityById::exists(entity_id));
-        assert!(versioned_store::EntityById::exists(entity_id + 1));
+        assert!(versioned_store::EntityById::contains_key(entity_id));
+        assert!(versioned_store::EntityById::contains_key(entity_id + 1));
     })
 }
 
@@ -589,7 +597,7 @@ fn batch_transaction_vector_of_entities() {
         }];
 
         assert_ok!(Permissions::add_class_schema(
-            Origin::ROOT,
+            system::RawOrigin::Root.into(),
             None,
             new_class_id,
             vec![],
@@ -645,9 +653,9 @@ fn batch_transaction_vector_of_entities() {
         ));
 
         // three entities created
-        assert!(versioned_store::EntityById::exists(entity_id));
-        assert!(versioned_store::EntityById::exists(entity_id + 1));
-        assert!(versioned_store::EntityById::exists(entity_id + 2));
+        assert!(versioned_store::EntityById::contains_key(entity_id));
+        assert!(versioned_store::EntityById::contains_key(entity_id + 1));
+        assert!(versioned_store::EntityById::contains_key(entity_id + 2));
 
         assert_eq!(
             versioned_store::EntityById::get(entity_id),