Skip to content

Commit

Permalink
change(pallet-communities-manager): implement pallet and benchmarkings
Browse files Browse the repository at this point in the history
  • Loading branch information
pandres95 committed Apr 18, 2024
1 parent f55c1db commit 7e9c2ab
Show file tree
Hide file tree
Showing 12 changed files with 627 additions and 166 deletions.
46 changes: 31 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ kusama-runtime-constants = { default-features = false, path = "runtime/kusama-ru

# Frame Contrib
fc-traits-memberships = { git = "https://github.com/virto-network/frame-contrib", branch = "main", default-features = false }
pallet-referenda-tracks = { git = "https://github.com/virto-network/frame-contrib", branch = "main", package="fc-pallet-referenda-tracks", default-features = false }
fc-traits-tracks = { git = "https://github.com/virto-network/frame-contrib", branch = "feature/trait-tracks", default-features = false }
pallet-referenda-tracks = { git = "https://github.com/virto-network/frame-contrib", branch = "feature/trait-tracks", package="fc-pallet-referenda-tracks", default-features = false }

# Substrate std
try-runtime-cli = { git = "https://github.com/virto-network/polkadot-sdk", branch = "release-virto-v1.5.0" }
Expand Down
20 changes: 18 additions & 2 deletions pallets/communities-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ edition = "2021"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
fc-traits-tracks = { workspace = true }

frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }

pallet-communities = { workspace = true }
pallet-nfts = { workspace = true }
pallet-referenda-tracks = { workspace = true }
pallet-referenda = { workspace = true }

log = { workspace = true }
Expand All @@ -32,22 +34,30 @@ sp-std = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }

pallet-assets = { workspace = true }
pallet-balances = { workspace = true }
pallet-ranked-collective = { workspace = true }
pallet-referenda-tracks = { workspace = true }
pallet-scheduler = { workspace = true }
virto-common = { workspace = true, default-features = false, features = ["runtime"] }

[features]
default = ["std", "testnet"]
testnet = []
std = [
"fc-traits-tracks/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-assets/std",
"pallet-balances/std",
"pallet-communities/std",
"pallet-nfts/std",
"pallet-ranked-collective/std",
"pallet-referenda-tracks/std",
"pallet-referenda/std",
"pallet-scheduler/std",
"parity-scale-codec/std",
"scale-info/std",
"sp-core/std",
Expand All @@ -60,19 +70,25 @@ runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-communities/runtime-benchmarks",
"pallet-nfts/runtime-benchmarks",
"pallet-ranked-collective/runtime-benchmarks",
"pallet-referenda-tracks/runtime-benchmarks",
"pallet-referenda/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-assets/try-runtime",
"pallet-balances/try-runtime",
"pallet-nfts/try-runtime",
"pallet-ranked-collective/try-runtime",
"pallet-referenda-tracks/try-runtime",
"pallet-referenda/try-runtime",
"pallet-scheduler/try-runtime",
"sp-runtime/try-runtime",
]
70 changes: 61 additions & 9 deletions pallets/communities-manager/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,73 @@ use super::*;

use frame_benchmarking::v2::*;

use crate::Pallet as CommunitiesManager;
use self::Pallet as CommunitiesManager;

#[benchmarks]
use frame_system::RawOrigin;
use pallet_referenda::Curve;
use sp_runtime::{str_array as s, traits::StaticLookup, Perbill};

type RuntimeEventFor<T> = <T as Config>::RuntimeEvent;

fn assert_has_event<T: Config>(generic_event: RuntimeEventFor<T>) {
frame_system::Pallet::<T>::assert_has_event(generic_event.into());
}

#[benchmarks(
where
RuntimeEventFor<T>: From<pallet_communities::Event<T>>,
BlockNumberFor<T>: From<u32>,
CommunityIdOf<T>: From<u16>
)]
mod benchmarks {
use super::*;

// #[benchmark]
// fn register() {
// // setup code
#[benchmark]
fn register() {
// setup code
let community_id: CommunityIdOf<T> = 1.into();
let first_member: AccountIdOf<T> = frame_benchmarking::account("founder", 0, 0);
let admin_origin: RuntimeOriginFor<T> = frame_system::Origin::<T>::Signed(first_member.clone()).into();
let admin_origin_caller: PalletsOriginOf<T> = admin_origin.into_caller();

// #[extrinsic_call]
// _();
#[extrinsic_call]
_(
RawOrigin::Root,
community_id,
TrackInfo {
name: s("Test Track"),
max_deciding: 1,
decision_deposit: 0u32.into(),
prepare_period: 1u32.into(),
decision_period: 2u32.into(),
confirm_period: 1u32.into(),
min_enactment_period: 1u32.into(),
min_approval: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::one(),
floor: Perbill::zero(),
ceil: Perbill::one(),
},
min_support: Curve::LinearDecreasing {
length: Perbill::one(),
floor: Perbill::zero(),
ceil: Perbill::one(),
},
},
Some(admin_origin_caller.clone()),
None,
Some(T::Lookup::unlookup(first_member)),
);

// // verification code
// }
// verification code
assert_has_event::<T>(
pallet_communities::Event::<T>::CommunityCreated {
id: community_id,
origin: admin_origin_caller,
}
.into(),
);
assert_has_event::<T>(crate::Event::<T>::CommunityRegistered { id: community_id }.into());
}

impl_benchmark_test_suite!(
CommunitiesManager,
Expand Down
Loading

0 comments on commit 7e9c2ab

Please sign in to comment.