Replace T::AccountId with <T::Lookup as StaticLookup>::Source (#11670)

* initial

* update

* update

* update

* cargo fmt

* update

* update benchmarks

* AccountIdLookupOf<T>

* cargo fmt

* fix conflits

* cargo fmt

* update

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
Doordashcon
2022-08-18 10:30:46 +01:00
committed by GitHub
parent 511e5c9651
commit d46f6f0d34
50 changed files with 465 additions and 309 deletions
+4 -2
View File
@@ -44,10 +44,11 @@ benchmarks! {
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
let recipient: T::AccountId = account("recipient", 0, SEED);
let recipient_lookup = T::Lookup::unlookup(recipient.clone());
T::Currency::make_free_balance_be(&recipient, BalanceOf::<T>::max_value());
// Claim the index
Indices::<T>::claim(RawOrigin::Signed(caller.clone()).into(), account_index)?;
}: _(RawOrigin::Signed(caller.clone()), recipient.clone(), account_index)
}: _(RawOrigin::Signed(caller.clone()), recipient_lookup, account_index)
verify {
assert_eq!(Accounts::<T>::get(account_index).unwrap().0, recipient);
}
@@ -70,10 +71,11 @@ benchmarks! {
let original: T::AccountId = account("original", 0, SEED);
T::Currency::make_free_balance_be(&original, BalanceOf::<T>::max_value());
let recipient: T::AccountId = account("recipient", 0, SEED);
let recipient_lookup = T::Lookup::unlookup(recipient.clone());
T::Currency::make_free_balance_be(&recipient, BalanceOf::<T>::max_value());
// Claim the index
Indices::<T>::claim(RawOrigin::Signed(original).into(), account_index)?;
}: _(RawOrigin::Root, recipient.clone(), account_index, false)
}: _(RawOrigin::Root, recipient_lookup, account_index, false)
verify {
assert_eq!(Accounts::<T>::get(account_index).unwrap().0, recipient);
}
+5 -2
View File
@@ -36,6 +36,7 @@ pub use weights::WeightInfo;
type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
pub use pallet::*;
@@ -133,10 +134,11 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::transfer())]
pub fn transfer(
origin: OriginFor<T>,
new: T::AccountId,
new: AccountIdLookupOf<T>,
index: T::AccountIndex,
) -> DispatchResult {
let who = ensure_signed(origin)?;
let new = T::Lookup::lookup(new)?;
ensure!(who != new, Error::<T>::NotTransfer);
Accounts::<T>::try_mutate(index, |maybe_value| -> DispatchResult {
@@ -208,11 +210,12 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::force_transfer())]
pub fn force_transfer(
origin: OriginFor<T>,
new: T::AccountId,
new: AccountIdLookupOf<T>,
index: T::AccountIndex,
freeze: bool,
) -> DispatchResult {
ensure_root(origin)?;
let new = T::Lookup::lookup(new)?;
Accounts::<T>::mutate(index, |maybe_value| {
if let Some((account, amount, _)) = maybe_value.take() {
+7 -6
View File
@@ -22,6 +22,7 @@
use super::{mock::*, *};
use frame_support::{assert_noop, assert_ok};
use pallet_balances::Error as BalancesError;
use sp_runtime::MultiAddress::Id;
#[test]
fn claiming_should_work() {
@@ -60,7 +61,7 @@ fn freezing_should_work() {
assert_noop!(Indices::freeze(Some(1).into(), 0), Error::<Test>::Permanent);
assert_noop!(Indices::free(Some(1).into(), 0), Error::<Test>::Permanent);
assert_noop!(Indices::transfer(Some(1).into(), 2, 0), Error::<Test>::Permanent);
assert_noop!(Indices::transfer(Some(1).into(), Id(2), 0), Error::<Test>::Permanent);
});
}
@@ -90,9 +91,9 @@ fn reclaim_index_on_accounts_should_work() {
fn transfer_index_on_accounts_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(Indices::claim(Some(1).into(), 0));
assert_noop!(Indices::transfer(Some(1).into(), 2, 1), Error::<Test>::NotAssigned);
assert_noop!(Indices::transfer(Some(2).into(), 3, 0), Error::<Test>::NotOwner);
assert_ok!(Indices::transfer(Some(1).into(), 3, 0));
assert_noop!(Indices::transfer(Some(1).into(), Id(2), 1), Error::<Test>::NotAssigned);
assert_noop!(Indices::transfer(Some(2).into(), Id(3), 0), Error::<Test>::NotOwner);
assert_ok!(Indices::transfer(Some(1).into(), Id(3), 0));
assert_eq!(Balances::reserved_balance(1), 0);
assert_eq!(Balances::reserved_balance(3), 1);
assert_eq!(Indices::lookup_index(0), Some(3));
@@ -103,7 +104,7 @@ fn transfer_index_on_accounts_should_work() {
fn force_transfer_index_on_preowned_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(Indices::claim(Some(1).into(), 0));
assert_ok!(Indices::force_transfer(Origin::root(), 3, 0, false));
assert_ok!(Indices::force_transfer(Origin::root(), Id(3), 0, false));
assert_eq!(Balances::reserved_balance(1), 0);
assert_eq!(Balances::reserved_balance(3), 0);
assert_eq!(Indices::lookup_index(0), Some(3));
@@ -113,7 +114,7 @@ fn force_transfer_index_on_preowned_should_work() {
#[test]
fn force_transfer_index_on_free_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(Indices::force_transfer(Origin::root(), 3, 0, false));
assert_ok!(Indices::force_transfer(Origin::root(), Id(3), 0, false));
assert_eq!(Balances::reserved_balance(3), 0);
assert_eq!(Indices::lookup_index(0), Some(3));
});