Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pallet::getter usage from the democracy pallet #4472

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions prdoc/pr_4472.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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: Remove `pallet::getter` usage from pallet-democracy

doc:
- audience: Runtime Dev
description: |
This PR removes the `pallet::getter`s from `pallet-democracy`.
The syntax `StorageItem::<T, I>::get()` should be used instead.

crates:
- name: pallet-democracy
bump: major
40 changes: 20 additions & 20 deletions substrate/frame/democracy/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ benchmarks! {
whitelist_account!(caller);
}: _(RawOrigin::Signed(caller), proposal, value)
verify {
assert_eq!(Democracy::<T>::public_props().len(), p as usize, "Proposals not created.");
assert_eq!(PublicProps::<T>::get().len(), p as usize, "Proposals not created.");
}

second {
Expand All @@ -122,12 +122,12 @@ benchmarks! {
Democracy::<T>::second(RawOrigin::Signed(seconder).into(), 0)?;
}

let deposits = Democracy::<T>::deposit_of(0).ok_or("Proposal not created")?;
let deposits = DepositOf::<T>::get(0).ok_or("Proposal not created")?;
assert_eq!(deposits.0.len(), (T::MaxDeposits::get() - 1) as usize, "Seconds not recorded");
whitelist_account!(caller);
}: _(RawOrigin::Signed(caller), 0)
verify {
let deposits = Democracy::<T>::deposit_of(0).ok_or("Proposal not created")?;
let deposits = DepositOf::<T>::get(0).ok_or("Proposal not created")?;
assert_eq!(deposits.0.len(), (T::MaxDeposits::get()) as usize, "`second` benchmark did not work");
}

Expand Down Expand Up @@ -175,7 +175,7 @@ benchmarks! {
// Change vote from aye to nay
let nay = Vote { aye: false, conviction: Conviction::Locked1x };
let new_vote = AccountVote::Standard { vote: nay, balance: 1000u32.into() };
let ref_index = Democracy::<T>::referendum_count() - 1;
let ref_index = ReferendumCount::<T>::get() - 1;

// This tests when a user changes a vote
whitelist_account!(caller);
Expand All @@ -186,7 +186,7 @@ benchmarks! {
_ => return Err("Votes are not direct".into()),
};
assert_eq!(votes.len(), T::MaxVotes::get() as usize, "Vote was incorrectly added");
let referendum_info = Democracy::<T>::referendum_info(ref_index)
let referendum_info = ReferendumInfoOf::<T>::get(ref_index)
.ok_or("referendum doesn't exist")?;
let tally = match referendum_info {
ReferendumInfo::Ongoing(r) => r.tally,
Expand Down Expand Up @@ -261,7 +261,7 @@ benchmarks! {
}: _<T::RuntimeOrigin>(origin, proposal)
verify {
// External proposal created
ensure!(<NextExternal<T>>::exists(), "External proposal didn't work");
ensure!(NextExternal::<T>::exists(), "External proposal didn't work");
}

external_propose_majority {
Expand All @@ -271,7 +271,7 @@ benchmarks! {
}: _<T::RuntimeOrigin>(origin, proposal)
verify {
// External proposal created
ensure!(<NextExternal<T>>::exists(), "External proposal didn't work");
ensure!(NextExternal::<T>::exists(), "External proposal didn't work");
}

external_propose_default {
Expand All @@ -281,7 +281,7 @@ benchmarks! {
}: _<T::RuntimeOrigin>(origin, proposal)
verify {
// External proposal created
ensure!(<NextExternal<T>>::exists(), "External proposal didn't work");
ensure!(NextExternal::<T>::exists(), "External proposal didn't work");
}

fast_track {
Expand All @@ -303,7 +303,7 @@ benchmarks! {
let delay = 0u32;
}: _<T::RuntimeOrigin>(origin_fast_track, proposal_hash, voting_period, delay.into())
verify {
assert_eq!(Democracy::<T>::referendum_count(), 1, "referendum not created");
assert_eq!(ReferendumCount::<T>::get(), 1, "referendum not created");
assert_last_event::<T>(crate::Event::MetadataTransferred {
prev_owner: MetadataOwner::External,
owner: MetadataOwner::Referendum(0),
Expand Down Expand Up @@ -338,7 +338,7 @@ benchmarks! {
}: _<T::RuntimeOrigin>(origin, proposal_hash)
verify {
assert!(NextExternal::<T>::get().is_none());
let (_, new_vetoers) = <Blacklist<T>>::get(&proposal_hash).ok_or("no blacklist")?;
let (_, new_vetoers) = Blacklist::<T>::get(&proposal_hash).ok_or("no blacklist")?;
assert_eq!(new_vetoers.len(), T::MaxBlacklisted::get() as usize, "vetoers not added");
}

Expand Down Expand Up @@ -382,7 +382,7 @@ benchmarks! {
add_referendum::<T>(i);
}

assert_eq!(Democracy::<T>::referendum_count(), r, "referenda not created");
assert_eq!(ReferendumCount::<T>::get(), r, "referenda not created");

// Launch external
LastTabledWasExternal::<T>::put(false);
Expand All @@ -393,15 +393,15 @@ benchmarks! {
let call = Call::<T>::external_propose_majority { proposal };
call.dispatch_bypass_filter(origin)?;
// External proposal created
ensure!(<NextExternal<T>>::exists(), "External proposal didn't work");
ensure!(NextExternal::<T>::exists(), "External proposal didn't work");

let block_number = T::LaunchPeriod::get();

}: { Democracy::<T>::on_initialize(block_number) }
verify {
// One extra because of next external
assert_eq!(Democracy::<T>::referendum_count(), r + 1, "referenda not created");
ensure!(!<NextExternal<T>>::exists(), "External wasn't taken");
assert_eq!(ReferendumCount::<T>::get(), r + 1, "referenda not created");
ensure!(!NextExternal::<T>::exists(), "External wasn't taken");

// All but the new next external should be finished
for i in 0 .. r {
Expand All @@ -422,7 +422,7 @@ benchmarks! {
add_referendum::<T>(i);
}

assert_eq!(Democracy::<T>::referendum_count(), r, "referenda not created");
assert_eq!(ReferendumCount::<T>::get(), r, "referenda not created");

// Launch public
assert!(add_proposal::<T>(r).is_ok(), "proposal not created");
Expand All @@ -433,7 +433,7 @@ benchmarks! {
}: { Democracy::<T>::on_initialize(block_number) }
verify {
// One extra because of next public
assert_eq!(Democracy::<T>::referendum_count(), r + 1, "proposal not accepted");
assert_eq!(ReferendumCount::<T>::get(), r + 1, "proposal not accepted");

// All should be finished
for i in 0 .. r {
Expand Down Expand Up @@ -461,8 +461,8 @@ benchmarks! {
ReferendumInfoOf::<T>::insert(key, info);
}

assert_eq!(Democracy::<T>::referendum_count(), r, "referenda not created");
assert_eq!(Democracy::<T>::lowest_unbaked(), 0, "invalid referenda init");
assert_eq!(ReferendumCount::<T>::get(), r, "referenda not created");
assert_eq!(LowestUnbaked::<T>::get(), 0, "invalid referenda init");

}: { Democracy::<T>::on_initialize(1u32.into()) }
verify {
Expand Down Expand Up @@ -491,8 +491,8 @@ benchmarks! {
ReferendumInfoOf::<T>::insert(key, info);
}

assert_eq!(Democracy::<T>::referendum_count(), r, "referenda not created");
assert_eq!(Democracy::<T>::lowest_unbaked(), 0, "invalid referenda init");
assert_eq!(ReferendumCount::<T>::get(), r, "referenda not created");
assert_eq!(LowestUnbaked::<T>::get(), 0, "invalid referenda init");

let block_number = T::LaunchPeriod::get();

Expand Down
Loading
Loading