pallet alliance (#11112)

* Add pallet-alliance

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Update multihash/cid and format

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Remove useless deps

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Add pallet-alliance into node runtime

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Fix has_identity

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Add TooMantBlacklist Error

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Add TooLongWebsiteUrlLength Error

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Add remove_announcement

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Derive pallet_identity::Config and Fix test/benchmarking

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Add part weight for call of pallet-alliance

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Remove pallet_identity Config trait

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Fix propose arguments

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Some nits

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* cargo fmt

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Fix benchmarking of add_blacklist/remove_blacklist

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Some nits

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Add benchmarking for init_members

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Add benchmarking for propose/vote/veto

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Fix benchmarking

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Remove some useless

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* fix some compile issue

* more fix

* all checks

* refactor

* refactor event

* refactor

* cleanup

* cleanup

* fix benchmarking

* fix warning

* fmt

* fix benchmarks

* with storage info

* fmt

* add new config

* fix benchmarks

* fix

* fmt

* Apply suggestions from code review

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* improvements

* fix

* update docs

* rename events, errors, and functions

* make kicking events clearer

* fix

* fix tests

* fix tests

* fix runtime

* fix build

* remove unneeded change

* remove Candidate role from Alliance

* fmt grumbles

* update lock

* update recursion limit

* benchmarks

* convert-try

* benchmark assertions

* fmt ,

* cargo lock

* Update frame/alliance/src/benchmarking.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* add docs to public interfaces

* Apply suggestions from code review

Co-authored-by: Squirrel <gilescope@gmail.com>

* fix build (node)

* review

* use EitherOfDiverse

* update cargo toml

* make all dispatch class Normal

* change blacklist to unscrupulous

* formatting

* fmt oops

* rename benchmarking unscrupulous account creator

Co-authored-by: koushiro <koushiro.cqx@gmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: joepetrowski <joe@parity.io>
Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
Co-authored-by: Squirrel <gilescope@gmail.com>
This commit is contained in:
Xiliang Chen
2022-06-11 06:39:26 +12:00
committed by GitHub
parent 09b5def9b1
commit 5788461196
16 changed files with 3745 additions and 165 deletions
@@ -0,0 +1,791 @@
// This file is part of Substrate.
// Copyright (C) 2022 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.
//! Alliance pallet benchmarking.
use sp_runtime::traits::{Bounded, Hash, StaticLookup};
use sp_std::{
convert::{TryFrom, TryInto},
mem::size_of,
prelude::*,
};
use frame_benchmarking::{account, benchmarks_instance_pallet};
use frame_support::traits::{EnsureOrigin, Get, UnfilteredDispatchable};
use frame_system::{Pallet as System, RawOrigin as SystemOrigin};
use super::{Call as AllianceCall, Pallet as Alliance, *};
const SEED: u32 = 0;
const MAX_BYTES: u32 = 1_024;
fn assert_last_event<T: Config<I>, I: 'static>(generic_event: <T as Config<I>>::Event) {
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
}
fn cid(input: impl AsRef<[u8]>) -> Cid {
use sha2::{Digest, Sha256};
let mut hasher = Sha256::new();
hasher.update(input);
let result = hasher.finalize();
Cid::new_v0(&*result)
}
fn rule(input: impl AsRef<[u8]>) -> Cid {
cid(input)
}
fn announcement(input: impl AsRef<[u8]>) -> Cid {
cid(input)
}
fn funded_account<T: Config<I>, I: 'static>(name: &'static str, index: u32) -> T::AccountId {
let account: T::AccountId = account(name, index, SEED);
T::Currency::make_free_balance_be(&account, BalanceOf::<T, I>::max_value() / 100u8.into());
account
}
fn founder<T: Config<I>, I: 'static>(index: u32) -> T::AccountId {
funded_account::<T, I>("founder", index)
}
fn fellow<T: Config<I>, I: 'static>(index: u32) -> T::AccountId {
funded_account::<T, I>("fellow", index)
}
fn ally<T: Config<I>, I: 'static>(index: u32) -> T::AccountId {
funded_account::<T, I>("ally", index)
}
fn outsider<T: Config<I>, I: 'static>(index: u32) -> T::AccountId {
funded_account::<T, I>("outsider", index)
}
fn generate_unscrupulous_account<T: Config<I>, I: 'static>(index: u32) -> T::AccountId {
funded_account::<T, I>("unscrupulous", index)
}
fn set_members<T: Config<I>, I: 'static>() {
let founders: BoundedVec<_, T::MaxMembersCount> =
BoundedVec::try_from(vec![founder::<T, I>(1), founder::<T, I>(2)]).unwrap();
Members::<T, I>::insert(MemberRole::Founder, founders.clone());
let fellows: BoundedVec<_, T::MaxMembersCount> =
BoundedVec::try_from(vec![fellow::<T, I>(1), fellow::<T, I>(2)]).unwrap();
fellows.iter().for_each(|who| {
T::Currency::reserve(&who, T::AllyDeposit::get()).unwrap();
<DepositOf<T, I>>::insert(&who, T::AllyDeposit::get());
});
Members::<T, I>::insert(MemberRole::Fellow, fellows.clone());
let allies: BoundedVec<_, T::MaxMembersCount> =
BoundedVec::try_from(vec![ally::<T, I>(1)]).unwrap();
allies.iter().for_each(|who| {
T::Currency::reserve(&who, T::AllyDeposit::get()).unwrap();
<DepositOf<T, I>>::insert(&who, T::AllyDeposit::get());
});
Members::<T, I>::insert(MemberRole::Ally, allies);
T::InitializeMembers::initialize_members(&[founders.as_slice(), fellows.as_slice()].concat());
}
benchmarks_instance_pallet! {
// This tests when proposal is created and queued as "proposed"
propose_proposed {
let b in 1 .. MAX_BYTES;
let x in 2 .. T::MaxFounders::get();
let y in 0 .. T::MaxFellows::get();
let p in 1 .. T::MaxProposals::get();
let m = x + y;
let bytes_in_storage = b + size_of::<Cid>() as u32 + 32;
// Construct `members`.
let founders = (0 .. x).map(founder::<T, I>).collect::<Vec<_>>();
let proposer = founders[0].clone();
let fellows = (0 .. y).map(fellow::<T, I>).collect::<Vec<_>>();
Alliance::<T, I>::init_members(SystemOrigin::Root.into(), founders, fellows, vec![])?;
let threshold = m;
// Add previous proposals.
for i in 0 .. p - 1 {
// Proposals should be different so that different proposal hashes are generated
let proposal: T::Proposal = AllianceCall::<T, I>::set_rule {
rule: rule(vec![i as u8; b as usize])
}.into();
Alliance::<T, I>::propose(
SystemOrigin::Signed(proposer.clone()).into(),
threshold,
Box::new(proposal),
bytes_in_storage,
)?;
}
let proposal: T::Proposal = AllianceCall::<T, I>::set_rule { rule: rule(vec![p as u8; b as usize]) }.into();
}: propose(SystemOrigin::Signed(proposer.clone()), threshold, Box::new(proposal.clone()), bytes_in_storage)
verify {
// New proposal is recorded
let proposal_hash = T::Hashing::hash_of(&proposal);
assert_eq!(T::ProposalProvider::proposal_of(proposal_hash), Some(proposal));
}
vote {
// We choose 5 (3 founders + 2 fellows) as a minimum so we always trigger a vote in the voting loop (`for j in ...`)
let x in 3 .. T::MaxFounders::get();
let y in 2 .. T::MaxFellows::get();
let m = x + y;
let p = T::MaxProposals::get();
let b = MAX_BYTES;
let bytes_in_storage = b + size_of::<Cid>() as u32 + 32;
// Construct `members`.
let founders = (0 .. x).map(founder::<T, I>).collect::<Vec<_>>();
let proposer = founders[0].clone();
let fellows = (0 .. y).map(fellow::<T, I>).collect::<Vec<_>>();
let mut members = Vec::with_capacity(founders.len() + fellows.len());
members.extend(founders.clone());
members.extend(fellows.clone());
Alliance::<T, I>::init_members(SystemOrigin::Root.into(), founders, fellows, vec![])?;
// Threshold is 1 less than the number of members so that one person can vote nay
let threshold = m - 1;
// Add previous proposals
let mut last_hash = T::Hash::default();
for i in 0 .. p {
// Proposals should be different so that different proposal hashes are generated
let proposal: T::Proposal = AllianceCall::<T, I>::set_rule {
rule: rule(vec![i as u8; b as usize])
}.into();
Alliance::<T, I>::propose(
SystemOrigin::Signed(proposer.clone()).into(),
threshold,
Box::new(proposal.clone()),
b,
)?;
last_hash = T::Hashing::hash_of(&proposal);
}
let index = p - 1;
// Have almost everyone vote aye on last proposal, while keeping it from passing.
for j in 0 .. m - 3 {
let voter = &members[j as usize];
Alliance::<T, I>::vote(
SystemOrigin::Signed(voter.clone()).into(),
last_hash.clone(),
index,
true,
)?;
}
let voter = members[m as usize - 3].clone();
// Voter votes aye without resolving the vote.
Alliance::<T, I>::vote(
SystemOrigin::Signed(voter.clone()).into(),
last_hash.clone(),
index,
true,
)?;
// Voter switches vote to nay, but does not kill the vote, just updates + inserts
let approve = false;
// Whitelist voter account from further DB operations.
let voter_key = frame_system::Account::<T>::hashed_key_for(&voter);
frame_benchmarking::benchmarking::add_to_whitelist(voter_key.into());
}: _(SystemOrigin::Signed(voter), last_hash.clone(), index, approve)
verify {
}
veto {
let p in 1 .. T::MaxProposals::get();
let m = 3;
let b = MAX_BYTES;
let bytes_in_storage = b + size_of::<Cid>() as u32 + 32;
// Construct `members`.
let founders = (0 .. m).map(founder::<T, I>).collect::<Vec<_>>();
let vetor = founders[0].clone();
Alliance::<T, I>::init_members(SystemOrigin::Root.into(), founders, vec![], vec![])?;
// Threshold is one less than total members so that two nays will disapprove the vote
let threshold = m - 1;
// Add proposals
let mut last_hash = T::Hash::default();
for i in 0 .. p {
// Proposals should be different so that different proposal hashes are generated
let proposal: T::Proposal = AllianceCall::<T, I>::set_rule {
rule: rule(vec![i as u8; b as usize])
}.into();
Alliance::<T, I>::propose(
SystemOrigin::Signed(vetor.clone()).into(),
threshold,
Box::new(proposal.clone()),
bytes_in_storage,
)?;
last_hash = T::Hashing::hash_of(&proposal);
}
}: _(SystemOrigin::Signed(vetor), last_hash.clone())
verify {
// The proposal is removed
assert_eq!(T::ProposalProvider::proposal_of(last_hash), None);
}
close_early_disapproved {
// We choose 4 (2 founders + 2 fellows) as a minimum so we always trigger a vote in the voting loop (`for j in ...`)
let x in 2 .. T::MaxFounders::get();
let y in 2 .. T::MaxFellows::get();
let p in 1 .. T::MaxProposals::get();
let m = x + y;
let bytes = 100;
let bytes_in_storage = bytes + size_of::<Cid>() as u32 + 32;
// Construct `members`.
let founders = (0 .. x).map(founder::<T, I>).collect::<Vec<_>>();
let fellows = (0 .. y).map(fellow::<T, I>).collect::<Vec<_>>();
let mut members = Vec::with_capacity(founders.len() + fellows.len());
members.extend(founders.clone());
members.extend(fellows.clone());
Alliance::<T, I>::init_members(SystemOrigin::Root.into(), founders, fellows, vec![])?;
let proposer = members[0].clone();
let voter = members[1].clone();
// Threshold is total members so that one nay will disapprove the vote
let threshold = m;
// Add previous proposals
let mut last_hash = T::Hash::default();
for i in 0 .. p {
// Proposals should be different so that different proposal hashes are generated
let proposal: T::Proposal = AllianceCall::<T, I>::set_rule {
rule: rule(vec![i as u8; bytes as usize])
}.into();
Alliance::<T, I>::propose(
SystemOrigin::Signed(proposer.clone()).into(),
threshold,
Box::new(proposal.clone()),
bytes_in_storage,
)?;
last_hash = T::Hashing::hash_of(&proposal);
assert_eq!(T::ProposalProvider::proposal_of(last_hash), Some(proposal));
}
let index = p - 1;
// Have most everyone vote aye on last proposal, while keeping it from passing.
for j in 2 .. m - 1 {
let voter = &members[j as usize];
Alliance::<T, I>::vote(
SystemOrigin::Signed(voter.clone()).into(),
last_hash.clone(),
index,
true,
)?;
}
// Voter votes aye without resolving the vote.
Alliance::<T, I>::vote(
SystemOrigin::Signed(voter.clone()).into(),
last_hash.clone(),
index,
true,
)?;
// Voter switches vote to nay, which kills the vote
Alliance::<T, I>::vote(
SystemOrigin::Signed(voter.clone()).into(),
last_hash.clone(),
index,
false,
)?;
// Whitelist voter account from further DB operations.
let voter_key = frame_system::Account::<T>::hashed_key_for(&voter);
frame_benchmarking::benchmarking::add_to_whitelist(voter_key.into());
}: close(SystemOrigin::Signed(voter), last_hash.clone(), index, Weight::max_value(), bytes_in_storage)
verify {
// The last proposal is removed.
assert_eq!(T::ProposalProvider::proposal_of(last_hash), None);
}
close_early_approved {
let b in 1 .. MAX_BYTES;
// We choose 4 (2 founders + 2 fellows) as a minimum so we always trigger a vote in the voting loop (`for j in ...`)
let x in 2 .. T::MaxFounders::get();
let y in 2 .. T::MaxFellows::get();
let p in 1 .. T::MaxProposals::get();
let m = x + y;
let bytes_in_storage = b + size_of::<Cid>() as u32 + 32;
// Construct `members`.
let founders = (0 .. x).map(founder::<T, I>).collect::<Vec<_>>();
let fellows = (0 .. y).map(fellow::<T, I>).collect::<Vec<_>>();
let mut members = Vec::with_capacity(founders.len() + fellows.len());
members.extend(founders.clone());
members.extend(fellows.clone());
Alliance::<T, I>::init_members(SystemOrigin::Root.into(), founders, fellows, vec![])?;
let proposer = members[0].clone();
let voter = members[1].clone();
// Threshold is 2 so any two ayes will approve the vote
let threshold = 2;
// Add previous proposals
let mut last_hash = T::Hash::default();
for i in 0 .. p {
// Proposals should be different so that different proposal hashes are generated
let proposal: T::Proposal = AllianceCall::<T, I>::set_rule {
rule: rule(vec![i as u8; b as usize])
}.into();
Alliance::<T, I>::propose(
SystemOrigin::Signed(proposer.clone()).into(),
threshold,
Box::new(proposal.clone()),
bytes_in_storage,
)?;
last_hash = T::Hashing::hash_of(&proposal);
assert_eq!(T::ProposalProvider::proposal_of(last_hash), Some(proposal));
}
let index = p - 1;
// Caller switches vote to nay on their own proposal, allowing them to be the deciding approval vote
Alliance::<T, I>::vote(
SystemOrigin::Signed(proposer.clone()).into(),
last_hash.clone(),
index,
false,
)?;
// Have almost everyone vote nay on last proposal, while keeping it from failing.
for j in 2 .. m - 1 {
let voter = &members[j as usize];
Alliance::<T, I>::vote(
SystemOrigin::Signed(voter.clone()).into(),
last_hash.clone(),
index,
false,
)?;
}
// Member zero is the first aye
Alliance::<T, I>::vote(
SystemOrigin::Signed(members[0].clone()).into(),
last_hash.clone(),
index,
true,
)?;
let voter = members[1].clone();
// Caller switches vote to aye, which passes the vote
Alliance::<T, I>::vote(
SystemOrigin::Signed(voter.clone()).into(),
last_hash.clone(),
index,
true,
)?;
}: close(SystemOrigin::Signed(voter), last_hash.clone(), index, Weight::max_value(), bytes_in_storage)
verify {
// The last proposal is removed.
assert_eq!(T::ProposalProvider::proposal_of(last_hash), None);
}
close_disapproved {
// We choose 2 (2 founders / 2 fellows) as a minimum so we always trigger a vote in the voting loop (`for j in ...`)
let x in 2 .. T::MaxFounders::get();
let y in 2 .. T::MaxFellows::get();
let p in 1 .. T::MaxProposals::get();
let m = x + y;
let bytes = 100;
let bytes_in_storage = bytes + size_of::<Cid>() as u32 + 32;
// Construct `members`.
let founders = (0 .. x).map(founder::<T, I>).collect::<Vec<_>>();
let fellows = (0 .. y).map(fellow::<T, I>).collect::<Vec<_>>();
let mut members = Vec::with_capacity(founders.len() + fellows.len());
members.extend(founders.clone());
members.extend(fellows.clone());
Alliance::<T, I>::init_members(SystemOrigin::Root.into(), founders, fellows, vec![])?;
let proposer = members[0].clone();
let voter = members[1].clone();
// Threshold is one less than total members so that two nays will disapprove the vote
let threshold = m - 1;
// Add proposals
let mut last_hash = T::Hash::default();
for i in 0 .. p {
// Proposals should be different so that different proposal hashes are generated
let proposal: T::Proposal = AllianceCall::<T, I>::set_rule {
rule: rule(vec![i as u8; bytes as usize])
}.into();
Alliance::<T, I>::propose(
SystemOrigin::Signed(proposer.clone()).into(),
threshold,
Box::new(proposal.clone()),
bytes_in_storage,
)?;
last_hash = T::Hashing::hash_of(&proposal);
assert_eq!(T::ProposalProvider::proposal_of(last_hash), Some(proposal));
}
let index = p - 1;
// Have almost everyone vote aye on last proposal, while keeping it from passing.
// A few abstainers will be the nay votes needed to fail the vote.
for j in 2 .. m - 1 {
let voter = &members[j as usize];
Alliance::<T, I>::vote(
SystemOrigin::Signed(voter.clone()).into(),
last_hash.clone(),
index,
true,
)?;
}
Alliance::<T, I>::vote(
SystemOrigin::Signed(voter.clone()).into(),
last_hash.clone(),
index,
false,
)?;
System::<T>::set_block_number(T::BlockNumber::max_value());
}: close(SystemOrigin::Signed(voter), last_hash.clone(), index, Weight::max_value(), bytes_in_storage)
verify {
// The last proposal is removed.
assert_eq!(T::ProposalProvider::proposal_of(last_hash), None);
}
close_approved {
let b in 1 .. MAX_BYTES;
// We choose 4 (2 founders + 2 fellows) as a minimum so we always trigger a vote in the voting loop (`for j in ...`)
let x in 2 .. T::MaxFounders::get();
let y in 2 .. T::MaxFellows::get();
let p in 1 .. T::MaxProposals::get();
let m = x + y;
let bytes_in_storage = b + size_of::<Cid>() as u32 + 32;
// Construct `members`.
let founders = (0 .. x).map(founder::<T, I>).collect::<Vec<_>>();
let fellows = (0 .. y).map(fellow::<T, I>).collect::<Vec<_>>();
let mut members = Vec::with_capacity(founders.len() + fellows.len());
members.extend(founders.clone());
members.extend(fellows.clone());
Alliance::<T, I>::init_members(SystemOrigin::Root.into(), founders, fellows, vec![])?;
let proposer = members[0].clone();
let voter = members[1].clone();
// Threshold is two, so any two ayes will pass the vote
let threshold = 2;
// Add proposals
let mut last_hash = T::Hash::default();
for i in 0 .. p {
// Proposals should be different so that different proposal hashes are generated
let proposal: T::Proposal = AllianceCall::<T, I>::set_rule {
rule: rule(vec![i as u8; b as usize])
}.into();
Alliance::<T, I>::propose(
SystemOrigin::Signed(proposer.clone()).into(),
threshold,
Box::new(proposal.clone()),
bytes_in_storage,
)?;
last_hash = T::Hashing::hash_of(&proposal);
assert_eq!(T::ProposalProvider::proposal_of(last_hash), Some(proposal));
}
// The prime member votes aye, so abstentions default to aye.
Alliance::<T, I>::vote(
SystemOrigin::Signed(proposer.clone()).into(),
last_hash.clone(),
p - 1,
true // Vote aye.
)?;
let index = p - 1;
// Have almost everyone vote nay on last proposal, while keeping it from failing.
// A few abstainers will be the aye votes needed to pass the vote.
for j in 2 .. m - 1 {
let voter = &members[j as usize];
Alliance::<T, I>::vote(
SystemOrigin::Signed(voter.clone()).into(),
last_hash.clone(),
index,
false
)?;
}
// caller is prime, prime already votes aye by creating the proposal
System::<T>::set_block_number(T::BlockNumber::max_value());
}: close(SystemOrigin::Signed(voter), last_hash.clone(), index, Weight::max_value(), bytes_in_storage)
verify {
// The last proposal is removed.
assert_eq!(T::ProposalProvider::proposal_of(last_hash), None);
}
init_members {
// at least 2 founders
let x in 2 .. T::MaxFounders::get();
let y in 0 .. T::MaxFellows::get();
let z in 0 .. T::MaxAllies::get();
let mut founders = (2 .. x).map(founder::<T, I>).collect::<Vec<_>>();
let mut fellows = (0 .. y).map(fellow::<T, I>).collect::<Vec<_>>();
let mut allies = (0 .. z).map(ally::<T, I>).collect::<Vec<_>>();
}: _(SystemOrigin::Root, founders.clone(), fellows.clone(), allies.clone())
verify {
founders.sort();
fellows.sort();
allies.sort();
assert_last_event::<T, I>(Event::MembersInitialized {
founders: founders.clone(),
fellows: fellows.clone(),
allies: allies.clone(),
}.into());
assert_eq!(Alliance::<T, I>::members(MemberRole::Founder), founders);
assert_eq!(Alliance::<T, I>::members(MemberRole::Fellow), fellows);
assert_eq!(Alliance::<T, I>::members(MemberRole::Ally), allies);
}
set_rule {
set_members::<T, I>();
let rule = rule(b"hello world");
let call = Call::<T, I>::set_rule { rule: rule.clone() };
let origin = T::AdminOrigin::successful_origin();
}: { call.dispatch_bypass_filter(origin)? }
verify {
assert_eq!(Alliance::<T, I>::rule(), Some(rule.clone()));
assert_last_event::<T, I>(Event::NewRuleSet { rule }.into());
}
announce {
set_members::<T, I>();
let announcement = announcement(b"hello world");
let call = Call::<T, I>::announce { announcement: announcement.clone() };
let origin = T::AnnouncementOrigin::successful_origin();
}: { call.dispatch_bypass_filter(origin)? }
verify {
assert!(Alliance::<T, I>::announcements().contains(&announcement));
assert_last_event::<T, I>(Event::Announced { announcement }.into());
}
remove_announcement {
set_members::<T, I>();
let announcement = announcement(b"hello world");
let announcements: BoundedVec<_, T::MaxAnnouncementsCount> = BoundedVec::try_from(vec![announcement.clone()]).unwrap();
Announcements::<T, I>::put(announcements);
let call = Call::<T, I>::remove_announcement { announcement: announcement.clone() };
let origin = T::AnnouncementOrigin::successful_origin();
}: { call.dispatch_bypass_filter(origin)? }
verify {
assert!(Alliance::<T, I>::announcements().is_empty());
assert_last_event::<T, I>(Event::AnnouncementRemoved { announcement }.into());
}
join_alliance {
set_members::<T, I>();
let outsider = outsider::<T, I>(1);
assert!(!Alliance::<T, I>::is_member(&outsider));
assert_eq!(DepositOf::<T, I>::get(&outsider), None);
}: _(SystemOrigin::Signed(outsider.clone()))
verify {
assert!(Alliance::<T, I>::is_member_of(&outsider, MemberRole::Ally)); // outsider is now an ally
assert_eq!(DepositOf::<T, I>::get(&outsider), Some(T::AllyDeposit::get())); // with a deposit
assert!(!Alliance::<T, I>::has_voting_rights(&outsider)); // allies don't have voting rights
assert_last_event::<T, I>(Event::NewAllyJoined {
ally: outsider,
nominator: None,
reserved: Some(T::AllyDeposit::get())
}.into());
}
nominate_ally {
set_members::<T, I>();
let founder1 = founder::<T, I>(1);
assert!(Alliance::<T, I>::is_member_of(&founder1, MemberRole::Founder));
let outsider = outsider::<T, I>(1);
assert!(!Alliance::<T, I>::is_member(&outsider));
assert_eq!(DepositOf::<T, I>::get(&outsider), None);
let outsider_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(outsider.clone());
}: _(SystemOrigin::Signed(founder1.clone()), outsider_lookup)
verify {
assert!(Alliance::<T, I>::is_member_of(&outsider, MemberRole::Ally)); // outsider is now an ally
assert_eq!(DepositOf::<T, I>::get(&outsider), None); // without a deposit
assert!(!Alliance::<T, I>::has_voting_rights(&outsider)); // allies don't have voting rights
assert_last_event::<T, I>(Event::NewAllyJoined {
ally: outsider,
nominator: Some(founder1),
reserved: None
}.into());
}
elevate_ally {
set_members::<T, I>();
let ally1 = ally::<T, I>(1);
assert!(Alliance::<T, I>::is_ally(&ally1));
let ally1_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(ally1.clone());
let call = Call::<T, I>::elevate_ally { ally: ally1_lookup };
let origin = T::MembershipManager::successful_origin();
}: { call.dispatch_bypass_filter(origin)? }
verify {
assert!(!Alliance::<T, I>::is_ally(&ally1));
assert!(Alliance::<T, I>::is_fellow(&ally1));
assert_last_event::<T, I>(Event::AllyElevated { ally: ally1 }.into());
}
retire {
set_members::<T, I>();
let fellow2 = fellow::<T, I>(2);
assert!(Alliance::<T, I>::is_fellow(&fellow2));
assert!(!Alliance::<T, I>::is_up_for_kicking(&fellow2));
assert_eq!(DepositOf::<T, I>::get(&fellow2), Some(T::AllyDeposit::get()));
}: _(SystemOrigin::Signed(fellow2.clone()))
verify {
assert!(!Alliance::<T, I>::is_member(&fellow2));
assert_eq!(DepositOf::<T, I>::get(&fellow2), None);
assert_last_event::<T, I>(Event::MemberRetired {
member: fellow2,
unreserved: Some(T::AllyDeposit::get())
}.into());
}
kick_member {
set_members::<T, I>();
let fellow2 = fellow::<T, I>(2);
UpForKicking::<T, I>::insert(&fellow2, true);
assert!(Alliance::<T, I>::is_member_of(&fellow2, MemberRole::Fellow));
assert!(Alliance::<T, I>::is_up_for_kicking(&fellow2));
assert_eq!(DepositOf::<T, I>::get(&fellow2), Some(T::AllyDeposit::get()));
let fellow2_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(fellow2.clone());
let call = Call::<T, I>::kick_member { who: fellow2_lookup };
let origin = T::MembershipManager::successful_origin();
}: { call.dispatch_bypass_filter(origin)? }
verify {
assert!(!Alliance::<T, I>::is_member(&fellow2));
assert_eq!(DepositOf::<T, I>::get(&fellow2), None);
assert_last_event::<T, I>(Event::MemberKicked {
member: fellow2,
slashed: Some(T::AllyDeposit::get())
}.into());
}
add_unscrupulous_items {
let n in 1 .. T::MaxUnscrupulousItems::get();
let l in 1 .. T::MaxWebsiteUrlLength::get();
set_members::<T, I>();
let accounts = (0 .. n)
.map(|i| generate_unscrupulous_account::<T, I>(i))
.collect::<Vec<_>>();
let websites = (0 .. n).map(|i| -> BoundedVec<u8, T::MaxWebsiteUrlLength> {
BoundedVec::try_from(vec![i as u8; l as usize]).unwrap()
}).collect::<Vec<_>>();
let mut unscrupulous_list = Vec::with_capacity(accounts.len() + websites.len());
unscrupulous_list.extend(accounts.into_iter().map(UnscrupulousItem::AccountId));
unscrupulous_list.extend(websites.into_iter().map(UnscrupulousItem::Website));
let call = Call::<T, I>::add_unscrupulous_items { items: unscrupulous_list.clone() };
let origin = T::AnnouncementOrigin::successful_origin();
}: { call.dispatch_bypass_filter(origin)? }
verify {
assert_last_event::<T, I>(Event::UnscrupulousItemAdded { items: unscrupulous_list }.into());
}
remove_unscrupulous_items {
let n in 1 .. T::MaxUnscrupulousItems::get();
let l in 1 .. T::MaxWebsiteUrlLength::get();
set_members::<T, I>();
let mut accounts = (0 .. n)
.map(|i| generate_unscrupulous_account::<T, I>(i))
.collect::<Vec<_>>();
accounts.sort();
let accounts: BoundedVec<_, T::MaxUnscrupulousItems> = accounts.try_into().unwrap();
UnscrupulousAccounts::<T, I>::put(accounts.clone());
let mut websites = (0 .. n).map(|i| -> BoundedVec<_, T::MaxWebsiteUrlLength>
{ BoundedVec::try_from(vec![i as u8; l as usize]).unwrap() }).collect::<Vec<_>>();
websites.sort();
let websites: BoundedVec<_, T::MaxUnscrupulousItems> = websites.try_into().unwrap();
UnscrupulousWebsites::<T, I>::put(websites.clone());
let mut unscrupulous_list = Vec::with_capacity(accounts.len() + websites.len());
unscrupulous_list.extend(accounts.into_iter().map(UnscrupulousItem::AccountId));
unscrupulous_list.extend(websites.into_iter().map(UnscrupulousItem::Website));
let call = Call::<T, I>::remove_unscrupulous_items { items: unscrupulous_list.clone() };
let origin = T::AnnouncementOrigin::successful_origin();
}: { call.dispatch_bypass_filter(origin)? }
verify {
assert_last_event::<T, I>(Event::UnscrupulousItemRemoved { items: unscrupulous_list }.into());
}
impl_benchmark_test_suite!(Alliance, crate::mock::new_bench_ext(), crate::mock::Test);
}
File diff suppressed because it is too large Load Diff
+324
View File
@@ -0,0 +1,324 @@
// This file is part of Substrate.
// Copyright (C) 2019-2021 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.
//! Test utilities
pub use sp_core::H256;
pub use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
use sp_std::convert::{TryFrom, TryInto};
pub use frame_support::{
assert_ok, ord_parameter_types, parameter_types,
traits::{EitherOfDiverse, GenesisBuild, SortedMembers},
BoundedVec,
};
use frame_system::{EnsureRoot, EnsureSignedBy};
use pallet_identity::{Data, IdentityInfo, Judgement};
pub use crate as pallet_alliance;
use super::*;
parameter_types! {
pub const BlockHashCount: u64 = 250;
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type Origin = Origin;
type Call = Call;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type BlockHashCount = BlockHashCount;
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
pub const MaxLocks: u32 = 10;
}
impl pallet_balances::Config for Test {
type Balance = u64;
type DustRemoval = ();
type Event = Event;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
type MaxLocks = MaxLocks;
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
}
parameter_types! {
pub const MotionDuration: u64 = 3;
pub const MaxProposals: u32 = 100;
pub const MaxMembers: u32 = 100;
}
type AllianceCollective = pallet_collective::Instance1;
impl pallet_collective::Config<AllianceCollective> for Test {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
type MotionDuration = MotionDuration;
type MaxProposals = MaxProposals;
type MaxMembers = MaxMembers;
type DefaultVote = pallet_collective::PrimeDefaultVote;
type WeightInfo = ();
}
parameter_types! {
pub const BasicDeposit: u64 = 10;
pub const FieldDeposit: u64 = 10;
pub const SubAccountDeposit: u64 = 10;
pub const MaxSubAccounts: u32 = 2;
pub const MaxAdditionalFields: u32 = 2;
pub const MaxRegistrars: u32 = 20;
}
ord_parameter_types! {
pub const One: u64 = 1;
pub const Two: u64 = 2;
pub const Three: u64 = 3;
pub const Four: u64 = 4;
pub const Five: u64 = 5;
}
type EnsureOneOrRoot = EitherOfDiverse<EnsureRoot<u64>, EnsureSignedBy<One, u64>>;
type EnsureTwoOrRoot = EitherOfDiverse<EnsureRoot<u64>, EnsureSignedBy<Two, u64>>;
impl pallet_identity::Config for Test {
type Event = Event;
type Currency = Balances;
type BasicDeposit = BasicDeposit;
type FieldDeposit = FieldDeposit;
type SubAccountDeposit = SubAccountDeposit;
type MaxSubAccounts = MaxSubAccounts;
type MaxAdditionalFields = MaxAdditionalFields;
type MaxRegistrars = MaxRegistrars;
type Slashed = ();
type RegistrarOrigin = EnsureOneOrRoot;
type ForceOrigin = EnsureTwoOrRoot;
type WeightInfo = ();
}
pub struct AllianceIdentityVerifier;
impl IdentityVerifier<u64> for AllianceIdentityVerifier {
fn has_identity(who: &u64, fields: u64) -> bool {
Identity::has_identity(who, fields)
}
fn has_good_judgement(who: &u64) -> bool {
if let Some(judgements) =
Identity::identity(who).map(|registration| registration.judgements)
{
judgements
.iter()
.any(|(_, j)| matches!(j, Judgement::KnownGood | Judgement::Reasonable))
} else {
false
}
}
fn super_account_id(who: &u64) -> Option<u64> {
Identity::super_of(who).map(|parent| parent.0)
}
}
pub struct AllianceProposalProvider;
impl ProposalProvider<u64, H256, Call> for AllianceProposalProvider {
fn propose_proposal(
who: u64,
threshold: u32,
proposal: Box<Call>,
length_bound: u32,
) -> Result<(u32, u32), DispatchError> {
AllianceMotion::do_propose_proposed(who, threshold, proposal, length_bound)
}
fn vote_proposal(
who: u64,
proposal: H256,
index: ProposalIndex,
approve: bool,
) -> Result<bool, DispatchError> {
AllianceMotion::do_vote(who, proposal, index, approve)
}
fn veto_proposal(proposal_hash: H256) -> u32 {
AllianceMotion::do_disapprove_proposal(proposal_hash)
}
fn close_proposal(
proposal_hash: H256,
proposal_index: ProposalIndex,
proposal_weight_bound: Weight,
length_bound: u32,
) -> DispatchResultWithPostInfo {
AllianceMotion::do_close(proposal_hash, proposal_index, proposal_weight_bound, length_bound)
}
fn proposal_of(proposal_hash: H256) -> Option<Call> {
AllianceMotion::proposal_of(proposal_hash)
}
}
parameter_types! {
pub const MaxFounders: u32 = 10;
pub const MaxFellows: u32 = MaxMembers::get() - MaxFounders::get();
pub const MaxAllies: u32 = 100;
pub const AllyDeposit: u64 = 25;
}
impl Config for Test {
type Event = Event;
type Proposal = Call;
type AdminOrigin = EnsureSignedBy<One, u64>;
type MembershipManager = EnsureSignedBy<Two, u64>;
type AnnouncementOrigin = EnsureSignedBy<Three, u64>;
type Currency = Balances;
type Slashed = ();
type InitializeMembers = AllianceMotion;
type MembershipChanged = AllianceMotion;
#[cfg(not(feature = "runtime-benchmarks"))]
type IdentityVerifier = AllianceIdentityVerifier;
#[cfg(feature = "runtime-benchmarks")]
type IdentityVerifier = ();
type ProposalProvider = AllianceProposalProvider;
type MaxProposals = MaxProposals;
type MaxFounders = MaxFounders;
type MaxFellows = MaxFellows;
type MaxAllies = MaxAllies;
type MaxUnscrupulousItems = ConstU32<100>;
type MaxWebsiteUrlLength = ConstU32<255>;
type MaxAnnouncementsCount = ConstU32<100>;
type MaxMembersCount = MaxMembers;
type AllyDeposit = AllyDeposit;
type WeightInfo = ();
}
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system,
Balances: pallet_balances,
Identity: pallet_identity,
AllianceMotion: pallet_collective::<Instance1>,
Alliance: pallet_alliance,
}
);
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
pallet_balances::GenesisConfig::<Test> {
balances: vec![(1, 50), (2, 50), (3, 50), (4, 50), (5, 30), (6, 50), (7, 50)],
}
.assimilate_storage(&mut t)
.unwrap();
GenesisBuild::<Test>::assimilate_storage(
&pallet_alliance::GenesisConfig {
founders: vec![],
fellows: vec![],
allies: vec![],
phantom: Default::default(),
},
&mut t,
)
.unwrap();
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| {
assert_ok!(Identity::add_registrar(Origin::signed(1), 1));
let info = IdentityInfo {
additional: BoundedVec::default(),
display: Data::Raw(b"name".to_vec().try_into().unwrap()),
legal: Data::default(),
web: Data::Raw(b"website".to_vec().try_into().unwrap()),
riot: Data::default(),
email: Data::default(),
pgp_fingerprint: None,
image: Data::default(),
twitter: Data::default(),
};
assert_ok!(Identity::set_identity(Origin::signed(1), Box::new(info.clone())));
assert_ok!(Identity::provide_judgement(Origin::signed(1), 0, 1, Judgement::KnownGood));
assert_ok!(Identity::set_identity(Origin::signed(2), Box::new(info.clone())));
assert_ok!(Identity::provide_judgement(Origin::signed(1), 0, 2, Judgement::KnownGood));
assert_ok!(Identity::set_identity(Origin::signed(3), Box::new(info.clone())));
assert_ok!(Identity::provide_judgement(Origin::signed(1), 0, 3, Judgement::KnownGood));
assert_ok!(Identity::set_identity(Origin::signed(4), Box::new(info.clone())));
assert_ok!(Identity::provide_judgement(Origin::signed(1), 0, 4, Judgement::KnownGood));
assert_ok!(Identity::set_identity(Origin::signed(5), Box::new(info.clone())));
assert_ok!(Identity::provide_judgement(Origin::signed(1), 0, 5, Judgement::KnownGood));
assert_ok!(Identity::set_identity(Origin::signed(6), Box::new(info.clone())));
assert_ok!(Alliance::init_members(Origin::root(), vec![1, 2], vec![3], vec![]));
System::set_block_number(1);
});
ext
}
#[cfg(feature = "runtime-benchmarks")]
pub fn new_bench_ext() -> sp_io::TestExternalities {
GenesisConfig::default().build_storage().unwrap().into()
}
pub fn test_cid() -> Cid {
use sha2::{Digest, Sha256};
let mut hasher = Sha256::new();
hasher.update(b"hello world");
let result = hasher.finalize();
Cid::new_v0(&*result)
}
pub fn make_proposal(value: u64) -> Call {
Call::System(frame_system::Call::remark { remark: value.encode() })
}
pub fn make_set_rule_proposal(rule: Cid) -> Call {
Call::Alliance(pallet_alliance::Call::set_rule { rule })
}
pub fn make_kick_member_proposal(who: u64) -> Call {
Call::Alliance(pallet_alliance::Call::kick_member { who })
}
+483
View File
@@ -0,0 +1,483 @@
// This file is part of Substrate.
// Copyright (C) 2019-2021 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.
//! Tests for the alliance pallet.
use sp_runtime::traits::Hash;
use frame_support::{assert_noop, assert_ok, Hashable};
use frame_system::{EventRecord, Phase};
use super::*;
use crate::mock::*;
type AllianceMotionEvent = pallet_collective::Event<Test, pallet_collective::Instance1>;
#[test]
fn propose_works() {
new_test_ext().execute_with(|| {
let proposal = make_proposal(42);
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
let hash: H256 = proposal.blake2_256().into();
// only votable member can propose proposal, 4 is ally not have vote rights
assert_noop!(
Alliance::propose(Origin::signed(4), 3, Box::new(proposal.clone()), proposal_len),
Error::<Test, ()>::NoVotingRights
);
assert_ok!(Alliance::propose(
Origin::signed(1),
3,
Box::new(proposal.clone()),
proposal_len
));
assert_eq!(*AllianceMotion::proposals(), vec![hash]);
assert_eq!(AllianceMotion::proposal_of(&hash), Some(proposal));
assert_eq!(
System::events(),
vec![EventRecord {
phase: Phase::Initialization,
event: mock::Event::AllianceMotion(AllianceMotionEvent::Proposed {
account: 1,
proposal_index: 0,
proposal_hash: hash,
threshold: 3,
}),
topics: vec![],
}]
);
});
}
#[test]
fn vote_works() {
new_test_ext().execute_with(|| {
let proposal = make_proposal(42);
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
let hash: H256 = proposal.blake2_256().into();
assert_ok!(Alliance::propose(
Origin::signed(1),
3,
Box::new(proposal.clone()),
proposal_len
));
assert_ok!(Alliance::vote(Origin::signed(2), hash.clone(), 0, true));
let record = |event| EventRecord { phase: Phase::Initialization, event, topics: vec![] };
assert_eq!(
System::events(),
vec![
record(mock::Event::AllianceMotion(AllianceMotionEvent::Proposed {
account: 1,
proposal_index: 0,
proposal_hash: hash.clone(),
threshold: 3
})),
record(mock::Event::AllianceMotion(AllianceMotionEvent::Voted {
account: 2,
proposal_hash: hash.clone(),
voted: true,
yes: 1,
no: 0,
})),
]
);
});
}
#[test]
fn veto_works() {
new_test_ext().execute_with(|| {
let proposal = make_proposal(42);
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
let hash: H256 = proposal.blake2_256().into();
assert_ok!(Alliance::propose(
Origin::signed(1),
3,
Box::new(proposal.clone()),
proposal_len
));
// only set_rule/elevate_ally can be veto
assert_noop!(
Alliance::veto(Origin::signed(1), hash.clone()),
Error::<Test, ()>::NotVetoableProposal
);
let cid = test_cid();
let vetoable_proposal = make_set_rule_proposal(cid);
let vetoable_proposal_len: u32 = vetoable_proposal.using_encoded(|p| p.len() as u32);
let vetoable_hash: H256 = vetoable_proposal.blake2_256().into();
assert_ok!(Alliance::propose(
Origin::signed(1),
3,
Box::new(vetoable_proposal.clone()),
vetoable_proposal_len
));
// only founder have veto rights, 3 is fellow
assert_noop!(
Alliance::veto(Origin::signed(3), vetoable_hash.clone()),
Error::<Test, ()>::NotFounder
);
assert_ok!(Alliance::veto(Origin::signed(2), vetoable_hash.clone()));
let record = |event| EventRecord { phase: Phase::Initialization, event, topics: vec![] };
assert_eq!(
System::events(),
vec![
record(mock::Event::AllianceMotion(AllianceMotionEvent::Proposed {
account: 1,
proposal_index: 0,
proposal_hash: hash.clone(),
threshold: 3
})),
record(mock::Event::AllianceMotion(AllianceMotionEvent::Proposed {
account: 1,
proposal_index: 1,
proposal_hash: vetoable_hash.clone(),
threshold: 3
})),
record(mock::Event::AllianceMotion(AllianceMotionEvent::Disapproved {
proposal_hash: vetoable_hash.clone()
})),
]
);
})
}
#[test]
fn close_works() {
new_test_ext().execute_with(|| {
let proposal = make_proposal(42);
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
let proposal_weight = proposal.get_dispatch_info().weight;
let hash = BlakeTwo256::hash_of(&proposal);
assert_ok!(Alliance::propose(
Origin::signed(1),
3,
Box::new(proposal.clone()),
proposal_len
));
assert_ok!(Alliance::vote(Origin::signed(1), hash.clone(), 0, true));
assert_ok!(Alliance::vote(Origin::signed(2), hash.clone(), 0, true));
assert_ok!(Alliance::vote(Origin::signed(3), hash.clone(), 0, true));
assert_ok!(Alliance::close(
Origin::signed(1),
hash.clone(),
0,
proposal_weight,
proposal_len
));
let record = |event| EventRecord { phase: Phase::Initialization, event, topics: vec![] };
assert_eq!(
System::events(),
vec![
record(mock::Event::AllianceMotion(AllianceMotionEvent::Proposed {
account: 1,
proposal_index: 0,
proposal_hash: hash.clone(),
threshold: 3
})),
record(mock::Event::AllianceMotion(AllianceMotionEvent::Voted {
account: 1,
proposal_hash: hash.clone(),
voted: true,
yes: 1,
no: 0,
})),
record(mock::Event::AllianceMotion(AllianceMotionEvent::Voted {
account: 2,
proposal_hash: hash.clone(),
voted: true,
yes: 2,
no: 0,
})),
record(mock::Event::AllianceMotion(AllianceMotionEvent::Voted {
account: 3,
proposal_hash: hash.clone(),
voted: true,
yes: 3,
no: 0,
})),
record(mock::Event::AllianceMotion(AllianceMotionEvent::Closed {
proposal_hash: hash.clone(),
yes: 3,
no: 0,
})),
record(mock::Event::AllianceMotion(AllianceMotionEvent::Approved {
proposal_hash: hash.clone()
})),
record(mock::Event::AllianceMotion(AllianceMotionEvent::Executed {
proposal_hash: hash.clone(),
result: Err(DispatchError::BadOrigin),
}))
]
);
});
}
#[test]
fn set_rule_works() {
new_test_ext().execute_with(|| {
let cid = test_cid();
assert_ok!(Alliance::set_rule(Origin::signed(1), cid.clone()));
assert_eq!(Alliance::rule(), Some(cid.clone()));
System::assert_last_event(mock::Event::Alliance(crate::Event::NewRuleSet { rule: cid }));
});
}
#[test]
fn announce_works() {
new_test_ext().execute_with(|| {
let cid = test_cid();
assert_ok!(Alliance::announce(Origin::signed(3), cid.clone()));
assert_eq!(Alliance::announcements(), vec![cid.clone()]);
System::assert_last_event(mock::Event::Alliance(crate::Event::Announced {
announcement: cid,
}));
});
}
#[test]
fn remove_announcement_works() {
new_test_ext().execute_with(|| {
let cid = test_cid();
assert_ok!(Alliance::announce(Origin::signed(3), cid.clone()));
assert_eq!(Alliance::announcements(), vec![cid.clone()]);
System::assert_last_event(mock::Event::Alliance(crate::Event::Announced {
announcement: cid.clone(),
}));
System::set_block_number(2);
assert_ok!(Alliance::remove_announcement(Origin::signed(3), cid.clone()));
assert_eq!(Alliance::announcements(), vec![]);
System::assert_last_event(mock::Event::Alliance(crate::Event::AnnouncementRemoved {
announcement: cid,
}));
});
}
#[test]
fn join_alliance_works() {
new_test_ext().execute_with(|| {
// check already member
assert_noop!(Alliance::join_alliance(Origin::signed(1)), Error::<Test, ()>::AlreadyMember);
// check already listed as unscrupulous
assert_ok!(Alliance::add_unscrupulous_items(
Origin::signed(3),
vec![UnscrupulousItem::AccountId(4)]
));
assert_noop!(
Alliance::join_alliance(Origin::signed(4)),
Error::<Test, ()>::AccountNonGrata
);
assert_ok!(Alliance::remove_unscrupulous_items(
Origin::signed(3),
vec![UnscrupulousItem::AccountId(4)]
));
// check deposit funds
assert_noop!(
Alliance::join_alliance(Origin::signed(5)),
Error::<Test, ()>::InsufficientFunds
);
// success to submit
assert_ok!(Alliance::join_alliance(Origin::signed(4)));
assert_eq!(Alliance::deposit_of(4), Some(25));
assert_eq!(Alliance::members(MemberRole::Ally), vec![4]);
// check already member
assert_noop!(Alliance::join_alliance(Origin::signed(4)), Error::<Test, ()>::AlreadyMember);
// check missing identity judgement
#[cfg(not(feature = "runtime-benchmarks"))]
assert_noop!(
Alliance::join_alliance(Origin::signed(6)),
Error::<Test, ()>::WithoutGoodIdentityJudgement
);
// check missing identity info
#[cfg(not(feature = "runtime-benchmarks"))]
assert_noop!(
Alliance::join_alliance(Origin::signed(7)),
Error::<Test, ()>::WithoutIdentityDisplayAndWebsite
);
});
}
#[test]
fn nominate_ally_works() {
new_test_ext().execute_with(|| {
// check already member
assert_noop!(
Alliance::nominate_ally(Origin::signed(1), 2),
Error::<Test, ()>::AlreadyMember
);
// only votable member(founder/fellow) have nominate right
assert_noop!(
Alliance::nominate_ally(Origin::signed(5), 4),
Error::<Test, ()>::NoVotingRights
);
// check already listed as unscrupulous
assert_ok!(Alliance::add_unscrupulous_items(
Origin::signed(3),
vec![UnscrupulousItem::AccountId(4)]
));
assert_noop!(
Alliance::nominate_ally(Origin::signed(1), 4),
Error::<Test, ()>::AccountNonGrata
);
assert_ok!(Alliance::remove_unscrupulous_items(
Origin::signed(3),
vec![UnscrupulousItem::AccountId(4)]
));
// success to nominate
assert_ok!(Alliance::nominate_ally(Origin::signed(1), 4));
assert_eq!(Alliance::deposit_of(4), None);
assert_eq!(Alliance::members(MemberRole::Ally), vec![4]);
// check already member
assert_noop!(
Alliance::nominate_ally(Origin::signed(1), 4),
Error::<Test, ()>::AlreadyMember
);
// check missing identity judgement
#[cfg(not(feature = "runtime-benchmarks"))]
assert_noop!(
Alliance::join_alliance(Origin::signed(6)),
Error::<Test, ()>::WithoutGoodIdentityJudgement
);
// check missing identity info
#[cfg(not(feature = "runtime-benchmarks"))]
assert_noop!(
Alliance::join_alliance(Origin::signed(7)),
Error::<Test, ()>::WithoutIdentityDisplayAndWebsite
);
});
}
#[test]
fn elevate_ally_works() {
new_test_ext().execute_with(|| {
assert_noop!(Alliance::elevate_ally(Origin::signed(2), 4), Error::<Test, ()>::NotAlly);
assert_ok!(Alliance::join_alliance(Origin::signed(4)));
assert_eq!(Alliance::members(MemberRole::Ally), vec![4]);
assert_eq!(Alliance::members(MemberRole::Fellow), vec![3]);
assert_ok!(Alliance::elevate_ally(Origin::signed(2), 4));
assert_eq!(Alliance::members(MemberRole::Ally), Vec::<u64>::new());
assert_eq!(Alliance::members(MemberRole::Fellow), vec![3, 4]);
});
}
#[test]
fn retire_works() {
new_test_ext().execute_with(|| {
let proposal = make_kick_member_proposal(2);
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
assert_ok!(Alliance::propose(
Origin::signed(1),
3,
Box::new(proposal.clone()),
proposal_len
));
assert_noop!(Alliance::retire(Origin::signed(2)), Error::<Test, ()>::UpForKicking);
assert_noop!(Alliance::retire(Origin::signed(4)), Error::<Test, ()>::NotMember);
assert_eq!(Alliance::members(MemberRole::Fellow), vec![3]);
assert_ok!(Alliance::retire(Origin::signed(3)));
assert_eq!(Alliance::members(MemberRole::Fellow), Vec::<u64>::new());
});
}
#[test]
fn kick_member_works() {
new_test_ext().execute_with(|| {
let proposal = make_kick_member_proposal(2);
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
assert_ok!(Alliance::propose(
Origin::signed(1),
3,
Box::new(proposal.clone()),
proposal_len
));
assert_eq!(Alliance::up_for_kicking(2), true);
assert_eq!(Alliance::members(MemberRole::Founder), vec![1, 2]);
assert_ok!(Alliance::kick_member(Origin::signed(2), 2));
assert_eq!(Alliance::members(MemberRole::Founder), vec![1]);
});
}
#[test]
fn add_unscrupulous_items_works() {
new_test_ext().execute_with(|| {
assert_ok!(Alliance::add_unscrupulous_items(
Origin::signed(3),
vec![
UnscrupulousItem::AccountId(3),
UnscrupulousItem::Website("abc".as_bytes().to_vec().try_into().unwrap())
]
));
assert_eq!(Alliance::unscrupulous_accounts().into_inner(), vec![3]);
assert_eq!(Alliance::unscrupulous_websites().into_inner(), vec!["abc".as_bytes().to_vec()]);
assert_noop!(
Alliance::add_unscrupulous_items(
Origin::signed(3),
vec![UnscrupulousItem::AccountId(3)]
),
Error::<Test, ()>::AlreadyUnscrupulous
);
});
}
#[test]
fn remove_unscrupulous_items_works() {
new_test_ext().execute_with(|| {
assert_noop!(
Alliance::remove_unscrupulous_items(
Origin::signed(3),
vec![UnscrupulousItem::AccountId(3)]
),
Error::<Test, ()>::NotListedAsUnscrupulous
);
assert_ok!(Alliance::add_unscrupulous_items(
Origin::signed(3),
vec![UnscrupulousItem::AccountId(3)]
));
assert_eq!(Alliance::unscrupulous_accounts(), vec![3]);
assert_ok!(Alliance::remove_unscrupulous_items(
Origin::signed(3),
vec![UnscrupulousItem::AccountId(3)]
));
assert_eq!(Alliance::unscrupulous_accounts(), Vec::<u64>::new());
});
}
+95
View File
@@ -0,0 +1,95 @@
// This file is part of Substrate.
// Copyright (C) 2022 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.
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{traits::ConstU32, BoundedVec};
use scale_info::TypeInfo;
use sp_runtime::RuntimeDebug;
use sp_std::{convert::TryInto, prelude::*};
/// A Multihash instance that only supports the basic functionality and no hashing.
#[derive(
Clone, PartialEq, Eq, PartialOrd, Ord, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen,
)]
pub struct Multihash {
/// The code of the Multihash.
pub code: u64,
/// The digest.
pub digest: BoundedVec<u8, ConstU32<68>>, // 4 byte dig size + 64 bytes hash digest
}
impl Multihash {
/// Returns the size of the digest.
pub fn size(&self) -> usize {
self.digest.len()
}
}
/// The version of the CID.
#[derive(
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
RuntimeDebug,
Encode,
Decode,
TypeInfo,
MaxEncodedLen,
)]
pub enum Version {
/// CID version 0.
V0,
/// CID version 1.
V1,
}
/// Representation of a CID.
///
/// The generic is about the allocated size of the multihash.
#[derive(
Clone, PartialEq, Eq, PartialOrd, Ord, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen,
)]
pub struct Cid {
/// The version of CID.
pub version: Version,
/// The codec of CID.
pub codec: u64,
/// The multihash of CID.
pub hash: Multihash,
}
impl Cid {
/// Creates a new CIDv0.
pub fn new_v0(sha2_256_digest: impl Into<Vec<u8>>) -> Self {
/// DAG-PB multicodec code
const DAG_PB: u64 = 0x70;
/// The SHA_256 multicodec code
const SHA2_256: u64 = 0x12;
let digest = sha2_256_digest.into();
assert_eq!(digest.len(), 32);
Self {
version: Version::V0,
codec: DAG_PB,
hash: Multihash { code: SHA2_256, digest: digest.try_into().expect("msg") },
}
}
}
+485
View File
@@ -0,0 +1,485 @@
// This file is part of Substrate.
// Copyright (C) 2021 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 pallet_alliance
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2021-10-11, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128
// Executed Command:
// ./target/release/substrate
// benchmark
// --chain=dev
// --steps=50
// --repeat=20
// --pallet=pallet_alliance
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --output=./frame/alliance/src/weights.rs
// --template=./.maintain/frame-weight-template.hbs
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use sp_std::marker::PhantomData;
/// Weight functions needed for pallet_alliance.
pub trait WeightInfo {
fn propose_proposed(b: u32, x: u32, y: u32, p: u32, ) -> Weight;
fn vote(x: u32, y: u32, ) -> Weight;
fn veto(p: u32, ) -> Weight;
fn close_early_disapproved(x: u32, y: u32, p: u32, ) -> Weight;
fn close_early_approved(b: u32, x: u32, y: u32, p: u32, ) -> Weight;
fn close_disapproved(x: u32, y: u32, p: u32, ) -> Weight;
fn close_approved(b: u32, x: u32, y: u32, p: u32, ) -> Weight;
fn init_members(x: u32, y: u32, z: u32, ) -> Weight;
fn set_rule() -> Weight;
fn announce() -> Weight;
fn remove_announcement() -> Weight;
fn join_alliance() -> Weight;
fn nominate_ally() -> Weight;
fn elevate_ally() -> Weight;
fn retire() -> Weight;
fn kick_member() -> Weight;
fn add_unscrupulous_items(n: u32, l: u32, ) -> Weight;
fn remove_unscrupulous_items(n: u32, l: u32, ) -> Weight;
}
/// Weights for pallet_alliance using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Alliance Members (r:1 w:0)
// Storage: AllianceMotion ProposalOf (r:1 w:1)
// Storage: AllianceMotion Proposals (r:1 w:1)
// Storage: AllianceMotion ProposalCount (r:1 w:1)
// Storage: AllianceMotion Voting (r:0 w:1)
fn propose_proposed(_b: u32, _x: u32, y: u32, p: u32, ) -> Weight {
(39_992_000 as Weight)
// Standard Error: 2_000
.saturating_add((44_000 as Weight).saturating_mul(y as Weight))
// Standard Error: 2_000
.saturating_add((323_000 as Weight).saturating_mul(p as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
// Storage: Alliance Members (r:2 w:0)
// Storage: AllianceMotion Voting (r:1 w:1)
fn vote(x: u32, y: u32, ) -> Weight {
(36_649_000 as Weight)
// Standard Error: 90_000
.saturating_add((42_000 as Weight).saturating_mul(x as Weight))
// Standard Error: 3_000
.saturating_add((195_000 as Weight).saturating_mul(y as Weight))
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Alliance Members (r:1 w:0)
// Storage: AllianceMotion ProposalOf (r:1 w:1)
// Storage: AllianceMotion Proposals (r:1 w:1)
// Storage: AllianceMotion Voting (r:0 w:1)
fn veto(p: u32, ) -> Weight {
(30_301_000 as Weight)
// Standard Error: 1_000
.saturating_add((330_000 as Weight).saturating_mul(p as Weight))
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
// Storage: Alliance Members (r:1 w:0)
// Storage: AllianceMotion ProposalOf (r:1 w:1)
// Storage: AllianceMotion Voting (r:1 w:1)
// Storage: AllianceMotion Members (r:1 w:0)
// Storage: AllianceMotion Proposals (r:1 w:1)
fn close_early_disapproved(x: u32, y: u32, p: u32, ) -> Weight {
(40_472_000 as Weight)
// Standard Error: 69_000
.saturating_add((485_000 as Weight).saturating_mul(x as Weight))
// Standard Error: 2_000
.saturating_add((192_000 as Weight).saturating_mul(y as Weight))
// Standard Error: 2_000
.saturating_add((330_000 as Weight).saturating_mul(p as Weight))
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
// Storage: Alliance Members (r:1 w:0)
// Storage: AllianceMotion ProposalOf (r:1 w:1)
// Storage: AllianceMotion Voting (r:1 w:1)
// Storage: AllianceMotion Members (r:1 w:0)
// Storage: AllianceMotion Proposals (r:1 w:1)
fn close_early_approved(b: u32, x: u32, y: u32, p: u32, ) -> Weight {
(52_076_000 as Weight)
// Standard Error: 0
.saturating_add((4_000 as Weight).saturating_mul(b as Weight))
// Standard Error: 77_000
.saturating_add((194_000 as Weight).saturating_mul(x as Weight))
// Standard Error: 3_000
.saturating_add((188_000 as Weight).saturating_mul(y as Weight))
// Standard Error: 2_000
.saturating_add((329_000 as Weight).saturating_mul(p as Weight))
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
// Storage: Alliance Members (r:1 w:0)
// Storage: AllianceMotion ProposalOf (r:1 w:1)
// Storage: AllianceMotion Voting (r:1 w:1)
// Storage: AllianceMotion Members (r:1 w:0)
// Storage: AllianceMotion Prime (r:1 w:0)
// Storage: AllianceMotion Proposals (r:1 w:1)
fn close_disapproved(x: u32, y: u32, p: u32, ) -> Weight {
(47_009_000 as Weight)
// Standard Error: 66_000
.saturating_add((256_000 as Weight).saturating_mul(x as Weight))
// Standard Error: 2_000
.saturating_add((176_000 as Weight).saturating_mul(y as Weight))
// Standard Error: 2_000
.saturating_add((327_000 as Weight).saturating_mul(p as Weight))
.saturating_add(T::DbWeight::get().reads(6 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
// Storage: Alliance Members (r:1 w:0)
// Storage: AllianceMotion ProposalOf (r:1 w:1)
// Storage: AllianceMotion Voting (r:1 w:1)
// Storage: AllianceMotion Members (r:1 w:0)
// Storage: AllianceMotion Prime (r:1 w:0)
// Storage: AllianceMotion Proposals (r:1 w:1)
fn close_approved(b: u32, x: u32, y: u32, p: u32, ) -> Weight {
(43_650_000 as Weight)
// Standard Error: 0
.saturating_add((3_000 as Weight).saturating_mul(b as Weight))
// Standard Error: 85_000
.saturating_add((124_000 as Weight).saturating_mul(x as Weight))
// Standard Error: 3_000
.saturating_add((199_000 as Weight).saturating_mul(y as Weight))
// Standard Error: 3_000
.saturating_add((326_000 as Weight).saturating_mul(p as Weight))
.saturating_add(T::DbWeight::get().reads(6 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
// Storage: Alliance Members (r:3 w:3)
// Storage: AllianceMotion Members (r:1 w:1)
fn init_members(_x: u32, y: u32, z: u32, ) -> Weight {
(45_100_000 as Weight)
// Standard Error: 4_000
.saturating_add((162_000 as Weight).saturating_mul(y as Weight))
// Standard Error: 4_000
.saturating_add((151_000 as Weight).saturating_mul(z as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
// Storage: Alliance Rule (r:0 w:1)
fn set_rule() -> Weight {
(14_517_000 as Weight)
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Alliance Announcements (r:1 w:1)
fn announce() -> Weight {
(16_801_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Alliance Announcements (r:1 w:1)
fn remove_announcement() -> Weight {
(17_133_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Alliance UnscrupulousAccounts (r:1 w:0)
// Storage: Alliance Members (r:4 w:0)
// Storage: System Account (r:1 w:1)
// Storage: Alliance DepositOf (r:0 w:1)
fn join_alliance() -> Weight {
(95_370_000 as Weight)
.saturating_add(T::DbWeight::get().reads(7 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
// Storage: Alliance Members (r:4 w:0)
// Storage: Alliance UnscrupulousAccounts (r:1 w:0)
fn nominate_ally() -> Weight {
(44_764_000 as Weight)
.saturating_add(T::DbWeight::get().reads(6 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Alliance Members (r:3 w:2)
// Storage: AllianceMotion Proposals (r:1 w:0)
// Storage: AllianceMotion Members (r:0 w:1)
// Storage: AllianceMotion Prime (r:0 w:1)
fn elevate_ally() -> Weight {
(44_013_000 as Weight)
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
// Storage: Alliance KickingMembers (r:1 w:0)
// Storage: Alliance Members (r:3 w:1)
// Storage: AllianceMotion Proposals (r:1 w:0)
// Storage: Alliance DepositOf (r:1 w:1)
// Storage: System Account (r:1 w:1)
// Storage: AllianceMotion Members (r:0 w:1)
// Storage: AllianceMotion Prime (r:0 w:1)
fn retire() -> Weight {
(60_183_000 as Weight)
.saturating_add(T::DbWeight::get().reads(7 as Weight))
.saturating_add(T::DbWeight::get().writes(5 as Weight))
}
// Storage: Alliance KickingMembers (r:1 w:0)
// Storage: Alliance Members (r:3 w:1)
// Storage: AllianceMotion Proposals (r:1 w:0)
// Storage: Alliance DepositOf (r:1 w:1)
// Storage: System Account (r:1 w:1)
// Storage: AllianceMotion Members (r:0 w:1)
// Storage: AllianceMotion Prime (r:0 w:1)
fn kick_member() -> Weight {
(67_467_000 as Weight)
.saturating_add(T::DbWeight::get().reads(7 as Weight))
.saturating_add(T::DbWeight::get().writes(5 as Weight))
}
// Storage: Alliance UnscrupulousAccounts (r:1 w:1)
// Storage: Alliance UnscrupulousWebsites (r:1 w:1)
fn add_unscrupulous_items(n: u32, l: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 16_000
.saturating_add((2_673_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 7_000
.saturating_add((224_000 as Weight).saturating_mul(l as Weight))
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: Alliance UnscrupulousAccounts (r:1 w:1)
// Storage: Alliance UnscrupulousWebsites (r:1 w:1)
fn remove_unscrupulous_items(n: u32, l: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 343_000
.saturating_add((59_025_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 153_000
.saturating_add((6_725_000 as Weight).saturating_mul(l as Weight))
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
}
// For backwards compatibility and tests
impl WeightInfo for () {
// Storage: Alliance Members (r:1 w:0)
// Storage: AllianceMotion ProposalOf (r:1 w:1)
// Storage: AllianceMotion Proposals (r:1 w:1)
// Storage: AllianceMotion ProposalCount (r:1 w:1)
// Storage: AllianceMotion Voting (r:0 w:1)
fn propose_proposed(_b: u32, _x: u32, y: u32, p: u32, ) -> Weight {
(39_992_000 as Weight)
// Standard Error: 2_000
.saturating_add((44_000 as Weight).saturating_mul(y as Weight))
// Standard Error: 2_000
.saturating_add((323_000 as Weight).saturating_mul(p as Weight))
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
}
// Storage: Alliance Members (r:2 w:0)
// Storage: AllianceMotion Voting (r:1 w:1)
fn vote(x: u32, y: u32, ) -> Weight {
(36_649_000 as Weight)
// Standard Error: 90_000
.saturating_add((42_000 as Weight).saturating_mul(x as Weight))
// Standard Error: 3_000
.saturating_add((195_000 as Weight).saturating_mul(y as Weight))
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: Alliance Members (r:1 w:0)
// Storage: AllianceMotion ProposalOf (r:1 w:1)
// Storage: AllianceMotion Proposals (r:1 w:1)
// Storage: AllianceMotion Voting (r:0 w:1)
fn veto(p: u32, ) -> Weight {
(30_301_000 as Weight)
// Standard Error: 1_000
.saturating_add((330_000 as Weight).saturating_mul(p as Weight))
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
}
// Storage: Alliance Members (r:1 w:0)
// Storage: AllianceMotion ProposalOf (r:1 w:1)
// Storage: AllianceMotion Voting (r:1 w:1)
// Storage: AllianceMotion Members (r:1 w:0)
// Storage: AllianceMotion Proposals (r:1 w:1)
fn close_early_disapproved(x: u32, y: u32, p: u32, ) -> Weight {
(40_472_000 as Weight)
// Standard Error: 69_000
.saturating_add((485_000 as Weight).saturating_mul(x as Weight))
// Standard Error: 2_000
.saturating_add((192_000 as Weight).saturating_mul(y as Weight))
// Standard Error: 2_000
.saturating_add((330_000 as Weight).saturating_mul(p as Weight))
.saturating_add(RocksDbWeight::get().reads(5 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
}
// Storage: Alliance Members (r:1 w:0)
// Storage: AllianceMotion ProposalOf (r:1 w:1)
// Storage: AllianceMotion Voting (r:1 w:1)
// Storage: AllianceMotion Members (r:1 w:0)
// Storage: AllianceMotion Proposals (r:1 w:1)
fn close_early_approved(b: u32, x: u32, y: u32, p: u32, ) -> Weight {
(52_076_000 as Weight)
// Standard Error: 0
.saturating_add((4_000 as Weight).saturating_mul(b as Weight))
// Standard Error: 77_000
.saturating_add((194_000 as Weight).saturating_mul(x as Weight))
// Standard Error: 3_000
.saturating_add((188_000 as Weight).saturating_mul(y as Weight))
// Standard Error: 2_000
.saturating_add((329_000 as Weight).saturating_mul(p as Weight))
.saturating_add(RocksDbWeight::get().reads(5 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
}
// Storage: Alliance Members (r:1 w:0)
// Storage: AllianceMotion ProposalOf (r:1 w:1)
// Storage: AllianceMotion Voting (r:1 w:1)
// Storage: AllianceMotion Members (r:1 w:0)
// Storage: AllianceMotion Prime (r:1 w:0)
// Storage: AllianceMotion Proposals (r:1 w:1)
fn close_disapproved(x: u32, y: u32, p: u32, ) -> Weight {
(47_009_000 as Weight)
// Standard Error: 66_000
.saturating_add((256_000 as Weight).saturating_mul(x as Weight))
// Standard Error: 2_000
.saturating_add((176_000 as Weight).saturating_mul(y as Weight))
// Standard Error: 2_000
.saturating_add((327_000 as Weight).saturating_mul(p as Weight))
.saturating_add(RocksDbWeight::get().reads(6 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
}
// Storage: Alliance Members (r:1 w:0)
// Storage: AllianceMotion ProposalOf (r:1 w:1)
// Storage: AllianceMotion Voting (r:1 w:1)
// Storage: AllianceMotion Members (r:1 w:0)
// Storage: AllianceMotion Prime (r:1 w:0)
// Storage: AllianceMotion Proposals (r:1 w:1)
fn close_approved(b: u32, x: u32, y: u32, p: u32, ) -> Weight {
(43_650_000 as Weight)
// Standard Error: 0
.saturating_add((3_000 as Weight).saturating_mul(b as Weight))
// Standard Error: 85_000
.saturating_add((124_000 as Weight).saturating_mul(x as Weight))
// Standard Error: 3_000
.saturating_add((199_000 as Weight).saturating_mul(y as Weight))
// Standard Error: 3_000
.saturating_add((326_000 as Weight).saturating_mul(p as Weight))
.saturating_add(RocksDbWeight::get().reads(6 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
}
// Storage: Alliance Members (r:3 w:3)
// Storage: AllianceMotion Members (r:1 w:1)
fn init_members(_x: u32, y: u32, z: u32, ) -> Weight {
(45_100_000 as Weight)
// Standard Error: 4_000
.saturating_add((162_000 as Weight).saturating_mul(y as Weight))
// Standard Error: 4_000
.saturating_add((151_000 as Weight).saturating_mul(z as Weight))
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
}
// Storage: Alliance Rule (r:0 w:1)
fn set_rule() -> Weight {
(14_517_000 as Weight)
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: Alliance Announcements (r:1 w:1)
fn announce() -> Weight {
(16_801_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: Alliance Announcements (r:1 w:1)
fn remove_announcement() -> Weight {
(17_133_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: Alliance UnscrupulousAccounts (r:1 w:0)
// Storage: Alliance Members (r:4 w:0)
// Storage: System Account (r:1 w:1)
// Storage: Alliance DepositOf (r:0 w:1)
fn join_alliance() -> Weight {
(95_370_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(7 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
}
// Storage: Alliance Members (r:4 w:0)
// Storage: Alliance UnscrupulousAccounts (r:1 w:0)
fn nominate_ally() -> Weight {
(44_764_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(6 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: Alliance Members (r:3 w:2)
// Storage: AllianceMotion Proposals (r:1 w:0)
// Storage: AllianceMotion Members (r:0 w:1)
// Storage: AllianceMotion Prime (r:0 w:1)
fn elevate_ally() -> Weight {
(44_013_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
}
// Storage: Alliance KickingMembers (r:1 w:0)
// Storage: Alliance Members (r:3 w:1)
// Storage: AllianceMotion Proposals (r:1 w:0)
// Storage: Alliance DepositOf (r:1 w:1)
// Storage: System Account (r:1 w:1)
// Storage: AllianceMotion Members (r:0 w:1)
// Storage: AllianceMotion Prime (r:0 w:1)
fn retire() -> Weight {
(60_183_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(7 as Weight))
.saturating_add(RocksDbWeight::get().writes(5 as Weight))
}
// Storage: Alliance KickingMembers (r:1 w:0)
// Storage: Alliance Members (r:3 w:1)
// Storage: AllianceMotion Proposals (r:1 w:0)
// Storage: Alliance DepositOf (r:1 w:1)
// Storage: System Account (r:1 w:1)
// Storage: AllianceMotion Members (r:0 w:1)
// Storage: AllianceMotion Prime (r:0 w:1)
fn kick_member() -> Weight {
(67_467_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(7 as Weight))
.saturating_add(RocksDbWeight::get().writes(5 as Weight))
}
// Storage: Alliance UnscrupulousAccounts (r:1 w:1)
// Storage: Alliance UnscrupulousWebsites (r:1 w:1)
fn add_unscrupulous_items(n: u32, l: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 16_000
.saturating_add((2_673_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 7_000
.saturating_add((224_000 as Weight).saturating_mul(l as Weight))
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
// Storage: Alliance UnscrupulousAccounts (r:1 w:1)
// Storage: Alliance UnscrupulousWebsites (r:1 w:1)
fn remove_unscrupulous_items(n: u32, l: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 343_000
.saturating_add((59_025_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 153_000
.saturating_add((6_725_000 as Weight).saturating_mul(l as Weight))
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
}