Skip to content

Commit 4e1ebc2

Browse files
authored
Restrict remove_proxies (#6383)
1 parent 544ad7c commit 4e1ebc2

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ pub trait Trait: frame_system::Trait {
6868

6969
/// A kind of proxy; specified with the proxy and passed in to the `IsProxyable` fitler.
7070
/// The instance filter determines whether a given call may be proxied under this type.
71+
///
72+
/// IMPORTANT: `Default` must be provided and MUST BE the the *most permissive* value.
7173
type ProxyType: Parameter + Member + Ord + PartialOrd + InstanceFilter<<Self as Trait>::Call>
7274
+ Default;
7375

@@ -174,6 +176,8 @@ decl_module! {
174176
match c.is_sub_type() {
175177
Some(Call::add_proxy(_, ref pt)) | Some(Call::remove_proxy(_, ref pt))
176178
if !proxy_type.is_superset(&pt) => false,
179+
Some(Call::remove_proxies(..)) | Some(Call::kill_anonymous(..))
180+
if proxy_type != T::ProxyType::default() => false,
177181
_ => proxy_type.filter(c)
178182
}
179183
});

src/tests.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ type Proxy = Module<Test>;
154154
use frame_system::Call as SystemCall;
155155
use pallet_balances::Call as BalancesCall;
156156
use pallet_balances::Error as BalancesError;
157+
use pallet_balances::Event as BalancesEvent;
157158
use pallet_utility::Call as UtilityCall;
158159
use pallet_utility::Event as UtilityEvent;
159160
use super::Call as ProxyCall;
@@ -242,6 +243,14 @@ fn filtering_works() {
242243
UtilityEvent::BatchInterrupted(0, DispatchError::BadOrigin).into(),
243244
RawEvent::ProxyExecuted(Ok(())).into(),
244245
]);
246+
247+
let call = Box::new(Call::Proxy(ProxyCall::remove_proxies()));
248+
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
249+
expect_event(RawEvent::ProxyExecuted(Err(DispatchError::BadOrigin)));
250+
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
251+
expect_event(RawEvent::ProxyExecuted(Err(DispatchError::BadOrigin)));
252+
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
253+
expect_events(vec![BalancesEvent::<Test>::Unreserved(1, 5).into(), RawEvent::ProxyExecuted(Ok(())).into()]);
245254
});
246255
}
247256

0 commit comments

Comments
 (0)