diff --git a/pallets/briefs/Cargo.toml b/pallets/briefs/Cargo.toml index b5d3f858..0710544b 100644 --- a/pallets/briefs/Cargo.toml +++ b/pallets/briefs/Cargo.toml @@ -86,7 +86,9 @@ runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "pallet-deposits/runtime-benchmarks", - "pallet-proposals/runtime-benchmarks" + "pallet-proposals/runtime-benchmarks", + "pallet-disputes/runtime-benchmarks", + "pallet-fellowship/runtime-benchmarks" ] try-runtime = [ diff --git a/pallets/disputes/src/benchmarking.rs b/pallets/disputes/src/benchmarking.rs index 5de0da95..e33e5f70 100644 --- a/pallets/disputes/src/benchmarking.rs +++ b/pallets/disputes/src/benchmarking.rs @@ -5,6 +5,7 @@ use crate::traits::DisputeRaiser; use crate::Pallet as PalletDisputes; use frame_benchmarking::v2::*; use frame_support::{assert_ok, traits::Get, BoundedVec}; +use frame_system::pallet_prelude::BlockNumberFor; use frame_system::Pallet as System; use sp_std::vec::Vec; @@ -161,7 +162,7 @@ mod benchmarks { } pub fn get_jury( - accounts: Vec>, + accounts: Vec>, ) -> BoundedVec, ::MaxJurySize> { accounts.try_into().expect("too many jury members") } diff --git a/pallets/fellowship/src/benchmarking.rs b/pallets/fellowship/src/benchmarking.rs index 3e32bec2..26178e6e 100644 --- a/pallets/fellowship/src/benchmarking.rs +++ b/pallets/fellowship/src/benchmarking.rs @@ -6,15 +6,16 @@ use crate::{traits::FellowshipHandle, Config, Role}; use common_types::CurrencyId; use frame_benchmarking::v2::*; use frame_support::assert_ok; +use frame_system::pallet_prelude::BlockNumberFor; use frame_system::Pallet as System; use frame_system::RawOrigin; use orml_traits::MultiCurrency; use sp_runtime::SaturatedConversion; use sp_std::vec; - -#[benchmarks( where BlockNumberFor: AsRef<[u8]>, crate::Event::: Into<::RuntimeEvent>)] +#[benchmarks( where crate::Event::: Into<::RuntimeEvent>)] mod benchmarks { use super::*; + #[benchmark] fn add_to_fellowship() { let alice: T::AccountId = @@ -23,7 +24,13 @@ mod benchmarks { #[block] { - as FellowshipHandle>>::add_to_fellowship(&alice, Role::Vetter, 10, Some(&bob), true); + as FellowshipHandle>>::add_to_fellowship( + &alice, + Role::Vetter, + 10, + Some(&bob), + true, + ); } } @@ -47,7 +54,13 @@ mod benchmarks { let alice: T::AccountId = create_funded_user::("alice", 1, 1_000_000_000_000_000_000u128); let bob: T::AccountId = create_funded_user::("bob", 1, 1_000_000_000_000_000_000u128); - as FellowshipHandle>>::add_to_fellowship(&alice, Role::Vetter, 10, Some(&bob), true); + as FellowshipHandle>>::add_to_fellowship( + &alice, + Role::Vetter, + 10, + Some(&bob), + true, + ); #[extrinsic_call] leave_fellowship(RawOrigin::Signed(alice.clone())); @@ -60,7 +73,13 @@ mod benchmarks { let alice: T::AccountId = create_funded_user::("alice", 1, 1_000_000_000_000_000_000u128); let bob: T::AccountId = create_funded_user::("bob", 1, 1_000_000_000_000_000_000u128); - as FellowshipHandle>>::add_to_fellowship(&alice, Role::Vetter, 10, Some(&bob), true); + as FellowshipHandle>>::add_to_fellowship( + &alice, + Role::Vetter, + 10, + Some(&bob), + true, + ); #[extrinsic_call] force_remove_and_slash_fellowship(RawOrigin::Root, alice.clone()); @@ -72,7 +91,13 @@ mod benchmarks { let alice: T::AccountId = create_funded_user::("alice", 1, 1_000_000_000_000_000_000u128); let bob: T::AccountId = create_funded_user::("bob", 1, 1_000_000_000_000_000_000u128); - as FellowshipHandle>>::add_to_fellowship(&alice, Role::Vetter, 10, Some(&bob), true); + as FellowshipHandle>>::add_to_fellowship( + &alice, + Role::Vetter, + 10, + Some(&bob), + true, + ); #[extrinsic_call] add_candidate_to_shortlist(RawOrigin::Signed(alice), bob.clone(), Role::Vetter, 10); @@ -84,7 +109,13 @@ mod benchmarks { let alice: T::AccountId = create_funded_user::("alice", 1, 1_000_000_000_000_000_000u128); let bob: T::AccountId = create_funded_user::("bob", 1, 1_000_000_000_000_000_000u128); - as FellowshipHandle>>::add_to_fellowship(&alice, Role::Vetter, 10, Some(&bob), true); + as FellowshipHandle>>::add_to_fellowship( + &alice, + Role::Vetter, + 10, + Some(&bob), + true, + ); assert_ok!(Fellowship::::add_candidate_to_shortlist( RawOrigin::Signed(alice.clone()).into(), bob.clone(), @@ -105,14 +136,20 @@ mod benchmarks { let charlie: T::AccountId = create_funded_user::("alice", 1, 1_000_000_000_000_000_000u128); - as FellowshipHandle>>::add_to_fellowship(&bob, Role::Vetter, 10, Some(&charlie), true); - assert_ok!(, - >>::deposit( - CurrencyId::Native, + as FellowshipHandle>>::add_to_fellowship( &bob, - 1_000_000_000_000_000_000u128.saturated_into() - )); + Role::Vetter, + 10, + Some(&charlie), + true, + ); + assert_ok!( + >>::deposit( + CurrencyId::Native, + &bob, + 1_000_000_000_000_000_000u128.saturated_into() + ) + ); #[extrinsic_call] pay_deposit_to_remove_pending_status(RawOrigin::Signed(bob.clone())); @@ -134,10 +171,12 @@ pub fn create_funded_user( balance_factor: u128, ) -> T::AccountId { let user = account(seed, n, 0); - assert_ok!(, - >>::deposit( - CurrencyId::Native, &user, balance_factor.saturated_into() - )); + assert_ok!( + >>::deposit( + CurrencyId::Native, + &user, + balance_factor.saturated_into() + ) + ); user } diff --git a/pallets/grants/Cargo.toml b/pallets/grants/Cargo.toml index cb52826f..54247bf6 100644 --- a/pallets/grants/Cargo.toml +++ b/pallets/grants/Cargo.toml @@ -74,7 +74,9 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "pallet-deposits/runtime-benchmarks", - "pallet-proposals/runtime-benchmarks" + "pallet-proposals/runtime-benchmarks", + "pallet-disputes/runtime-benchmarks", + "pallet-fellowship/runtime-benchmarks" ] try-runtime = [ "common-runtime/try-runtime", diff --git a/pallets/grants/src/benchmarking.rs b/pallets/grants/src/benchmarking.rs index f68a62c0..80f632fb 100644 --- a/pallets/grants/src/benchmarking.rs +++ b/pallets/grants/src/benchmarking.rs @@ -17,10 +17,9 @@ use sp_std::{convert::TryInto, str, vec, vec::Vec}; const SEED: u32 = 0; -#[benchmarks( where - [u8; 32]: From>, -)] - +// #[benchmarks( where +// [u8; 32]: From>, +// )] #[benchmarks] mod benchmarks { use super::*; diff --git a/pallets/proposals/Cargo.toml b/pallets/proposals/Cargo.toml index 17de1dd0..42460eb9 100644 --- a/pallets/proposals/Cargo.toml +++ b/pallets/proposals/Cargo.toml @@ -32,10 +32,12 @@ frame-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "r pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false } pallet-identity = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false } pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false } +pallet-transaction-payment = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0"} cumulus-pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false } cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false } xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v1.1.0" } orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v1.1.0", default-features = false } orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v1.1.0", default-features = false } orml-xtokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v1.1.0", default-features = false } @@ -54,9 +56,7 @@ sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "releas sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0"} sp-keystore = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0"} sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0"} -pallet-transaction-payment = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0"} pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0"} -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v1.1.0" } orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v1.1.0" } orml-xtokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v1.1.0" } common-runtime = { path = "../../runtime/common"} @@ -79,6 +79,7 @@ std = [ "hex/std", "lite-json/std", "log/std", + "orml-currencies/std", "orml-tokens/std", "orml-traits/std", "orml-xtokens/std", @@ -86,6 +87,7 @@ std = [ "pallet-deposits/std", "pallet-identity/std", "pallet-timestamp/std", + "pallet-transaction-payment/std", "scale-info/std", "serde/std", "sp-api/std", @@ -101,6 +103,8 @@ runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "pallet-deposits/runtime-benchmarks", + "pallet-disputes/runtime-benchmarks", + "pallet-fellowship/runtime-benchmarks" ] try-runtime = [ "common-runtime/try-runtime", diff --git a/pallets/proposals/src/benchmarking.rs b/pallets/proposals/src/benchmarking.rs index 9ac5f905..b9ba98e5 100644 --- a/pallets/proposals/src/benchmarking.rs +++ b/pallets/proposals/src/benchmarking.rs @@ -11,13 +11,15 @@ use sp_runtime::SaturatedConversion; use sp_runtime::Saturating; use sp_std::convert::TryInto; -use pallet_disputes::DisputeResult; use pallet_disputes::traits::DisputeHooks; +use pallet_disputes::DisputeResult; -use test_utils::{create_and_fund_project, assert_last_event, create_funded_user, get_contributions, get_max_milestones}; +use test_utils::{ + assert_last_event, create_and_fund_project, create_funded_user, get_contributions, + get_max_milestones, +}; #[benchmarks( where - ::BlockNumber: From, BalanceOf: From, )] @@ -37,7 +39,8 @@ mod benchmarks { contributions, prop_milestones, CurrencyId::Native, - ).unwrap(); + ) + .unwrap(); #[extrinsic_call] submit_milestone(RawOrigin::Signed(bob), project_key, 0); @@ -58,7 +61,8 @@ mod benchmarks { contributions, prop_milestones, CurrencyId::Native, - ).unwrap(); + ) + .unwrap(); assert_ok!(Proposals::::submit_milestone( RawOrigin::Signed(alice).into(), @@ -84,14 +88,15 @@ mod benchmarks { let raised_funds: BalanceOf = 100_000_000_000_000_000u128.saturated_into(); let milestone_count = ::MaxMilestonesPerProject::get(); - let prop_milestones = get_milestones(milestone_count as u8); + let prop_milestones = get_max_milestones::(); let project_key = create_and_fund_project::( alice.clone(), contributions, prop_milestones, CurrencyId::Native, - ).unwrap(); + ) + .unwrap(); for milestone_key in 0..milestone_count { // The initiator submits a milestone @@ -147,28 +152,38 @@ mod benchmarks { let bob: T::AccountId = create_funded_user::("contributor", 0, 1_000_000_000_000_000_000u128); - let contributors: Vec = (0..::MaximumContributorsPerProject::get()).map(|i| { - create_funded_user::("contributor", i, 1_000_000_000_000_000_000u128) - }).collect(); + let contributors: Vec = (0 + ..::MaximumContributorsPerProject::get()) + .map(|i| create_funded_user::("contributor", i, 1_000_000_000_000_000_000u128)) + .collect(); let contributions = get_contributions::(contributors, 100_000_000_000_000_000u128); - let total_amount = 100_000_000_000_000_000u128 * ::MaximumContributorsPerProject::get() as u128; + let total_amount = 100_000_000_000_000_000u128 + * ::MaximumContributorsPerProject::get() as u128; let milestone_count = ::MaxMilestonesPerProject::get(); - let prop_milestones = get_milestones(milestone_count as u8); - let milestone_keys: BoundedVec::MaxMilestonesPerProject> = (0u32..prop_milestones.len() as u32).collect::>().try_into().unwrap(); + let prop_milestones = get_max_milestones::(); + let milestone_keys: BoundedVec::MaxMilestonesPerProject> = (0u32 + ..prop_milestones.len() as u32) + .collect::>() + .try_into() + .unwrap(); let project_key = create_and_fund_project::( alice.clone(), contributions, prop_milestones, CurrencyId::Native, - ).unwrap(); + ) + .unwrap(); #[extrinsic_call] - raise_dispute(RawOrigin::Signed(bob.clone()), project_key, milestone_keys.clone()); + raise_dispute( + RawOrigin::Signed(bob.clone()), + project_key, + milestone_keys.clone(), + ); } - #[benchmark] fn refund() { let alice: T::AccountId = @@ -176,35 +191,52 @@ mod benchmarks { let bob: T::AccountId = create_funded_user::("contributor", 0, 1_000_000_000_000_000_000u128); - let contributors: Vec = (0..::MaximumContributorsPerProject::get()).map(|i| { - create_funded_user::("contributor", i, 1_000_000_000_000_000_000u128) - }).collect(); + let contributors: Vec = (0 + ..::MaximumContributorsPerProject::get()) + .map(|i| create_funded_user::("contributor", i, 1_000_000_000_000_000_000u128)) + .collect(); let contributions = get_contributions::(contributors, 100_000_000_000u128); - let total_amount = 100_000_000_000u128 * ::MaximumContributorsPerProject::get() as u128; + let total_amount = + 100_000_000_000u128 * ::MaximumContributorsPerProject::get() as u128; let milestone_count = ::MaxMilestonesPerProject::get(); - let prop_milestones = get_milestones(milestone_count as u8); - let milestone_keys: BoundedVec::MaxMilestonesPerProject> = (0u32..prop_milestones.len() as u32).collect::>().try_into().unwrap(); + let prop_milestones = get_max_milestones::(); + let milestone_keys: BoundedVec::MaxMilestonesPerProject> = (0u32 + ..prop_milestones.len() as u32) + .collect::>() + .try_into() + .unwrap(); let project_key = create_and_fund_project::( alice.clone(), contributions, prop_milestones, CurrencyId::Native, - ).unwrap(); + ) + .unwrap(); - assert_ok!(crate::Pallet::::raise_dispute(RawOrigin::Signed(bob.clone()).into(), project_key, milestone_keys.clone())); - let _ = as DisputeHooks>::on_dispute_complete(project_key, milestone_keys.into_inner(), DisputeResult::Success); + assert_ok!(crate::Pallet::::raise_dispute( + RawOrigin::Signed(bob.clone()).into(), + project_key, + milestone_keys.clone() + )); + let _ = as DisputeHooks>::on_dispute_complete( + project_key, + milestone_keys.into_inner(), + DisputeResult::Success, + ); #[extrinsic_call] refund(RawOrigin::Signed(bob.clone()), project_key); assert_last_event::( - Event::::ProjectRefunded{project_key, total_amount: (total_amount as u64).into()} - .into(), + Event::::ProjectRefunded { + project_key, + total_amount: (total_amount as u64).into(), + } + .into(), ); } - impl_benchmark_test_suite!( Proposals, crate::mock::build_test_externality(), diff --git a/pallets/proposals/src/mock.rs b/pallets/proposals/src/mock.rs index 2ffe1535..5a5bffb1 100644 --- a/pallets/proposals/src/mock.rs +++ b/pallets/proposals/src/mock.rs @@ -9,10 +9,9 @@ use frame_support::{ use crate::*; use common_types::CurrencyId; use frame_system::EnsureRoot; -use sp_core::H256; - use orml_traits::MultiCurrency; use sp_arithmetic::per_things::Percent; +use sp_core::H256; use sp_runtime::{ traits::{AccountIdConversion, BlakeTwo256, IdentityLookup}, BuildStorage, @@ -233,7 +232,6 @@ parameter_types! { pub DepositCurrencyId: CurrencyId = CurrencyId::Native; } - parameter_types! { pub const UnitWeightCost: u64 = 10; pub const MaxInstructions: u32 = 100; @@ -270,9 +268,7 @@ pub enum StorageItems { } pub struct MockDepositHandler; -impl DepositHandler - for MockDepositHandler -{ +impl DepositHandler for MockDepositHandler { type DepositId = u64; type StorageItem = StorageItems; fn take_deposit( @@ -292,10 +288,10 @@ impl DepositHandler pub struct MockDisputeRaiser; impl DisputeRaiser for MockDisputeRaiser { -type DisputeKey = ProjectKey; -type SpecificId = MilestoneKey; -type MaxJurySize = MaxJuryMembers; -type MaxSpecifics = MaxMilestonesPerProject; + type DisputeKey = ProjectKey; + type SpecificId = MilestoneKey; + type MaxJurySize = MaxJuryMembers; + type MaxSpecifics = MaxMilestonesPerProject; fn raise_dispute( dispute_key: Self::DisputeKey, raised_by: AccountId, @@ -306,7 +302,6 @@ type MaxSpecifics = MaxMilestonesPerProject; } } - pub struct MockJurySelector; impl pallet_fellowship::traits::SelectJury for MockJurySelector { type JurySize = MaxJuryMembers; diff --git a/pallets/proposals/src/test_utils.rs b/pallets/proposals/src/test_utils.rs index a38e0bb9..5b13ff9e 100644 --- a/pallets/proposals/src/test_utils.rs +++ b/pallets/proposals/src/test_utils.rs @@ -1,22 +1,21 @@ +use crate::mock::*; use crate::*; -use common_types::{CurrencyId}; +use common_types::CurrencyId; use frame_support::{assert_ok, traits::Hooks, BoundedVec}; use frame_system::EventRecord; use orml_traits::{MultiCurrency, MultiReservableCurrency}; use pallet_deposits::traits::DepositHandler; +use pallet_disputes::traits::DisputeHooks; use sp_arithmetic::per_things::Percent; use sp_core::{Get, H256}; use sp_runtime::Saturating; use sp_runtime::{DispatchError, SaturatedConversion}; use sp_std::{collections::btree_map::BTreeMap, convert::TryInto}; -use pallet_disputes::traits::DisputeHooks; -use crate::mock::*; #[cfg(feature = "runtime-benchmarks")] -use sp_std::vec::Vec; +use frame_benchmarking::account; #[cfg(feature = "runtime-benchmarks")] -use frame_benchmarking::{account}; - +use sp_std::vec::Vec; pub fn run_to_block(n: BlockNumber) { while System::block_number() < n { @@ -30,7 +29,6 @@ pub fn run_to_block(n: BlockNumber) { } } - pub fn get_contributions( accounts: Vec>, contribution: u128, @@ -69,8 +67,7 @@ pub fn create_and_fund_project( contributions: ContributionsFor, proposed_milestones: Vec, currency_id: CurrencyId, -) -> Result -{ +) -> Result { contributions.iter().for_each(|(acc, c)| { ::MultiCurrency::reserve(currency_id, acc, c.value).unwrap(); }); @@ -79,9 +76,7 @@ pub fn create_and_fund_project( AccountIdOf, BalanceOf, BlockNumberFor, - >>::convert_contributions_to_refund_locations( - &contributions.clone() - ); + >>::convert_contributions_to_refund_locations(&contributions.clone()); // Reserve the assets from the contributors used. as IntoProposal, BalanceOf, BlockNumberFor>>::convert_to_proposal( @@ -129,16 +124,22 @@ pub fn create_funded_user( balance_factor: u128, ) -> T::AccountId { let user = account(seed, n, 0); - assert_ok!(, - >>::deposit( - CurrencyId::Native, &user, balance_factor.saturated_into() - )); + assert_ok!( + >>::deposit( + CurrencyId::Native, + &user, + balance_factor.saturated_into() + ) + ); user } /// Manually call the hook OnDisputeCompleteWith a predefined result for testing> -pub fn complete_dispute(project_key: ProjectKey, milestone_keys: Vec, result: pallet_disputes::DisputeResult) -> crate::Weight { +pub fn complete_dispute( + project_key: ProjectKey, + milestone_keys: Vec, + result: pallet_disputes::DisputeResult, +) -> crate::Weight { Proposals::on_dispute_complete(project_key, milestone_keys, result) } diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index 5c45fb10..7be3b198 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -103,7 +103,8 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "kusama-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", - "common-runtime/runtime-benchmarks" + "common-runtime/runtime-benchmarks", + "pallet-fellowship/runtime-benchmarks" ] try-runtime = [ "kusama-runtime/try-runtime",