Parcourir la source

Merge branch 'development' into council-recurring-rewards

Mokhtar Naamani il y a 4 ans
Parent
commit
c43bb8072e

+ 5 - 0
devops/git-hooks/pre-commit

@@ -0,0 +1,5 @@
+#!/bin/sh
+set -e
+
+echo 'cargo fmt --all -- --check'
+cargo fmt --all -- --check

+ 10 - 0
devops/git-hooks/pre-push

@@ -0,0 +1,10 @@
+#!/bin/sh
+set -e
+
+export BUILD_DUMMY_WASM_BINARY=1
+
+echo '+cargo test --all'
+cargo test --all
+
+echo '+cargo clippy --all -- -D warnings'
+cargo clippy --all -- -D warnings

+ 4 - 2
node/src/chain_spec.rs

@@ -23,8 +23,9 @@ use node_runtime::{
     AuthorityDiscoveryConfig, BabeConfig, Balance, BalancesConfig, ContentWorkingGroupConfig,
     CouncilConfig, CouncilElectionConfig, DataObjectStorageRegistryConfig,
     DataObjectTypeRegistryConfig, ElectionParameters, GrandpaConfig, ImOnlineConfig, IndicesConfig,
-    MembersConfig, Perbill, ProposalsCodexConfig, SessionConfig, SessionKeys, Signature,
-    StakerStatus, StakingConfig, SudoConfig, SystemConfig, VersionedStoreConfig, DAYS, WASM_BINARY,
+    MembersConfig, MigrationConfig, Perbill, ProposalsCodexConfig, SessionConfig, SessionKeys,
+    Signature, StakerStatus, StakingConfig, SudoConfig, SystemConfig, VersionedStoreConfig, DAYS,
+    WASM_BINARY,
 };
 pub use node_runtime::{AccountId, GenesisConfig};
 use primitives::{sr25519, Pair, Public};
@@ -301,6 +302,7 @@ pub fn testnet_genesis(
             channel_banner_constraint: crate::forum_config::new_validation(5, 1024),
             channel_title_constraint: crate::forum_config::new_validation(5, 1024),
         }),
+        migration: Some(MigrationConfig {}),
         proposals_codex: Some(ProposalsCodexConfig {
             set_validator_count_proposal_voting_period: cpcp
                 .set_validator_count_proposal_voting_period,

+ 9 - 4
node/src/forum_config/from_serialized.rs

@@ -1,7 +1,9 @@
+#![allow(clippy::type_complexity)]
+
 use super::new_validation;
 use node_runtime::{
-    forum::{Category, CategoryId, Post, PostId, Thread, ThreadId},
-    AccountId, BlockNumber, ForumConfig, Moment,
+    forum::{Category, CategoryId, Post, Thread},
+    AccountId, BlockNumber, ForumConfig, Moment, PostId, ThreadId,
 };
 use serde::Deserialize;
 use serde_json::Result;
@@ -9,8 +11,11 @@ use serde_json::Result;
 #[derive(Deserialize)]
 struct ForumData {
     categories: Vec<(CategoryId, Category<BlockNumber, Moment, AccountId>)>,
-    posts: Vec<(PostId, Post<BlockNumber, Moment, AccountId>)>,
-    threads: Vec<(ThreadId, Thread<BlockNumber, Moment, AccountId>)>,
+    posts: Vec<(
+        PostId,
+        Post<BlockNumber, Moment, AccountId, ThreadId, PostId>,
+    )>,
+    threads: Vec<(ThreadId, Thread<BlockNumber, Moment, AccountId, ThreadId>)>,
 }
 
 fn parse_forum_json() -> Result<ForumData> {

+ 10 - 1
package.json

@@ -7,5 +7,14 @@
 	},
 	"workspaces": [
 		"tests/network-tests"
-	]
+	],
+	"devDependencies": {
+		"husky": "^4.2.5"
+	},
+	"husky": {
+	  "hooks": {
+		"pre-commit": "devops/git-hooks/pre-commit",
+		"pre-push": "devops/git-hooks/pre-push"
+	  }
+	}
 }

+ 1 - 1
runtime-modules/content-working-group/src/lib.rs

@@ -1894,7 +1894,7 @@ decl_module! {
             origin,
             curator_id: CuratorId<T>,
             rationale_text: Vec<u8>
-            ) {
+        ) {
 
             // Ensure lead is set and is origin signer
             Self::ensure_origin_is_set_lead(origin)?;

+ 55 - 36
runtime-modules/forum/src/lib.rs

@@ -12,8 +12,9 @@ use serde_derive::{Deserialize, Serialize};
 use rstd::borrow::ToOwned;
 use rstd::prelude::*;
 
-use codec::{Decode, Encode};
-use srml_support::{decl_event, decl_module, decl_storage, dispatch, ensure};
+use codec::{Codec, Decode, Encode};
+use runtime_primitives::traits::{MaybeSerialize, Member, One, SimpleArithmetic};
+use srml_support::{decl_event, decl_module, decl_storage, dispatch, ensure, Parameter};
 
 mod mock;
 mod tests;
@@ -156,13 +157,10 @@ pub struct PostTextChange<BlockNumber, Moment> {
     text: Vec<u8>,
 }
 
-/// Represents a post identifier
-pub type PostId = u64;
-
 /// Represents a thread post
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
 #[derive(Encode, Decode, Default, Clone, PartialEq, Eq)]
-pub struct Post<BlockNumber, Moment, AccountId> {
+pub struct Post<BlockNumber, Moment, AccountId, ThreadId, PostId> {
     /// Post identifier
     id: PostId,
 
@@ -192,13 +190,10 @@ pub struct Post<BlockNumber, Moment, AccountId> {
     author_id: AccountId,
 }
 
-/// Represents a thread identifier
-pub type ThreadId = u64;
-
 /// Represents a thread
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
 #[derive(Encode, Decode, Default, Clone, PartialEq, Eq)]
-pub struct Thread<BlockNumber, Moment, AccountId> {
+pub struct Thread<BlockNumber, Moment, AccountId, ThreadId> {
     /// Thread identifier
     id: ThreadId,
 
@@ -238,7 +233,7 @@ pub struct Thread<BlockNumber, Moment, AccountId> {
     author_id: AccountId,
 }
 
-impl<BlockNumber, Moment, AccountId> Thread<BlockNumber, Moment, AccountId> {
+impl<BlockNumber, Moment, AccountId, ThreadId> Thread<BlockNumber, Moment, AccountId, ThreadId> {
     fn num_posts_ever_created(&self) -> u32 {
         self.num_unmoderated_posts + self.num_moderated_posts
     }
@@ -321,6 +316,26 @@ pub trait Trait: system::Trait + timestamp::Trait + Sized {
     type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
 
     type MembershipRegistry: ForumUserRegistry<Self::AccountId>;
+
+    /// Thread Id type
+    type ThreadId: Parameter
+        + Member
+        + SimpleArithmetic
+        + Codec
+        + Default
+        + Copy
+        + MaybeSerialize
+        + PartialEq;
+
+    /// Post Id type
+    type PostId: Parameter
+        + Member
+        + SimpleArithmetic
+        + Codec
+        + Default
+        + Copy
+        + MaybeSerialize
+        + PartialEq;
 }
 
 decl_storage! {
@@ -333,16 +348,16 @@ decl_storage! {
         pub NextCategoryId get(next_category_id) config(): CategoryId;
 
         /// Map thread identifier to corresponding thread.
-        pub ThreadById get(thread_by_id) config(): map ThreadId => Thread<T::BlockNumber, T::Moment, T::AccountId>;
+        pub ThreadById get(thread_by_id) config(): map T::ThreadId => Thread<T::BlockNumber, T::Moment, T::AccountId, T::ThreadId>;
 
         /// Thread identifier value to be used for next Thread in threadById.
-        pub NextThreadId get(next_thread_id) config(): ThreadId;
+        pub NextThreadId get(next_thread_id) config(): T::ThreadId;
 
         /// Map post identifier to corresponding post.
-        pub PostById get(post_by_id) config(): map PostId => Post<T::BlockNumber, T::Moment, T::AccountId>;
+        pub PostById get(post_by_id) config(): map T::PostId => Post<T::BlockNumber, T::Moment, T::AccountId, T::ThreadId, T::PostId>;
 
         /// Post identifier value to be used for for next post created.
-        pub NextPostId get(next_post_id) config(): PostId;
+        pub NextPostId get(next_post_id) config(): T::PostId;
 
         /// Account of forum sudo.
         pub ForumSudo get(forum_sudo) config(): Option<T::AccountId>;
@@ -386,6 +401,8 @@ decl_event!(
     pub enum Event<T>
     where
         <T as system::Trait>::AccountId,
+        <T as Trait>::ThreadId,
+        <T as Trait>::PostId,
     {
         /// A category was introduced
         CategoryCreated(CategoryId),
@@ -632,7 +649,7 @@ decl_module! {
         }
 
         /// Moderate thread
-        fn moderate_thread(origin, thread_id: ThreadId, rationale: Vec<u8>) -> dispatch::Result {
+        fn moderate_thread(origin, thread_id: T::ThreadId, rationale: Vec<u8>) -> dispatch::Result {
 
             // Check that its a valid signature
             let who = ensure_signed(origin)?;
@@ -683,7 +700,7 @@ decl_module! {
         }
 
         /// Edit post text
-        fn add_post(origin, thread_id: ThreadId, text: Vec<u8>) -> dispatch::Result {
+        fn add_post(origin, thread_id: T::ThreadId, text: Vec<u8>) -> dispatch::Result {
 
             /*
              * Update SPEC with new errors,
@@ -720,7 +737,7 @@ decl_module! {
         }
 
         /// Edit post text
-        fn edit_post_text(origin, post_id: PostId, new_text: Vec<u8>) -> dispatch::Result {
+        fn edit_post_text(origin, post_id: T::PostId, new_text: Vec<u8>) -> dispatch::Result {
 
             /* Edit spec.
               - forum member guard missing
@@ -767,7 +784,7 @@ decl_module! {
         }
 
         /// Moderate post
-        fn moderate_post(origin, post_id: PostId, rationale: Vec<u8>) -> dispatch::Result {
+        fn moderate_post(origin, post_id: T::PostId, rationale: Vec<u8>) -> dispatch::Result {
 
             // Check that its a valid signature
             let who = ensure_signed(origin)?;
@@ -867,8 +884,9 @@ impl<T: Trait> Module<T> {
     }
 
     fn ensure_post_is_mutable(
-        post_id: PostId,
-    ) -> Result<Post<T::BlockNumber, T::Moment, T::AccountId>, &'static str> {
+        post_id: T::PostId,
+    ) -> Result<Post<T::BlockNumber, T::Moment, T::AccountId, T::ThreadId, T::PostId>, &'static str>
+    {
         // Make sure post exists
         let post = Self::ensure_post_exists(post_id)?;
 
@@ -882,8 +900,9 @@ impl<T: Trait> Module<T> {
     }
 
     fn ensure_post_exists(
-        post_id: PostId,
-    ) -> Result<Post<T::BlockNumber, T::Moment, T::AccountId>, &'static str> {
+        post_id: T::PostId,
+    ) -> Result<Post<T::BlockNumber, T::Moment, T::AccountId, T::ThreadId, T::PostId>, &'static str>
+    {
         if <PostById<T>>::exists(post_id) {
             Ok(<PostById<T>>::get(post_id))
         } else {
@@ -892,8 +911,8 @@ impl<T: Trait> Module<T> {
     }
 
     fn ensure_thread_is_mutable(
-        thread_id: ThreadId,
-    ) -> Result<Thread<T::BlockNumber, T::Moment, T::AccountId>, &'static str> {
+        thread_id: T::ThreadId,
+    ) -> Result<Thread<T::BlockNumber, T::Moment, T::AccountId, T::ThreadId>, &'static str> {
         // Make sure thread exists
         let thread = Self::ensure_thread_exists(thread_id)?;
 
@@ -907,8 +926,8 @@ impl<T: Trait> Module<T> {
     }
 
     fn ensure_thread_exists(
-        thread_id: ThreadId,
-    ) -> Result<Thread<T::BlockNumber, T::Moment, T::AccountId>, &'static str> {
+        thread_id: T::ThreadId,
+    ) -> Result<Thread<T::BlockNumber, T::Moment, T::AccountId, T::ThreadId>, &'static str> {
         if <ThreadById<T>>::exists(thread_id) {
             Ok(<ThreadById<T>>::get(thread_id))
         } else {
@@ -1045,12 +1064,12 @@ impl<T: Trait> Module<T> {
         category_id: CategoryId,
         title: &[u8],
         author_id: &T::AccountId,
-    ) -> Thread<T::BlockNumber, T::Moment, T::AccountId> {
+    ) -> Thread<T::BlockNumber, T::Moment, T::AccountId, T::ThreadId> {
         // Get category
         let category = <CategoryById<T>>::get(category_id);
 
         // Create and add new thread
-        let new_thread_id = NextThreadId::get();
+        let new_thread_id = NextThreadId::<T>::get();
 
         let new_thread = Thread {
             id: new_thread_id,
@@ -1068,8 +1087,8 @@ impl<T: Trait> Module<T> {
         <ThreadById<T>>::insert(new_thread_id, new_thread.clone());
 
         // Update next thread id
-        NextThreadId::mutate(|n| {
-            *n += 1;
+        NextThreadId::<T>::mutate(|n| {
+            *n += One::one();
         });
 
         // Update unmoderated thread count in corresponding category
@@ -1083,15 +1102,15 @@ impl<T: Trait> Module<T> {
     /// Creates and ads a new post ot the given thread, and makes all required state updates
     /// `thread_id` must be valid
     fn add_new_post(
-        thread_id: ThreadId,
+        thread_id: T::ThreadId,
         text: &[u8],
         author_id: &T::AccountId,
-    ) -> Post<T::BlockNumber, T::Moment, T::AccountId> {
+    ) -> Post<T::BlockNumber, T::Moment, T::AccountId, T::ThreadId, T::PostId> {
         // Get thread
         let thread = <ThreadById<T>>::get(thread_id);
 
         // Make and add initial post
-        let new_post_id = NextPostId::get();
+        let new_post_id = NextPostId::<T>::get();
 
         let new_post = Post {
             id: new_post_id,
@@ -1108,8 +1127,8 @@ impl<T: Trait> Module<T> {
         <PostById<T>>::insert(new_post_id, new_post.clone());
 
         // Update next post id
-        NextPostId::mutate(|n| {
-            *n += 1;
+        NextPostId::<T>::mutate(|n| {
+            *n += One::one();
         });
 
         // Update unmoderated post count of thread

+ 17 - 10
runtime-modules/forum/src/mock.rs

@@ -100,6 +100,8 @@ impl timestamp::Trait for Runtime {
 impl Trait for Runtime {
     type Event = ();
     type MembershipRegistry = registry::TestMembershipRegistryModule;
+    type ThreadId = u64;
+    type PostId = u64;
 }
 
 #[derive(Clone)]
@@ -123,9 +125,9 @@ pub const NOT_MEMBER_ORIGIN: OriginType = OriginType::Signed(222);
 
 pub const INVLAID_CATEGORY_ID: CategoryId = 333;
 
-pub const INVLAID_THREAD_ID: ThreadId = 444;
+pub const INVLAID_THREAD_ID: RuntimeThreadId = 444;
 
-pub const INVLAID_POST_ID: ThreadId = 555;
+pub const INVLAID_POST_ID: RuntimePostId = 555;
 
 pub fn generate_text(len: usize) -> Vec<u8> {
     vec![b'x'; len]
@@ -228,7 +230,7 @@ impl CreateThreadFixture {
 
 pub struct CreatePostFixture {
     pub origin: OriginType,
-    pub thread_id: ThreadId,
+    pub thread_id: RuntimeThreadId,
     pub text: Vec<u8>,
     pub result: dispatch::Result,
 }
@@ -285,7 +287,7 @@ pub fn assert_create_thread(
 
 pub fn assert_create_post(
     forum_sudo: OriginType,
-    thread_id: ThreadId,
+    thread_id: RuntimeThreadId,
     expected_result: dispatch::Result,
 ) {
     CreatePostFixture {
@@ -312,7 +314,7 @@ pub fn create_root_category(forum_sudo: OriginType) -> CategoryId {
 
 pub fn create_root_category_and_thread(
     forum_sudo: OriginType,
-) -> (OriginType, CategoryId, ThreadId) {
+) -> (OriginType, CategoryId, RuntimeThreadId) {
     let member_origin = create_forum_member();
     let category_id = create_root_category(forum_sudo);
     let thread_id = TestForumModule::next_thread_id();
@@ -331,7 +333,7 @@ pub fn create_root_category_and_thread(
 
 pub fn create_root_category_and_thread_and_post(
     forum_sudo: OriginType,
-) -> (OriginType, CategoryId, ThreadId, PostId) {
+) -> (OriginType, CategoryId, RuntimeThreadId, RuntimePostId) {
     let (member_origin, category_id, thread_id) = create_root_category_and_thread(forum_sudo);
     let post_id = TestForumModule::next_post_id();
 
@@ -348,7 +350,7 @@ pub fn create_root_category_and_thread_and_post(
 
 pub fn moderate_thread(
     forum_sudo: OriginType,
-    thread_id: ThreadId,
+    thread_id: RuntimeThreadId,
     rationale: Vec<u8>,
 ) -> dispatch::Result {
     TestForumModule::moderate_thread(mock_origin(forum_sudo), thread_id, rationale)
@@ -356,7 +358,7 @@ pub fn moderate_thread(
 
 pub fn moderate_post(
     forum_sudo: OriginType,
-    post_id: PostId,
+    post_id: RuntimePostId,
     rationale: Vec<u8>,
 ) -> dispatch::Result {
     TestForumModule::moderate_post(mock_origin(forum_sudo), post_id, rationale)
@@ -456,23 +458,28 @@ pub type RuntimeThread = Thread<
     <Runtime as system::Trait>::BlockNumber,
     <Runtime as timestamp::Trait>::Moment,
     <Runtime as system::Trait>::AccountId,
+    RuntimeThreadId,
 >;
 pub type RuntimePost = Post<
     <Runtime as system::Trait>::BlockNumber,
     <Runtime as timestamp::Trait>::Moment,
     <Runtime as system::Trait>::AccountId,
+    RuntimeThreadId,
+    RuntimePostId,
 >;
 pub type RuntimeBlockchainTimestamp = BlockchainTimestamp<
     <Runtime as system::Trait>::BlockNumber,
     <Runtime as timestamp::Trait>::Moment,
 >;
+pub type RuntimeThreadId = <Runtime as Trait>::ThreadId;
+pub type RuntimePostId = <Runtime as Trait>::PostId;
 
 pub fn genesis_config(
     category_by_id: &RuntimeMap<CategoryId, RuntimeCategory>,
     next_category_id: u64,
-    thread_by_id: &RuntimeMap<ThreadId, RuntimeThread>,
+    thread_by_id: &RuntimeMap<RuntimeThreadId, RuntimeThread>,
     next_thread_id: u64,
-    post_by_id: &RuntimeMap<PostId, RuntimePost>,
+    post_by_id: &RuntimeMap<RuntimePostId, RuntimePost>,
     next_post_id: u64,
     forum_sudo: <Runtime as system::Trait>::AccountId,
     category_title_constraint: &InputValidationLengthConstraint,

+ 154 - 84
runtime-modules/proposals/codex/src/lib.rs

@@ -61,13 +61,10 @@ use governance::election_params::ElectionParameters;
 use proposal_engine::ProposalParameters;
 use roles::actors::RoleParameters;
 use rstd::clone::Clone;
-use rstd::convert::TryInto;
 use rstd::prelude::*;
 use rstd::str::from_utf8;
 use rstd::vec::Vec;
-use sr_primitives::traits::SaturatedConversion;
-use sr_primitives::traits::{One, Zero};
-use sr_primitives::Perbill;
+use sr_primitives::traits::Zero;
 use srml_support::dispatch::DispatchResult;
 use srml_support::traits::{Currency, Get};
 use srml_support::{decl_error, decl_module, decl_storage, ensure, print};
@@ -76,9 +73,82 @@ use system::{ensure_root, RawOrigin};
 pub use crate::proposal_types::ProposalsConfigParameters;
 pub use proposal_types::{ProposalDetails, ProposalDetailsOf, ProposalEncoder};
 
-// Percentage of the total token issue as max mint balance value. Shared with spending
-// proposal max balance percentage.
-const COUNCIL_MINT_MAX_BALANCE_PERCENT: u32 = 2;
+// 'Set working group mint capacity' proposal limit
+const CONTENT_WORKING_GROUP_MINT_CAPACITY_MAX_VALUE: u32 = 1_000_000;
+// Max allowed value for 'spending' proposal
+const MAX_SPENDING_PROPOSAL_VALUE: u32 = 2_000_000_u32;
+// Max validator count for the 'set validator count' proposal
+const MAX_VALIDATOR_COUNT: u32 = 100;
+// min_actors min value for the 'set storage role parameters' proposal
+const ROLE_PARAMETERS_MIN_ACTORS_MAX_VALUE: u32 = 2;
+// max_actors min value for the 'set storage role parameters' proposal
+const ROLE_PARAMETERS_MAX_ACTORS_MIN_VALUE: u32 = 2;
+// max_actors max value for the 'set storage role parameters' proposal
+const ROLE_PARAMETERS_MAX_ACTORS_MAX_VALUE: u32 = 100;
+// reward_period min value for the 'set storage role parameters' proposal
+const ROLE_PARAMETERS_REWARD_PERIOD_MIN_VALUE: u32 = 600;
+// reward_period max value for the 'set storage role parameters' proposal
+const ROLE_PARAMETERS_REWARD_PERIOD_MAX_VALUE: u32 = 3600;
+// bonding_period min value for the 'set storage role parameters' proposal
+const ROLE_PARAMETERS_BONDING_PERIOD_MIN_VALUE: u32 = 600;
+// bonding_period max value for the 'set storage role parameters' proposal
+const ROLE_PARAMETERS_BONDING_PERIOD_MAX_VALUE: u32 = 28800;
+// unbonding_period min value for the 'set storage role parameters' proposal
+const ROLE_PARAMETERS_UNBONDING_PERIOD_MIN_VALUE: u32 = 600;
+// unbonding_period max value for the 'set storage role parameters' proposal
+const ROLE_PARAMETERS_UNBONDING_PERIOD_MAX_VALUE: u32 = 28800;
+// min_service_period min value for the 'set storage role parameters' proposal
+const ROLE_PARAMETERS_MIN_SERVICE_PERIOD_MIN_VALUE: u32 = 600;
+// min_service_period max value for the 'set storage role parameters' proposal
+const ROLE_PARAMETERS_MIN_SERVICE_PERIOD_MAX_VALUE: u32 = 28800;
+// startup_grace_period min value for the 'set storage role parameters' proposal
+const ROLE_PARAMETERS_STARTUP_GRACE_PERIOD_MIN_VALUE: u32 = 600;
+// startup_grace_period max value for the 'set storage role parameters' proposal
+const ROLE_PARAMETERS_STARTUP_GRACE_PERIOD_MAX_VALUE: u32 = 28800;
+// min_stake min value for the 'set storage role parameters' proposal
+const ROLE_PARAMETERS_MIN_STAKE_MIN_VALUE: u32 = 0;
+// min_stake max value for the 'set storage role parameters' proposal
+const ROLE_PARAMETERS_MIN_STAKE_MAX_VALUE: u32 = 10_000_000;
+// entry_request_fee min value for the 'set storage role parameters' proposal
+const ROLE_PARAMETERS_ENTRY_REQUEST_FEE_MIN_VALUE: u32 = 0;
+// entry_request_fee max value for the 'set storage role parameters' proposal
+const ROLE_PARAMETERS_ENTRY_REQUEST_FEE_MAX_VALUE: u32 = 100_000;
+// reward min value for the 'set storage role parameters' proposal
+const ROLE_PARAMETERS_REWARD_MIN_VALUE: u32 = 0;
+// reward max value for the 'set storage role parameters' proposal
+const ROLE_PARAMETERS_REWARD_MAX_VALUE: u32 = 1000;
+// council_size min value for the 'set election parameters' proposal
+const ELECTION_PARAMETERS_COUNCIL_SIZE_MIN_VALUE: u32 = 4;
+// council_size max value for the 'set election parameters' proposal
+const ELECTION_PARAMETERS_COUNCIL_SIZE_MAX_VALUE: u32 = 20;
+// candidacy_limit min value for the 'set election parameters' proposal
+const ELECTION_PARAMETERS_CANDIDACY_LIMIT_MIN_VALUE: u32 = 25;
+// candidacy_limit max value for the 'set election parameters' proposal
+const ELECTION_PARAMETERS_CANDIDACY_LIMIT_MAX_VALUE: u32 = 100;
+// min_voting_stake min value for the 'set election parameters' proposal
+const ELECTION_PARAMETERS_MIN_STAKE_MIN_VALUE: u32 = 1;
+// min_voting_stake max value for the 'set election parameters' proposal
+const ELECTION_PARAMETERS_MIN_STAKE_MAX_VALUE: u32 = 100_000_u32;
+// new_term_duration min value for the 'set election parameters' proposal
+const ELECTION_PARAMETERS_NEW_TERM_DURATION_MIN_VALUE: u32 = 14400;
+// new_term_duration max value for the 'set election parameters' proposal
+const ELECTION_PARAMETERS_NEW_TERM_DURATION_MAX_VALUE: u32 = 432_000;
+// revealing_period min value for the 'set election parameters' proposal
+const ELECTION_PARAMETERS_REVEALING_PERIOD_MIN_VALUE: u32 = 14400;
+// revealing_period max value for the 'set election parameters' proposal
+const ELECTION_PARAMETERS_REVEALING_PERIOD_MAX_VALUE: u32 = 28800;
+// voting_period min value for the 'set election parameters' proposal
+const ELECTION_PARAMETERS_VOTING_PERIOD_MIN_VALUE: u32 = 14400;
+// voting_period max value for the 'set election parameters' proposal
+const ELECTION_PARAMETERS_VOTING_PERIOD_MAX_VALUE: u32 = 28800;
+// announcing_period min value for the 'set election parameters' proposal
+const ELECTION_PARAMETERS_ANNOUNCING_PERIOD_MIN_VALUE: u32 = 14400;
+// announcing_period max value for the 'set election parameters' proposal
+const ELECTION_PARAMETERS_ANNOUNCING_PERIOD_MAX_VALUE: u32 = 43200;
+// min_council_stake min value for the 'set election parameters' proposal
+const ELECTION_PARAMETERS_MIN_COUNCIL_STAKE_MIN_VALUE: u32 = 1;
+// min_council_stake max value for the 'set election parameters' proposal
+const ELECTION_PARAMETERS_MIN_COUNCIL_STAKE_MAX_VALUE: u32 = 100_000_u32;
 
 /// 'Proposals codex' substrate module Trait
 pub trait Trait:
@@ -340,6 +410,12 @@ decl_module! {
         /// Predefined errors
         type Error = Error;
 
+        /// Exports max allowed text proposal length const.
+        const TextProposalMaxLength: u32 = T::TextProposalMaxLength::get();
+
+        /// Exports max wasm code length of the runtime upgrade proposal const.
+        const RuntimeUpgradeWasmProposalMaxLength: u32 = T::RuntimeUpgradeWasmProposalMaxLength::get();
+
         /// Create 'Text (signal)' proposal type.
         pub fn create_text_proposal(
             origin,
@@ -440,12 +516,8 @@ decl_module! {
             stake_balance: Option<BalanceOf<T>>,
             mint_balance: BalanceOfMint<T>,
         ) {
-
-            let max_mint_capacity: u32 = get_required_stake_by_fraction::<T>(1, 100)
-                .try_into()
-                .unwrap_or_default() as u32;
             ensure!(
-                mint_balance < <BalanceOfMint<T>>::from(max_mint_capacity),
+                mint_balance <= <BalanceOfMint<T>>::from(CONTENT_WORKING_GROUP_MINT_CAPACITY_MAX_VALUE),
                 Error::InvalidStorageWorkingGroupMintCapacity
             );
 
@@ -478,16 +550,8 @@ decl_module! {
             destination: T::AccountId,
         ) {
             ensure!(balance != BalanceOfMint::<T>::zero(), Error::InvalidSpendingProposalBalance);
-
-            let max_balance: u32 = get_required_stake_by_fraction::<T>(
-                COUNCIL_MINT_MAX_BALANCE_PERCENT,
-                100
-            )
-            .try_into()
-            .unwrap_or_default() as u32;
-
             ensure!(
-                balance < <BalanceOfMint<T>>::from(max_balance),
+                balance <= <BalanceOfMint<T>>::from(MAX_SPENDING_PROPOSAL_VALUE),
                 Error::InvalidSpendingProposalBalance
             );
 
@@ -586,7 +650,7 @@ decl_module! {
             );
 
             ensure!(
-                new_validator_count <= 1000, // max validator count
+                new_validator_count <= MAX_VALIDATOR_COUNT,
                 Error::InvalidValidatorCount
             );
 
@@ -741,110 +805,117 @@ impl<T: Trait> Module<T> {
         role_parameters: &RoleParameters<BalanceOfGovernanceCurrency<T>, T::BlockNumber>,
     ) -> Result<(), Error> {
         ensure!(
-            role_parameters.min_actors <= 5,
+            role_parameters.min_actors < ROLE_PARAMETERS_MIN_ACTORS_MAX_VALUE,
             Error::InvalidStorageRoleParameterMinActors
         );
 
         ensure!(
-            role_parameters.max_actors >= 5,
+            role_parameters.max_actors >= ROLE_PARAMETERS_MAX_ACTORS_MIN_VALUE,
             Error::InvalidStorageRoleParameterMaxActors
         );
 
         ensure!(
-            role_parameters.max_actors < 100,
+            role_parameters.max_actors < ROLE_PARAMETERS_MAX_ACTORS_MAX_VALUE,
             Error::InvalidStorageRoleParameterMaxActors
         );
 
         ensure!(
-            role_parameters.reward_period >= T::BlockNumber::from(600),
+            role_parameters.reward_period
+                >= T::BlockNumber::from(ROLE_PARAMETERS_REWARD_PERIOD_MIN_VALUE),
             Error::InvalidStorageRoleParameterRewardPeriod
         );
 
         ensure!(
-            role_parameters.reward_period <= T::BlockNumber::from(3600),
+            role_parameters.reward_period
+                <= T::BlockNumber::from(ROLE_PARAMETERS_REWARD_PERIOD_MAX_VALUE),
             Error::InvalidStorageRoleParameterRewardPeriod
         );
 
         ensure!(
-            role_parameters.bonding_period >= T::BlockNumber::from(600),
+            role_parameters.bonding_period
+                >= T::BlockNumber::from(ROLE_PARAMETERS_BONDING_PERIOD_MIN_VALUE),
             Error::InvalidStorageRoleParameterBondingPeriod
         );
 
         ensure!(
-            role_parameters.bonding_period <= T::BlockNumber::from(28800),
+            role_parameters.bonding_period
+                <= T::BlockNumber::from(ROLE_PARAMETERS_BONDING_PERIOD_MAX_VALUE),
             Error::InvalidStorageRoleParameterBondingPeriod
         );
 
         ensure!(
-            role_parameters.unbonding_period >= T::BlockNumber::from(600),
+            role_parameters.unbonding_period
+                >= T::BlockNumber::from(ROLE_PARAMETERS_UNBONDING_PERIOD_MIN_VALUE),
             Error::InvalidStorageRoleParameterUnbondingPeriod
         );
 
         ensure!(
-            role_parameters.unbonding_period <= T::BlockNumber::from(28800),
+            role_parameters.unbonding_period
+                <= T::BlockNumber::from(ROLE_PARAMETERS_UNBONDING_PERIOD_MAX_VALUE),
             Error::InvalidStorageRoleParameterUnbondingPeriod
         );
 
         ensure!(
-            role_parameters.min_service_period >= T::BlockNumber::from(600),
+            role_parameters.min_service_period
+                >= T::BlockNumber::from(ROLE_PARAMETERS_MIN_SERVICE_PERIOD_MIN_VALUE),
             Error::InvalidStorageRoleParameterMinServicePeriod
         );
 
         ensure!(
-            role_parameters.min_service_period <= T::BlockNumber::from(28800),
+            role_parameters.min_service_period
+                <= T::BlockNumber::from(ROLE_PARAMETERS_MIN_SERVICE_PERIOD_MAX_VALUE),
             Error::InvalidStorageRoleParameterMinServicePeriod
         );
 
         ensure!(
-            role_parameters.startup_grace_period >= T::BlockNumber::from(600),
+            role_parameters.startup_grace_period
+                >= T::BlockNumber::from(ROLE_PARAMETERS_STARTUP_GRACE_PERIOD_MIN_VALUE),
             Error::InvalidStorageRoleParameterStartupGracePeriod
         );
 
         ensure!(
-            role_parameters.startup_grace_period <= T::BlockNumber::from(28800),
+            role_parameters.startup_grace_period
+                <= T::BlockNumber::from(ROLE_PARAMETERS_STARTUP_GRACE_PERIOD_MAX_VALUE),
             Error::InvalidStorageRoleParameterStartupGracePeriod
         );
 
         ensure!(
-            role_parameters.min_stake > <BalanceOfGovernanceCurrency<T>>::from(0u32),
+            role_parameters.min_stake
+                > <BalanceOfGovernanceCurrency<T>>::from(ROLE_PARAMETERS_MIN_STAKE_MIN_VALUE),
             Error::InvalidStorageRoleParameterMinStake
         );
 
-        let max_min_stake: u32 = get_required_stake_by_fraction::<T>(1, 100)
-            .try_into()
-            .unwrap_or_default() as u32;
-
         ensure!(
-            role_parameters.min_stake < <BalanceOfGovernanceCurrency<T>>::from(max_min_stake),
+            role_parameters.min_stake
+                <= <BalanceOfGovernanceCurrency<T>>::from(ROLE_PARAMETERS_MIN_STAKE_MAX_VALUE),
             Error::InvalidStorageRoleParameterMinStake
         );
 
         ensure!(
-            role_parameters.entry_request_fee > <BalanceOfGovernanceCurrency<T>>::from(0u32),
+            role_parameters.entry_request_fee
+                > <BalanceOfGovernanceCurrency<T>>::from(
+                    ROLE_PARAMETERS_ENTRY_REQUEST_FEE_MIN_VALUE
+                ),
             Error::InvalidStorageRoleParameterEntryRequestFee
         );
 
-        let max_entry_request_fee: u32 = get_required_stake_by_fraction::<T>(1, 100)
-            .try_into()
-            .unwrap_or_default() as u32;
-
         ensure!(
             role_parameters.entry_request_fee
-                < <BalanceOfGovernanceCurrency<T>>::from(max_entry_request_fee),
+                <= <BalanceOfGovernanceCurrency<T>>::from(
+                    ROLE_PARAMETERS_ENTRY_REQUEST_FEE_MAX_VALUE
+                ),
             Error::InvalidStorageRoleParameterEntryRequestFee
         );
 
         ensure!(
-            role_parameters.reward > <BalanceOfGovernanceCurrency<T>>::from(0u32),
+            role_parameters.reward
+                > <BalanceOfGovernanceCurrency<T>>::from(ROLE_PARAMETERS_REWARD_MIN_VALUE),
             Error::InvalidStorageRoleParameterReward
         );
 
-        let max_reward: u32 = get_required_stake_by_fraction::<T>(1, 1000)
-            .try_into()
-            .unwrap_or_default() as u32;
-
         ensure!(
-            role_parameters.reward < <BalanceOfGovernanceCurrency<T>>::from(max_reward),
+            role_parameters.reward
+                < <BalanceOfGovernanceCurrency<T>>::from(ROLE_PARAMETERS_REWARD_MAX_VALUE),
             Error::InvalidStorageRoleParameterReward
         );
 
@@ -862,84 +933,98 @@ impl<T: Trait> Module<T> {
         election_parameters: &ElectionParameters<BalanceOfGovernanceCurrency<T>, T::BlockNumber>,
     ) -> Result<(), Error> {
         ensure!(
-            election_parameters.council_size >= 4,
+            election_parameters.council_size >= ELECTION_PARAMETERS_COUNCIL_SIZE_MIN_VALUE,
             Error::InvalidCouncilElectionParameterCouncilSize
         );
 
         ensure!(
-            election_parameters.council_size <= 20,
+            election_parameters.council_size <= ELECTION_PARAMETERS_COUNCIL_SIZE_MAX_VALUE,
             Error::InvalidCouncilElectionParameterCouncilSize
         );
 
         ensure!(
-            election_parameters.candidacy_limit >= 25,
+            election_parameters.candidacy_limit >= ELECTION_PARAMETERS_CANDIDACY_LIMIT_MIN_VALUE,
             Error::InvalidCouncilElectionParameterCandidacyLimit
         );
 
         ensure!(
-            election_parameters.candidacy_limit <= 100,
+            election_parameters.candidacy_limit <= ELECTION_PARAMETERS_CANDIDACY_LIMIT_MAX_VALUE,
             Error::InvalidCouncilElectionParameterCandidacyLimit
         );
 
         ensure!(
-            election_parameters.min_voting_stake >= <BalanceOfGovernanceCurrency<T>>::one(),
+            election_parameters.min_voting_stake
+                >= <BalanceOfGovernanceCurrency<T>>::from(ELECTION_PARAMETERS_MIN_STAKE_MIN_VALUE),
             Error::InvalidCouncilElectionParameterMinVotingStake
         );
 
         ensure!(
             election_parameters.min_voting_stake
-                <= <BalanceOfGovernanceCurrency<T>>::from(100_000_u32),
+                <= <BalanceOfGovernanceCurrency<T>>::from(ELECTION_PARAMETERS_MIN_STAKE_MAX_VALUE),
             Error::InvalidCouncilElectionParameterMinVotingStake
         );
 
         ensure!(
-            election_parameters.new_term_duration >= T::BlockNumber::from(14400),
+            election_parameters.new_term_duration
+                >= T::BlockNumber::from(ELECTION_PARAMETERS_NEW_TERM_DURATION_MIN_VALUE),
             Error::InvalidCouncilElectionParameterNewTermDuration
         );
 
         ensure!(
-            election_parameters.new_term_duration <= T::BlockNumber::from(432_000),
+            election_parameters.new_term_duration
+                <= T::BlockNumber::from(ELECTION_PARAMETERS_NEW_TERM_DURATION_MAX_VALUE),
             Error::InvalidCouncilElectionParameterNewTermDuration
         );
 
         ensure!(
-            election_parameters.revealing_period >= T::BlockNumber::from(14400),
+            election_parameters.revealing_period
+                >= T::BlockNumber::from(ELECTION_PARAMETERS_REVEALING_PERIOD_MIN_VALUE),
             Error::InvalidCouncilElectionParameterRevealingPeriod
         );
 
         ensure!(
-            election_parameters.revealing_period <= T::BlockNumber::from(43200),
+            election_parameters.revealing_period
+                <= T::BlockNumber::from(ELECTION_PARAMETERS_REVEALING_PERIOD_MAX_VALUE),
             Error::InvalidCouncilElectionParameterRevealingPeriod
         );
 
         ensure!(
-            election_parameters.voting_period >= T::BlockNumber::from(14400),
+            election_parameters.voting_period
+                >= T::BlockNumber::from(ELECTION_PARAMETERS_VOTING_PERIOD_MIN_VALUE),
             Error::InvalidCouncilElectionParameterVotingPeriod
         );
 
         ensure!(
-            election_parameters.voting_period <= T::BlockNumber::from(43200),
+            election_parameters.voting_period
+                <= T::BlockNumber::from(ELECTION_PARAMETERS_VOTING_PERIOD_MAX_VALUE),
             Error::InvalidCouncilElectionParameterVotingPeriod
         );
 
         ensure!(
-            election_parameters.announcing_period >= T::BlockNumber::from(14400),
+            election_parameters.announcing_period
+                >= T::BlockNumber::from(ELECTION_PARAMETERS_ANNOUNCING_PERIOD_MIN_VALUE),
             Error::InvalidCouncilElectionParameterAnnouncingPeriod
         );
 
         ensure!(
-            election_parameters.announcing_period <= T::BlockNumber::from(43200),
+            election_parameters.announcing_period
+                <= T::BlockNumber::from(ELECTION_PARAMETERS_ANNOUNCING_PERIOD_MAX_VALUE),
             Error::InvalidCouncilElectionParameterAnnouncingPeriod
         );
 
         ensure!(
-            election_parameters.min_council_stake >= <BalanceOfGovernanceCurrency<T>>::one(),
+            election_parameters.min_council_stake
+                >= <BalanceOfGovernanceCurrency<T>>::from(
+                    ELECTION_PARAMETERS_MIN_COUNCIL_STAKE_MIN_VALUE
+                ),
             Error::InvalidCouncilElectionParameterMinCouncilStake
         );
 
         ensure!(
             election_parameters.min_council_stake
-                <= <BalanceOfGovernanceCurrency<T>>::from(100_000_u32),
+                <= <BalanceOfGovernanceCurrency<T>>::from(
+                    ELECTION_PARAMETERS_MIN_COUNCIL_STAKE_MAX_VALUE
+                ),
             Error::InvalidCouncilElectionParameterMinCouncilStake
         );
 
@@ -1003,18 +1088,3 @@ impl<T: Trait> Module<T> {
         ));
     }
 }
-
-// calculates required stake value using total issuance value and stake percentage. Truncates to
-// lowest integer value. Value fraction is defined by numerator and denominator.
-pub(crate) fn get_required_stake_by_fraction<T: crate::Trait>(
-    numerator: u32,
-    denominator: u32,
-) -> BalanceOf<T> {
-    let total_issuance: u128 = <CurrencyOf<T>>::total_issuance().try_into().unwrap_or(0) as u128;
-    let required_stake =
-        Perbill::from_rational_approximation(numerator, denominator) * total_issuance;
-
-    let balance: BalanceOf<T> = required_stake.saturated_into();
-
-    balance
-}

+ 16 - 46
runtime-modules/proposals/codex/src/proposal_types/parameters.rs

@@ -1,4 +1,4 @@
-use crate::{get_required_stake_by_fraction, BalanceOf, Module, ProposalParameters};
+use crate::{BalanceOf, Module, ProposalParameters};
 
 // Proposal parameters for the 'Set validator count' proposal
 pub(crate) fn set_validator_count_proposal<T: crate::Trait>(
@@ -10,7 +10,7 @@ pub(crate) fn set_validator_count_proposal<T: crate::Trait>(
         approval_threshold_percentage: 80,
         slashing_quorum_percentage: 60,
         slashing_threshold_percentage: 80,
-        required_stake: Some(get_required_stake_by_fraction::<T>(25, 10000)),
+        required_stake: Some(<BalanceOf<T>>::from(100_000_u32)),
     }
 }
 
@@ -24,7 +24,7 @@ pub(crate) fn runtime_upgrade_proposal<T: crate::Trait>(
         approval_threshold_percentage: 100,
         slashing_quorum_percentage: 60,
         slashing_threshold_percentage: 80,
-        required_stake: Some(get_required_stake_by_fraction::<T>(1, 100)),
+        required_stake: Some(<BalanceOf<T>>::from(1_000_000_u32)),
     }
 }
 
@@ -33,11 +33,11 @@ pub(crate) fn text_proposal<T: crate::Trait>() -> ProposalParameters<T::BlockNum
     ProposalParameters {
         voting_period: <Module<T>>::text_proposal_voting_period(),
         grace_period: <Module<T>>::text_proposal_grace_period(),
-        approval_quorum_percentage: 66,
+        approval_quorum_percentage: 60,
         approval_threshold_percentage: 80,
         slashing_quorum_percentage: 60,
         slashing_threshold_percentage: 80,
-        required_stake: Some(get_required_stake_by_fraction::<T>(25, 10000)),
+        required_stake: Some(<BalanceOf<T>>::from(25000u32)),
     }
 }
 
@@ -51,7 +51,7 @@ pub(crate) fn set_election_parameters_proposal<T: crate::Trait>(
         approval_threshold_percentage: 80,
         slashing_quorum_percentage: 60,
         slashing_threshold_percentage: 80,
-        required_stake: Some(get_required_stake_by_fraction::<T>(75, 10000)),
+        required_stake: Some(<BalanceOf<T>>::from(200_000_u32)),
     }
 }
 
@@ -62,11 +62,11 @@ pub(crate) fn set_content_working_group_mint_capacity_proposal<T: crate::Trait>(
         voting_period: <Module<T>>::set_content_working_group_mint_capacity_proposal_voting_period(
         ),
         grace_period: <Module<T>>::set_content_working_group_mint_capacity_proposal_grace_period(),
-        approval_quorum_percentage: 50,
+        approval_quorum_percentage: 60,
         approval_threshold_percentage: 75,
         slashing_quorum_percentage: 60,
         slashing_threshold_percentage: 80,
-        required_stake: Some(get_required_stake_by_fraction::<T>(25, 10000)),
+        required_stake: Some(<BalanceOf<T>>::from(50000u32)),
     }
 }
 
@@ -76,11 +76,11 @@ pub(crate) fn spending_proposal<T: crate::Trait>(
     ProposalParameters {
         voting_period: <Module<T>>::spending_proposal_voting_period(),
         grace_period: <Module<T>>::spending_proposal_grace_period(),
-        approval_quorum_percentage: 66,
+        approval_quorum_percentage: 60,
         approval_threshold_percentage: 80,
         slashing_quorum_percentage: 60,
         slashing_threshold_percentage: 80,
-        required_stake: Some(get_required_stake_by_fraction::<T>(25, 10000)),
+        required_stake: Some(<BalanceOf<T>>::from(25000u32)),
     }
 }
 
@@ -90,11 +90,11 @@ pub(crate) fn set_lead_proposal<T: crate::Trait>(
     ProposalParameters {
         voting_period: <Module<T>>::set_lead_proposal_voting_period(),
         grace_period: <Module<T>>::set_lead_proposal_grace_period(),
-        approval_quorum_percentage: 66,
-        approval_threshold_percentage: 80,
+        approval_quorum_percentage: 60,
+        approval_threshold_percentage: 75,
         slashing_quorum_percentage: 60,
         slashing_threshold_percentage: 80,
-        required_stake: Some(get_required_stake_by_fraction::<T>(25, 10000)),
+        required_stake: Some(<BalanceOf<T>>::from(50000u32)),
     }
 }
 
@@ -108,7 +108,7 @@ pub(crate) fn evict_storage_provider_proposal<T: crate::Trait>(
         approval_threshold_percentage: 75,
         slashing_quorum_percentage: 60,
         slashing_threshold_percentage: 80,
-        required_stake: Some(get_required_stake_by_fraction::<T>(1, 1000)),
+        required_stake: Some(<BalanceOf<T>>::from(25000u32)),
     }
 }
 
@@ -118,40 +118,10 @@ pub(crate) fn set_storage_role_parameters_proposal<T: crate::Trait>(
     ProposalParameters {
         voting_period: <Module<T>>::set_storage_role_parameters_proposal_voting_period(),
         grace_period: <Module<T>>::set_storage_role_parameters_proposal_grace_period(),
-        approval_quorum_percentage: 75,
+        approval_quorum_percentage: 66,
         approval_threshold_percentage: 80,
         slashing_quorum_percentage: 60,
         slashing_threshold_percentage: 80,
-        required_stake: Some(get_required_stake_by_fraction::<T>(25, 10000)),
-    }
-}
-
-#[cfg(test)]
-mod test {
-    use crate::proposal_types::parameters::get_required_stake_by_fraction;
-    use crate::tests::{increase_total_balance_issuance, initial_test_ext, Test};
-
-    pub use sr_primitives::Perbill;
-
-    #[test]
-    fn calculate_get_required_stake_by_fraction_with_zero_issuance() {
-        initial_test_ext()
-            .execute_with(|| assert_eq!(get_required_stake_by_fraction::<Test>(5, 7), 0));
-    }
-
-    #[test]
-    fn calculate_stake_by_percentage_for_defined_issuance_succeeds() {
-        initial_test_ext().execute_with(|| {
-            increase_total_balance_issuance(50000);
-            assert_eq!(get_required_stake_by_fraction::<Test>(1, 1000), 50)
-        });
-    }
-
-    #[test]
-    fn calculate_stake_by_percentage_for_defined_issuance_with_fraction_loss() {
-        initial_test_ext().execute_with(|| {
-            increase_total_balance_issuance(1111);
-            assert_eq!(get_required_stake_by_fraction::<Test>(3, 1000), 3);
-        });
+        required_stake: Some(<BalanceOf<T>>::from(100_000_u32)),
     }
 }

+ 2 - 2
runtime-modules/proposals/codex/src/tests/mock.rs

@@ -141,8 +141,8 @@ parameter_types! {
 impl proposal_discussion::Trait for Test {
     type Event = ();
     type PostAuthorOriginValidator = ();
-    type ThreadId = u32;
-    type PostId = u32;
+    type ThreadId = u64;
+    type PostId = u64;
     type MaxPostEditionNumber = MaxPostEditionNumber;
     type ThreadTitleLengthLimit = ThreadTitleLengthLimit;
     type PostLengthLimit = PostLengthLimit;

+ 55 - 48
runtime-modules/proposals/codex/src/tests/mod.rs

@@ -134,7 +134,7 @@ fn create_text_proposal_common_checks_succeed() {
                     1,
                     b"title".to_vec(),
                     b"body".to_vec(),
-                    Some(<BalanceOf<Test>>::from(1250u32)),
+                    Some(<BalanceOf<Test>>::from(25000u32)),
                     b"text".to_vec(),
                 )
             },
@@ -180,7 +180,7 @@ fn create_text_proposal_codex_call_fails_with_incorrect_text_size() {
 #[test]
 fn create_runtime_upgrade_common_checks_succeed() {
     initial_test_ext().execute_with(|| {
-        increase_total_balance_issuance(500000);
+        increase_total_balance_issuance_using_account_id(1, 5000000);
 
         let proposal_fixture = ProposalTestFixture {
             insufficient_rights_call: || {
@@ -219,7 +219,7 @@ fn create_runtime_upgrade_common_checks_succeed() {
                     1,
                     b"title".to_vec(),
                     b"body".to_vec(),
-                    Some(<BalanceOf<Test>>::from(5000u32)),
+                    Some(<BalanceOf<Test>>::from(1_000_000_u32)),
                     b"wasm".to_vec(),
                 )
             },
@@ -265,7 +265,7 @@ fn create_upgrade_runtime_proposal_codex_call_fails_with_incorrect_wasm_size() {
 #[test]
 fn create_set_election_parameters_proposal_common_checks_succeed() {
     initial_test_ext().execute_with(|| {
-        increase_total_balance_issuance(500000);
+        increase_total_balance_issuance_using_account_id(1, 500000);
 
         let proposal_fixture = ProposalTestFixture {
             insufficient_rights_call: || {
@@ -304,7 +304,7 @@ fn create_set_election_parameters_proposal_common_checks_succeed() {
                     1,
                     b"title".to_vec(),
                     b"body".to_vec(),
-                    Some(<BalanceOf<Test>>::from(3750u32)),
+                    Some(<BalanceOf<Test>>::from(200_000_u32)),
                     get_valid_election_parameters(),
                 )
             },
@@ -469,7 +469,7 @@ fn create_set_election_parameters_call_fails_with_incorrect_parameters() {
 #[test]
 fn create_working_group_mint_capacity_proposal_fails_with_invalid_parameters() {
     initial_test_ext().execute_with(|| {
-        increase_total_balance_issuance(500000);
+        increase_total_balance_issuance_using_account_id(1, 500000);
 
         assert_eq!(
             ProposalCodex::create_set_content_working_group_mint_capacity_proposal(
@@ -477,8 +477,8 @@ fn create_working_group_mint_capacity_proposal_fails_with_invalid_parameters() {
                 1,
                 b"title".to_vec(),
                 b"body".to_vec(),
-                Some(<BalanceOf<Test>>::from(1250u32)),
-                5001,
+                Some(<BalanceOf<Test>>::from(50000u32)),
+                (crate::CONTENT_WORKING_GROUP_MINT_CAPACITY_MAX_VALUE + 1) as u64,
             ),
             Err(Error::InvalidStorageWorkingGroupMintCapacity)
         );
@@ -527,7 +527,7 @@ fn create_set_content_working_group_mint_capacity_proposal_common_checks_succeed
                     1,
                     b"title".to_vec(),
                     b"body".to_vec(),
-                    Some(<BalanceOf<Test>>::from(1250u32)),
+                    Some(<BalanceOf<Test>>::from(50000u32)),
                     10,
                 )
             },
@@ -583,7 +583,7 @@ fn create_spending_proposal_common_checks_succeed() {
                     1,
                     b"title".to_vec(),
                     b"body".to_vec(),
-                    Some(<BalanceOf<Test>>::from(1250u32)),
+                    Some(<BalanceOf<Test>>::from(25000u32)),
                     100,
                     2,
                 )
@@ -620,7 +620,7 @@ fn create_spending_proposal_call_fails_with_incorrect_balance() {
                 b"title".to_vec(),
                 b"body".to_vec(),
                 Some(<BalanceOf<Test>>::from(1250u32)),
-                1001,
+                2000001,
                 2,
             ),
             Err(Error::InvalidSpendingProposalBalance)
@@ -696,7 +696,7 @@ fn create_set_lead_proposal_common_checks_succeed() {
                     1,
                     b"title".to_vec(),
                     b"body".to_vec(),
-                    Some(<BalanceOf<Test>>::from(1250u32)),
+                    Some(<BalanceOf<Test>>::from(50000u32)),
                     Some((20, 10)),
                 )
             },
@@ -749,7 +749,7 @@ fn create_evict_storage_provider_proposal_common_checks_succeed() {
                     1,
                     b"title".to_vec(),
                     b"body".to_vec(),
-                    Some(<BalanceOf<Test>>::from(500u32)),
+                    Some(<BalanceOf<Test>>::from(25000u32)),
                     1,
                 )
             },
@@ -763,7 +763,7 @@ fn create_evict_storage_provider_proposal_common_checks_succeed() {
 #[test]
 fn create_set_validator_count_proposal_common_checks_succeed() {
     initial_test_ext().execute_with(|| {
-        increase_total_balance_issuance(500000);
+        increase_total_balance_issuance_using_account_id(1, 500000);
 
         let proposal_fixture = ProposalTestFixture {
             insufficient_rights_call: || {
@@ -802,7 +802,7 @@ fn create_set_validator_count_proposal_common_checks_succeed() {
                     1,
                     b"title".to_vec(),
                     b"body".to_vec(),
-                    Some(<BalanceOf<Test>>::from(1250u32)),
+                    Some(<BalanceOf<Test>>::from(100_000_u32)),
                     4,
                 )
             },
@@ -847,8 +847,11 @@ fn create_set_validator_count_proposal_failed_with_invalid_validator_count() {
 #[test]
 fn create_set_storage_role_parameters_proposal_common_checks_succeed() {
     initial_test_ext().execute_with(|| {
-        increase_total_balance_issuance(500000);
-
+        increase_total_balance_issuance_using_account_id(1, 500000);
+        let role_parameters = RoleParameters {
+            min_actors: 1,
+            ..RoleParameters::default()
+        };
         let proposal_fixture = ProposalTestFixture {
             insufficient_rights_call: || {
                 ProposalCodex::create_set_storage_role_parameters_proposal(
@@ -857,7 +860,7 @@ fn create_set_storage_role_parameters_proposal_common_checks_succeed() {
                     b"title".to_vec(),
                     b"body".to_vec(),
                     None,
-                    RoleParameters::default(),
+                    role_parameters.clone(),
                 )
             },
             empty_stake_call: || {
@@ -867,7 +870,7 @@ fn create_set_storage_role_parameters_proposal_common_checks_succeed() {
                     b"title".to_vec(),
                     b"body".to_vec(),
                     None,
-                    RoleParameters::default(),
+                    role_parameters.clone(),
                 )
             },
             invalid_stake_call: || {
@@ -877,7 +880,7 @@ fn create_set_storage_role_parameters_proposal_common_checks_succeed() {
                     b"title".to_vec(),
                     b"body".to_vec(),
                     Some(<BalanceOf<Test>>::from(5000u32)),
-                    RoleParameters::default(),
+                    role_parameters.clone(),
                 )
             },
             successful_call: || {
@@ -886,13 +889,13 @@ fn create_set_storage_role_parameters_proposal_common_checks_succeed() {
                     1,
                     b"title".to_vec(),
                     b"body".to_vec(),
-                    Some(<BalanceOf<Test>>::from(1250u32)),
-                    RoleParameters::default(),
+                    Some(<BalanceOf<Test>>::from(100_000_u32)),
+                    role_parameters.clone(),
                 )
             },
             proposal_parameters:
                 crate::proposal_types::parameters::set_storage_role_parameters_proposal::<Test>(),
-            proposal_details: ProposalDetails::SetStorageRoleParameters(RoleParameters::default()),
+            proposal_details: ProposalDetails::SetStorageRoleParameters(role_parameters),
         };
         proposal_fixture.check_all();
     });
@@ -908,7 +911,7 @@ fn assert_failed_set_storage_parameters_call(
             1,
             b"title".to_vec(),
             b"body".to_vec(),
-            Some(<BalanceOf<Test>>::from(500u32)),
+            Some(<BalanceOf<Test>>::from(100_000_u32)),
             role_parameters,
         ),
         Err(error)
@@ -918,30 +921,34 @@ fn assert_failed_set_storage_parameters_call(
 #[test]
 fn create_set_storage_role_parameters_proposal_fails_with_invalid_parameters() {
     initial_test_ext().execute_with(|| {
-        increase_total_balance_issuance(500000);
+        increase_total_balance_issuance_using_account_id(1, 500000);
 
-        let mut role_parameters = RoleParameters::default();
-        role_parameters.min_actors = 6;
+        let working_role_parameters = RoleParameters {
+            min_actors: 1,
+            ..RoleParameters::default()
+        };
+        let mut role_parameters = working_role_parameters.clone();
+        role_parameters.min_actors = 2;
         assert_failed_set_storage_parameters_call(
             role_parameters,
             Error::InvalidStorageRoleParameterMinActors,
         );
 
-        role_parameters = RoleParameters::default();
-        role_parameters.max_actors = 4;
+        role_parameters = working_role_parameters.clone();
+        role_parameters.max_actors = 1;
         assert_failed_set_storage_parameters_call(
             role_parameters,
             Error::InvalidStorageRoleParameterMaxActors,
         );
 
-        role_parameters = RoleParameters::default();
+        role_parameters = working_role_parameters.clone();
         role_parameters.max_actors = 100;
         assert_failed_set_storage_parameters_call(
             role_parameters,
             Error::InvalidStorageRoleParameterMaxActors,
         );
 
-        role_parameters = RoleParameters::default();
+        role_parameters = working_role_parameters.clone();
         role_parameters.reward_period = 599;
         assert_failed_set_storage_parameters_call(
             role_parameters,
@@ -954,99 +961,99 @@ fn create_set_storage_role_parameters_proposal_fails_with_invalid_parameters() {
             Error::InvalidStorageRoleParameterRewardPeriod,
         );
 
-        role_parameters = RoleParameters::default();
+        role_parameters = working_role_parameters.clone();
         role_parameters.bonding_period = 599;
         assert_failed_set_storage_parameters_call(
             role_parameters,
             Error::InvalidStorageRoleParameterBondingPeriod,
         );
 
-        role_parameters = RoleParameters::default();
+        role_parameters = working_role_parameters.clone();
         role_parameters.bonding_period = 28801;
         assert_failed_set_storage_parameters_call(
             role_parameters,
             Error::InvalidStorageRoleParameterBondingPeriod,
         );
 
-        role_parameters = RoleParameters::default();
+        role_parameters = working_role_parameters.clone();
         role_parameters.unbonding_period = 599;
         assert_failed_set_storage_parameters_call(
             role_parameters,
             Error::InvalidStorageRoleParameterUnbondingPeriod,
         );
 
-        role_parameters = RoleParameters::default();
+        role_parameters = working_role_parameters.clone();
         role_parameters.unbonding_period = 28801;
         assert_failed_set_storage_parameters_call(
             role_parameters,
             Error::InvalidStorageRoleParameterUnbondingPeriod,
         );
 
-        role_parameters = RoleParameters::default();
+        role_parameters = working_role_parameters.clone();
         role_parameters.min_service_period = 599;
         assert_failed_set_storage_parameters_call(
             role_parameters,
             Error::InvalidStorageRoleParameterMinServicePeriod,
         );
 
-        role_parameters = RoleParameters::default();
+        role_parameters = working_role_parameters.clone();
         role_parameters.min_service_period = 28801;
         assert_failed_set_storage_parameters_call(
             role_parameters,
             Error::InvalidStorageRoleParameterMinServicePeriod,
         );
 
-        role_parameters = RoleParameters::default();
+        role_parameters = working_role_parameters.clone();
         role_parameters.startup_grace_period = 599;
         assert_failed_set_storage_parameters_call(
             role_parameters,
             Error::InvalidStorageRoleParameterStartupGracePeriod,
         );
 
-        role_parameters = RoleParameters::default();
+        role_parameters = working_role_parameters.clone();
         role_parameters.startup_grace_period = 28801;
         assert_failed_set_storage_parameters_call(
             role_parameters,
             Error::InvalidStorageRoleParameterStartupGracePeriod,
         );
 
-        role_parameters = RoleParameters::default();
+        role_parameters = working_role_parameters.clone();
         role_parameters.min_stake = 0;
         assert_failed_set_storage_parameters_call(
             role_parameters,
             Error::InvalidStorageRoleParameterMinStake,
         );
 
-        role_parameters = RoleParameters::default();
-        role_parameters.min_stake = 5001;
+        role_parameters = working_role_parameters.clone();
+        role_parameters.min_stake = 10000001;
         assert_failed_set_storage_parameters_call(
             role_parameters,
             Error::InvalidStorageRoleParameterMinStake,
         );
 
-        role_parameters = RoleParameters::default();
+        role_parameters = working_role_parameters.clone();
         role_parameters.entry_request_fee = 0;
         assert_failed_set_storage_parameters_call(
             role_parameters,
             Error::InvalidStorageRoleParameterEntryRequestFee,
         );
 
-        role_parameters = RoleParameters::default();
-        role_parameters.entry_request_fee = 5001;
+        role_parameters = working_role_parameters.clone();
+        role_parameters.entry_request_fee = 100001;
         assert_failed_set_storage_parameters_call(
             role_parameters,
             Error::InvalidStorageRoleParameterEntryRequestFee,
         );
 
-        role_parameters = RoleParameters::default();
+        role_parameters = working_role_parameters.clone();
         role_parameters.reward = 0;
         assert_failed_set_storage_parameters_call(
             role_parameters,
             Error::InvalidStorageRoleParameterReward,
         );
 
-        role_parameters = RoleParameters::default();
-        role_parameters.reward = 501;
+        role_parameters = working_role_parameters;
+        role_parameters.reward = 1001;
         assert_failed_set_storage_parameters_call(
             role_parameters,
             Error::InvalidStorageRoleParameterReward,

+ 16 - 4
runtime-modules/proposals/discussion/src/lib.rs

@@ -95,10 +95,10 @@ pub trait Trait: system::Trait + membership::members::Trait {
     >;
 
     /// Discussion thread Id type
-    type ThreadId: From<u32> + Into<u32> + Parameter + Default + Copy;
+    type ThreadId: From<u64> + Into<u64> + Parameter + Default + Copy;
 
     /// Post Id type
-    type PostId: From<u32> + Parameter + Default + Copy;
+    type PostId: From<u64> + Parameter + Default + Copy;
 
     /// Defines post edition number limit.
     type MaxPostEditionNumber: Get<u32>;
@@ -166,14 +166,14 @@ decl_storage! {
             Thread<MemberId<T>, T::BlockNumber>;
 
         /// Count of all threads that have been created.
-        pub ThreadCount get(fn thread_count): u32;
+        pub ThreadCount get(fn thread_count): u64;
 
         /// Map thread id and post id to corresponding post.
         pub PostThreadIdByPostId: double_map T::ThreadId, twox_128(T::PostId) =>
              Post<MemberId<T>, T::BlockNumber, T::ThreadId>;
 
         /// Count of all posts that have been created.
-        pub PostCount get(fn post_count): u32;
+        pub PostCount get(fn post_count): u64;
 
         /// Last author thread counter (part of the antispam mechanism)
         pub LastThreadAuthorCounter get(fn last_thread_author_counter):
@@ -190,6 +190,18 @@ decl_module! {
         /// Emits an event. Default substrate implementation.
         fn deposit_event() = default;
 
+        /// Exports post edition number limit const.
+        const MaxPostEditionNumber: u32 = T::MaxPostEditionNumber::get();
+
+        /// Exports thread title length limit const.
+        const ThreadTitleLengthLimit: u32 = T::ThreadTitleLengthLimit::get();
+
+        /// Exports post length limit const.
+        const PostLengthLimit: u32 = T::PostLengthLimit::get();
+
+        /// Exports max thread by same author in a row number limit const.
+        const MaxThreadInARowNumber: u32 = T::MaxThreadInARowNumber::get();
+
         /// Adds a post with author origin check.
         pub fn add_post(
             origin,

+ 2 - 2
runtime-modules/proposals/discussion/src/tests/mock.rs

@@ -87,8 +87,8 @@ impl membership::members::Trait for Test {
 impl crate::Trait for Test {
     type Event = TestEvent;
     type PostAuthorOriginValidator = ();
-    type ThreadId = u32;
-    type PostId = u32;
+    type ThreadId = u64;
+    type PostId = u64;
     type MaxPostEditionNumber = MaxPostEditionNumber;
     type ThreadTitleLengthLimit = ThreadTitleLengthLimit;
     type PostLengthLimit = PostLengthLimit;

+ 10 - 10
runtime-modules/proposals/discussion/src/tests/mod.rs

@@ -8,7 +8,7 @@ use system::{EventRecord, Phase};
 
 struct EventFixture;
 impl EventFixture {
-    fn assert_events(expected_raw_events: Vec<RawEvent<u32, u64, u32>>) {
+    fn assert_events(expected_raw_events: Vec<RawEvent<u64, u64, u64>>) {
         let expected_events = expected_raw_events
             .iter()
             .map(|ev| EventRecord {
@@ -23,13 +23,13 @@ impl EventFixture {
 }
 
 struct TestPostEntry {
-    pub post_id: u32,
+    pub post_id: u64,
     pub text: Vec<u8>,
     pub edition_number: u32,
 }
 
 struct TestThreadEntry {
-    pub thread_id: u32,
+    pub thread_id: u64,
     pub title: Vec<u8>,
 }
 
@@ -81,7 +81,7 @@ impl DiscussionFixture {
         DiscussionFixture { title, ..self }
     }
 
-    fn create_discussion_and_assert(&self, result: Result<u32, Error>) -> Option<u32> {
+    fn create_discussion_and_assert(&self, result: Result<u64, Error>) -> Option<u64> {
         let create_discussion_result =
             Discussions::create_thread(self.author_id, self.title.clone());
 
@@ -94,13 +94,13 @@ impl DiscussionFixture {
 struct PostFixture {
     pub text: Vec<u8>,
     pub origin: RawOrigin<u64>,
-    pub thread_id: u32,
-    pub post_id: Option<u32>,
+    pub thread_id: u64,
+    pub post_id: Option<u64>,
     pub author_id: u64,
 }
 
 impl PostFixture {
-    fn default_for_thread(thread_id: u32) -> Self {
+    fn default_for_thread(thread_id: u64) -> Self {
         PostFixture {
             text: b"text".to_vec(),
             author_id: 1,
@@ -122,18 +122,18 @@ impl PostFixture {
         PostFixture { author_id, ..self }
     }
 
-    fn change_thread_id(self, thread_id: u32) -> Self {
+    fn change_thread_id(self, thread_id: u64) -> Self {
         PostFixture { thread_id, ..self }
     }
 
-    fn change_post_id(self, post_id: u32) -> Self {
+    fn change_post_id(self, post_id: u64) -> Self {
         PostFixture {
             post_id: Some(post_id),
             ..self
         }
     }
 
-    fn add_post_and_assert(&mut self, result: Result<(), Error>) -> Option<u32> {
+    fn add_post_and_assert(&mut self, result: Result<(), Error>) -> Option<u64> {
         let add_post_result = Discussions::add_post(
             self.origin.clone().into(),
             self.author_id,

+ 15 - 0
runtime-modules/proposals/engine/src/lib.rs

@@ -315,6 +315,21 @@ decl_module! {
         /// Emits an event. Default substrate implementation.
         fn deposit_event() = default;
 
+        /// Exports const - the fee is applied when cancel the proposal. A fee would be slashed (burned).
+        const CancellationFee: BalanceOf<T> = T::CancellationFee::get();
+
+        /// Exports const -  the fee is applied when the proposal gets rejected. A fee would be slashed (burned).
+        const RejectionFee: BalanceOf<T> = T::RejectionFee::get();
+
+        /// Exports const -  max allowed proposal title length.
+        const TitleMaxLength: u32 = T::TitleMaxLength::get();
+
+        /// Exports const -  max allowed proposal description length.
+        const DescriptionMaxLength: u32 = T::DescriptionMaxLength::get();
+
+        /// Exports const -  max simultaneous active proposals number.
+        const MaxActiveProposalLimit: u32 = T::MaxActiveProposalLimit::get();
+
         /// Vote extrinsic. Conditions:  origin must allow votes.
         pub fn vote(origin, voter_id: MemberId<T>, proposal_id: T::ProposalId, vote: VoteKind)  {
             T::VoterOriginValidator::ensure_actor_origin(

+ 1 - 1
runtime-modules/roles/src/actors.rs

@@ -67,7 +67,7 @@ impl<Balance: From<u32>, BlockNumber: From<u32>> Default for RoleParameters<Bala
             entry_request_fee: Balance::from(50),
 
             // not currently used
-            min_actors: 5,
+            min_actors: 1,
             bonding_period: BlockNumber::from(600),
             min_service_period: BlockNumber::from(600),
             startup_grace_period: BlockNumber::from(600),

+ 24 - 6
runtime/src/lib.rs

@@ -94,6 +94,22 @@ pub type Moment = u64;
 /// Credential type
 pub type Credential = u64;
 
+/// Represents a thread identifier for both Forum and Proposals Discussion
+///
+/// Note: Both modules expose type names ThreadId and PostId (which are defined on their Trait) and
+/// used in state storage and dispatchable method's argument types,
+/// and are therefore part of the public API/metadata of the runtime.
+/// In the currenlty version the polkadot-js/api that is used and is compatible with the runtime,
+/// the type registry has flat namespace and its not possible
+/// to register identically named types from different modules, separately. And so we MUST configure
+/// the underlying types to be identicaly to avoid issues with encoding/decoding these types on the client side.
+pub type ThreadId = u64;
+
+/// Represents a post identifier for both Forum and Proposals Discussion
+///
+/// See the Note about ThreadId
+pub type PostId = u64;
+
 /// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
 /// the specifics of the runtime. They can then be made to be agnostic over specific formats
 /// of data like extrinsics, allowing for them to continue syncing the network through upgrades
@@ -176,7 +192,7 @@ pub fn native_version() -> NativeVersion {
 
 parameter_types! {
     pub const BlockHashCount: BlockNumber = 250;
-    pub const MaximumBlockWeight: Weight = 1_000_000;
+    pub const MaximumBlockWeight: Weight = 1_000_000_000;
     pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
     pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
     pub const Version: RuntimeVersion = VERSION;
@@ -784,6 +800,8 @@ impl forum::ForumUserRegistry<AccountId> for ShimMembershipRegistry {
 impl forum::Trait for Runtime {
     type Event = Event;
     type MembershipRegistry = ShimMembershipRegistry;
+    type ThreadId = ThreadId;
+    type PostId = PostId;
 }
 
 impl migration::Trait for Runtime {
@@ -808,8 +826,8 @@ impl discovery::Trait for Runtime {
 }
 
 parameter_types! {
-    pub const ProposalCancellationFee: u64 = 5;
-    pub const ProposalRejectionFee: u64 = 3;
+    pub const ProposalCancellationFee: u64 = 10000;
+    pub const ProposalRejectionFee: u64 = 5000;
     pub const ProposalTitleMaxLength: u32 = 40;
     pub const ProposalDescriptionMaxLength: u32 = 3000;
     pub const ProposalMaxActiveProposalLimit: u32 = 5;
@@ -845,8 +863,8 @@ parameter_types! {
 impl proposals_discussion::Trait for Runtime {
     type Event = Event;
     type PostAuthorOriginValidator = MembershipOriginValidator<Self>;
-    type ThreadId = u32;
-    type PostId = u32;
+    type ThreadId = ThreadId;
+    type PostId = PostId;
     type MaxPostEditionNumber = ProposalMaxPostEditionNumber;
     type ThreadTitleLengthLimit = ProposalThreadTitleLengthLimit;
     type PostLengthLimit = ProposalPostLengthLimit;
@@ -889,12 +907,12 @@ construct_runtime!(
         RandomnessCollectiveFlip: randomness_collective_flip::{Module, Call, Storage},
         Sudo: sudo,
         // Joystream
+        Migration: migration::{Module, Call, Storage, Event<T>, Config},
         CouncilElection: election::{Module, Call, Storage, Event<T>, Config<T>},
         Council: council::{Module, Call, Storage, Event<T>, Config<T>},
         Memo: memo::{Module, Call, Storage, Event<T>},
         Members: members::{Module, Call, Storage, Event<T>, Config<T>},
         Forum: forum::{Module, Call, Storage, Event<T>, Config<T>},
-        Migration: migration::{Module, Call, Storage, Event<T>},
         Actors: actors::{Module, Call, Storage, Event<T>, Config},
         DataObjectTypeRegistry: data_object_type_registry::{Module, Call, Storage, Event<T>, Config<T>},
         DataDirectory: data_directory::{Module, Call, Storage, Event<T>},

+ 32 - 25
runtime/src/migration.rs

@@ -2,47 +2,45 @@
 #![allow(clippy::redundant_closure_call)] // disable it because of the substrate lib design
 
 use crate::VERSION;
+use rstd::prelude::*;
 use sr_primitives::{print, traits::Zero};
 use srml_support::{debug, decl_event, decl_module, decl_storage};
 
 impl<T: Trait> Module<T> {
+    /// This method is called from on_initialize() when a runtime upgrade is detected. This
+    /// happens when the runtime spec version is found to be higher than the stored value.
+    /// Important to note this method should be carefully maintained, because it runs on every runtime
+    /// upgrade.
     fn runtime_upgraded() {
-        print("running runtime initializers...");
+        print("Running runtime upgraded handler");
 
-        // ...
-        // add initialization of modules introduced in new runtime release. This
+        // Add initialization of modules introduced in new runtime release. Typically this
         // would be any new storage values that need an initial value which would not
-        // have been initialized with config() or build() mechanism.
-        // ...
+        // have been initialized with config() or build() chainspec construction mechanism.
+        // Other tasks like resetting values, migrating values etc.
+
+        // Runtime Upgrade Code for going from Rome to Constantinople
 
         // Create the Council mint. If it fails, we can't do anything about it here.
-        let mint_creation_result = governance::council::Module::<T>::create_new_council_mint(
+        if let Err(err) = governance::council::Module::<T>::create_new_council_mint(
             minting::BalanceOf::<T>::zero(),
-        );
-
-        if mint_creation_result.is_err() {
+        ) {
             debug::warn!(
                 "Failed to create a mint for council during migration: {:?}",
-                mint_creation_result
+                err
             );
         }
 
+        // Initialise the proposal system various periods
         proposals_codex::Module::<T>::set_default_config_values();
-
-        Self::deposit_event(RawEvent::Migrated(
-            <system::Module<T>>::block_number(),
-            VERSION.spec_version,
-        ));
     }
 }
 
 pub trait Trait:
     system::Trait
-    + storage::data_directory::Trait
-    + storage::data_object_storage_registry::Trait
-    + forum::Trait
-    + sudo::Trait
-    + governance::council::Trait
+    + governance::election::Trait
+    + content_working_group::Trait
+    + roles::actors::Trait
     + proposals_codex::Trait
 {
     type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
@@ -50,9 +48,13 @@ pub trait Trait:
 
 decl_storage! {
     trait Store for Module<T: Trait> as Migration {
-        /// Records at what runtime spec version the store was initialized. This allows the runtime
-        /// to know when to run initialize code if it was installed as an update.
-        pub SpecVersion get(spec_version) build(|_| VERSION.spec_version) : Option<u32>;
+        /// Records at what runtime spec version the store was initialized. At genesis this will be
+        /// initialized to Some(VERSION.spec_version). It is an Option because the first time the module
+        /// was introduced was as a runtime upgrade and type was never changed.
+        /// When the runtime is upgraded the spec version be updated.
+        pub SpecVersion get(spec_version) build(|_config: &GenesisConfig| {
+            VERSION.spec_version
+        }) : Option<u32>;
     }
 }
 
@@ -68,11 +70,16 @@ decl_module! {
 
         fn on_initialize(_now: T::BlockNumber) {
             if Self::spec_version().map_or(true, |spec_version| VERSION.spec_version > spec_version) {
-                // mark store version with current version of the runtime
+                // Mark store version with current version of the runtime
                 SpecVersion::put(VERSION.spec_version);
 
-                // run migrations and store initializers
+                // Run migrations and store initializers
                 Self::runtime_upgraded();
+
+                Self::deposit_event(RawEvent::Migrated(
+                    <system::Module<T>>::block_number(),
+                    VERSION.spec_version,
+                ));
             }
         }
     }

+ 17 - 12
runtime/src/test/proposals_integration.rs

@@ -269,7 +269,7 @@ fn proposal_cancellation_with_slashes_with_balance_checks_succeeds() {
         setup_members(2);
         let member_id = 0; // newly created member_id
 
-        let stake_amount = 200u128;
+        let stake_amount = 20000u128;
         let parameters = ProposalParameters {
             voting_period: 3,
             approval_quorum_percentage: 50,
@@ -285,7 +285,7 @@ fn proposal_cancellation_with_slashes_with_balance_checks_succeeds() {
             .with_stake(stake_amount)
             .with_proposer(member_id);
 
-        let account_balance = 500;
+        let account_balance = 500000;
         let _imbalance =
             <Runtime as stake::Trait>::Currency::deposit_creating(&account_id, account_balance);
 
@@ -462,7 +462,7 @@ fn text_proposal_execution_succeeds() {
                     member_id as u64,
                     b"title".to_vec(),
                     b"body".to_vec(),
-                    Some(<BalanceOf<Runtime>>::from(1250u32)),
+                    Some(<BalanceOf<Runtime>>::from(25000u32)),
                     b"text".to_vec(),
                 )
             },
@@ -486,7 +486,7 @@ fn set_lead_proposal_execution_succeeds() {
                     member_id as u64,
                     b"title".to_vec(),
                     b"body".to_vec(),
-                    Some(<BalanceOf<Runtime>>::from(1250u32)),
+                    Some(<BalanceOf<Runtime>>::from(50000u32)),
                     Some((member_id as u64, account_id.into())),
                 )
             },
@@ -519,7 +519,7 @@ fn spending_proposal_execution_succeeds() {
                     member_id as u64,
                     b"title".to_vec(),
                     b"body".to_vec(),
-                    Some(<BalanceOf<Runtime>>::from(1250u32)),
+                    Some(<BalanceOf<Runtime>>::from(25_000_u32)),
                     new_balance,
                     target_account_id.clone().into(),
                 )
@@ -561,7 +561,7 @@ fn set_content_working_group_mint_capacity_execution_succeeds() {
                     member_id as u64,
                     b"title".to_vec(),
                     b"body".to_vec(),
-                    Some(<BalanceOf<Runtime>>::from(1250u32)),
+                    Some(<BalanceOf<Runtime>>::from(50000u32)),
                     new_balance,
                 )
             },
@@ -599,7 +599,7 @@ fn set_election_parameters_proposal_execution_succeeds() {
                     member_id as u64,
                     b"title".to_vec(),
                     b"body".to_vec(),
-                    Some(<BalanceOf<Runtime>>::from(3750u32)),
+                    Some(<BalanceOf<Runtime>>::from(200_000_u32)),
                     election_parameters,
                 )
             },
@@ -648,7 +648,7 @@ fn evict_storage_provider_proposal_execution_succeeds() {
                     member_id as u64,
                     b"title".to_vec(),
                     b"body".to_vec(),
-                    Some(<BalanceOf<Runtime>>::from(500u32)),
+                    Some(<BalanceOf<Runtime>>::from(25000u32)),
                     target_account.into(),
                 )
             },
@@ -668,14 +668,19 @@ fn set_storage_role_parameters_proposal_execution_succeeds() {
         let member_id = 1;
         let account_id: [u8; 32] = [member_id; 32];
 
+        let default_role_parameters = RoleParameters {
+            min_actors: 1,
+            ..RoleParameters::default()
+        };
+
         <roles::actors::Parameters<Runtime>>::insert(
             Role::StorageProvider,
-            RoleParameters::default(),
+            default_role_parameters.clone(),
         );
 
         let target_role_parameters = RoleParameters {
             startup_grace_period: 700,
-            ..RoleParameters::default()
+            ..default_role_parameters
         };
 
         let codex_extrinsic_test_fixture = CodexProposalTestFixture {
@@ -686,7 +691,7 @@ fn set_storage_role_parameters_proposal_execution_succeeds() {
                     member_id as u64,
                     b"title".to_vec(),
                     b"body".to_vec(),
-                    Some(<BalanceOf<Runtime>>::from(1250u32)),
+                    Some(<BalanceOf<Runtime>>::from(100_000_u32)),
                     target_role_parameters.clone(),
                 )
             },
@@ -717,7 +722,7 @@ fn set_validator_count_proposal_execution_succeeds() {
                     member_id as u64,
                     b"title".to_vec(),
                     b"body".to_vec(),
-                    Some(<BalanceOf<Runtime>>::from(1250u32)),
+                    Some(<BalanceOf<Runtime>>::from(100_000_u32)),
                     new_validator_count,
                 )
             },

+ 4 - 3
setup.sh

@@ -7,8 +7,9 @@ set -e
 #  - rustup - rust insaller
 #  - rust compiler and toolchains
 #  - skips installing substrate and subkey
-curl https://getsubstrate.io -sSf | bash -s -- --fast \
-    && rustup component add rustfmt
+curl https://getsubstrate.io -sSf | bash -s -- --fast
+
+rustup component add rustfmt clippy
 
 # TODO: Install additional tools...
-# - b2sum
+# - b2sum