Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
deprecate and remove every usage of #[pallet::getter]
Browse files Browse the repository at this point in the history
Signed-off-by: muraca <[email protected]>
  • Loading branch information
muraca committed Apr 12, 2023
1 parent b4f857e commit 3af83a5
Show file tree
Hide file tree
Showing 109 changed files with 1,696 additions and 1,602 deletions.
1 change: 0 additions & 1 deletion bin/node-template/pallets/template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ pub mod pallet {
// The pallet's runtime storage items.
// https://docs.substrate.io/main-docs/build/runtime-storage/
#[pallet::storage]
#[pallet::getter(fn something)]
// Learn more about declaring storage items:
// https://docs.substrate.io/main-docs/build/runtime-storage/#declaring-storage-items
pub type Something<T> = StorageValue<_, u32>;
Expand Down
4 changes: 2 additions & 2 deletions bin/node-template/pallets/template/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{mock::*, Error, Event};
use crate::{mock::*, Error, Event, Something};
use frame_support::{assert_noop, assert_ok};

#[test]
Expand All @@ -9,7 +9,7 @@ fn it_works_for_default_value() {
// Dispatch a signed extrinsic.
assert_ok!(TemplateModule::do_something(RuntimeOrigin::signed(1), 42));
// Read pallet storage and assert an expected result.
assert_eq!(TemplateModule::something(), Some(42));
assert_eq!(Something::<Test>::get(), Some(42));
// Assert that the correct event was deposited
System::assert_last_event(Event::SomethingStored { something: 42, who: 1 }.into());
});
Expand Down
10 changes: 6 additions & 4 deletions bin/node/executor/tests/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use frame_support::{
use kitchensink_runtime::{
constants::{currency::*, time::SLOT_DURATION},
Balances, CheckedExtrinsic, Multiplier, Runtime, RuntimeCall, TransactionByteFee,
TransactionPayment,
};
use node_primitives::Balance;
use node_testing::keyring::*;
Expand All @@ -41,7 +40,10 @@ fn fee_multiplier_increases_and_decreases_on_big_weight() {
let mut prev_multiplier = Multiplier::one();

t.execute_with(|| {
assert_eq!(TransactionPayment::next_fee_multiplier(), prev_multiplier);
assert_eq!(
pallet_transaction_payment::NextFeeMultiplier::<Runtime>::get(),
prev_multiplier
);
});

let mut tt = new_test_ext(compact_code_unwrap());
Expand Down Expand Up @@ -99,7 +101,7 @@ fn fee_multiplier_increases_and_decreases_on_big_weight() {

// weight multiplier is increased for next block.
t.execute_with(|| {
let fm = TransactionPayment::next_fee_multiplier();
let fm = pallet_transaction_payment::NextFeeMultiplier::<Runtime>::get();
println!("After a big block: {:?} -> {:?}", prev_multiplier, fm);
assert!(fm > prev_multiplier);
prev_multiplier = fm;
Expand All @@ -110,7 +112,7 @@ fn fee_multiplier_increases_and_decreases_on_big_weight() {

// weight multiplier is increased for next block.
t.execute_with(|| {
let fm = TransactionPayment::next_fee_multiplier();
let fm = pallet_transaction_payment::NextFeeMultiplier::<Runtime>::get();
println!("After a small block: {:?} -> {:?}", prev_multiplier, fm);
assert!(fm < prev_multiplier);
});
Expand Down
4 changes: 2 additions & 2 deletions bin/node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ mod multiplier_tests {
use crate::{
constants::{currency::*, time::*},
AdjustmentVariable, MaximumMultiplier, MinimumMultiplier, Runtime,
RuntimeBlockWeights as BlockWeights, System, TargetBlockFullness, TransactionPayment,
RuntimeBlockWeights as BlockWeights, System, TargetBlockFullness,
};
use frame_support::{
dispatch::DispatchClass,
Expand Down Expand Up @@ -293,7 +293,7 @@ mod multiplier_tests {
run_with_system_weight(block_weight, || {
// initial value configured on module
let mut fm = Multiplier::one();
assert_eq!(fm, TransactionPayment::next_fee_multiplier());
assert_eq!(fm, pallet_transaction_payment::NextFeeMultiplier::<Runtime>::get());

let mut iterations: u64 = 0;
loop {
Expand Down
8 changes: 4 additions & 4 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2056,8 +2056,8 @@ impl_runtime_apis! {
slot_duration: Babe::slot_duration(),
epoch_length: EpochDuration::get(),
c: epoch_config.c,
authorities: Babe::authorities().to_vec(),
randomness: Babe::randomness(),
authorities: pallet_babe::Authorities::<Runtime>::get().to_vec(),
randomness: pallet_babe::Randomness::<Runtime>::get(),
allowed_slots: epoch_config.allowed_slots,
}
}
Expand Down Expand Up @@ -2279,11 +2279,11 @@ impl_runtime_apis! {
BlockNumber,
> for Runtime {
fn mmr_root() -> Result<mmr::Hash, mmr::Error> {
Ok(Mmr::mmr_root())
Ok(pallet_mmr::RootHash::<Runtime>::get())
}

fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
Ok(Mmr::mmr_leaves())
Ok(pallet_mmr::NumberOfLeaves::<Runtime>::get())
}

fn generate_proof(
Expand Down
10 changes: 5 additions & 5 deletions frame/alliance/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ benchmarks_instance_pallet! {
fellows: fellows.clone(),
allies: allies.clone(),
}.into());
assert_eq!(Alliance::<T, I>::members(MemberRole::Fellow), fellows);
assert_eq!(Alliance::<T, I>::members(MemberRole::Ally), allies);
assert_eq!(Members::<T, I>::get(MemberRole::Fellow), fellows);
assert_eq!(Members::<T, I>::get(MemberRole::Ally), allies);
}

disband {
Expand Down Expand Up @@ -582,7 +582,7 @@ benchmarks_instance_pallet! {
T::AdminOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
}: { call.dispatch_bypass_filter(origin)? }
verify {
assert_eq!(Alliance::<T, I>::rule(), Some(rule.clone()));
assert_eq!(Rule::<T, I>::get(), Some(rule.clone()));
assert_last_event::<T, I>(Event::NewRuleSet { rule }.into());
}

Expand All @@ -596,7 +596,7 @@ benchmarks_instance_pallet! {
T::AnnouncementOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
}: { call.dispatch_bypass_filter(origin)? }
verify {
assert!(Alliance::<T, I>::announcements().contains(&announcement));
assert!(Announcements::<T, I>::get().contains(&announcement));
assert_last_event::<T, I>(Event::Announced { announcement }.into());
}

Expand All @@ -612,7 +612,7 @@ benchmarks_instance_pallet! {
T::AnnouncementOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
}: { call.dispatch_bypass_filter(origin)? }
verify {
assert!(Alliance::<T, I>::announcements().is_empty());
assert!(Announcements::<T, I>::get().is_empty());
assert_last_event::<T, I>(Event::AnnouncementRemoved { announcement }.into());
}

Expand Down
12 changes: 6 additions & 6 deletions frame/alliance/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,18 @@ pub(crate) mod v1_to_v2 {
#[cfg(test)]
mod test {
use super::*;
use crate::{mock::*, MemberRole};
use crate::{mock::*, MemberRole, Members};

#[test]
fn migration_v1_to_v2_works() {
new_test_ext().execute_with(|| {
assert_ok!(Alliance::join_alliance(RuntimeOrigin::signed(4)));
assert_eq!(Alliance::members(MemberRole::Ally), vec![4]);
assert_eq!(Alliance::members(MemberRole::Fellow), vec![1, 2, 3]);
assert_eq!(Members::<Test>::get(MemberRole::Ally), vec![4]);
assert_eq!(Members::<Test>::get(MemberRole::Fellow), vec![1, 2, 3]);
v1_to_v2::migrate::<Test, ()>();
assert_eq!(Alliance::members(MemberRole::Fellow), vec![1, 2, 3, 4]);
assert_eq!(Alliance::members(MemberRole::Ally), vec![]);
assert_eq!(Alliance::members(MemberRole::Retiring), vec![]);
assert_eq!(Members::<Test>::get(MemberRole::Fellow), vec![1, 2, 3, 4]);
assert_eq!(Members::<Test>::get(MemberRole::Ally), vec![]);
assert_eq!(Members::<Test>::get(MemberRole::Retiring), vec![]);
});
}
}
2 changes: 1 addition & 1 deletion frame/alliance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,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)
}
}

Expand Down
57 changes: 30 additions & 27 deletions frame/alliance/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn disband_works() {
// join alliance and reserve funds
assert_eq!(Balances::free_balance(9), 40);
assert_ok!(Alliance::join_alliance(RuntimeOrigin::signed(9)));
assert_eq!(Alliance::deposit_of(9), Some(25));
assert_eq!(DepositOf::<Test>::get(9), Some(25));
assert_eq!(Balances::free_balance(9), 15);
assert!(Alliance::is_member_of(&9, MemberRole::Ally));

Expand Down Expand Up @@ -184,8 +184,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 {
Expand Down Expand Up @@ -311,7 +311,7 @@ fn set_rule_works() {
new_test_ext().execute_with(|| {
let cid = test_cid();
assert_ok!(Alliance::set_rule(RuntimeOrigin::signed(1), cid.clone()));
assert_eq!(Alliance::rule(), Some(cid.clone()));
assert_eq!(Rule::<Test>::get(), Some(cid.clone()));

System::assert_last_event(mock::RuntimeEvent::Alliance(crate::Event::NewRuleSet {
rule: cid,
Expand All @@ -327,7 +327,7 @@ fn announce_works() {
assert_noop!(Alliance::announce(RuntimeOrigin::signed(2), cid.clone()), BadOrigin);

assert_ok!(Alliance::announce(RuntimeOrigin::signed(3), cid.clone()));
assert_eq!(Alliance::announcements(), vec![cid.clone()]);
assert_eq!(Announcements::<Test>::get(), vec![cid.clone()]);

System::assert_last_event(mock::RuntimeEvent::Alliance(crate::Event::Announced {
announcement: cid,
Expand All @@ -340,15 +340,15 @@ fn remove_announcement_works() {
new_test_ext().execute_with(|| {
let cid = test_cid();
assert_ok!(Alliance::announce(RuntimeOrigin::signed(3), cid.clone()));
assert_eq!(Alliance::announcements(), vec![cid.clone()]);
assert_eq!(Announcements::<Test>::get(), vec![cid.clone()]);
System::assert_last_event(mock::RuntimeEvent::Alliance(crate::Event::Announced {
announcement: cid.clone(),
}));

System::set_block_number(2);

assert_ok!(Alliance::remove_announcement(RuntimeOrigin::signed(3), cid.clone()));
assert_eq!(Alliance::announcements(), vec![]);
assert_eq!(Announcements::<Test>::get(), vec![]);
System::assert_last_event(mock::RuntimeEvent::Alliance(
crate::Event::AnnouncementRemoved { announcement: cid },
));
Expand Down Expand Up @@ -386,8 +386,8 @@ fn join_alliance_works() {

// success to submit
assert_ok!(Alliance::join_alliance(RuntimeOrigin::signed(4)));
assert_eq!(Alliance::deposit_of(4), Some(25));
assert_eq!(Alliance::members(MemberRole::Ally), vec![4]);
assert_eq!(DepositOf::<Test>::get(4), Some(25));
assert_eq!(Members::<Test>::get(MemberRole::Ally), vec![4]);

// check already member
assert_noop!(
Expand Down Expand Up @@ -441,8 +441,8 @@ fn nominate_ally_works() {

// success to nominate
assert_ok!(Alliance::nominate_ally(RuntimeOrigin::signed(1), 4));
assert_eq!(Alliance::deposit_of(4), None);
assert_eq!(Alliance::members(MemberRole::Ally), vec![4]);
assert_eq!(DepositOf::<Test>::get(4), None);
assert_eq!(Members::<Test>::get(MemberRole::Ally), vec![4]);

// check already member
assert_noop!(
Expand Down Expand Up @@ -474,12 +474,12 @@ fn elevate_ally_works() {
);

assert_ok!(Alliance::join_alliance(RuntimeOrigin::signed(4)));
assert_eq!(Alliance::members(MemberRole::Ally), vec![4]);
assert_eq!(Alliance::members(MemberRole::Fellow), vec![1, 2, 3]);
assert_eq!(Members::<Test>::get(MemberRole::Ally), vec![4]);
assert_eq!(Members::<Test>::get(MemberRole::Fellow), vec![1, 2, 3]);

assert_ok!(Alliance::elevate_ally(RuntimeOrigin::signed(2), 4));
assert_eq!(Alliance::members(MemberRole::Ally), Vec::<u64>::new());
assert_eq!(Alliance::members(MemberRole::Fellow), vec![1, 2, 3, 4]);
assert_eq!(Members::<Test>::get(MemberRole::Ally), Vec::<u64>::new());
assert_eq!(Members::<Test>::get(MemberRole::Fellow), vec![1, 2, 3, 4]);
});
}

Expand All @@ -491,10 +491,10 @@ fn give_retirement_notice_work() {
Error::<Test, ()>::NotMember
);

assert_eq!(Alliance::members(MemberRole::Fellow), vec![1, 2, 3]);
assert_eq!(Members::<Test>::get(MemberRole::Fellow), vec![1, 2, 3]);
assert_ok!(Alliance::give_retirement_notice(RuntimeOrigin::signed(3)));
assert_eq!(Alliance::members(MemberRole::Fellow), vec![1, 2]);
assert_eq!(Alliance::members(MemberRole::Retiring), vec![3]);
assert_eq!(Members::<Test>::get(MemberRole::Fellow), vec![1, 2]);
assert_eq!(Members::<Test>::get(MemberRole::Retiring), vec![3]);
System::assert_last_event(mock::RuntimeEvent::Alliance(
crate::Event::MemberRetirementPeriodStarted { member: (3) },
));
Expand All @@ -519,15 +519,15 @@ fn retire_works() {
Error::<Test, ()>::RetirementNoticeNotGiven
);

assert_eq!(Alliance::members(MemberRole::Fellow), vec![1, 2, 3]);
assert_eq!(Members::<Test>::get(MemberRole::Fellow), vec![1, 2, 3]);
assert_ok!(Alliance::give_retirement_notice(RuntimeOrigin::signed(3)));
assert_noop!(
Alliance::retire(RuntimeOrigin::signed(3)),
Error::<Test, ()>::RetirementPeriodNotPassed
);
System::set_block_number(System::block_number() + RetirementPeriod::get());
assert_ok!(Alliance::retire(RuntimeOrigin::signed(3)));
assert_eq!(Alliance::members(MemberRole::Fellow), vec![1, 2]);
assert_eq!(Members::<Test>::get(MemberRole::Fellow), vec![1, 2]);
System::assert_last_event(mock::RuntimeEvent::Alliance(crate::Event::MemberRetired {
member: (3),
unreserved: None,
Expand All @@ -543,7 +543,7 @@ fn retire_works() {
#[test]
fn abdicate_works() {
new_test_ext().execute_with(|| {
assert_eq!(Alliance::members(MemberRole::Fellow), vec![1, 2, 3]);
assert_eq!(Members::<Test>::get(MemberRole::Fellow), vec![1, 2, 3]);
assert_ok!(Alliance::abdicate_fellow_status(RuntimeOrigin::signed(3)));

System::assert_last_event(mock::RuntimeEvent::Alliance(crate::Event::FellowAbdicated {
Expand All @@ -565,9 +565,9 @@ fn kick_member_works() {
);

<DepositOf<Test, ()>>::insert(2, 25);
assert_eq!(Alliance::members(MemberRole::Fellow), vec![1, 2, 3]);
assert_eq!(Members::<Test>::get(MemberRole::Fellow), vec![1, 2, 3]);
assert_ok!(Alliance::kick_member(RuntimeOrigin::signed(2), 2));
assert_eq!(Alliance::members(MemberRole::Fellow), vec![1, 3]);
assert_eq!(Members::<Test>::get(MemberRole::Fellow), vec![1, 3]);
assert_eq!(<DepositOf<Test, ()>>::get(2), None);
System::assert_last_event(mock::RuntimeEvent::Alliance(crate::Event::MemberKicked {
member: (2),
Expand All @@ -588,8 +588,11 @@ fn add_unscrupulous_items_works() {
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_eq!(UnscrupulousAccounts::<Test>::get().into_inner(), vec![3]);
assert_eq!(
UnscrupulousWebsites::<Test>::get().into_inner(),
vec!["abc".as_bytes().to_vec()]
);

assert_noop!(
Alliance::add_unscrupulous_items(
Expand Down Expand Up @@ -621,11 +624,11 @@ fn remove_unscrupulous_items_works() {
RuntimeOrigin::signed(3),
vec![UnscrupulousItem::AccountId(3)]
));
assert_eq!(Alliance::unscrupulous_accounts(), vec![3]);
assert_eq!(UnscrupulousAccounts::<Test>::get(), vec![3]);
assert_ok!(Alliance::remove_unscrupulous_items(
RuntimeOrigin::signed(3),
vec![UnscrupulousItem::AccountId(3)]
));
assert_eq!(Alliance::unscrupulous_accounts(), Vec::<u64>::new());
assert_eq!(UnscrupulousAccounts::<Test>::get(), Vec::<u64>::new());
});
}
Loading

0 comments on commit 3af83a5

Please sign in to comment.