Browse Source

runtime: joystream-utilities: fix comments and rename

conectado 4 years ago
parent
commit
c937f142c4

+ 26 - 26
Cargo.lock

@@ -2345,6 +2345,7 @@ dependencies = [
  "frame-system-benchmarking",
  "frame-system-rpc-runtime-api",
  "hex-literal",
+ "joystream-utility",
  "lazy_static",
  "lite-json",
  "pallet-authority-discovery",
@@ -2380,7 +2381,6 @@ dependencies = [
  "pallet-timestamp",
  "pallet-transaction-payment",
  "pallet-transaction-payment-rpc-runtime-api",
- "pallet-utilities",
  "pallet-utility",
  "pallet-working-group",
  "parity-scale-codec",
@@ -2405,6 +2405,31 @@ dependencies = [
  "substrate-wasm-builder-runner",
 ]
 
+[[package]]
+name = "joystream-utility"
+version = "1.0.0"
+dependencies = [
+ "frame-benchmarking",
+ "frame-support",
+ "frame-system",
+ "pallet-balances",
+ "pallet-common",
+ "pallet-council",
+ "pallet-membership",
+ "pallet-referendum",
+ "pallet-staking-handler",
+ "pallet-timestamp",
+ "pallet-working-group",
+ "parity-scale-codec",
+ "serde",
+ "sp-arithmetic",
+ "sp-core",
+ "sp-io",
+ "sp-runtime",
+ "sp-std",
+ "strum 0.19.5",
+]
+
 [[package]]
 name = "js-sys"
 version = "0.3.46"
@@ -4295,31 +4320,6 @@ dependencies = [
  "sp-std",
 ]
 
-[[package]]
-name = "pallet-utilities"
-version = "1.0.0"
-dependencies = [
- "frame-benchmarking",
- "frame-support",
- "frame-system",
- "pallet-balances",
- "pallet-common",
- "pallet-council",
- "pallet-membership",
- "pallet-referendum",
- "pallet-staking-handler",
- "pallet-timestamp",
- "pallet-working-group",
- "parity-scale-codec",
- "serde",
- "sp-arithmetic",
- "sp-core",
- "sp-io",
- "sp-runtime",
- "sp-std",
- "strum 0.19.5",
-]
-
 [[package]]
 name = "pallet-utility"
 version = "2.0.0"

+ 1 - 1
Cargo.toml

@@ -17,7 +17,7 @@ members = [
 	"runtime-modules/constitution",
 	"runtime-modules/staking-handler",
     "runtime-modules/blog",
-    "runtime-modules/utilities",
+    "runtime-modules/joystream-utility",
 	"node",
 	"utils/chain-spec-builder/"
 ]

+ 4 - 2
runtime-modules/utilities/Cargo.toml → runtime-modules/joystream-utility/Cargo.toml

@@ -1,5 +1,5 @@
 [package]
-name = 'pallet-utilities'
+name = 'joystream-utility'
 version = '1.0.0'
 authors = ['Joystream contributors']
 edition = '2018'
@@ -11,12 +11,14 @@ sp-std = { package = 'sp-std', default-features = false, git = 'https://github.c
 frame-support = { package = 'frame-support', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
 frame_system = { package = 'frame-system', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
 sp-runtime = { package = 'sp-runtime', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
-frame-benchmarking = { package = 'frame-benchmarking', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca', optional = true}
 council = { package = 'pallet-council', default-features = false, path = '../council'}
 common = { package = 'pallet-common', default-features = false, path = '../common'}
 balances = { package = 'pallet-balances', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
 sp-arithmetic = { package = 'sp-arithmetic', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
 
+# Benchmarking dependencies
+frame-benchmarking = { package = 'frame-benchmarking', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca', optional = true}
+
 [dev-dependencies]
 sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
 sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}

+ 1 - 0
runtime-modules/utilities/src/benchmarking.rs → runtime-modules/joystream-utility/src/benchmarking.rs

@@ -177,6 +177,7 @@ benchmarks! {
     verify {
         assert_eq!(Balances::<T>::free_balance(&account_id), Zero::zero());
         assert_eq!(Balances::<T>::total_issuance(),  initial_issuance);
+        assert_last_event::<T>(RawEvent::TokensBurned(account_id, One::one()).into());
     }
 }
 

+ 22 - 10
runtime-modules/utilities/src/lib.rs → runtime-modules/joystream-utility/src/lib.rs

@@ -1,8 +1,20 @@
-//! # Constitution pallet.
-//! `Constitution` pallet for the Joystream platform. Version 1.
-//! It contains current constitution text hash and amendment number in the storage and extrinsic for
-//! setting the new constitution.
+//! # Joystream Utility pallet.
+//! `Utility` pallet for the Joystream platform.
 //!
+//! Different extrinsics that doesn't fit anywhere else
+//!
+//! ## Extrinsics
+//!
+//! - [execute_runtime_upgrade_proposal](./struct.Module.html#method.execute_runtime_upgrade_proposal) - Sets the
+//! runtime code
+//! - [execute_signal_proposal](./struct.Module.html#method.execute_signal_proposal) - prints the proposal to the log
+//! - [update_working_group_budget](./struct.Module.html#method.update_working_group_budget) - Move funds between
+//! council and working group
+//! - [burn_account_tokens](./struct.Module.html#method.burn_account_tokens) - Burns token from account
+//!
+//! ## Dependencies
+//! - [council](../substrate_council_module/index.html)
+//! - [common](../substrate_common_module/index.html)
 
 // Ensure we're `no_std` when compiling for Wasm.
 #![cfg_attr(not(feature = "std"), no_std)]
@@ -40,7 +52,7 @@ pub trait Trait: frame_system::Trait + balances::Trait + council::Trait {
     type WeightInfo: WeightInfo;
 }
 
-/// Utilities WeightInfo.
+/// Utility WeightInfo.
 /// Note: This was auto generated through the benchmark CLI using the `--weight-trait` flag
 pub trait WeightInfo {
     fn execute_signal_proposal(i: u32) -> Weight;
@@ -99,7 +111,7 @@ decl_event!(
         /// Params:
         /// - Account Id of the burning tokens
         /// - Balance burned from that account
-        AccountBurned(AccountId, Balance),
+        TokensBurned(AccountId, Balance),
     }
 );
 
@@ -120,7 +132,7 @@ decl_module! {
         /// - DB:
         ///    - O(1) doesn't depend on the state or parameters
         /// # </weight>
-        #[weight = WeightInfoUtilities::<T>::execute_signal_proposal(signal.len().saturated_into())] // TODO: adjust weight
+        #[weight = WeightInfoUtilities::<T>::execute_signal_proposal(signal.len().saturated_into())]
         pub fn execute_signal_proposal(
             origin,
             signal: Vec<u8>,
@@ -165,7 +177,7 @@ decl_module! {
         /// - DB:
         ///    - O(1) doesn't depend on the state or parameters
         /// # </weight>
-        #[weight = Module::<T>::get_update_working_group_budget_weight(&working_group, &balance_kind)] // TODO: adjust weight
+        #[weight = Module::<T>::get_update_working_group_budget_weight(&working_group, &balance_kind)]
         pub fn update_working_group_budget(
             origin,
             working_group: WorkingGroup,
@@ -204,7 +216,7 @@ decl_module! {
         /// - DB:
         ///    - O(1) doesn't depend on the state or parameters
         /// # </weight>
-        #[weight = 10_000_000] // TODO: adjust weight
+        #[weight = WeightInfoUtilities::<T>::burn_account_tokens()]
         pub fn burn_account_tokens(
             origin,
             amount: BalanceOf<T>
@@ -220,7 +232,7 @@ decl_module! {
 
             let _ = Balances::<T>::slash(&account_id, amount);
 
-            Self::deposit_event(RawEvent::AccountBurned(account_id, amount));
+            Self::deposit_event(RawEvent::TokensBurned(account_id, amount));
         }
 
     }

+ 14 - 2
runtime-modules/utilities/src/tests/mocks.rs → runtime-modules/joystream-utility/src/tests/mocks.rs

@@ -6,8 +6,7 @@ use common::working_group::{WorkingGroup, WorkingGroupBudgetHandler};
 use frame_support::dispatch::DispatchError;
 use frame_support::traits::{LockIdentifier, OnFinalize, OnInitialize};
 use frame_support::{impl_outer_event, impl_outer_origin, parameter_types};
-use frame_system::RawOrigin;
-use frame_system::{EnsureOneOf, EnsureRoot, EnsureSigned};
+use frame_system::{EnsureOneOf, EnsureRoot, EnsureSigned, EventRecord, RawOrigin};
 use sp_core::H256;
 use sp_runtime::DispatchResult;
 use sp_runtime::{
@@ -17,6 +16,18 @@ use sp_runtime::{
 };
 use staking_handler::{LockComparator, StakingManager};
 
+pub(crate) fn assert_last_event(generic_event: <Test as Trait>::Event) {
+    let events = System::events();
+    let system_event: <Test as frame_system::Trait>::Event = generic_event.into();
+    assert!(
+        events.len() > 0,
+        "If you are checking for last event there must be at least 1 event"
+    );
+
+    let EventRecord { event, .. } = &events[events.len() - 1];
+    assert_eq!(event, &system_event);
+}
+
 impl_outer_origin! {
     pub enum Origin for Test {}
 }
@@ -628,6 +639,7 @@ impl BurnTokensFixture {
                 Balances::<Test>::total_issuance(),
                 initial_balance + self.account_initial_balance - self.burn_balance
             );
+            assert_last_event(RawEvent::TokensBurned(self.account_id, self.burn_balance).into());
         } else {
             assert_eq!(
                 Balances::<Test>::usable_balance(&self.account_id),

+ 2 - 14
runtime-modules/utilities/src/tests/mod.rs → runtime-modules/joystream-utility/src/tests/mod.rs

@@ -3,24 +3,12 @@
 pub(crate) mod mocks;
 
 use crate::*;
-use frame_system::{EventRecord, RawOrigin};
-use mocks::{initial_test_ext, BurnTokensFixture, System, Test, Utilities};
+use frame_system::RawOrigin;
+use mocks::{assert_last_event, initial_test_ext, BurnTokensFixture, Test, Utilities};
 use sp_arithmetic::traits::{One, Zero};
 use sp_runtime::DispatchError;
 use strum::IntoEnumIterator;
 
-fn assert_last_event(generic_event: <Test as Trait>::Event) {
-    let events = System::events();
-    let system_event: <Test as frame_system::Trait>::Event = generic_event.into();
-    assert!(
-        events.len() > 0,
-        "If you are checking for last event there must be at least 1 event"
-    );
-
-    let EventRecord { event, .. } = &events[events.len() - 1];
-    assert_eq!(event, &system_event);
-}
-
 #[test]
 fn execute_signal_proposal_fails() {
     initial_test_ext().execute_with(|| {

+ 1 - 1
runtime-modules/proposals/codex/Cargo.toml

@@ -22,10 +22,10 @@ constitution = { package = 'pallet-constitution', default-features = false, path
 membership = { package = 'pallet-membership', default-features = false, path = '../../membership'}
 blog = { package = 'pallet-blog', default-features = false, path = '../../blog'}
 balances = { package = 'pallet-balances', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca', optional = true}
-council = { package = 'pallet-council', default-features = false, path = '../../council', optional = true}
 
 # Benchmarking dependencies
 frame-benchmarking = { package = 'frame-benchmarking', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca', optional = true}
+council = { package = 'pallet-council', default-features = false, path = '../../council', optional = true}
 
 [dev-dependencies]
 sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}

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

@@ -17,12 +17,6 @@
 //! ## Extrinsics
 //!
 //! - [create_proposal](./struct.Module.html#method.create_proposal) - creates proposal
-//! - [execute_runtime_upgrade_proposal](./struct.Module.html#method.execute_runtime_upgrade_proposal) - Sets the
-//! runtime code
-//! - [execute_signal_proposal](./struct.Module.html#method.execute_signal_proposal) - prints the proposal to the log
-//! - [update_working_group_budget](./struct.Module.html#method.update_working_group_budget) - Move funds between
-//! council and working group
-//!
 //!
 //! ### Dependencies:
 //! - [proposals engine](../substrate_proposals_engine_module/index.html)

+ 3 - 3
runtime/Cargo.toml

@@ -79,7 +79,7 @@ content-directory = { package = 'pallet-content-directory', default-features = f
 pallet_constitution = { package = 'pallet-constitution', default-features = false, path = '../runtime-modules/constitution' }
 staking-handler = { package = 'pallet-staking-handler', default-features = false, path = '../runtime-modules/staking-handler'}
 blog = { package = 'pallet-blog', default-features = false, path = '../runtime-modules/blog'}
-utilities = { package = 'pallet-utilities', default-features = false, path = '../runtime-modules/utilities'}
+joystream-utility = { package = 'joystream-utility', default-features = false, path = '../runtime-modules/joystream-utility'}
 
 [dev-dependencies]
 sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
@@ -154,7 +154,7 @@ std = [
     'pallet_constitution/std',
     'staking-handler/std',
     'blog/std',
-    'utilities/std'
+    'joystream-utility/std'
 ]
 runtime-benchmarks = [
     "frame-system/runtime-benchmarks",
@@ -171,7 +171,7 @@ runtime-benchmarks = [
     "proposals-discussion/runtime-benchmarks",
     "proposals-engine/runtime-benchmarks",
     "proposals-codex/runtime-benchmarks",
-    "utilities/runtime-benchmarks",
+    "joystream-utility/runtime-benchmarks",
     "pallet_constitution/runtime-benchmarks",
     "working-group/runtime-benchmarks",
     "forum/runtime-benchmarks",

+ 5 - 5
runtime/src/integration/proposals/proposal_encoder.rs

@@ -34,7 +34,7 @@ impl ProposalEncoder<Runtime> for ExtrinsicProposalEncoder {
     fn encode_proposal(proposal_details: ProposalDetailsOf<Runtime>) -> Vec<u8> {
         let call = match proposal_details {
             ProposalDetails::Signal(signal) => {
-                Call::Utilities(utilities::Call::execute_signal_proposal(signal))
+                Call::JoystreamUtility(joystream_utility::Call::execute_signal_proposal(signal))
             }
             ProposalDetails::FundingRequest(params) => {
                 Call::Council(council::Call::funding_request(params))
@@ -42,9 +42,9 @@ impl ProposalEncoder<Runtime> for ExtrinsicProposalEncoder {
             ProposalDetails::SetMaxValidatorCount(new_validator_count) => Call::Staking(
                 pallet_staking::Call::set_validator_count(new_validator_count),
             ),
-            ProposalDetails::RuntimeUpgrade(blob) => {
-                Call::Utilities(utilities::Call::execute_runtime_upgrade_proposal(blob))
-            }
+            ProposalDetails::RuntimeUpgrade(blob) => Call::JoystreamUtility(
+                joystream_utility::Call::execute_runtime_upgrade_proposal(blob),
+            ),
             ProposalDetails::CreateWorkingGroupLeadOpening(create_opening_params) => {
                 wrap_working_group_call!(
                     create_opening_params.group,
@@ -58,7 +58,7 @@ impl ProposalEncoder<Runtime> for ExtrinsicProposalEncoder {
                 )
             }
             ProposalDetails::UpdateWorkingGroupBudget(amount, working_group, balance_kind) => {
-                Call::Utilities(utilities::Call::update_working_group_budget(
+                Call::JoystreamUtility(joystream_utility::Call::update_working_group_budget(
                     working_group,
                     amount,
                     balance_kind,

+ 3 - 3
runtime/src/lib.rs

@@ -827,10 +827,10 @@ impl proposals_discussion::Trait for Runtime {
     type WeightInfo = weights::proposals_discussion::WeightInfo;
 }
 
-impl utilities::Trait for Runtime {
+impl joystream_utility::Trait for Runtime {
     type Event = Event;
 
-    type WeightInfo = weights::utilities::WeightInfo;
+    type WeightInfo = weights::joystream_utility::WeightInfo;
 
     fn get_working_group_budget(working_group: WorkingGroup) -> Balance {
         call_wg!(working_group, get_budget)
@@ -957,7 +957,7 @@ construct_runtime!(
         ContentDirectory: content_directory::{Module, Call, Storage, Event<T>, Config<T>},
         Constitution: pallet_constitution::{Module, Call, Storage, Event},
         Blog: blog::<Instance1>::{Module, Call, Storage, Event<T>},
-        Utilities: utilities::{Module, Call, Event<T>},
+        JoystreamUtility: joystream_utility::{Module, Call, Event<T>},
         // --- Storage
         DataObjectTypeRegistry: data_object_type_registry::{Module, Call, Storage, Event<T>, Config<T>},
         DataDirectory: data_directory::{Module, Call, Storage, Event<T>},

+ 2 - 2
runtime/src/runtime_api.rs

@@ -295,7 +295,7 @@ impl_runtime_apis! {
             use crate::Council;
             use crate::Referendum;
             use crate::Blog;
-            use crate::Utilities;
+            use crate::JoystreamUtility;
 
 
             // Trying to add benchmarks directly to the Session Pallet caused cyclic dependency issues.
@@ -386,7 +386,7 @@ impl_runtime_apis! {
             add_benchmark!(params, batches, referendum, Referendum);
             add_benchmark!(params, batches, council, Council);
             add_benchmark!(params, batches, blog, Blog);
-            add_benchmark!(params, batches, utilities, Utilities);
+            add_benchmark!(params, batches, joystream_utility, JoystreamUtility);
 
             if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
             Ok(batches)

+ 1 - 1
runtime/src/tests/proposals_integration/mod.rs

@@ -120,7 +120,7 @@ impl Default for DummyProposalFixture {
         let title = b"title".to_vec();
         let description = b"description".to_vec();
         let dummy_proposal =
-            utilities::Call::<Runtime>::execute_signal_proposal(b"signal".to_vec());
+            joystream_utility::Call::<Runtime>::execute_signal_proposal(b"signal".to_vec());
 
         DummyProposalFixture {
             parameters: ProposalParameters {

+ 1 - 1
runtime/src/weights/utilities.rs → runtime/src/weights/joystream_utility.rs

@@ -6,7 +6,7 @@
 use frame_support::weights::{constants::RocksDbWeight as DbWeight, Weight};
 
 pub struct WeightInfo;
-impl utilities::WeightInfo for WeightInfo {
+impl joystream_utility::WeightInfo for WeightInfo {
     fn execute_signal_proposal(i: u32) -> Weight {
         (81_623_000 as Weight).saturating_add((162_000 as Weight).saturating_mul(i as Weight))
     }

+ 1 - 1
runtime/src/weights/mod.rs

@@ -27,11 +27,11 @@ pub mod pallet_utility;
 pub mod blog;
 pub mod council;
 pub mod forum;
+pub mod joystream_utility;
 pub mod membership;
 pub mod pallet_constitution;
 pub mod proposals_codex;
 pub mod proposals_discussion;
 pub mod proposals_engine;
 pub mod referendum;
-pub mod utilities;
 pub mod working_group;