mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-06 02:07:25 +00:00
87d41d0a89
* frame::support: GenesisConfig types for Runtime enabled * frame::support: macro generating GenesisBuild::build for RuntimeGenesisConfig * frame: ambiguity BuildStorage vs GenesisBuild fixed * fix * RuntimeGenesisBuild added * Revert "frame: ambiguity BuildStorage vs GenesisBuild fixed" This reverts commit 950f3d019d0e21c55a739c44cc19cdabd3ff0293. * Revert "fix" This reverts commit a2f76dd24e9a16cf9230d45825ed28787211118b. * Revert "RuntimeGenesisBuild added" This reverts commit 3c131b618138ced29c01ab8d15d8c6410c9e128b. * Revert "Revert "frame: ambiguity BuildStorage vs GenesisBuild fixed"" This reverts commit 2b1ecd467231eddec69f8d328039ba48a380da3d. * Revert "Revert "fix"" This reverts commit fd7fa629adf579d83e30e6ae9fd162637fc45e30. * Code review suggestions * frame: BuildGenesisConfig added, BuildGenesis deprecated * frame: some pallets updated with BuildGenesisConfig * constuct_runtime: support for BuildGenesisConfig * frame::support: genesis_build macro supports BuildGenesisConfig * frame: BuildGenesisConfig added, BuildGenesis deprecated * Cargo.lock update * test-runtime: fixes * Revert "fix" This reverts commit a2f76dd24e9a16cf9230d45825ed28787211118b. * Revert "frame: ambiguity BuildStorage vs GenesisBuild fixed" This reverts commit 950f3d019d0e21c55a739c44cc19cdabd3ff0293. * self review * doc fixed * ui tests fixed * fmt * tests fixed * genesis_build macrto fixed for non-generic GenesisConfig * BuildGenesisConfig constraints added * warning fixed * some duplication removed * fmt * fix * doc tests fix * doc fix * cleanup: remove BuildModuleGenesisStorage * self review comments * fix * Update frame/treasury/src/tests.rs Co-authored-by: Sebastian Kunert <skunert49@gmail.com> * Update frame/support/src/traits/hooks.rs Co-authored-by: Sebastian Kunert <skunert49@gmail.com> * doc fix: GenesisBuild exposed * ".git/.scripts/commands/fmt/fmt.sh" * frame: more serde(skip) + cleanup * Update frame/support/src/traits/hooks.rs Co-authored-by: Davide Galassi <davxy@datawok.net> * frame: phantom fields moved to the end of structs * chain-spec: Default::default cleanup * test-runtime: phantom at the end * merge master fixes * fix * fix * fix * fix * fix (facepalm) * Update frame/support/procedural/src/pallet/expand/genesis_build.rs Co-authored-by: Bastian Köcher <git@kchr.de> * fmt * fix * fix --------- Co-authored-by: parity-processbot <> Co-authored-by: Sebastian Kunert <skunert49@gmail.com> Co-authored-by: Davide Galassi <davxy@datawok.net> Co-authored-by: Bastian Köcher <git@kchr.de>
380 lines
14 KiB
Rust
380 lines
14 KiB
Rust
// This file is part of Substrate.
|
|
|
|
// 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.
|
|
|
|
//! Society pallet benchmarking.
|
|
|
|
#![cfg(feature = "runtime-benchmarks")]
|
|
|
|
use super::*;
|
|
|
|
use frame_benchmarking::{account, benchmarks_instance_pallet, whitelisted_caller};
|
|
use frame_system::RawOrigin;
|
|
|
|
use sp_runtime::traits::Bounded;
|
|
|
|
use crate::Pallet as Society;
|
|
|
|
fn mock_balance_deposit<T: Config<I>, I: 'static>() -> BalanceOf<T, I> {
|
|
T::Currency::minimum_balance().saturating_mul(1_000u32.into())
|
|
}
|
|
|
|
fn make_deposit<T: Config<I>, I: 'static>(who: &T::AccountId) -> BalanceOf<T, I> {
|
|
let amount = mock_balance_deposit::<T, I>();
|
|
let required = amount.saturating_add(T::Currency::minimum_balance());
|
|
if T::Currency::free_balance(who) < required {
|
|
T::Currency::make_free_balance_be(who, required);
|
|
}
|
|
T::Currency::reserve(who, amount).expect("Pre-funded account; qed");
|
|
amount
|
|
}
|
|
|
|
fn make_bid<T: Config<I>, I: 'static>(
|
|
who: &T::AccountId,
|
|
) -> BidKind<T::AccountId, BalanceOf<T, I>> {
|
|
BidKind::Deposit(make_deposit::<T, I>(who))
|
|
}
|
|
|
|
fn fund_society<T: Config<I>, I: 'static>() {
|
|
T::Currency::make_free_balance_be(
|
|
&Society::<T, I>::account_id(),
|
|
BalanceOf::<T, I>::max_value(),
|
|
);
|
|
Pot::<T, I>::put(&BalanceOf::<T, I>::max_value());
|
|
}
|
|
|
|
// Set up Society
|
|
fn setup_society<T: Config<I>, I: 'static>() -> Result<T::AccountId, &'static str> {
|
|
let origin = T::FounderSetOrigin::try_successful_origin().map_err(|_| "No origin")?;
|
|
let founder: T::AccountId = account("founder", 0, 0);
|
|
let founder_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(founder.clone());
|
|
let max_members = 5u32;
|
|
let max_intake = 3u32;
|
|
let max_strikes = 3u32;
|
|
Society::<T, I>::found_society(
|
|
origin,
|
|
founder_lookup,
|
|
max_members,
|
|
max_intake,
|
|
max_strikes,
|
|
mock_balance_deposit::<T, I>(),
|
|
b"benchmarking-society".to_vec(),
|
|
)?;
|
|
T::Currency::make_free_balance_be(
|
|
&Society::<T, I>::account_id(),
|
|
T::Currency::minimum_balance(),
|
|
);
|
|
T::Currency::make_free_balance_be(&Society::<T, I>::payouts(), T::Currency::minimum_balance());
|
|
Ok(founder)
|
|
}
|
|
|
|
fn setup_funded_society<T: Config<I>, I: 'static>() -> Result<T::AccountId, &'static str> {
|
|
let founder = setup_society::<T, I>()?;
|
|
fund_society::<T, I>();
|
|
Ok(founder)
|
|
}
|
|
|
|
fn add_candidate<T: Config<I>, I: 'static>(
|
|
name: &'static str,
|
|
tally: Tally,
|
|
skeptic_struck: bool,
|
|
) -> T::AccountId {
|
|
let candidate: T::AccountId = account(name, 0, 0);
|
|
let candidacy = Candidacy {
|
|
round: RoundCount::<T, I>::get(),
|
|
kind: make_bid::<T, I>(&candidate),
|
|
bid: 0u32.into(),
|
|
tally,
|
|
skeptic_struck,
|
|
};
|
|
Candidates::<T, I>::insert(&candidate, &candidacy);
|
|
candidate
|
|
}
|
|
|
|
fn increment_round<T: Config<I>, I: 'static>() {
|
|
let mut round_count = RoundCount::<T, I>::get();
|
|
round_count.saturating_inc();
|
|
RoundCount::<T, I>::put(round_count);
|
|
}
|
|
|
|
benchmarks_instance_pallet! {
|
|
bid {
|
|
let founder = setup_society::<T, I>()?;
|
|
let caller: T::AccountId = whitelisted_caller();
|
|
T::Currency::make_free_balance_be(&caller, BalanceOf::<T, I>::max_value());
|
|
}: _(RawOrigin::Signed(caller.clone()), 10u32.into())
|
|
verify {
|
|
let first_bid: Bid<T::AccountId, BalanceOf<T, I>> = Bid {
|
|
who: caller.clone(),
|
|
kind: BidKind::Deposit(mock_balance_deposit::<T, I>()),
|
|
value: 10u32.into(),
|
|
};
|
|
assert_eq!(Bids::<T, I>::get(), vec![first_bid]);
|
|
}
|
|
|
|
unbid {
|
|
let founder = setup_society::<T, I>()?;
|
|
let caller: T::AccountId = whitelisted_caller();
|
|
T::Currency::make_free_balance_be(&caller, BalanceOf::<T, I>::max_value());
|
|
let mut bids = Bids::<T, I>::get();
|
|
Society::<T, I>::insert_bid(&mut bids, &caller, 10u32.into(), make_bid::<T, I>(&caller));
|
|
Bids::<T, I>::put(bids);
|
|
}: _(RawOrigin::Signed(caller.clone()))
|
|
verify {
|
|
assert_eq!(Bids::<T, I>::get(), vec![]);
|
|
}
|
|
|
|
vouch {
|
|
let founder = setup_society::<T, I>()?;
|
|
let caller: T::AccountId = whitelisted_caller();
|
|
let vouched: T::AccountId = account("vouched", 0, 0);
|
|
T::Currency::make_free_balance_be(&caller, BalanceOf::<T, I>::max_value());
|
|
let _ = Society::<T, I>::insert_member(&caller, 1u32.into());
|
|
let vouched_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(vouched.clone());
|
|
}: _(RawOrigin::Signed(caller.clone()), vouched_lookup, 0u32.into(), 0u32.into())
|
|
verify {
|
|
let bids = Bids::<T, I>::get();
|
|
let vouched_bid: Bid<T::AccountId, BalanceOf<T, I>> = Bid {
|
|
who: vouched.clone(),
|
|
kind: BidKind::Vouch(caller.clone(), 0u32.into()),
|
|
value: 0u32.into(),
|
|
};
|
|
assert_eq!(bids, vec![vouched_bid]);
|
|
}
|
|
|
|
unvouch {
|
|
let founder = setup_society::<T, I>()?;
|
|
let caller: T::AccountId = whitelisted_caller();
|
|
let vouched: T::AccountId = account("vouched", 0, 0);
|
|
T::Currency::make_free_balance_be(&caller, BalanceOf::<T, I>::max_value());
|
|
let mut bids = Bids::<T, I>::get();
|
|
Society::<T, I>::insert_bid(&mut bids, &caller, 10u32.into(), BidKind::Vouch(caller.clone(), 0u32.into()));
|
|
Bids::<T, I>::put(bids);
|
|
}: _(RawOrigin::Signed(caller.clone()))
|
|
verify {
|
|
assert_eq!(Bids::<T, I>::get(), vec![]);
|
|
}
|
|
|
|
vote {
|
|
let founder = setup_society::<T, I>()?;
|
|
let caller: T::AccountId = whitelisted_caller();
|
|
T::Currency::make_free_balance_be(&caller, BalanceOf::<T, I>::max_value());
|
|
let _ = Society::<T, I>::insert_member(&caller, 1u32.into());
|
|
let candidate = add_candidate::<T, I>("candidate", Default::default(), false);
|
|
let candidate_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(candidate.clone());
|
|
}: _(RawOrigin::Signed(caller.clone()), candidate_lookup, true)
|
|
verify {
|
|
let maybe_vote: Vote = <Votes<T, I>>::get(candidate.clone(), caller).unwrap();
|
|
assert_eq!(maybe_vote.approve, true);
|
|
}
|
|
|
|
defender_vote {
|
|
let founder = setup_society::<T, I>()?;
|
|
let caller: T::AccountId = whitelisted_caller();
|
|
T::Currency::make_free_balance_be(&caller, BalanceOf::<T, I>::max_value());
|
|
let _ = Society::<T, I>::insert_member(&caller, 1u32.into());
|
|
let defender: T::AccountId = account("defender", 0, 0);
|
|
Defending::<T, I>::put((defender, caller.clone(), Tally::default()));
|
|
}: _(RawOrigin::Signed(caller.clone()), false)
|
|
verify {
|
|
let round = RoundCount::<T, I>::get();
|
|
let skeptic_vote: Vote = DefenderVotes::<T, I>::get(round, &caller).unwrap();
|
|
assert_eq!(skeptic_vote.approve, false);
|
|
}
|
|
|
|
payout {
|
|
let founder = setup_funded_society::<T, I>()?;
|
|
// Payee's account already exists and is a member.
|
|
let caller: T::AccountId = whitelisted_caller();
|
|
T::Currency::make_free_balance_be(&caller, mock_balance_deposit::<T, I>());
|
|
let _ = Society::<T, I>::insert_member(&caller, 0u32.into());
|
|
// Introduce payout.
|
|
Society::<T, I>::bump_payout(&caller, 0u32.into(), 1u32.into());
|
|
}: _(RawOrigin::Signed(caller.clone()))
|
|
verify {
|
|
let record = Payouts::<T, I>::get(caller);
|
|
assert!(record.payouts.is_empty());
|
|
}
|
|
|
|
waive_repay {
|
|
let founder = setup_funded_society::<T, I>()?;
|
|
let caller: T::AccountId = whitelisted_caller();
|
|
T::Currency::make_free_balance_be(&caller, BalanceOf::<T, I>::max_value());
|
|
let _ = Society::<T, I>::insert_member(&caller, 0u32.into());
|
|
Society::<T, I>::bump_payout(&caller, 0u32.into(), 1u32.into());
|
|
}: _(RawOrigin::Signed(caller.clone()), 1u32.into())
|
|
verify {
|
|
let record = Payouts::<T, I>::get(caller);
|
|
assert!(record.payouts.is_empty());
|
|
}
|
|
|
|
found_society {
|
|
let founder: T::AccountId = whitelisted_caller();
|
|
let can_found = T::FounderSetOrigin::try_successful_origin().map_err(|_| "No origin")?;
|
|
let founder_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(founder.clone());
|
|
}: _<T::RuntimeOrigin>(can_found, founder_lookup, 5, 3, 3, mock_balance_deposit::<T, I>(), b"benchmarking-society".to_vec())
|
|
verify {
|
|
assert_eq!(Founder::<T, I>::get(), Some(founder.clone()));
|
|
}
|
|
|
|
dissolve {
|
|
let founder = setup_society::<T, I>()?;
|
|
let members_and_candidates = vec![("m1", "c1"), ("m2", "c2"), ("m3", "c3"), ("m4", "c4")];
|
|
let members_count = members_and_candidates.clone().len() as u32;
|
|
for (m, c) in members_and_candidates {
|
|
let member: T::AccountId = account(m, 0, 0);
|
|
let _ = Society::<T, I>::insert_member(&member, 100u32.into());
|
|
let candidate = add_candidate::<T, I>(c, Tally { approvals: 1u32.into(), rejections: 1u32.into() }, false);
|
|
let candidate_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(candidate);
|
|
let _ = Society::<T, I>::vote(RawOrigin::Signed(member).into(), candidate_lookup, true);
|
|
}
|
|
// Leaving only Founder member.
|
|
MemberCount::<T, I>::mutate(|i| { i.saturating_reduce(members_count) });
|
|
}: _(RawOrigin::Signed(founder))
|
|
verify {
|
|
assert_eq!(Founder::<T, I>::get(), None);
|
|
}
|
|
|
|
judge_suspended_member {
|
|
let founder = setup_society::<T, I>()?;
|
|
let caller: T::AccountId = whitelisted_caller();
|
|
let caller_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(caller.clone());
|
|
let _ = Society::<T, I>::insert_member(&caller, 0u32.into());
|
|
let _ = Society::<T, I>::suspend_member(&caller);
|
|
}: _(RawOrigin::Signed(founder), caller_lookup, false)
|
|
verify {
|
|
assert_eq!(SuspendedMembers::<T, I>::contains_key(&caller), false);
|
|
}
|
|
|
|
set_parameters {
|
|
let founder = setup_society::<T, I>()?;
|
|
let max_members = 10u32;
|
|
let max_intake = 10u32;
|
|
let max_strikes = 10u32;
|
|
let candidate_deposit: BalanceOf<T, I> = 10u32.into();
|
|
let params = GroupParams { max_members, max_intake, max_strikes, candidate_deposit };
|
|
}: _(RawOrigin::Signed(founder), max_members, max_intake, max_strikes, candidate_deposit)
|
|
verify {
|
|
assert_eq!(Parameters::<T, I>::get(), Some(params));
|
|
}
|
|
|
|
punish_skeptic {
|
|
let founder = setup_society::<T, I>()?;
|
|
let candidate = add_candidate::<T, I>("candidate", Default::default(), false);
|
|
let skeptic: T::AccountId = account("skeptic", 0, 0);
|
|
let _ = Society::<T, I>::insert_member(&skeptic, 0u32.into());
|
|
Skeptic::<T, I>::put(&skeptic);
|
|
if let Period::Voting { more, .. } = Society::<T, I>::period() {
|
|
frame_system::Pallet::<T>::set_block_number(frame_system::Pallet::<T>::block_number() + more);
|
|
}
|
|
}: _(RawOrigin::Signed(candidate.clone()))
|
|
verify {
|
|
let candidacy = Candidates::<T, I>::get(&candidate).unwrap();
|
|
assert_eq!(candidacy.skeptic_struck, true);
|
|
}
|
|
|
|
claim_membership {
|
|
let founder = setup_society::<T, I>()?;
|
|
let candidate = add_candidate::<T, I>("candidate", Tally { approvals: 3u32.into(), rejections: 0u32.into() }, false);
|
|
increment_round::<T, I>();
|
|
}: _(RawOrigin::Signed(candidate.clone()))
|
|
verify {
|
|
assert!(!Candidates::<T, I>::contains_key(&candidate));
|
|
assert!(Members::<T, I>::contains_key(&candidate));
|
|
}
|
|
|
|
bestow_membership {
|
|
let founder = setup_society::<T, I>()?;
|
|
let candidate = add_candidate::<T, I>("candidate", Tally { approvals: 3u32.into(), rejections: 1u32.into() }, false);
|
|
increment_round::<T, I>();
|
|
}: _(RawOrigin::Signed(founder), candidate.clone())
|
|
verify {
|
|
assert!(!Candidates::<T, I>::contains_key(&candidate));
|
|
assert!(Members::<T, I>::contains_key(&candidate));
|
|
}
|
|
|
|
kick_candidate {
|
|
let founder = setup_society::<T, I>()?;
|
|
let candidate = add_candidate::<T, I>("candidate", Tally { approvals: 1u32.into(), rejections: 1u32.into() }, false);
|
|
increment_round::<T, I>();
|
|
}: _(RawOrigin::Signed(founder), candidate.clone())
|
|
verify {
|
|
assert!(!Candidates::<T, I>::contains_key(&candidate));
|
|
}
|
|
|
|
resign_candidacy {
|
|
let founder = setup_society::<T, I>()?;
|
|
let candidate = add_candidate::<T, I>("candidate", Tally { approvals: 0u32.into(), rejections: 0u32.into() }, false);
|
|
}: _(RawOrigin::Signed(candidate.clone()))
|
|
verify {
|
|
assert!(!Candidates::<T, I>::contains_key(&candidate));
|
|
}
|
|
|
|
drop_candidate {
|
|
let founder = setup_society::<T, I>()?;
|
|
let candidate = add_candidate::<T, I>("candidate", Tally { approvals: 0u32.into(), rejections: 3u32.into() }, false);
|
|
let caller: T::AccountId = whitelisted_caller();
|
|
let _ = Society::<T, I>::insert_member(&caller, 0u32.into());
|
|
let mut round_count = RoundCount::<T, I>::get();
|
|
round_count = round_count.saturating_add(2u32);
|
|
RoundCount::<T, I>::put(round_count);
|
|
}: _(RawOrigin::Signed(caller), candidate.clone())
|
|
verify {
|
|
assert!(!Candidates::<T, I>::contains_key(&candidate));
|
|
}
|
|
|
|
cleanup_candidacy {
|
|
let founder = setup_society::<T, I>()?;
|
|
let candidate = add_candidate::<T, I>("candidate", Tally { approvals: 0u32.into(), rejections: 0u32.into() }, false);
|
|
let member_one: T::AccountId = account("one", 0, 0);
|
|
let member_two: T::AccountId = account("two", 0, 0);
|
|
let _ = Society::<T, I>::insert_member(&member_one, 0u32.into());
|
|
let _ = Society::<T, I>::insert_member(&member_two, 0u32.into());
|
|
let candidate_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(candidate.clone());
|
|
let _ = Society::<T, I>::vote(RawOrigin::Signed(member_one.clone()).into(), candidate_lookup.clone(), true);
|
|
let _ = Society::<T, I>::vote(RawOrigin::Signed(member_two.clone()).into(), candidate_lookup, true);
|
|
Candidates::<T, I>::remove(&candidate);
|
|
}: _(RawOrigin::Signed(member_one), candidate.clone(), 5)
|
|
verify {
|
|
assert_eq!(Votes::<T, I>::get(&candidate, &member_two), None);
|
|
}
|
|
|
|
cleanup_challenge {
|
|
let founder = setup_society::<T, I>()?;
|
|
ChallengeRoundCount::<T, I>::put(1u32);
|
|
let member: T::AccountId = whitelisted_caller();
|
|
let _ = Society::<T, I>::insert_member(&member, 0u32.into());
|
|
let defender: T::AccountId = account("defender", 0, 0);
|
|
Defending::<T, I>::put((defender.clone(), member.clone(), Tally::default()));
|
|
let _ = Society::<T, I>::defender_vote(RawOrigin::Signed(member.clone()).into(), true);
|
|
ChallengeRoundCount::<T, I>::put(2u32);
|
|
let mut challenge_round = ChallengeRoundCount::<T, I>::get();
|
|
challenge_round = challenge_round.saturating_sub(1u32);
|
|
}: _(RawOrigin::Signed(member.clone()), challenge_round, 1u32)
|
|
verify {
|
|
assert_eq!(DefenderVotes::<T, I>::get(challenge_round, &defender), None);
|
|
}
|
|
|
|
impl_benchmark_test_suite!(
|
|
Society,
|
|
sp_io::TestExternalities::from(
|
|
<frame_system::GenesisConfig::<crate::mock::Test> as sp_runtime::BuildStorage>::build_storage(
|
|
&frame_system::GenesisConfig::default()).unwrap()
|
|
),
|
|
crate::mock::Test
|
|
);
|
|
}
|