Don't allow self proxies (#7803)

This commit is contained in:
Shawn Tabrizi
2020-12-29 13:31:44 -04:00
committed by GitHub
parent 0b7ae4440c
commit 8c795accc8
2 changed files with 4 additions and 0 deletions
+3
View File
@@ -168,6 +168,8 @@ decl_error! {
NoPermission,
/// Announcement, if made at all, was made too recently.
Unannounced,
/// Cannot add self as proxy.
NoSelfProxy,
}
}
@@ -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 };
+1
View File
@@ -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);
});
}