feat: Rebrand Polkadot/Substrate references to PezkuwiChain
This commit systematically rebrands various references from Parity Technologies' Polkadot/Substrate ecosystem to PezkuwiChain within the kurdistan-sdk. Key changes include: - Updated external repository URLs (zombienet-sdk, parity-db, parity-scale-codec, wasm-instrument) to point to pezkuwichain forks. - Modified internal documentation and code comments to reflect PezkuwiChain naming and structure. - Replaced direct references to with or specific paths within the for XCM, Pezkuwi, and other modules. - Cleaned up deprecated issue and PR references in various and files, particularly in and modules. - Adjusted image and logo URLs in documentation to point to PezkuwiChain assets. - Removed or rephrased comments related to external Polkadot/Substrate PRs and issues. This is a significant step towards fully customizing the SDK for the PezkuwiChain ecosystem.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
[package]
|
||||
name = "pezpallet-ranked-collective"
|
||||
version = "28.0.0"
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license = "Apache-2.0"
|
||||
homepage.workspace = true
|
||||
repository.workspace = true
|
||||
description = "Ranked collective system: Members of a set of account IDs can make their collective feelings known through dispatched calls from one of two specialized origins."
|
||||
readme = "README.md"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
codec = { features = ["derive"], workspace = true }
|
||||
pezframe-benchmarking = { optional = true, workspace = true }
|
||||
pezframe-support = { workspace = true }
|
||||
pezframe-system = { workspace = true }
|
||||
impl-trait-for-tuples = { workspace = true }
|
||||
log = { workspace = true }
|
||||
scale-info = { features = ["derive"], workspace = true }
|
||||
pezsp-arithmetic = { workspace = true }
|
||||
pezsp-core = { workspace = true }
|
||||
pezsp-io = { workspace = true }
|
||||
pezsp-runtime = { workspace = true }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"codec/std",
|
||||
"pezframe-benchmarking?/std",
|
||||
"pezframe-support/std",
|
||||
"pezframe-system/std",
|
||||
"log/std",
|
||||
"scale-info/std",
|
||||
"pezsp-arithmetic/std",
|
||||
"pezsp-core/std",
|
||||
"pezsp-io/std",
|
||||
"pezsp-runtime/std",
|
||||
]
|
||||
runtime-benchmarks = [
|
||||
"pezframe-benchmarking/runtime-benchmarks",
|
||||
"pezframe-support/runtime-benchmarks",
|
||||
"pezframe-system/runtime-benchmarks",
|
||||
"pezsp-io/runtime-benchmarks",
|
||||
"pezsp-runtime/runtime-benchmarks",
|
||||
]
|
||||
try-runtime = [
|
||||
"pezframe-support/try-runtime",
|
||||
"pezframe-system/try-runtime",
|
||||
"pezsp-runtime/try-runtime",
|
||||
]
|
||||
@@ -0,0 +1,22 @@
|
||||
# Ranked collective system
|
||||
|
||||
This is a membership pallet providing a `Tally` implementation ready for use with polling
|
||||
systems such as the Referenda pallet. Members each have a rank, with zero being the lowest.
|
||||
There is no complexity limitation on either the number of members at a rank or the number of
|
||||
ranks in the system thus allowing potentially public membership. A member of at least a given
|
||||
rank can be selected at random in O(1) time, allowing for various games to constructed using
|
||||
this as a primitive. Members may only be promoted and demoted by one rank at a time, however
|
||||
all operations (save one) are O(1) in complexity. The only operation which is not O(1) is the
|
||||
`remove_member` since they must be removed from all ranks from the present down to zero.
|
||||
|
||||
Different ranks have different voting power, and are able to vote in different polls. In general
|
||||
rank privileges are cumulative. Higher ranks are able to vote in any polls open to lower ranks.
|
||||
Similarly, higher ranks always have at least as much voting power in any given poll as lower
|
||||
ranks.
|
||||
|
||||
Two `Config` trait items control these "rank privileges": `MinRankOfClass` and `VoteWeight`.
|
||||
The first controls which ranks are allowed to vote on a particular class of poll. The second
|
||||
controls the weight of a vote given the voters rank compared to the minimum rank of the poll.
|
||||
|
||||
An origin control, `EnsureRank`, ensures that the origin is a member of the collective of at
|
||||
least a particular rank.
|
||||
@@ -0,0 +1,344 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Staking pallet benchmarking.
|
||||
|
||||
use super::*;
|
||||
#[allow(unused_imports)]
|
||||
use crate::Pallet as RankedCollective;
|
||||
use alloc::vec::Vec;
|
||||
use pezframe_benchmarking::{
|
||||
v1::{account, BenchmarkError},
|
||||
v2::*,
|
||||
};
|
||||
|
||||
use pezframe_support::{assert_err, assert_ok, traits::NoOpPoll};
|
||||
use pezframe_system::{pezpallet_prelude::BlockNumberFor, RawOrigin as SystemOrigin};
|
||||
|
||||
const SEED: u32 = 0;
|
||||
|
||||
fn assert_last_event<T: Config<I>, I: 'static>(generic_event: <T as Config<I>>::RuntimeEvent) {
|
||||
pezframe_system::Pallet::<T>::assert_last_event(generic_event.into());
|
||||
}
|
||||
|
||||
fn assert_has_event<T: Config<I>, I: 'static>(generic_event: <T as Config<I>>::RuntimeEvent) {
|
||||
pezframe_system::Pallet::<T>::assert_has_event(generic_event.into());
|
||||
}
|
||||
|
||||
fn make_member<T: Config<I>, I: 'static>(rank: Rank) -> T::AccountId {
|
||||
let who = account::<T::AccountId>("member", MemberCount::<T, I>::get(0), SEED);
|
||||
let who_lookup = T::Lookup::unlookup(who.clone());
|
||||
assert_ok!(Pallet::<T, I>::add_member(
|
||||
T::AddOrigin::try_successful_origin()
|
||||
.expect("AddOrigin has no successful origin required for the benchmark"),
|
||||
who_lookup.clone(),
|
||||
));
|
||||
for _ in 0..rank {
|
||||
assert_ok!(Pallet::<T, I>::promote_member(
|
||||
T::PromoteOrigin::try_successful_origin()
|
||||
.expect("PromoteOrigin has no successful origin required for the benchmark"),
|
||||
who_lookup.clone(),
|
||||
));
|
||||
}
|
||||
who
|
||||
}
|
||||
|
||||
#[instance_benchmarks(
|
||||
where
|
||||
<<T as pallet::Config<I>>::Polls as pezframe_support::traits::Polling<Tally<T, I, pallet::Pallet<T, I>>>>::Index: From<u8>,
|
||||
<T as pezframe_system::Config>::RuntimeEvent: TryInto<pallet::Event<T, I>>,
|
||||
)]
|
||||
mod benchmarks {
|
||||
use super::*;
|
||||
|
||||
#[benchmark]
|
||||
fn add_member() -> Result<(), BenchmarkError> {
|
||||
// Generate a test account for the new member.
|
||||
let who = account::<T::AccountId>("member", 0, SEED);
|
||||
let who_lookup = T::Lookup::unlookup(who.clone());
|
||||
|
||||
// Attempt to get the successful origin for adding a member.
|
||||
let origin =
|
||||
T::AddOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
|
||||
#[extrinsic_call]
|
||||
_(origin as T::RuntimeOrigin, who_lookup);
|
||||
|
||||
// Ensure the member count has increased (or is 1 for rank 0).
|
||||
assert_eq!(MemberCount::<T, I>::get(0), 1);
|
||||
|
||||
// Check that the correct event was emitted.
|
||||
assert_last_event::<T, I>(Event::MemberAdded { who }.into());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn remove_member(r: Linear<0, 10>) -> Result<(), BenchmarkError> {
|
||||
// Convert `r` to a rank and create members.
|
||||
let rank = r as u16;
|
||||
let who = make_member::<T, I>(rank);
|
||||
let who_lookup = T::Lookup::unlookup(who.clone());
|
||||
let last = make_member::<T, I>(rank);
|
||||
|
||||
// Collect the index of the `last` member for each rank.
|
||||
let last_index: Vec<_> =
|
||||
(0..=rank).map(|r| IdToIndex::<T, I>::get(r, &last).unwrap()).collect();
|
||||
|
||||
// Fetch the remove origin.
|
||||
let origin =
|
||||
T::RemoveOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
|
||||
#[extrinsic_call]
|
||||
_(origin as T::RuntimeOrigin, who_lookup, rank);
|
||||
|
||||
for r in 0..=rank {
|
||||
assert_eq!(MemberCount::<T, I>::get(r), 1);
|
||||
assert_ne!(last_index[r as usize], IdToIndex::<T, I>::get(r, &last).unwrap());
|
||||
}
|
||||
|
||||
// Ensure the correct event was emitted for the member removal.
|
||||
assert_last_event::<T, I>(Event::MemberRemoved { who, rank }.into());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn promote_member(r: Linear<0, 10>) -> Result<(), BenchmarkError> {
|
||||
// Convert `r` to a rank and create the member.
|
||||
let rank = r as u16;
|
||||
let who = make_member::<T, I>(rank);
|
||||
let who_lookup = T::Lookup::unlookup(who.clone());
|
||||
|
||||
// Try to fetch the promotion origin.
|
||||
let origin =
|
||||
T::PromoteOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
|
||||
#[extrinsic_call]
|
||||
_(origin as T::RuntimeOrigin, who_lookup);
|
||||
|
||||
// Ensure the member's rank has increased by 1.
|
||||
assert_eq!(Members::<T, I>::get(&who).unwrap().rank, rank + 1);
|
||||
|
||||
// Ensure the correct event was emitted for the rank change.
|
||||
assert_last_event::<T, I>(Event::RankChanged { who, rank: rank + 1 }.into());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn demote_member(r: Linear<0, 10>) -> Result<(), BenchmarkError> {
|
||||
// Convert `r` to a rank and create necessary members for the benchmark.
|
||||
let rank = r as u16;
|
||||
let who = make_member::<T, I>(rank);
|
||||
let who_lookup = T::Lookup::unlookup(who.clone());
|
||||
let last = make_member::<T, I>(rank);
|
||||
|
||||
// Get the last index for the member.
|
||||
let last_index = IdToIndex::<T, I>::get(rank, &last).unwrap();
|
||||
|
||||
// Try to fetch the demotion origin.
|
||||
let origin =
|
||||
T::DemoteOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
|
||||
#[extrinsic_call]
|
||||
_(origin as T::RuntimeOrigin, who_lookup);
|
||||
|
||||
// Ensure the member's rank has decreased by 1.
|
||||
assert_eq!(Members::<T, I>::get(&who).map(|x| x.rank), rank.checked_sub(1));
|
||||
|
||||
// Ensure the member count remains as expected.
|
||||
assert_eq!(MemberCount::<T, I>::get(rank), 1);
|
||||
|
||||
// Ensure the index of the last member has changed.
|
||||
assert_ne!(last_index, IdToIndex::<T, I>::get(rank, &last).unwrap());
|
||||
|
||||
// Ensure the correct event was emitted depending on the member's rank.
|
||||
assert_last_event::<T, I>(
|
||||
match rank {
|
||||
0 => Event::MemberRemoved { who, rank: 0 },
|
||||
r => Event::RankChanged { who, rank: r - 1 },
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn vote() -> Result<(), BenchmarkError> {
|
||||
// Get the first available class or set it to None if no class exists.
|
||||
let class = T::Polls::classes().into_iter().next();
|
||||
|
||||
// Convert the class to a rank if it exists, otherwise use the default rank.
|
||||
let rank = class.as_ref().map_or(
|
||||
<Pallet<T, I> as pezframe_support::traits::RankedMembers>::Rank::default(),
|
||||
|class| T::MinRankOfClass::convert(class.clone()),
|
||||
);
|
||||
|
||||
// Create a caller based on the rank.
|
||||
let caller = make_member::<T, I>(rank);
|
||||
|
||||
// Determine the poll to use: create an ongoing poll if class exists, or use an invalid
|
||||
// poll.
|
||||
let poll = if let Some(ref class) = class {
|
||||
T::Polls::create_ongoing(class.clone())
|
||||
.expect("Poll creation should succeed for rank 0")
|
||||
} else {
|
||||
<NoOpPoll<BlockNumberFor<T>> as Polling<T>>::Index::MAX.into()
|
||||
};
|
||||
|
||||
// Benchmark the vote logic for a positive vote (true).
|
||||
#[block]
|
||||
{
|
||||
let vote_result =
|
||||
Pallet::<T, I>::vote(SystemOrigin::Signed(caller.clone()).into(), poll, true);
|
||||
|
||||
// If the class exists, expect success; otherwise expect a "NotPolling" error.
|
||||
if class.is_some() {
|
||||
assert_ok!(vote_result);
|
||||
} else {
|
||||
assert_err!(vote_result, crate::Error::<T, I>::NotPolling);
|
||||
};
|
||||
}
|
||||
|
||||
// Vote logic for a negative vote (false).
|
||||
let vote_result =
|
||||
Pallet::<T, I>::vote(SystemOrigin::Signed(caller.clone()).into(), poll, false);
|
||||
|
||||
// Check the result of the negative vote.
|
||||
if class.is_some() {
|
||||
assert_ok!(vote_result);
|
||||
} else {
|
||||
assert_err!(vote_result, crate::Error::<T, I>::NotPolling);
|
||||
};
|
||||
|
||||
// If the class exists, verify the vote event and tally.
|
||||
if let Some(_) = class {
|
||||
// Get the actual vote weight from the latest event's VoteRecord::Nay
|
||||
let mut events = pezframe_system::Pallet::<T>::events();
|
||||
let last_event = events.pop().expect("At least one event should exist");
|
||||
let event: Event<T, I> = last_event
|
||||
.event
|
||||
.try_into()
|
||||
.unwrap_or_else(|_| panic!("Event conversion failed"));
|
||||
|
||||
match event {
|
||||
Event::Voted { vote: VoteRecord::Nay(vote_weight), who, poll: poll2, tally } => {
|
||||
assert_eq!(tally, Tally::from_parts(0, 0, vote_weight));
|
||||
assert_eq!(caller, who);
|
||||
assert_eq!(poll, poll2);
|
||||
},
|
||||
_ => panic!("Invalid event"),
|
||||
};
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn cleanup_poll(n: Linear<0, 100>) -> Result<(), BenchmarkError> {
|
||||
let alice: T::AccountId = whitelisted_caller();
|
||||
let origin = SystemOrigin::Signed(alice.clone());
|
||||
|
||||
// Try to retrieve the first class if it exists.
|
||||
let class = T::Polls::classes().into_iter().next();
|
||||
|
||||
// Convert the class to a rank, or use a default rank if no class exists.
|
||||
let rank = class.as_ref().map_or(
|
||||
<Pallet<T, I> as pezframe_support::traits::RankedMembers>::Rank::default(),
|
||||
|class| T::MinRankOfClass::convert(class.clone()),
|
||||
);
|
||||
|
||||
// Determine the poll to use: create an ongoing poll if class exists, or use an invalid
|
||||
// poll.
|
||||
let poll = if let Some(ref class) = class {
|
||||
T::Polls::create_ongoing(class.clone())
|
||||
.expect("Poll creation should succeed for rank 0")
|
||||
} else {
|
||||
<NoOpPoll<BlockNumberFor<T>> as Polling<T>>::Index::MAX.into()
|
||||
};
|
||||
|
||||
// Simulate voting by `n` members.
|
||||
for _ in 0..n {
|
||||
let voter = make_member::<T, I>(rank);
|
||||
let result = Pallet::<T, I>::vote(SystemOrigin::Signed(voter).into(), poll, true);
|
||||
|
||||
// Check voting results based on class existence.
|
||||
if class.is_some() {
|
||||
assert_ok!(result);
|
||||
} else {
|
||||
assert_err!(result, crate::Error::<T, I>::NotPolling);
|
||||
}
|
||||
}
|
||||
|
||||
// End the poll if the class exists.
|
||||
if class.is_some() {
|
||||
T::Polls::end_ongoing(poll, false)
|
||||
.map_err(|_| BenchmarkError::Stop("Failed to end poll"))?;
|
||||
}
|
||||
|
||||
// Verify the number of votes cast.
|
||||
let expected_votes = if class.is_some() { n as usize } else { 0 };
|
||||
assert_eq!(Voting::<T, I>::iter_prefix(poll).count(), expected_votes);
|
||||
|
||||
// Benchmark the cleanup function.
|
||||
#[extrinsic_call]
|
||||
_(origin, poll, n);
|
||||
|
||||
// Ensure all votes are cleaned up after the extrinsic call.
|
||||
assert_eq!(Voting::<T, I>::iter().count(), 0);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn exchange_member() -> Result<(), BenchmarkError> {
|
||||
// Create an existing member.
|
||||
let who = make_member::<T, I>(1);
|
||||
T::BenchmarkSetup::ensure_member(&who);
|
||||
let who_lookup = T::Lookup::unlookup(who.clone());
|
||||
|
||||
// Create a new account for the new member.
|
||||
let new_who = account::<T::AccountId>("new-member", 0, SEED);
|
||||
let new_who_lookup = T::Lookup::unlookup(new_who.clone());
|
||||
|
||||
// Attempt to get the successful origin for exchanging a member.
|
||||
let origin =
|
||||
T::ExchangeOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
|
||||
#[extrinsic_call]
|
||||
_(origin as T::RuntimeOrigin, who_lookup, new_who_lookup);
|
||||
|
||||
// Check that the new member was successfully exchanged and holds the correct rank.
|
||||
assert_eq!(Members::<T, I>::get(&new_who).unwrap().rank, 1);
|
||||
|
||||
// Ensure the old member no longer exists.
|
||||
assert_eq!(Members::<T, I>::get(&who), None);
|
||||
|
||||
// Ensure the correct event was emitted.
|
||||
assert_has_event::<T, I>(Event::MemberExchanged { who, new_who }.into());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(
|
||||
RankedCollective,
|
||||
crate::tests::ExtBuilder::default().build(),
|
||||
crate::tests::Test
|
||||
);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,686 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! The crate's tests.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use pezframe_support::{
|
||||
assert_noop, assert_ok, derive_impl, parameter_types,
|
||||
traits::{ConstU16, EitherOf, MapSuccess, Polling},
|
||||
};
|
||||
use pezsp_core::Get;
|
||||
use pezsp_runtime::{
|
||||
traits::{BadOrigin, MaybeConvert, ReduceBy, ReplaceWithDefault},
|
||||
BuildStorage,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
use crate as pezpallet_ranked_collective;
|
||||
|
||||
type Block = pezframe_system::mocking::MockBlock<Test>;
|
||||
type Class = Rank;
|
||||
|
||||
pezframe_support::construct_runtime!(
|
||||
pub enum Test
|
||||
{
|
||||
System: pezframe_system,
|
||||
Club: pezpallet_ranked_collective,
|
||||
}
|
||||
);
|
||||
|
||||
#[derive_impl(pezframe_system::config_preludes::TestDefaultConfig)]
|
||||
impl pezframe_system::Config for Test {
|
||||
type Block = Block;
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub enum TestPollState {
|
||||
Ongoing(TallyOf<Test>, Rank),
|
||||
Completed(u64, bool),
|
||||
}
|
||||
use TestPollState::*;
|
||||
|
||||
parameter_types! {
|
||||
pub static Polls: BTreeMap<u8, TestPollState> = vec![
|
||||
(1, Completed(1, true)),
|
||||
(2, Completed(2, false)),
|
||||
(3, Ongoing(Tally::from_parts(0, 0, 0), 1)),
|
||||
].into_iter().collect();
|
||||
}
|
||||
|
||||
pub struct TestPolls;
|
||||
impl Polling<TallyOf<Test>> for TestPolls {
|
||||
type Index = u8;
|
||||
type Votes = Votes;
|
||||
type Moment = u64;
|
||||
type Class = Class;
|
||||
fn classes() -> Vec<Self::Class> {
|
||||
vec![0, 1, 2]
|
||||
}
|
||||
fn as_ongoing(index: u8) -> Option<(TallyOf<Test>, Self::Class)> {
|
||||
Polls::get().remove(&index).and_then(|x| {
|
||||
if let TestPollState::Ongoing(t, c) = x {
|
||||
Some((t, c))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
fn access_poll<R>(
|
||||
index: Self::Index,
|
||||
f: impl FnOnce(PollStatus<&mut TallyOf<Test>, Self::Moment, Self::Class>) -> R,
|
||||
) -> R {
|
||||
let mut polls = Polls::get();
|
||||
let entry = polls.get_mut(&index);
|
||||
let r = match entry {
|
||||
Some(Ongoing(ref mut tally_mut_ref, class)) =>
|
||||
f(PollStatus::Ongoing(tally_mut_ref, *class)),
|
||||
Some(Completed(when, succeeded)) => f(PollStatus::Completed(*when, *succeeded)),
|
||||
None => f(PollStatus::None),
|
||||
};
|
||||
Polls::set(polls);
|
||||
r
|
||||
}
|
||||
fn try_access_poll<R>(
|
||||
index: Self::Index,
|
||||
f: impl FnOnce(
|
||||
PollStatus<&mut TallyOf<Test>, Self::Moment, Self::Class>,
|
||||
) -> Result<R, DispatchError>,
|
||||
) -> Result<R, DispatchError> {
|
||||
let mut polls = Polls::get();
|
||||
let entry = polls.get_mut(&index);
|
||||
let r = match entry {
|
||||
Some(Ongoing(ref mut tally_mut_ref, class)) =>
|
||||
f(PollStatus::Ongoing(tally_mut_ref, *class)),
|
||||
Some(Completed(when, succeeded)) => f(PollStatus::Completed(*when, *succeeded)),
|
||||
None => f(PollStatus::None),
|
||||
}?;
|
||||
Polls::set(polls);
|
||||
Ok(r)
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn create_ongoing(class: Self::Class) -> Result<Self::Index, ()> {
|
||||
let mut polls = Polls::get();
|
||||
let i = polls.keys().rev().next().map_or(0, |x| x + 1);
|
||||
polls.insert(i, Ongoing(Tally::new(class), class));
|
||||
Polls::set(polls);
|
||||
Ok(i)
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn end_ongoing(index: Self::Index, approved: bool) -> Result<(), ()> {
|
||||
let mut polls = Polls::get();
|
||||
match polls.get(&index) {
|
||||
Some(Ongoing(..)) => {},
|
||||
_ => return Err(()),
|
||||
}
|
||||
let now = pezframe_system::Pallet::<Test>::block_number();
|
||||
polls.insert(index, Completed(now, approved));
|
||||
Polls::set(polls);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert the tally class into the minimum rank required to vote on the poll.
|
||||
/// MinRank(Class) = Class - Delta
|
||||
pub struct MinRankOfClass<Delta>(PhantomData<Delta>);
|
||||
impl<Delta: Get<Rank>> Convert<Class, Rank> for MinRankOfClass<Delta> {
|
||||
fn convert(a: Class) -> Rank {
|
||||
a.saturating_sub(Delta::get())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MaxMemberCount;
|
||||
impl MaybeConvert<Rank, MemberIndex> for MaxMemberCount {
|
||||
fn maybe_convert(a: Rank) -> Option<MemberIndex> {
|
||||
if a == 11 {
|
||||
Some(2)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub static MinRankOfClassDelta: Rank = 0;
|
||||
}
|
||||
|
||||
impl Config for Test {
|
||||
type WeightInfo = ();
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type AddOrigin = MapSuccess<Self::PromoteOrigin, ReplaceWithDefault<()>>;
|
||||
type RemoveOrigin = Self::DemoteOrigin;
|
||||
type PromoteOrigin = EitherOf<
|
||||
// Root can promote arbitrarily.
|
||||
pezframe_system::EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
|
||||
// Members can promote up to the rank of 2 below them.
|
||||
MapSuccess<EnsureRanked<Test, (), 2>, ReduceBy<ConstU16<2>>>,
|
||||
>;
|
||||
type DemoteOrigin = EitherOf<
|
||||
// Root can demote arbitrarily.
|
||||
pezframe_system::EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
|
||||
// Members can demote up to the rank of 3 below them.
|
||||
MapSuccess<EnsureRanked<Test, (), 3>, ReduceBy<ConstU16<3>>>,
|
||||
>;
|
||||
type ExchangeOrigin = EitherOf<
|
||||
// Root can exchange arbitrarily.
|
||||
pezframe_system::EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
|
||||
// Members can exchange up to the rank of 2 below them.
|
||||
MapSuccess<EnsureRanked<Test, (), 2>, ReduceBy<ConstU16<2>>>,
|
||||
>;
|
||||
type Polls = TestPolls;
|
||||
type MinRankOfClass = MinRankOfClass<MinRankOfClassDelta>;
|
||||
type MemberSwappedHandler = ();
|
||||
type VoteWeight = Geometric;
|
||||
type MaxMemberCount = MaxMemberCount;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
type BenchmarkSetup = ();
|
||||
}
|
||||
|
||||
pub struct ExtBuilder {}
|
||||
|
||||
impl Default for ExtBuilder {
|
||||
fn default() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl ExtBuilder {
|
||||
pub fn build(self) -> pezsp_io::TestExternalities {
|
||||
let t = pezframe_system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
let mut ext = pezsp_io::TestExternalities::new(t);
|
||||
ext.execute_with(|| System::set_block_number(1));
|
||||
ext
|
||||
}
|
||||
|
||||
pub fn build_and_execute(self, test: impl FnOnce() -> ()) {
|
||||
self.build().execute_with(|| {
|
||||
test();
|
||||
Club::do_try_state().expect("All invariants must hold after a test");
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn next_block() {
|
||||
System::set_block_number(System::block_number() + 1);
|
||||
}
|
||||
|
||||
fn member_count(r: Rank) -> MemberIndex {
|
||||
MemberCount::<Test>::get(r)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn run_to(n: u64) {
|
||||
while System::block_number() < n {
|
||||
next_block();
|
||||
}
|
||||
}
|
||||
|
||||
fn tally(index: u8) -> TallyOf<Test> {
|
||||
<TestPolls as Polling<TallyOf<Test>>>::as_ongoing(index).expect("No poll").0
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
#[should_panic(expected = "No poll")]
|
||||
fn unknown_poll_should_panic() {
|
||||
let _ = tally(0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
#[should_panic(expected = "No poll")]
|
||||
fn completed_poll_should_panic() {
|
||||
let _ = tally(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn basic_stuff() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_eq!(tally(3), Tally::from_parts(0, 0, 0));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn member_lifecycle_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 1));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 1));
|
||||
assert_ok!(Club::demote_member(RuntimeOrigin::root(), 1));
|
||||
assert_ok!(Club::demote_member(RuntimeOrigin::root(), 1));
|
||||
assert_eq!(member_count(0), 0);
|
||||
assert_eq!(member_count(1), 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_remove_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_noop!(Club::add_member(RuntimeOrigin::signed(1), 1), DispatchError::BadOrigin);
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 1));
|
||||
assert_eq!(member_count(0), 1);
|
||||
|
||||
assert_ok!(Club::demote_member(RuntimeOrigin::root(), 1));
|
||||
assert_eq!(member_count(0), 0);
|
||||
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 1));
|
||||
assert_eq!(member_count(0), 1);
|
||||
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 2));
|
||||
assert_eq!(member_count(0), 2);
|
||||
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 3));
|
||||
assert_eq!(member_count(0), 3);
|
||||
|
||||
assert_ok!(Club::demote_member(RuntimeOrigin::root(), 3));
|
||||
assert_eq!(member_count(0), 2);
|
||||
|
||||
assert_ok!(Club::demote_member(RuntimeOrigin::root(), 1));
|
||||
assert_eq!(member_count(0), 1);
|
||||
|
||||
assert_ok!(Club::demote_member(RuntimeOrigin::root(), 2));
|
||||
assert_eq!(member_count(0), 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn promote_demote_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_noop!(Club::add_member(RuntimeOrigin::signed(1), 1), DispatchError::BadOrigin);
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 1));
|
||||
assert_eq!(member_count(0), 1);
|
||||
assert_eq!(member_count(1), 0);
|
||||
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 2));
|
||||
assert_eq!(member_count(0), 2);
|
||||
assert_eq!(member_count(1), 0);
|
||||
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 1));
|
||||
assert_eq!(member_count(0), 2);
|
||||
assert_eq!(member_count(1), 1);
|
||||
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 2));
|
||||
assert_eq!(member_count(0), 2);
|
||||
assert_eq!(member_count(1), 2);
|
||||
|
||||
assert_ok!(Club::demote_member(RuntimeOrigin::root(), 1));
|
||||
assert_eq!(member_count(0), 2);
|
||||
assert_eq!(member_count(1), 1);
|
||||
|
||||
assert_noop!(Club::demote_member(RuntimeOrigin::signed(1), 1), DispatchError::BadOrigin);
|
||||
assert_ok!(Club::demote_member(RuntimeOrigin::root(), 1));
|
||||
assert_eq!(member_count(0), 1);
|
||||
assert_eq!(member_count(1), 1);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn promote_demote_by_rank_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 1));
|
||||
for _ in 0..7 {
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 1));
|
||||
}
|
||||
|
||||
// #1 can add #2 and promote to rank 1
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::signed(1), 2));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::signed(1), 2));
|
||||
// #2 as rank 1 cannot do anything privileged
|
||||
assert_noop!(Club::add_member(RuntimeOrigin::signed(2), 3), BadOrigin);
|
||||
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::signed(1), 2));
|
||||
// #2 as rank 2 can add #3.
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::signed(2), 3));
|
||||
|
||||
// #2 as rank 2 cannot promote #3 to rank 1
|
||||
assert_noop!(
|
||||
Club::promote_member(RuntimeOrigin::signed(2), 3),
|
||||
Error::<Test>::NoPermission
|
||||
);
|
||||
|
||||
// #1 as rank 7 can promote #2 only up to rank 5 and once there cannot demote them.
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::signed(1), 2));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::signed(1), 2));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::signed(1), 2));
|
||||
assert_noop!(
|
||||
Club::promote_member(RuntimeOrigin::signed(1), 2),
|
||||
Error::<Test>::NoPermission
|
||||
);
|
||||
assert_noop!(Club::demote_member(RuntimeOrigin::signed(1), 2), Error::<Test>::NoPermission);
|
||||
|
||||
// #2 as rank 5 can promote #3 only up to rank 3 and once there cannot demote them.
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::signed(2), 3));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::signed(2), 3));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::signed(2), 3));
|
||||
assert_noop!(
|
||||
Club::promote_member(RuntimeOrigin::signed(2), 3),
|
||||
Error::<Test>::NoPermission
|
||||
);
|
||||
assert_noop!(Club::demote_member(RuntimeOrigin::signed(2), 3), Error::<Test>::NoPermission);
|
||||
|
||||
// #2 can add #4 & #5 as rank 0 and #6 & #7 as rank 1.
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::signed(2), 4));
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::signed(2), 5));
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::signed(2), 6));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::signed(2), 6));
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::signed(2), 7));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::signed(2), 7));
|
||||
|
||||
// #3 as rank 3 can demote/remove #4 & #5 but not #6 & #7
|
||||
assert_ok!(Club::demote_member(RuntimeOrigin::signed(3), 4));
|
||||
assert_ok!(Club::remove_member(RuntimeOrigin::signed(3), 5, 0));
|
||||
assert_noop!(Club::demote_member(RuntimeOrigin::signed(3), 6), Error::<Test>::NoPermission);
|
||||
assert_noop!(
|
||||
Club::remove_member(RuntimeOrigin::signed(3), 7, 1),
|
||||
Error::<Test>::NoPermission
|
||||
);
|
||||
|
||||
// #2 as rank 5 can demote/remove #6 & #7
|
||||
assert_ok!(Club::demote_member(RuntimeOrigin::signed(2), 6));
|
||||
assert_ok!(Club::remove_member(RuntimeOrigin::signed(2), 7, 1));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn voting_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 0));
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 1));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 1));
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 2));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 2));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 2));
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 3));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 3));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 3));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 3));
|
||||
|
||||
assert_noop!(Club::vote(RuntimeOrigin::signed(0), 3, true), Error::<Test>::RankTooLow);
|
||||
assert_eq!(tally(3), Tally::from_parts(0, 0, 0));
|
||||
|
||||
assert_ok!(Club::vote(RuntimeOrigin::signed(1), 3, true));
|
||||
assert_eq!(tally(3), Tally::from_parts(1, 1, 0));
|
||||
assert_ok!(Club::vote(RuntimeOrigin::signed(1), 3, false));
|
||||
assert_eq!(tally(3), Tally::from_parts(0, 0, 1));
|
||||
|
||||
assert_ok!(Club::vote(RuntimeOrigin::signed(2), 3, true));
|
||||
assert_eq!(tally(3), Tally::from_parts(1, 3, 1));
|
||||
assert_ok!(Club::vote(RuntimeOrigin::signed(2), 3, false));
|
||||
assert_eq!(tally(3), Tally::from_parts(0, 0, 4));
|
||||
|
||||
assert_ok!(Club::vote(RuntimeOrigin::signed(3), 3, true));
|
||||
assert_eq!(tally(3), Tally::from_parts(1, 6, 4));
|
||||
assert_ok!(Club::vote(RuntimeOrigin::signed(3), 3, false));
|
||||
assert_eq!(tally(3), Tally::from_parts(0, 0, 10));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cleanup_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 1));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 1));
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 2));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 2));
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 3));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 3));
|
||||
|
||||
assert_ok!(Club::vote(RuntimeOrigin::signed(1), 3, true));
|
||||
assert_ok!(Club::vote(RuntimeOrigin::signed(2), 3, false));
|
||||
assert_ok!(Club::vote(RuntimeOrigin::signed(3), 3, true));
|
||||
|
||||
assert_noop!(Club::cleanup_poll(RuntimeOrigin::signed(4), 3, 10), Error::<Test>::Ongoing);
|
||||
Polls::set(
|
||||
vec![(1, Completed(1, true)), (2, Completed(2, false)), (3, Completed(3, true))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
);
|
||||
assert_ok!(Club::cleanup_poll(RuntimeOrigin::signed(4), 3, 10));
|
||||
// NOTE: This will fail until #10016 is merged.
|
||||
// assert_noop!(Club::cleanup_poll(RuntimeOrigin::signed(4), 3, 10),
|
||||
// Error::<Test>::NoneRemaining);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_member_cleanup_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 1));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 1));
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 2));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 2));
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 3));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 3));
|
||||
|
||||
assert_eq!(IdToIndex::<Test>::get(1, 2), Some(1));
|
||||
assert_eq!(IndexToId::<Test>::get(1, 1), Some(2));
|
||||
|
||||
assert_eq!(IdToIndex::<Test>::get(1, 3), Some(2));
|
||||
assert_eq!(IndexToId::<Test>::get(1, 2), Some(3));
|
||||
|
||||
assert_ok!(Club::remove_member(RuntimeOrigin::root(), 2, 1));
|
||||
|
||||
assert_eq!(IdToIndex::<Test>::get(1, 2), None);
|
||||
assert_eq!(IndexToId::<Test>::get(1, 1), Some(3));
|
||||
|
||||
assert_eq!(IdToIndex::<Test>::get(1, 3), Some(1));
|
||||
assert_eq!(IndexToId::<Test>::get(1, 2), None);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ensure_ranked_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 1));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 1));
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 2));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 2));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 2));
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 3));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 3));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 3));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 3));
|
||||
|
||||
use pezframe_support::traits::OriginTrait;
|
||||
type Rank1 = EnsureRanked<Test, (), 1>;
|
||||
type Rank2 = EnsureRanked<Test, (), 2>;
|
||||
type Rank3 = EnsureRanked<Test, (), 3>;
|
||||
type Rank4 = EnsureRanked<Test, (), 4>;
|
||||
assert_eq!(<Rank1 as EnsureOrigin<_>>::try_origin(RuntimeOrigin::signed(1)).unwrap(), 1);
|
||||
assert_eq!(<Rank1 as EnsureOrigin<_>>::try_origin(RuntimeOrigin::signed(2)).unwrap(), 2);
|
||||
assert_eq!(<Rank1 as EnsureOrigin<_>>::try_origin(RuntimeOrigin::signed(3)).unwrap(), 3);
|
||||
assert_eq!(
|
||||
<Rank2 as EnsureOrigin<_>>::try_origin(RuntimeOrigin::signed(1))
|
||||
.unwrap_err()
|
||||
.into_signer()
|
||||
.unwrap(),
|
||||
1
|
||||
);
|
||||
assert_eq!(<Rank2 as EnsureOrigin<_>>::try_origin(RuntimeOrigin::signed(2)).unwrap(), 2);
|
||||
assert_eq!(<Rank2 as EnsureOrigin<_>>::try_origin(RuntimeOrigin::signed(3)).unwrap(), 3);
|
||||
assert_eq!(
|
||||
<Rank3 as EnsureOrigin<_>>::try_origin(RuntimeOrigin::signed(1))
|
||||
.unwrap_err()
|
||||
.into_signer()
|
||||
.unwrap(),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
<Rank3 as EnsureOrigin<_>>::try_origin(RuntimeOrigin::signed(2))
|
||||
.unwrap_err()
|
||||
.into_signer()
|
||||
.unwrap(),
|
||||
2
|
||||
);
|
||||
assert_eq!(<Rank3 as EnsureOrigin<_>>::try_origin(RuntimeOrigin::signed(3)).unwrap(), 3);
|
||||
assert_eq!(
|
||||
<Rank4 as EnsureOrigin<_>>::try_origin(RuntimeOrigin::signed(1))
|
||||
.unwrap_err()
|
||||
.into_signer()
|
||||
.unwrap(),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
<Rank4 as EnsureOrigin<_>>::try_origin(RuntimeOrigin::signed(2))
|
||||
.unwrap_err()
|
||||
.into_signer()
|
||||
.unwrap(),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
<Rank4 as EnsureOrigin<_>>::try_origin(RuntimeOrigin::signed(3))
|
||||
.unwrap_err()
|
||||
.into_signer()
|
||||
.unwrap(),
|
||||
3
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn do_add_member_to_rank_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let max_rank = 9u16;
|
||||
assert_ok!(Club::do_add_member_to_rank(69, max_rank / 2, true));
|
||||
assert_ok!(Club::do_add_member_to_rank(1337, max_rank, true));
|
||||
for i in 0..=max_rank {
|
||||
if i <= max_rank / 2 {
|
||||
assert_eq!(member_count(i), 2);
|
||||
} else {
|
||||
assert_eq!(member_count(i), 1);
|
||||
}
|
||||
}
|
||||
assert_eq!(member_count(max_rank + 1), 0);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tally_support_correct() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
// add members,
|
||||
// rank 1: accounts 1, 2, 3
|
||||
// rank 2: accounts 2, 3
|
||||
// rank 3: accounts 3.
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 1));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 1));
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 2));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 2));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 2));
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 3));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 3));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 3));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 3));
|
||||
|
||||
// init tally with 1 aye vote.
|
||||
let tally: TallyOf<Test> = Tally::from_parts(1, 1, 0);
|
||||
|
||||
// with minRank(Class) = Class
|
||||
// for class 3, 100% support.
|
||||
MinRankOfClassDelta::set(0);
|
||||
assert_eq!(tally.support(3), Perbill::from_rational(1u32, 1));
|
||||
|
||||
// with minRank(Class) = (Class - 1)
|
||||
// for class 3, ~50% support.
|
||||
MinRankOfClassDelta::set(1);
|
||||
assert_eq!(tally.support(3), Perbill::from_rational(1u32, 2));
|
||||
|
||||
// with minRank(Class) = (Class - 2)
|
||||
// for class 3, ~33% support.
|
||||
MinRankOfClassDelta::set(2);
|
||||
assert_eq!(tally.support(3), Perbill::from_rational(1u32, 3));
|
||||
|
||||
// reset back.
|
||||
MinRankOfClassDelta::set(0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exchange_member_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 1));
|
||||
assert_eq!(member_count(0), 1);
|
||||
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 1));
|
||||
|
||||
let member_record = MemberRecord { rank: 1 };
|
||||
assert_eq!(Members::<Test>::get(1), Some(member_record.clone()));
|
||||
assert_eq!(Members::<Test>::get(2), None);
|
||||
|
||||
assert_ok!(Club::exchange_member(RuntimeOrigin::root(), 1, 2));
|
||||
assert_eq!(member_count(0), 1);
|
||||
|
||||
assert_eq!(Members::<Test>::get(1), None);
|
||||
assert_eq!(Members::<Test>::get(2), Some(member_record));
|
||||
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 3));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 3));
|
||||
|
||||
assert_noop!(
|
||||
Club::exchange_member(RuntimeOrigin::signed(3), 2, 1),
|
||||
DispatchError::BadOrigin
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exchange_member_same_noops() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 1));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 1));
|
||||
assert_ok!(Club::add_member(RuntimeOrigin::root(), 2));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 2));
|
||||
|
||||
// Swapping the same accounts is a noop:
|
||||
assert_noop!(Club::exchange_member(RuntimeOrigin::root(), 1, 1), Error::<Test>::SameMember);
|
||||
// Swapping with a different member is a noop:
|
||||
assert_noop!(
|
||||
Club::exchange_member(RuntimeOrigin::root(), 1, 2),
|
||||
Error::<Test>::AlreadyMember
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn max_member_count_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Club::do_add_member_to_rank(1, 10, false));
|
||||
assert_ok!(Club::do_add_member_to_rank(2, 10, false));
|
||||
assert_ok!(Club::do_add_member_to_rank(3, 10, false));
|
||||
assert_eq!(member_count(10), 3);
|
||||
assert_eq!(member_count(11), 0);
|
||||
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 1));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 2));
|
||||
assert_noop!(Club::promote_member(RuntimeOrigin::root(), 3), Error::<Test>::TooManyMembers);
|
||||
assert_eq!(member_count(10), 3);
|
||||
assert_eq!(member_count(11), 2);
|
||||
|
||||
assert_ok!(Club::demote_member(RuntimeOrigin::root(), 1));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 3));
|
||||
assert_eq!(member_count(10), 3);
|
||||
assert_eq!(member_count(11), 2);
|
||||
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 2));
|
||||
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 3));
|
||||
assert_noop!(Club::promote_member(RuntimeOrigin::root(), 1), Error::<Test>::TooManyMembers);
|
||||
assert_eq!(member_count(10), 3);
|
||||
assert_eq!(member_count(11), 2);
|
||||
assert_eq!(member_count(12), 2);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,375 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Autogenerated weights for `pezpallet_ranked_collective`
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE BIZINIKIWI BENCHMARK CLI VERSION 32.0.0
|
||||
//! DATE: 2025-02-21, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
|
||||
//! WORST CASE MAP SIZE: `1000000`
|
||||
//! HOSTNAME: `4563561839a5`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
|
||||
//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024`
|
||||
|
||||
// Executed Command:
|
||||
// frame-omni-bencher
|
||||
// v1
|
||||
// benchmark
|
||||
// pallet
|
||||
// --extrinsic=*
|
||||
// --runtime=target/production/wbuild/kitchensink-runtime/kitchensink_runtime.wasm
|
||||
// --pallet=pezpallet_ranked_collective
|
||||
// --header=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/HEADER-APACHE2
|
||||
// --output=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/pezframe/ranked-collective/src/weights.rs
|
||||
// --wasm-execution=compiled
|
||||
// --steps=50
|
||||
// --repeat=20
|
||||
// --heap-pages=4096
|
||||
// --template=bizinikiwi/.maintain/frame-weight-template.hbs
|
||||
// --no-storage-info
|
||||
// --no-min-squares
|
||||
// --no-median-slopes
|
||||
// --genesis-builder-policy=none
|
||||
// --exclude-pallets=pezpallet_xcm,pezpallet_xcm_benchmarks::fungible,pezpallet_xcm_benchmarks::generic,pezpallet_nomination_pools,pezpallet_remark,pezpallet_transaction_storage,pezpallet_election_provider_multi_block,pezpallet_election_provider_multi_block::signed,pezpallet_election_provider_multi_block::unsigned,pezpallet_election_provider_multi_block::verifier
|
||||
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
#![allow(unused_parens)]
|
||||
#![allow(unused_imports)]
|
||||
#![allow(missing_docs)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
use pezframe_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
|
||||
use core::marker::PhantomData;
|
||||
|
||||
/// Weight functions needed for `pezpallet_ranked_collective`.
|
||||
pub trait WeightInfo {
|
||||
fn add_member() -> Weight;
|
||||
fn remove_member(r: u32, ) -> Weight;
|
||||
fn promote_member(r: u32, ) -> Weight;
|
||||
fn demote_member(r: u32, ) -> Weight;
|
||||
fn vote() -> Weight;
|
||||
fn cleanup_poll(n: u32, ) -> Weight;
|
||||
fn exchange_member() -> Weight;
|
||||
}
|
||||
|
||||
/// Weights for `pezpallet_ranked_collective` using the Bizinikiwi node and recommended hardware.
|
||||
pub struct BizinikiwiWeight<T>(PhantomData<T>);
|
||||
impl<T: pezframe_system::Config> WeightInfo for BizinikiwiWeight<T> {
|
||||
/// Storage: `RankedCollective::Members` (r:1 w:1)
|
||||
/// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::MemberCount` (r:1 w:1)
|
||||
/// Proof: `RankedCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IndexToId` (r:0 w:1)
|
||||
/// Proof: `RankedCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IdToIndex` (r:0 w:1)
|
||||
/// Proof: `RankedCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
fn add_member() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `3507`
|
||||
// Minimum execution time: 12_027_000 picoseconds.
|
||||
Weight::from_parts(12_401_000, 3507)
|
||||
.saturating_add(T::DbWeight::get().reads(2_u64))
|
||||
.saturating_add(T::DbWeight::get().writes(4_u64))
|
||||
}
|
||||
/// Storage: `RankedCollective::Members` (r:1 w:1)
|
||||
/// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::MemberCount` (r:11 w:11)
|
||||
/// Proof: `RankedCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IdToIndex` (r:11 w:22)
|
||||
/// Proof: `RankedCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IndexToId` (r:11 w:22)
|
||||
/// Proof: `RankedCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
/// The range of component `r` is `[0, 10]`.
|
||||
fn remove_member(r: u32, ) -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `357 + r * (213 ±0)`
|
||||
// Estimated: `3519 + r * (2529 ±0)`
|
||||
// Minimum execution time: 30_318_000 picoseconds.
|
||||
Weight::from_parts(31_539_535, 3519)
|
||||
// Standard Error: 28_134
|
||||
.saturating_add(Weight::from_parts(17_834_009, 0).saturating_mul(r.into()))
|
||||
.saturating_add(T::DbWeight::get().reads(4_u64))
|
||||
.saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(r.into())))
|
||||
.saturating_add(T::DbWeight::get().writes(6_u64))
|
||||
.saturating_add(T::DbWeight::get().writes((5_u64).saturating_mul(r.into())))
|
||||
.saturating_add(Weight::from_parts(0, 2529).saturating_mul(r.into()))
|
||||
}
|
||||
/// Storage: `RankedCollective::Members` (r:1 w:1)
|
||||
/// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::MemberCount` (r:1 w:1)
|
||||
/// Proof: `RankedCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IndexToId` (r:0 w:1)
|
||||
/// Proof: `RankedCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IdToIndex` (r:0 w:1)
|
||||
/// Proof: `RankedCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
/// The range of component `r` is `[0, 10]`.
|
||||
fn promote_member(r: u32, ) -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `156 + r * (17 ±0)`
|
||||
// Estimated: `3507`
|
||||
// Minimum execution time: 17_423_000 picoseconds.
|
||||
Weight::from_parts(18_370_282, 3507)
|
||||
// Standard Error: 4_969
|
||||
.saturating_add(Weight::from_parts(396_009, 0).saturating_mul(r.into()))
|
||||
.saturating_add(T::DbWeight::get().reads(2_u64))
|
||||
.saturating_add(T::DbWeight::get().writes(4_u64))
|
||||
}
|
||||
/// Storage: `RankedCollective::Members` (r:1 w:1)
|
||||
/// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::MemberCount` (r:1 w:1)
|
||||
/// Proof: `RankedCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IdToIndex` (r:1 w:2)
|
||||
/// Proof: `RankedCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IndexToId` (r:1 w:2)
|
||||
/// Proof: `RankedCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
/// The range of component `r` is `[0, 10]`.
|
||||
fn demote_member(r: u32, ) -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `372 + r * (72 ±0)`
|
||||
// Estimated: `3519`
|
||||
// Minimum execution time: 30_221_000 picoseconds.
|
||||
Weight::from_parts(33_322_970, 3519)
|
||||
// Standard Error: 31_522
|
||||
.saturating_add(Weight::from_parts(891_487, 0).saturating_mul(r.into()))
|
||||
.saturating_add(T::DbWeight::get().reads(4_u64))
|
||||
.saturating_add(T::DbWeight::get().writes(6_u64))
|
||||
}
|
||||
/// Storage: `RankedCollective::Members` (r:1 w:0)
|
||||
/// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedPolls::ReferendumInfoFor` (r:1 w:1)
|
||||
/// Proof: `RankedPolls::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(330), added: 2805, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::Voting` (r:1 w:1)
|
||||
/// Proof: `RankedCollective::Voting` (`max_values`: None, `max_size`: Some(65), added: 2540, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Scheduler::Agenda` (r:2 w:2)
|
||||
/// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(107022), added: 109497, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Scheduler::Retries` (r:0 w:1)
|
||||
/// Proof: `Scheduler::Retries` (`max_values`: None, `max_size`: Some(30), added: 2505, mode: `MaxEncodedLen`)
|
||||
fn vote() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `383`
|
||||
// Estimated: `219984`
|
||||
// Minimum execution time: 38_707_000 picoseconds.
|
||||
Weight::from_parts(39_868_000, 219984)
|
||||
.saturating_add(T::DbWeight::get().reads(5_u64))
|
||||
.saturating_add(T::DbWeight::get().writes(5_u64))
|
||||
}
|
||||
/// Storage: `RankedPolls::ReferendumInfoFor` (r:1 w:0)
|
||||
/// Proof: `RankedPolls::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(330), added: 2805, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::VotingCleanup` (r:1 w:0)
|
||||
/// Proof: `RankedCollective::VotingCleanup` (`max_values`: None, `max_size`: Some(114), added: 2589, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::Voting` (r:100 w:100)
|
||||
/// Proof: `RankedCollective::Voting` (`max_values`: None, `max_size`: Some(65), added: 2540, mode: `MaxEncodedLen`)
|
||||
/// The range of component `n` is `[0, 100]`.
|
||||
fn cleanup_poll(n: u32, ) -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `319 + n * (50 ±0)`
|
||||
// Estimated: `3795 + n * (2540 ±0)`
|
||||
// Minimum execution time: 11_978_000 picoseconds.
|
||||
Weight::from_parts(16_360_588, 3795)
|
||||
// Standard Error: 3_424
|
||||
.saturating_add(Weight::from_parts(1_360_238, 0).saturating_mul(n.into()))
|
||||
.saturating_add(T::DbWeight::get().reads(2_u64))
|
||||
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into())))
|
||||
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into())))
|
||||
.saturating_add(Weight::from_parts(0, 2540).saturating_mul(n.into()))
|
||||
}
|
||||
/// Storage: `RankedCollective::Members` (r:2 w:2)
|
||||
/// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::MemberCount` (r:2 w:2)
|
||||
/// Proof: `RankedCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IdToIndex` (r:2 w:4)
|
||||
/// Proof: `RankedCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
/// Storage: `CoreFellowship::Member` (r:2 w:2)
|
||||
/// Proof: `CoreFellowship::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`)
|
||||
/// Storage: `CoreFellowship::MemberEvidence` (r:1 w:0)
|
||||
/// Proof: `CoreFellowship::MemberEvidence` (`max_values`: None, `max_size`: Some(16429), added: 18904, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Salary::Claimant` (r:2 w:2)
|
||||
/// Proof: `Salary::Claimant` (`max_values`: None, `max_size`: Some(78), added: 2553, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IndexToId` (r:0 w:2)
|
||||
/// Proof: `RankedCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
fn exchange_member() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `364`
|
||||
// Estimated: `19894`
|
||||
// Minimum execution time: 68_754_000 picoseconds.
|
||||
Weight::from_parts(70_469_000, 19894)
|
||||
.saturating_add(T::DbWeight::get().reads(11_u64))
|
||||
.saturating_add(T::DbWeight::get().writes(14_u64))
|
||||
}
|
||||
}
|
||||
|
||||
// For backwards compatibility and tests.
|
||||
impl WeightInfo for () {
|
||||
/// Storage: `RankedCollective::Members` (r:1 w:1)
|
||||
/// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::MemberCount` (r:1 w:1)
|
||||
/// Proof: `RankedCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IndexToId` (r:0 w:1)
|
||||
/// Proof: `RankedCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IdToIndex` (r:0 w:1)
|
||||
/// Proof: `RankedCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
fn add_member() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `3507`
|
||||
// Minimum execution time: 12_027_000 picoseconds.
|
||||
Weight::from_parts(12_401_000, 3507)
|
||||
.saturating_add(RocksDbWeight::get().reads(2_u64))
|
||||
.saturating_add(RocksDbWeight::get().writes(4_u64))
|
||||
}
|
||||
/// Storage: `RankedCollective::Members` (r:1 w:1)
|
||||
/// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::MemberCount` (r:11 w:11)
|
||||
/// Proof: `RankedCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IdToIndex` (r:11 w:22)
|
||||
/// Proof: `RankedCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IndexToId` (r:11 w:22)
|
||||
/// Proof: `RankedCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
/// The range of component `r` is `[0, 10]`.
|
||||
fn remove_member(r: u32, ) -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `357 + r * (213 ±0)`
|
||||
// Estimated: `3519 + r * (2529 ±0)`
|
||||
// Minimum execution time: 30_318_000 picoseconds.
|
||||
Weight::from_parts(31_539_535, 3519)
|
||||
// Standard Error: 28_134
|
||||
.saturating_add(Weight::from_parts(17_834_009, 0).saturating_mul(r.into()))
|
||||
.saturating_add(RocksDbWeight::get().reads(4_u64))
|
||||
.saturating_add(RocksDbWeight::get().reads((3_u64).saturating_mul(r.into())))
|
||||
.saturating_add(RocksDbWeight::get().writes(6_u64))
|
||||
.saturating_add(RocksDbWeight::get().writes((5_u64).saturating_mul(r.into())))
|
||||
.saturating_add(Weight::from_parts(0, 2529).saturating_mul(r.into()))
|
||||
}
|
||||
/// Storage: `RankedCollective::Members` (r:1 w:1)
|
||||
/// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::MemberCount` (r:1 w:1)
|
||||
/// Proof: `RankedCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IndexToId` (r:0 w:1)
|
||||
/// Proof: `RankedCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IdToIndex` (r:0 w:1)
|
||||
/// Proof: `RankedCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
/// The range of component `r` is `[0, 10]`.
|
||||
fn promote_member(r: u32, ) -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `156 + r * (17 ±0)`
|
||||
// Estimated: `3507`
|
||||
// Minimum execution time: 17_423_000 picoseconds.
|
||||
Weight::from_parts(18_370_282, 3507)
|
||||
// Standard Error: 4_969
|
||||
.saturating_add(Weight::from_parts(396_009, 0).saturating_mul(r.into()))
|
||||
.saturating_add(RocksDbWeight::get().reads(2_u64))
|
||||
.saturating_add(RocksDbWeight::get().writes(4_u64))
|
||||
}
|
||||
/// Storage: `RankedCollective::Members` (r:1 w:1)
|
||||
/// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::MemberCount` (r:1 w:1)
|
||||
/// Proof: `RankedCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IdToIndex` (r:1 w:2)
|
||||
/// Proof: `RankedCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IndexToId` (r:1 w:2)
|
||||
/// Proof: `RankedCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
/// The range of component `r` is `[0, 10]`.
|
||||
fn demote_member(r: u32, ) -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `372 + r * (72 ±0)`
|
||||
// Estimated: `3519`
|
||||
// Minimum execution time: 30_221_000 picoseconds.
|
||||
Weight::from_parts(33_322_970, 3519)
|
||||
// Standard Error: 31_522
|
||||
.saturating_add(Weight::from_parts(891_487, 0).saturating_mul(r.into()))
|
||||
.saturating_add(RocksDbWeight::get().reads(4_u64))
|
||||
.saturating_add(RocksDbWeight::get().writes(6_u64))
|
||||
}
|
||||
/// Storage: `RankedCollective::Members` (r:1 w:0)
|
||||
/// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedPolls::ReferendumInfoFor` (r:1 w:1)
|
||||
/// Proof: `RankedPolls::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(330), added: 2805, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::Voting` (r:1 w:1)
|
||||
/// Proof: `RankedCollective::Voting` (`max_values`: None, `max_size`: Some(65), added: 2540, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Scheduler::Agenda` (r:2 w:2)
|
||||
/// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(107022), added: 109497, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Scheduler::Retries` (r:0 w:1)
|
||||
/// Proof: `Scheduler::Retries` (`max_values`: None, `max_size`: Some(30), added: 2505, mode: `MaxEncodedLen`)
|
||||
fn vote() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `383`
|
||||
// Estimated: `219984`
|
||||
// Minimum execution time: 38_707_000 picoseconds.
|
||||
Weight::from_parts(39_868_000, 219984)
|
||||
.saturating_add(RocksDbWeight::get().reads(5_u64))
|
||||
.saturating_add(RocksDbWeight::get().writes(5_u64))
|
||||
}
|
||||
/// Storage: `RankedPolls::ReferendumInfoFor` (r:1 w:0)
|
||||
/// Proof: `RankedPolls::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(330), added: 2805, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::VotingCleanup` (r:1 w:0)
|
||||
/// Proof: `RankedCollective::VotingCleanup` (`max_values`: None, `max_size`: Some(114), added: 2589, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::Voting` (r:100 w:100)
|
||||
/// Proof: `RankedCollective::Voting` (`max_values`: None, `max_size`: Some(65), added: 2540, mode: `MaxEncodedLen`)
|
||||
/// The range of component `n` is `[0, 100]`.
|
||||
fn cleanup_poll(n: u32, ) -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `319 + n * (50 ±0)`
|
||||
// Estimated: `3795 + n * (2540 ±0)`
|
||||
// Minimum execution time: 11_978_000 picoseconds.
|
||||
Weight::from_parts(16_360_588, 3795)
|
||||
// Standard Error: 3_424
|
||||
.saturating_add(Weight::from_parts(1_360_238, 0).saturating_mul(n.into()))
|
||||
.saturating_add(RocksDbWeight::get().reads(2_u64))
|
||||
.saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(n.into())))
|
||||
.saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(n.into())))
|
||||
.saturating_add(Weight::from_parts(0, 2540).saturating_mul(n.into()))
|
||||
}
|
||||
/// Storage: `RankedCollective::Members` (r:2 w:2)
|
||||
/// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::MemberCount` (r:2 w:2)
|
||||
/// Proof: `RankedCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IdToIndex` (r:2 w:4)
|
||||
/// Proof: `RankedCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
/// Storage: `CoreFellowship::Member` (r:2 w:2)
|
||||
/// Proof: `CoreFellowship::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`)
|
||||
/// Storage: `CoreFellowship::MemberEvidence` (r:1 w:0)
|
||||
/// Proof: `CoreFellowship::MemberEvidence` (`max_values`: None, `max_size`: Some(16429), added: 18904, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Salary::Claimant` (r:2 w:2)
|
||||
/// Proof: `Salary::Claimant` (`max_values`: None, `max_size`: Some(78), added: 2553, mode: `MaxEncodedLen`)
|
||||
/// Storage: `RankedCollective::IndexToId` (r:0 w:2)
|
||||
/// Proof: `RankedCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
|
||||
fn exchange_member() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `364`
|
||||
// Estimated: `19894`
|
||||
// Minimum execution time: 68_754_000 picoseconds.
|
||||
Weight::from_parts(70_469_000, 19894)
|
||||
.saturating_add(RocksDbWeight::get().reads(11_u64))
|
||||
.saturating_add(RocksDbWeight::get().writes(14_u64))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user