Skip to content

Commit

Permalink
identity: Don't let subs be re-registered (paritytech#6667)
Browse files Browse the repository at this point in the history
* Fixes and tests

* Don't set subs be re-registered.

Also allow subs to de-register themselves and collect the deposit.

Also allow individual registering and removal of subs.

* Make it build

* Update frame/identity/src/lib.rs

Co-authored-by: joe petrowski <[email protected]>

* Tests

* Add benchmarks

* Add some reasonable weights

* Docs

Co-authored-by: joe petrowski <[email protected]>
  • Loading branch information
gavofyork and joepetrowski authored Jul 17, 2020
1 parent 81e6a0c commit 640dd1a
Show file tree
Hide file tree
Showing 24 changed files with 305 additions and 29 deletions.
2 changes: 1 addition & 1 deletion frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ mod tests {
use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup}, testing::Header};

impl_outer_origin! {
pub enum Origin for Test where system = frame_system {}
pub enum Origin for Test where system = frame_system {}
}

#[derive(Clone, Eq, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion frame/aura/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use sp_io;
use sp_core::H256;

impl_outer_origin!{
pub enum Origin for Test where system = frame_system {}
pub enum Origin for Test where system = frame_system {}
}

// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
Expand Down
2 changes: 1 addition & 1 deletion frame/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ mod tests {
}

impl_outer_origin! {
pub enum Origin for Test where system = frame_system {}
pub enum Origin for Test where system = frame_system {}
}

pub struct TestSessionHandler;
Expand Down
2 changes: 1 addition & 1 deletion frame/authorship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ mod tests {
use frame_support::{parameter_types, impl_outer_origin, ConsensusEngineId, weights::Weight};

impl_outer_origin!{
pub enum Origin for Test where system = frame_system {}
pub enum Origin for Test where system = frame_system {}
}

#[derive(Clone, Eq, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl_outer_event! {
}
}
impl_outer_origin! {
pub enum Origin for Test where system = frame_system { }
pub enum Origin for Test where system = frame_system { }
}
impl_outer_dispatch! {
pub enum Call for Test where origin: Origin {
Expand Down
2 changes: 1 addition & 1 deletion frame/democracy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const BIG_AYE: Vote = Vote { aye: true, conviction: Conviction::Locked1x };
const BIG_NAY: Vote = Vote { aye: false, conviction: Conviction::Locked1x };

impl_outer_origin! {
pub enum Origin for Test where system = frame_system {}
pub enum Origin for Test where system = frame_system {}
}

impl_outer_dispatch! {
Expand Down
2 changes: 1 addition & 1 deletion frame/evm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use sp_runtime::{
};

impl_outer_origin! {
pub enum Origin for Test where system = frame_system {}
pub enum Origin for Test where system = frame_system {}
}

impl_outer_dispatch! {
Expand Down
2 changes: 1 addition & 1 deletion frame/example-offchain-worker/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use sp_runtime::{
};

impl_outer_origin! {
pub enum Origin for Test where system = frame_system {}
pub enum Origin for Test where system = frame_system {}
}

// For testing the module, we construct most of a mock runtime. This means
Expand Down
2 changes: 1 addition & 1 deletion frame/example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ mod tests {
};

impl_outer_origin! {
pub enum Origin for Test where system = frame_system {}
pub enum Origin for Test where system = frame_system {}
}

impl_outer_dispatch! {
Expand Down
2 changes: 1 addition & 1 deletion frame/finality-tracker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ mod tests {
pub struct Test;

impl_outer_origin! {
pub enum Origin for Test where system = frame_system {}
pub enum Origin for Test where system = frame_system {}
}

thread_local! {
Expand Down
42 changes: 42 additions & 0 deletions frame/identity/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,48 @@ benchmarks! {

}: _(RawOrigin::Signed(caller), subs)

add_sub {
let caller = account::<T>("caller", 0);

// Give them p many previous sub accounts.
let p in 1 .. T::MaxSubAccounts::get() - 1 => {
let _ = add_sub_accounts::<T>(&caller, p)?;
};
let sub = account::<T>("new_sub", 0);
let data = Data::Raw(vec![0; 32]);
}: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub), data)

rename_sub {
let caller = account::<T>("caller", 0);

let p in 1 .. T::MaxSubAccounts::get();

// Give them p many previous sub accounts.
let (sub, _) = add_sub_accounts::<T>(&caller, p)?.remove(0);
let data = Data::Raw(vec![1; 32]);

}: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub), data)

remove_sub {
let caller = account::<T>("caller", 0);

// Give them p many previous sub accounts.
let p in 1 .. T::MaxSubAccounts::get();
let (sub, _) = add_sub_accounts::<T>(&caller, p)?.remove(0);
}: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub))

quit_sub {
let caller = account::<T>("caller", 0);
let sup = account::<T>("super", 0);

// Give them p many previous sub accounts.
let p in 1 .. T::MaxSubAccounts::get() - 1 => {
let _ = add_sub_accounts::<T>(&sup, p)?;
};
let sup_origin = RawOrigin::Signed(sup).into();
Identity::<T>::add_sub(sup_origin, T::Lookup::unlookup(caller.clone()), Data::Raw(vec![0; 32]))?;
}: _(RawOrigin::Signed(caller))

clear_identity {
let caller = account::<T>("caller", 0);
let caller_origin = <T as frame_system::Trait>::Origin::from(RawOrigin::Signed(caller.clone()));
Expand Down
Loading

0 comments on commit 640dd1a

Please sign in to comment.