Browse Source

Merge branch 'sumer' into sumer-new-substrate-update-apps

Mokhtar Naamani 3 years ago
parent
commit
f7661220d8

+ 2 - 2
Cargo.lock

@@ -2330,7 +2330,7 @@ dependencies = [
 
 [[package]]
 name = "joystream-node"
-version = "5.2.0"
+version = "5.3.0"
 dependencies = [
  "frame-benchmarking",
  "frame-benchmarking-cli",
@@ -2391,7 +2391,7 @@ dependencies = [
 
 [[package]]
 name = "joystream-node-runtime"
-version = "9.4.0"
+version = "9.5.0"
 dependencies = [
  "frame-benchmarking",
  "frame-executive",

+ 1 - 1
node/Cargo.toml

@@ -3,7 +3,7 @@ authors = ['Joystream contributors']
 build = 'build.rs'
 edition = '2018'
 name = 'joystream-node'
-version = '5.2.0'
+version = '5.3.0'
 default-run = "joystream-node"
 
 [[bin]]

+ 1 - 0
runtime-modules/proposals/codex/src/lib.rs

@@ -823,6 +823,7 @@ impl<T: Trait> Module<T> {
             &params.title,
             &params.description,
             params.stake_balance,
+            &account_id,
         )?;
 
         <proposals_discussion::Module<T>>::ensure_can_create_thread(

+ 9 - 15
runtime-modules/proposals/codex/src/tests/mod.rs

@@ -72,9 +72,16 @@ where
         );
     }
 
+    fn check_for_insufficient_balance(&self) {
+        assert_eq!(
+            (self.successful_call)(),
+            Err(proposals_engine::Error::<Test>::InsufficientBalance.into())
+        );
+    }
+
     fn check_for_successful_call(&self) {
         let account_id = 1;
-        let _imbalance = <Test as stake::Trait>::Currency::deposit_creating(&account_id, 150000);
+        let _imbalance = <Test as stake::Trait>::Currency::deposit_creating(&account_id, 5_000_000);
 
         assert_eq!((self.successful_call)(), Ok(()));
 
@@ -95,6 +102,7 @@ where
     pub fn check_all(&self) {
         self.check_call_for_insufficient_rights();
         self.check_for_invalid_stakes();
+        self.check_for_insufficient_balance();
         self.check_for_successful_call();
     }
 }
@@ -102,8 +110,6 @@ where
 #[test]
 fn create_text_proposal_common_checks_succeed() {
     initial_test_ext().execute_with(|| {
-        increase_total_balance_issuance(500000);
-
         let proposal_fixture = ProposalTestFixture {
             insufficient_rights_call: || {
                 ProposalCodex::create_text_proposal(
@@ -187,8 +193,6 @@ 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_using_account_id(1, 10000000);
-
         let proposal_fixture = ProposalTestFixture {
             insufficient_rights_call: || {
                 ProposalCodex::create_runtime_upgrade_proposal(
@@ -272,8 +276,6 @@ 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_using_account_id(1, 2000000);
-
         let proposal_fixture = ProposalTestFixture {
             insufficient_rights_call: || {
                 ProposalCodex::create_set_election_parameters_proposal(
@@ -566,8 +568,6 @@ fn create_spending_proposal_call_fails_with_incorrect_balance() {
 #[test]
 fn create_set_validator_count_proposal_common_checks_succeed() {
     initial_test_ext().execute_with(|| {
-        increase_total_balance_issuance_using_account_id(1, 1000000);
-
         let proposal_fixture = ProposalTestFixture {
             insufficient_rights_call: || {
                 ProposalCodex::create_set_validator_count_proposal(
@@ -785,8 +785,6 @@ fn run_create_add_working_group_leader_opening_proposal_common_checks_succeed(
             working_group,
         };
 
-        increase_total_balance_issuance_using_account_id(1, 500000);
-
         let proposal_fixture = ProposalTestFixture {
             insufficient_rights_call: || {
                 ProposalCodex::create_add_working_group_leader_opening_proposal(
@@ -853,8 +851,6 @@ fn run_create_begin_review_working_group_leader_applications_proposal_common_che
     initial_test_ext().execute_with(|| {
         let opening_id = 1; // random opening id.
 
-        increase_total_balance_issuance_using_account_id(1, 500000);
-
         let proposal_fixture = ProposalTestFixture {
             insufficient_rights_call: || {
                 ProposalCodex::create_begin_review_working_group_leader_applications_proposal(
@@ -931,8 +927,6 @@ fn run_create_fill_working_group_leader_opening_proposal_common_checks_succeed(
             working_group,
         };
 
-        increase_total_balance_issuance_using_account_id(1, 500000);
-
         let proposal_fixture = ProposalTestFixture {
             insufficient_rights_call: || {
                 ProposalCodex::create_fill_working_group_leader_opening_proposal(

+ 2 - 0
runtime-modules/proposals/engine/Cargo.toml

@@ -16,6 +16,7 @@ sp-runtime = { package = 'sp-runtime', default-features = false, git = 'https://
 membership = { package = 'pallet-membership', default-features = false, path = '../../membership'}
 stake = { package = 'pallet-stake', default-features = false, path = '../../stake'}
 common = { package = 'pallet-common', default-features = false, path = '../../common'}
+balances = { package = 'pallet-balances', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
 
 [dev-dependencies]
 mockall = "0.7.1"
@@ -37,4 +38,5 @@ std = [
     'membership/std',
     'stake/std',
     'common/std',
+    'balances/std',
 ]

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

@@ -87,7 +87,8 @@
 //!                 &parameters,
 //!                 &title,
 //!                 &description,
-//!                 None
+//!                 None,
+//!                 &account_id,
 //!             )?;
 //!             <engine::Module<T>>::create_proposal(
 //!                 account_id,
@@ -135,7 +136,7 @@ use frame_support::{
     decl_error, decl_event, decl_module, decl_storage, ensure, print, Parameter, StorageDoubleMap,
 };
 use frame_system::{ensure_root, RawOrigin};
-use sp_arithmetic::traits::Zero;
+use sp_arithmetic::traits::{SaturatedConversion, Zero};
 use sp_std::vec::Vec;
 
 use common::origin::ActorOriginValidator;
@@ -144,7 +145,7 @@ type MemberId<T> = <T as membership::Trait>::MemberId;
 
 /// Proposals engine trait.
 pub trait Trait:
-    frame_system::Trait + pallet_timestamp::Trait + stake::Trait + membership::Trait
+    frame_system::Trait + pallet_timestamp::Trait + stake::Trait + membership::Trait + balances::Trait
 {
     /// Engine event type.
     type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
@@ -265,6 +266,9 @@ decl_error! {
 
         /// Require root origin in extrinsics
         RequireRootOrigin,
+
+        /// Insufficient balance for operation.
+        InsufficientBalance,
     }
 }
 
@@ -434,6 +438,7 @@ impl<T: Trait> Module<T> {
             &title,
             &description,
             stake_balance,
+            &account_id,
         )?;
 
         // checks passed
@@ -492,6 +497,7 @@ impl<T: Trait> Module<T> {
         title: &[u8],
         description: &[u8],
         stake_balance: Option<types::BalanceOf<T>>,
+        stake_account_id: &T::AccountId,
     ) -> DispatchResult {
         ensure!(!title.is_empty(), Error::<T>::EmptyTitleProvided);
         ensure!(
@@ -533,6 +539,12 @@ impl<T: Trait> Module<T> {
             } else {
                 return Err(Error::<T>::EmptyStake.into());
             }
+
+            ensure!(
+                types::Balances::<T>::usable_balance(stake_account_id).saturated_into::<u128>()
+                    >= required_stake.saturated_into::<u128>(),
+                Error::<T>::InsufficientBalance
+            );
         }
 
         if stake_balance.is_some() && parameters.required_stake.is_none() {

+ 5 - 1
runtime-modules/proposals/engine/src/tests/mod.rs

@@ -1096,7 +1096,7 @@ fn create_dummy_proposal_fail_with_stake_on_empty_account() {
             .with_account_id(account_id)
             .with_stake(required_stake);
 
-        dummy_proposal.create_proposal_and_assert(Err(DispatchError::Other("InsufficientBalance")));
+        dummy_proposal.create_proposal_and_assert(Err(Error::<Test>::InsufficientBalance.into()));
     });
 }
 
@@ -1301,6 +1301,8 @@ fn finalize_proposal_using_stake_mocks_succeeds() {
 
             let account_id = 1;
 
+            increase_total_balance_issuance_using_account_id(account_id, 1000000);
+
             let stake_amount = 200;
             let parameters_fixture =
                 ProposalParametersFixture::default().with_required_stake(stake_amount);
@@ -1385,6 +1387,8 @@ fn finalize_proposal_using_stake_mocks_failed() {
 
             let account_id = 1;
 
+            increase_total_balance_issuance_using_account_id(account_id, 1000000);
+
             let stake_amount = 200;
             let parameters_fixture =
                 ProposalParametersFixture::default().with_required_stake(stake_amount);

+ 2 - 0
runtime-modules/proposals/engine/src/types/mod.rs

@@ -29,6 +29,8 @@ pub(crate) use stakes::DefaultStakeHandler;
 #[cfg(test)]
 pub(crate) use stakes::MockStakeHandler;
 
+pub(crate) type Balances<T> = balances::Module<T>;
+
 /// Vote kind for the proposal. Sum of all votes defines proposal status.
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
 #[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]

+ 1 - 1
runtime/Cargo.toml

@@ -4,7 +4,7 @@ edition = '2018'
 name = 'joystream-node-runtime'
 # Follow convention: https://github.com/Joystream/substrate-runtime-joystream/issues/1
 # {Authoring}.{Spec}.{Impl} of the RuntimeVersion
-version = '9.4.0'
+version = '9.5.0'
 
 [dependencies]
 # Third-party dependencies

+ 1 - 1
runtime/src/lib.rs

@@ -85,7 +85,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
     spec_name: create_runtime_str!("joystream-node"),
     impl_name: create_runtime_str!("joystream-node"),
     authoring_version: 9,
-    spec_version: 4,
+    spec_version: 5,
     impl_version: 0,
     apis: crate::runtime_api::EXPORTED_RUNTIME_API_VERSIONS,
     transaction_version: 1,