mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 17:01:09 +00:00
Removed pallet::getter usage from pallet-collective (#3456)
Part of #3326 This one is easier as all the storage items are public. @ggwpez @kianenigma @shawntabrizi --------- Signed-off-by: Matteo Muraca <mmuraca247@gmail.com> Co-authored-by: Liam Aharon <liam.aharon@hotmail.com> Co-authored-by: command-bot <> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
@@ -81,7 +81,7 @@ where
|
||||
}
|
||||
|
||||
fn proposal_of(proposal_hash: HashOf<T>) -> Option<ProposalOf<T, I>> {
|
||||
pallet_collective::Pallet::<T, I>::proposal_of(proposal_hash)
|
||||
pallet_collective::ProposalOf::<T, I>::get(proposal_hash)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
|
||||
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
|
||||
|
||||
title: Removed `pallet::getter` usage from `pallet-collective`
|
||||
|
||||
doc:
|
||||
- audience: Runtime Dev
|
||||
description: |
|
||||
This PR removes `pallet::getter` usage from `pallet-collective`, and updates dependant code accordingly.
|
||||
The syntax `StorageItem::<T, I>::get()` should be used instead.
|
||||
|
||||
crates:
|
||||
- name: pallet-collective
|
||||
- name: kitchensink-runtime
|
||||
- name: collectives-westend-runtime
|
||||
@@ -30,8 +30,8 @@ use pallet_identity::legacy::IdentityField;
|
||||
use sp_std::prelude::*;
|
||||
|
||||
use crate::{
|
||||
AccountId, AllianceMotion, Assets, Authorship, Balances, Hash, NegativeImbalance, Runtime,
|
||||
RuntimeCall,
|
||||
AccountId, AllianceCollective, AllianceMotion, Assets, Authorship, Balances, Hash,
|
||||
NegativeImbalance, Runtime, RuntimeCall,
|
||||
};
|
||||
|
||||
pub struct Author;
|
||||
@@ -107,7 +107,7 @@ impl ProposalProvider<AccountId, Hash, RuntimeCall> for AllianceProposalProvider
|
||||
}
|
||||
|
||||
fn proposal_of(proposal_hash: Hash) -> Option<RuntimeCall> {
|
||||
AllianceMotion::proposal_of(proposal_hash)
|
||||
pallet_collective::ProposalOf::<Runtime, AllianceCollective>::get(proposal_hash)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ mod multiplier_tests {
|
||||
let next = runtime_multiplier_update(fm);
|
||||
fm = next;
|
||||
if fm == min_multiplier() {
|
||||
break
|
||||
break;
|
||||
}
|
||||
iterations += 1;
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ impl ProposalProvider<AccountId, H256, RuntimeCall> for AllianceProposalProvider
|
||||
}
|
||||
|
||||
fn proposal_of(proposal_hash: H256) -> Option<RuntimeCall> {
|
||||
AllianceMotion::proposal_of(proposal_hash)
|
||||
pallet_collective::ProposalOf::<Test, Instance1>::get(proposal_hash)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -187,8 +187,8 @@ fn propose_works() {
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_eq!(*AllianceMotion::proposals(), vec![hash]);
|
||||
assert_eq!(AllianceMotion::proposal_of(&hash), Some(proposal));
|
||||
assert_eq!(*pallet_collective::Proposals::<Test, Instance1>::get(), vec![hash]);
|
||||
assert_eq!(pallet_collective::ProposalOf::<Test, Instance1>::get(&hash), Some(proposal));
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
vec![EventRecord {
|
||||
|
||||
@@ -105,7 +105,7 @@ benchmarks_instance_pallet! {
|
||||
}: _(SystemOrigin::Root, new_members.clone(), new_members.last().cloned(), T::MaxMembers::get())
|
||||
verify {
|
||||
new_members.sort();
|
||||
assert_eq!(Collective::<T, I>::members(), new_members);
|
||||
assert_eq!(Members::<T, I>::get(), new_members);
|
||||
}
|
||||
|
||||
execute {
|
||||
@@ -199,14 +199,14 @@ benchmarks_instance_pallet! {
|
||||
)?;
|
||||
}
|
||||
|
||||
assert_eq!(Collective::<T, I>::proposals().len(), (p - 1) as usize);
|
||||
assert_eq!(Proposals::<T, I>::get().len(), (p - 1) as usize);
|
||||
|
||||
let proposal: T::Proposal = SystemCall::<T>::remark { remark: id_to_remark_data(p, b as usize) }.into();
|
||||
|
||||
}: propose(SystemOrigin::Signed(caller.clone()), threshold, Box::new(proposal.clone()), bytes_in_storage)
|
||||
verify {
|
||||
// New proposal is recorded
|
||||
assert_eq!(Collective::<T, I>::proposals().len(), p as usize);
|
||||
assert_eq!(Proposals::<T, I>::get().len(), p as usize);
|
||||
let proposal_hash = T::Hashing::hash_of(&proposal);
|
||||
assert_last_event::<T, I>(Event::Proposed { account: caller, proposal_index: p - 1, proposal_hash, threshold }.into());
|
||||
}
|
||||
@@ -269,7 +269,7 @@ benchmarks_instance_pallet! {
|
||||
approve,
|
||||
)?;
|
||||
|
||||
assert_eq!(Collective::<T, I>::proposals().len(), p as usize);
|
||||
assert_eq!(Proposals::<T, I>::get().len(), p as usize);
|
||||
|
||||
// Voter switches vote to nay, but does not kill the vote, just updates + inserts
|
||||
let approve = false;
|
||||
@@ -280,8 +280,8 @@ benchmarks_instance_pallet! {
|
||||
}: _(SystemOrigin::Signed(voter), last_hash, index, approve)
|
||||
verify {
|
||||
// All proposals exist and the last proposal has just been updated.
|
||||
assert_eq!(Collective::<T, I>::proposals().len(), p as usize);
|
||||
let voting = Collective::<T, I>::voting(&last_hash).ok_or("Proposal Missing")?;
|
||||
assert_eq!(Proposals::<T, I>::get().len(), p as usize);
|
||||
let voting = Voting::<T, I>::get(&last_hash).ok_or("Proposal Missing")?;
|
||||
assert_eq!(voting.ayes.len(), (m - 3) as usize);
|
||||
assert_eq!(voting.nays.len(), 1);
|
||||
}
|
||||
@@ -344,7 +344,7 @@ benchmarks_instance_pallet! {
|
||||
approve,
|
||||
)?;
|
||||
|
||||
assert_eq!(Collective::<T, I>::proposals().len(), p as usize);
|
||||
assert_eq!(Proposals::<T, I>::get().len(), p as usize);
|
||||
|
||||
// Voter switches vote to nay, which kills the vote
|
||||
let approve = false;
|
||||
@@ -361,7 +361,7 @@ benchmarks_instance_pallet! {
|
||||
}: close(SystemOrigin::Signed(voter), last_hash, index, Weight::MAX, bytes_in_storage)
|
||||
verify {
|
||||
// The last proposal is removed.
|
||||
assert_eq!(Collective::<T, I>::proposals().len(), (p - 1) as usize);
|
||||
assert_eq!(Proposals::<T, I>::get().len(), (p - 1) as usize);
|
||||
assert_last_event::<T, I>(Event::Disapproved { proposal_hash: last_hash }.into());
|
||||
}
|
||||
|
||||
@@ -428,7 +428,7 @@ benchmarks_instance_pallet! {
|
||||
true,
|
||||
)?;
|
||||
|
||||
assert_eq!(Collective::<T, I>::proposals().len(), p as usize);
|
||||
assert_eq!(Proposals::<T, I>::get().len(), p as usize);
|
||||
|
||||
// Caller switches vote to aye, which passes the vote
|
||||
let index = p - 1;
|
||||
@@ -442,7 +442,7 @@ benchmarks_instance_pallet! {
|
||||
}: close(SystemOrigin::Signed(caller), last_hash, index, Weight::MAX, bytes_in_storage)
|
||||
verify {
|
||||
// The last proposal is removed.
|
||||
assert_eq!(Collective::<T, I>::proposals().len(), (p - 1) as usize);
|
||||
assert_eq!(Proposals::<T, I>::get().len(), (p - 1) as usize);
|
||||
assert_last_event::<T, I>(Event::Executed { proposal_hash: last_hash, result: Ok(()) }.into());
|
||||
}
|
||||
|
||||
@@ -519,12 +519,12 @@ benchmarks_instance_pallet! {
|
||||
)?;
|
||||
|
||||
System::<T>::set_block_number(BlockNumberFor::<T>::max_value());
|
||||
assert_eq!(Collective::<T, I>::proposals().len(), p as usize);
|
||||
assert_eq!(Proposals::<T, I>::get().len(), p as usize);
|
||||
|
||||
// Prime nay will close it as disapproved
|
||||
}: close(SystemOrigin::Signed(caller), last_hash, index, Weight::MAX, bytes_in_storage)
|
||||
verify {
|
||||
assert_eq!(Collective::<T, I>::proposals().len(), (p - 1) as usize);
|
||||
assert_eq!(Proposals::<T, I>::get().len(), (p - 1) as usize);
|
||||
assert_last_event::<T, I>(Event::Disapproved { proposal_hash: last_hash }.into());
|
||||
}
|
||||
|
||||
@@ -591,12 +591,12 @@ benchmarks_instance_pallet! {
|
||||
|
||||
// caller is prime, prime already votes aye by creating the proposal
|
||||
System::<T>::set_block_number(BlockNumberFor::<T>::max_value());
|
||||
assert_eq!(Collective::<T, I>::proposals().len(), p as usize);
|
||||
assert_eq!(Proposals::<T, I>::get().len(), p as usize);
|
||||
|
||||
// Prime aye will close it as approved
|
||||
}: close(SystemOrigin::Signed(caller), last_hash, p - 1, Weight::MAX, bytes_in_storage)
|
||||
verify {
|
||||
assert_eq!(Collective::<T, I>::proposals().len(), (p - 1) as usize);
|
||||
assert_eq!(Proposals::<T, I>::get().len(), (p - 1) as usize);
|
||||
assert_last_event::<T, I>(Event::Executed { proposal_hash: last_hash, result: Ok(()) }.into());
|
||||
}
|
||||
|
||||
@@ -640,11 +640,11 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
System::<T>::set_block_number(BlockNumberFor::<T>::max_value());
|
||||
assert_eq!(Collective::<T, I>::proposals().len(), p as usize);
|
||||
assert_eq!(Proposals::<T, I>::get().len(), p as usize);
|
||||
|
||||
}: _(SystemOrigin::Root, last_hash)
|
||||
verify {
|
||||
assert_eq!(Collective::<T, I>::proposals().len(), (p - 1) as usize);
|
||||
assert_eq!(Proposals::<T, I>::get().len(), (p - 1) as usize);
|
||||
assert_last_event::<T, I>(Event::Disapproved { proposal_hash: last_hash }.into());
|
||||
}
|
||||
|
||||
|
||||
@@ -261,36 +261,30 @@ pub mod pallet {
|
||||
|
||||
/// The hashes of the active proposals.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn proposals)]
|
||||
pub type Proposals<T: Config<I>, I: 'static = ()> =
|
||||
StorageValue<_, BoundedVec<T::Hash, T::MaxProposals>, ValueQuery>;
|
||||
|
||||
/// Actual proposal for a given hash, if it's current.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn proposal_of)]
|
||||
pub type ProposalOf<T: Config<I>, I: 'static = ()> =
|
||||
StorageMap<_, Identity, T::Hash, <T as Config<I>>::Proposal, OptionQuery>;
|
||||
|
||||
/// Votes on a given proposal, if it is ongoing.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn voting)]
|
||||
pub type Voting<T: Config<I>, I: 'static = ()> =
|
||||
StorageMap<_, Identity, T::Hash, Votes<T::AccountId, BlockNumberFor<T>>, OptionQuery>;
|
||||
|
||||
/// Proposals so far.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn proposal_count)]
|
||||
pub type ProposalCount<T: Config<I>, I: 'static = ()> = StorageValue<_, u32, ValueQuery>;
|
||||
|
||||
/// The current members of the collective. This is stored sorted (just by value).
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn members)]
|
||||
pub type Members<T: Config<I>, I: 'static = ()> =
|
||||
StorageValue<_, Vec<T::AccountId>, ValueQuery>;
|
||||
|
||||
/// The prime member that helps determine the default vote behavior in case of absentations.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn prime)]
|
||||
pub type Prime<T: Config<I>, I: 'static = ()> = StorageValue<_, T::AccountId, OptionQuery>;
|
||||
|
||||
#[pallet::event]
|
||||
@@ -459,7 +453,7 @@ pub mod pallet {
|
||||
#[pallet::compact] length_bound: u32,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
let who = ensure_signed(origin)?;
|
||||
let members = Self::members();
|
||||
let members = Members::<T, I>::get();
|
||||
ensure!(members.contains(&who), Error::<T, I>::NotMember);
|
||||
let proposal_len = proposal.encoded_size();
|
||||
ensure!(proposal_len <= length_bound as usize, Error::<T, I>::WrongProposalLength);
|
||||
@@ -519,7 +513,7 @@ pub mod pallet {
|
||||
#[pallet::compact] length_bound: u32,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
let who = ensure_signed(origin)?;
|
||||
let members = Self::members();
|
||||
let members = Members::<T, I>::get();
|
||||
ensure!(members.contains(&who), Error::<T, I>::NotMember);
|
||||
|
||||
if threshold < 2 {
|
||||
@@ -565,7 +559,7 @@ pub mod pallet {
|
||||
approve: bool,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
let who = ensure_signed(origin)?;
|
||||
let members = Self::members();
|
||||
let members = Members::<T, I>::get();
|
||||
ensure!(members.contains(&who), Error::<T, I>::NotMember);
|
||||
|
||||
// Detects first vote of the member in the motion
|
||||
@@ -669,7 +663,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
pub fn is_member(who: &T::AccountId) -> bool {
|
||||
// Note: The dispatchables *do not* use this to check membership so make sure
|
||||
// to update those if this is changed.
|
||||
Self::members().contains(who)
|
||||
Members::<T, I>::get().contains(who)
|
||||
}
|
||||
|
||||
/// Execute immediately when adding a new proposal.
|
||||
@@ -688,7 +682,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
let proposal_hash = T::Hashing::hash_of(&proposal);
|
||||
ensure!(!<ProposalOf<T, I>>::contains_key(proposal_hash), Error::<T, I>::DuplicateProposal);
|
||||
|
||||
let seats = Self::members().len() as MemberCount;
|
||||
let seats = Members::<T, I>::get().len() as MemberCount;
|
||||
let result = proposal.dispatch(RawOrigin::Members(1, seats).into());
|
||||
Self::deposit_event(Event::Executed {
|
||||
proposal_hash,
|
||||
@@ -721,7 +715,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
Ok(proposals.len())
|
||||
})?;
|
||||
|
||||
let index = Self::proposal_count();
|
||||
let index = ProposalCount::<T, I>::get();
|
||||
<ProposalCount<T, I>>::mutate(|i| *i += 1);
|
||||
<ProposalOf<T, I>>::insert(proposal_hash, proposal);
|
||||
let votes = {
|
||||
@@ -747,7 +741,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
index: ProposalIndex,
|
||||
approve: bool,
|
||||
) -> Result<bool, DispatchError> {
|
||||
let mut voting = Self::voting(&proposal).ok_or(Error::<T, I>::ProposalMissing)?;
|
||||
let mut voting = Voting::<T, I>::get(&proposal).ok_or(Error::<T, I>::ProposalMissing)?;
|
||||
ensure!(voting.index == index, Error::<T, I>::WrongIndex);
|
||||
|
||||
let position_yes = voting.ayes.iter().position(|a| a == &who);
|
||||
@@ -798,12 +792,12 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
proposal_weight_bound: Weight,
|
||||
length_bound: u32,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
let voting = Self::voting(&proposal_hash).ok_or(Error::<T, I>::ProposalMissing)?;
|
||||
let voting = Voting::<T, I>::get(&proposal_hash).ok_or(Error::<T, I>::ProposalMissing)?;
|
||||
ensure!(voting.index == index, Error::<T, I>::WrongIndex);
|
||||
|
||||
let mut no_votes = voting.nays.len() as MemberCount;
|
||||
let mut yes_votes = voting.ayes.len() as MemberCount;
|
||||
let seats = Self::members().len() as MemberCount;
|
||||
let seats = Members::<T, I>::get().len() as MemberCount;
|
||||
let approved = yes_votes >= voting.threshold;
|
||||
let disapproved = seats.saturating_sub(no_votes) < voting.threshold;
|
||||
// Allow (dis-)approving the proposal as soon as there are enough votes.
|
||||
@@ -837,7 +831,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
// Only allow actual closing of the proposal after the voting period has ended.
|
||||
ensure!(frame_system::Pallet::<T>::block_number() >= voting.end, Error::<T, I>::TooEarly);
|
||||
|
||||
let prime_vote = Self::prime().map(|who| voting.ayes.iter().any(|a| a == &who));
|
||||
let prime_vote = Prime::<T, I>::get().map(|who| voting.ayes.iter().any(|a| a == &who));
|
||||
|
||||
// default voting strategy.
|
||||
let default = T::DefaultVote::default_vote(prime_vote, yes_votes, no_votes, seats);
|
||||
@@ -978,29 +972,28 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
/// * The prime account must be a member of the collective.
|
||||
#[cfg(any(feature = "try-runtime", test))]
|
||||
fn do_try_state() -> Result<(), TryRuntimeError> {
|
||||
Self::proposals()
|
||||
.into_iter()
|
||||
.try_for_each(|proposal| -> Result<(), TryRuntimeError> {
|
||||
Proposals::<T, I>::get().into_iter().try_for_each(
|
||||
|proposal| -> Result<(), TryRuntimeError> {
|
||||
ensure!(
|
||||
Self::proposal_of(proposal).is_some(),
|
||||
ProposalOf::<T, I>::get(proposal).is_some(),
|
||||
"Proposal hash from `Proposals` is not found inside the `ProposalOf` mapping."
|
||||
);
|
||||
Ok(())
|
||||
})?;
|
||||
},
|
||||
)?;
|
||||
|
||||
ensure!(
|
||||
Self::proposals().into_iter().count() <= Self::proposal_count() as usize,
|
||||
Proposals::<T, I>::get().into_iter().count() <= ProposalCount::<T, I>::get() as usize,
|
||||
"The actual number of proposals is greater than `ProposalCount`"
|
||||
);
|
||||
ensure!(
|
||||
Self::proposals().into_iter().count() == <ProposalOf<T, I>>::iter_keys().count(),
|
||||
Proposals::<T, I>::get().into_iter().count() == <ProposalOf<T, I>>::iter_keys().count(),
|
||||
"Proposal count inside `Proposals` is not equal to the proposal count in `ProposalOf`"
|
||||
);
|
||||
|
||||
Self::proposals()
|
||||
.into_iter()
|
||||
.try_for_each(|proposal| -> Result<(), TryRuntimeError> {
|
||||
if let Some(votes) = Self::voting(proposal) {
|
||||
Proposals::<T, I>::get().into_iter().try_for_each(
|
||||
|proposal| -> Result<(), TryRuntimeError> {
|
||||
if let Some(votes) = Voting::<T, I>::get(proposal) {
|
||||
let ayes = votes.ayes.len();
|
||||
let nays = votes.nays.len();
|
||||
|
||||
@@ -1010,13 +1003,13 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
})?;
|
||||
},
|
||||
)?;
|
||||
|
||||
let mut proposal_indices = vec![];
|
||||
Self::proposals()
|
||||
.into_iter()
|
||||
.try_for_each(|proposal| -> Result<(), TryRuntimeError> {
|
||||
if let Some(votes) = Self::voting(proposal) {
|
||||
Proposals::<T, I>::get().into_iter().try_for_each(
|
||||
|proposal| -> Result<(), TryRuntimeError> {
|
||||
if let Some(votes) = Voting::<T, I>::get(proposal) {
|
||||
let proposal_index = votes.index;
|
||||
ensure!(
|
||||
!proposal_indices.contains(&proposal_index),
|
||||
@@ -1025,12 +1018,13 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
proposal_indices.push(proposal_index);
|
||||
}
|
||||
Ok(())
|
||||
})?;
|
||||
},
|
||||
)?;
|
||||
|
||||
<Voting<T, I>>::iter_keys().try_for_each(
|
||||
|proposal_hash| -> Result<(), TryRuntimeError> {
|
||||
ensure!(
|
||||
Self::proposals().contains(&proposal_hash),
|
||||
Proposals::<T, I>::get().contains(&proposal_hash),
|
||||
"`Proposals` doesn't contain the proposal hash from the `Voting` storage map."
|
||||
);
|
||||
Ok(())
|
||||
@@ -1038,17 +1032,17 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
)?;
|
||||
|
||||
ensure!(
|
||||
Self::members().len() <= T::MaxMembers::get() as usize,
|
||||
Members::<T, I>::get().len() <= T::MaxMembers::get() as usize,
|
||||
"The member count is greater than `MaxMembers`."
|
||||
);
|
||||
|
||||
ensure!(
|
||||
Self::members().windows(2).all(|members| members[0] <= members[1]),
|
||||
Members::<T, I>::get().windows(2).all(|members| members[0] <= members[1]),
|
||||
"The members are not sorted by value."
|
||||
);
|
||||
|
||||
if let Some(prime) = Self::prime() {
|
||||
ensure!(Self::members().contains(&prime), "Prime account is not a member.");
|
||||
if let Some(prime) = Prime::<T, I>::get() {
|
||||
ensure!(Members::<T, I>::get().contains(&prime), "Prime account is not a member.");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -1082,7 +1076,7 @@ impl<T: Config<I>, I: 'static> ChangeMembers<T::AccountId> for Pallet<T, I> {
|
||||
// remove accounts from all current voting in motions.
|
||||
let mut outgoing = outgoing.to_vec();
|
||||
outgoing.sort();
|
||||
for h in Self::proposals().into_iter() {
|
||||
for h in Proposals::<T, I>::get().into_iter() {
|
||||
<Voting<T, I>>::mutate(h, |v| {
|
||||
if let Some(mut votes) = v.take() {
|
||||
votes.ayes = votes
|
||||
|
||||
@@ -193,8 +193,8 @@ fn default_max_proposal_weight() -> Weight {
|
||||
#[test]
|
||||
fn motions_basic_environment_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_eq!(Collective::members(), vec![1, 2, 3]);
|
||||
assert_eq!(*Collective::proposals(), Vec::<H256>::new());
|
||||
assert_eq!(Members::<Test, Instance1>::get(), vec![1, 2, 3]);
|
||||
assert_eq!(*Proposals::<Test, Instance1>::get(), Vec::<H256>::new());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ fn initialize_members_sorts_members() {
|
||||
ExtBuilder::default()
|
||||
.set_collective_members(unsorted_members)
|
||||
.build_and_execute(|| {
|
||||
assert_eq!(Collective::members(), expected_members);
|
||||
assert_eq!(Members::<Test, Instance1>::get(), expected_members);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -219,8 +219,8 @@ fn set_members_with_prime_works() {
|
||||
Some(3),
|
||||
MaxMembers::get()
|
||||
));
|
||||
assert_eq!(Collective::members(), members.clone());
|
||||
assert_eq!(Collective::prime(), Some(3));
|
||||
assert_eq!(Members::<Test, Instance1>::get(), members.clone());
|
||||
assert_eq!(Prime::<Test, Instance1>::get(), Some(3));
|
||||
assert_noop!(
|
||||
Collective::set_members(RuntimeOrigin::root(), members, Some(4), MaxMembers::get()),
|
||||
Error::<Test, Instance1>::PrimeAccountNotMember
|
||||
@@ -632,12 +632,12 @@ fn removal_of_old_voters_votes_works() {
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true));
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Voting::<Test, Instance1>::get(&hash),
|
||||
Some(Votes { index: 0, threshold: 3, ayes: vec![1, 2], nays: vec![], end })
|
||||
);
|
||||
Collective::change_members_sorted(&[4], &[1], &[2, 3, 4]);
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Voting::<Test, Instance1>::get(&hash),
|
||||
Some(Votes { index: 0, threshold: 3, ayes: vec![2], nays: vec![], end })
|
||||
);
|
||||
|
||||
@@ -653,12 +653,12 @@ fn removal_of_old_voters_votes_works() {
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 1, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(3), hash, 1, false));
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Voting::<Test, Instance1>::get(&hash),
|
||||
Some(Votes { index: 1, threshold: 2, ayes: vec![2], nays: vec![3], end })
|
||||
);
|
||||
Collective::change_members_sorted(&[], &[3], &[2, 4]);
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Voting::<Test, Instance1>::get(&hash),
|
||||
Some(Votes { index: 1, threshold: 2, ayes: vec![2], nays: vec![], end })
|
||||
);
|
||||
});
|
||||
@@ -680,7 +680,7 @@ fn removal_of_old_voters_votes_works_with_set_members() {
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true));
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Voting::<Test, Instance1>::get(&hash),
|
||||
Some(Votes { index: 0, threshold: 3, ayes: vec![1, 2], nays: vec![], end })
|
||||
);
|
||||
assert_ok!(Collective::set_members(
|
||||
@@ -690,7 +690,7 @@ fn removal_of_old_voters_votes_works_with_set_members() {
|
||||
MaxMembers::get()
|
||||
));
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Voting::<Test, Instance1>::get(&hash),
|
||||
Some(Votes { index: 0, threshold: 3, ayes: vec![2], nays: vec![], end })
|
||||
);
|
||||
|
||||
@@ -706,7 +706,7 @@ fn removal_of_old_voters_votes_works_with_set_members() {
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 1, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(3), hash, 1, false));
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Voting::<Test, Instance1>::get(&hash),
|
||||
Some(Votes { index: 1, threshold: 2, ayes: vec![2], nays: vec![3], end })
|
||||
);
|
||||
assert_ok!(Collective::set_members(
|
||||
@@ -716,7 +716,7 @@ fn removal_of_old_voters_votes_works_with_set_members() {
|
||||
MaxMembers::get()
|
||||
));
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Voting::<Test, Instance1>::get(&hash),
|
||||
Some(Votes { index: 1, threshold: 2, ayes: vec![2], nays: vec![], end })
|
||||
);
|
||||
});
|
||||
@@ -735,10 +735,10 @@ fn propose_works() {
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_eq!(*Collective::proposals(), vec![hash]);
|
||||
assert_eq!(Collective::proposal_of(&hash), Some(proposal));
|
||||
assert_eq!(*Proposals::<Test, Instance1>::get(), vec![hash]);
|
||||
assert_eq!(ProposalOf::<Test, Instance1>::get(&hash), Some(proposal));
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Voting::<Test, Instance1>::get(&hash),
|
||||
Some(Votes { index: 0, threshold: 3, ayes: vec![], nays: vec![], end })
|
||||
);
|
||||
|
||||
@@ -898,13 +898,13 @@ fn motions_vote_after_works() {
|
||||
));
|
||||
// Initially there a no votes when the motion is proposed.
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Voting::<Test, Instance1>::get(&hash),
|
||||
Some(Votes { index: 0, threshold: 2, ayes: vec![], nays: vec![], end })
|
||||
);
|
||||
// Cast first aye vote.
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true));
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Voting::<Test, Instance1>::get(&hash),
|
||||
Some(Votes { index: 0, threshold: 2, ayes: vec![1], nays: vec![], end })
|
||||
);
|
||||
// Try to cast a duplicate aye vote.
|
||||
@@ -915,7 +915,7 @@ fn motions_vote_after_works() {
|
||||
// Cast a nay vote.
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, false));
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Voting::<Test, Instance1>::get(&hash),
|
||||
Some(Votes { index: 0, threshold: 2, ayes: vec![], nays: vec![1], end })
|
||||
);
|
||||
// Try to cast a duplicate nay vote.
|
||||
@@ -966,7 +966,7 @@ fn motions_all_first_vote_free_works() {
|
||||
proposal_len,
|
||||
));
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Voting::<Test, Instance1>::get(&hash),
|
||||
Some(Votes { index: 0, threshold: 2, ayes: vec![], nays: vec![], end })
|
||||
);
|
||||
|
||||
@@ -1031,14 +1031,14 @@ fn motions_reproposing_disapproved_works() {
|
||||
proposal_weight,
|
||||
proposal_len
|
||||
));
|
||||
assert_eq!(*Collective::proposals(), vec![]);
|
||||
assert_eq!(*Proposals::<Test, Instance1>::get(), vec![]);
|
||||
assert_ok!(Collective::propose(
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_eq!(*Collective::proposals(), vec![hash]);
|
||||
assert_eq!(*Proposals::<Test, Instance1>::get(), vec![hash]);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user