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

Commit

Permalink
Don't allow self proxies (#7803)
Browse files Browse the repository at this point in the history
  • Loading branch information
shawntabrizi authored Dec 29, 2020
1 parent 7c9f9a5 commit 5d5a3b8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions frame/proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ decl_error! {
NoPermission,
/// Announcement, if made at all, was made too recently.
Unannounced,
/// Cannot add self as proxy.
NoSelfProxy,
}
}

Expand Down Expand Up @@ -567,6 +569,7 @@ impl<T: Config> Module<T> {
proxy_type: T::ProxyType,
delay: T::BlockNumber,
) -> DispatchResult {
ensure!(delegator != &delegatee, Error::<T>::NoSelfProxy);
Proxies::<T>::try_mutate(delegator, |(ref mut proxies, ref mut deposit)| {
ensure!(proxies.len() < T::MaxProxies::get() as usize, Error::<T>::TooMany);
let proxy_def = ProxyDefinition { delegate: delegatee, proxy_type, delay };
Expand Down
1 change: 1 addition & 0 deletions frame/proxy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ fn add_remove_proxies_works() {
assert_eq!(Balances::reserved_balance(1), 2);
assert_ok!(Proxy::remove_proxy(Origin::signed(1), 2, ProxyType::JustTransfer, 0));
assert_eq!(Balances::reserved_balance(1), 0);
assert_noop!(Proxy::add_proxy(Origin::signed(1), 1, ProxyType::Any, 0), Error::<Test>::NoSelfProxy);
});
}

Expand Down

0 comments on commit 5d5a3b8

Please sign in to comment.