@@ -23,7 +23,7 @@ use super::*;
23
23
24
24
use frame_support:: {
25
25
assert_ok, assert_noop, impl_outer_origin, parameter_types, impl_outer_dispatch,
26
- impl_filter_stack , weights:: Weight , impl_outer_event, RuntimeDebug , dispatch:: DispatchError
26
+ weights:: Weight , impl_outer_event, RuntimeDebug , dispatch:: DispatchError , traits :: Filter ,
27
27
} ;
28
28
use codec:: { Encode , Decode } ;
29
29
use sp_core:: H256 ;
@@ -62,6 +62,7 @@ parameter_types! {
62
62
pub const AvailableBlockRatio : Perbill = Perbill :: one( ) ;
63
63
}
64
64
impl frame_system:: Trait for Test {
65
+ type BaseCallFilter = BaseFilter ;
65
66
type Origin = Origin ;
66
67
type Index = u64 ;
67
68
type BlockNumber = u64 ;
@@ -99,15 +100,12 @@ impl pallet_balances::Trait for Test {
99
100
impl pallet_utility:: Trait for Test {
100
101
type Event = TestEvent ;
101
102
type Call = Call ;
102
- type IsCallable = IsCallable ;
103
103
}
104
104
parameter_types ! {
105
105
pub const ProxyDepositBase : u64 = 1 ;
106
106
pub const ProxyDepositFactor : u64 = 1 ;
107
107
pub const MaxProxies : u16 = 4 ;
108
108
}
109
- pub struct IsCallable ;
110
- impl_filter_stack ! ( crate :: tests:: IsCallable , crate :: tests:: BaseFilter , crate :: tests:: Call , is_callable) ;
111
109
#[ derive( Copy , Clone , Eq , PartialEq , Ord , PartialOrd , Encode , Decode , RuntimeDebug ) ]
112
110
pub enum ProxyType {
113
111
Any ,
@@ -142,7 +140,6 @@ impl Trait for Test {
142
140
type Event = TestEvent ;
143
141
type Call = Call ;
144
142
type Currency = Balances ;
145
- type IsCallable = IsCallable ;
146
143
type ProxyType = ProxyType ;
147
144
type ProxyDepositBase = ProxyDepositBase ;
148
145
type ProxyDepositFactor = ProxyDepositFactor ;
@@ -158,7 +155,6 @@ use frame_system::Call as SystemCall;
158
155
use pallet_balances:: Call as BalancesCall ;
159
156
use pallet_balances:: Error as BalancesError ;
160
157
use pallet_utility:: Call as UtilityCall ;
161
- use pallet_utility:: Error as UtilityError ;
162
158
use pallet_utility:: Event as UtilityEvent ;
163
159
use super :: Call as ProxyCall ;
164
160
@@ -201,7 +197,8 @@ fn filtering_works() {
201
197
expect_event ( RawEvent :: ProxyExecuted ( Ok ( ( ) ) ) ) ;
202
198
assert_ok ! ( Proxy :: proxy( Origin :: signed( 3 ) , 1 , None , call. clone( ) ) ) ;
203
199
expect_event ( RawEvent :: ProxyExecuted ( Ok ( ( ) ) ) ) ;
204
- assert_noop ! ( Proxy :: proxy( Origin :: signed( 4 ) , 1 , None , call. clone( ) ) , Error :: <Test >:: Uncallable ) ;
200
+ assert_ok ! ( Proxy :: proxy( Origin :: signed( 4 ) , 1 , None , call. clone( ) ) ) ;
201
+ expect_event ( RawEvent :: ProxyExecuted ( Err ( DispatchError :: BadOrigin ) ) ) ;
205
202
206
203
let sub_id = Utility :: sub_account_id ( 1 , 0 ) ;
207
204
Balances :: mutate_account ( & sub_id, |a| a. free = 1000 ) ;
@@ -210,32 +207,41 @@ fn filtering_works() {
210
207
let call = Box :: new ( Call :: Utility ( UtilityCall :: as_sub ( 0 , inner. clone ( ) ) ) ) ;
211
208
assert_ok ! ( Proxy :: proxy( Origin :: signed( 2 ) , 1 , None , call. clone( ) ) ) ;
212
209
expect_event ( RawEvent :: ProxyExecuted ( Ok ( ( ) ) ) ) ;
213
- assert_noop ! ( Proxy :: proxy( Origin :: signed( 3 ) , 1 , None , call. clone( ) ) , Error :: <Test >:: Uncallable ) ;
210
+ assert_ok ! ( Proxy :: proxy( Origin :: signed( 3 ) , 1 , None , call. clone( ) ) ) ;
211
+ expect_event ( RawEvent :: ProxyExecuted ( Err ( DispatchError :: BadOrigin ) ) ) ;
214
212
assert_ok ! ( Proxy :: proxy( Origin :: signed( 4 ) , 1 , None , call. clone( ) ) ) ;
215
213
expect_event ( RawEvent :: ProxyExecuted ( Ok ( ( ) ) ) ) ;
216
214
217
215
let call = Box :: new ( Call :: Utility ( UtilityCall :: as_limited_sub ( 0 , inner. clone ( ) ) ) ) ;
218
216
assert_ok ! ( Proxy :: proxy( Origin :: signed( 2 ) , 1 , None , call. clone( ) ) ) ;
219
217
expect_event ( RawEvent :: ProxyExecuted ( Ok ( ( ) ) ) ) ;
220
- assert_noop ! ( Proxy :: proxy( Origin :: signed( 3 ) , 1 , None , call. clone( ) ) , Error :: <Test >:: Uncallable ) ;
218
+ assert_ok ! ( Proxy :: proxy( Origin :: signed( 3 ) , 1 , None , call. clone( ) ) ) ;
219
+ expect_event ( RawEvent :: ProxyExecuted ( Err ( DispatchError :: BadOrigin ) ) ) ;
221
220
assert_ok ! ( Proxy :: proxy( Origin :: signed( 4 ) , 1 , None , call. clone( ) ) ) ;
222
- let de = DispatchError :: from ( UtilityError :: < Test > :: Uncallable ) . stripped ( ) ;
223
- expect_event ( RawEvent :: ProxyExecuted ( Err ( de) ) ) ;
221
+ expect_event ( RawEvent :: ProxyExecuted ( Err ( DispatchError :: BadOrigin ) ) ) ;
224
222
225
223
let call = Box :: new ( Call :: Utility ( UtilityCall :: batch ( vec ! [ * inner] ) ) ) ;
226
224
assert_ok ! ( Proxy :: proxy( Origin :: signed( 2 ) , 1 , None , call. clone( ) ) ) ;
227
225
expect_events ( vec ! [ UtilityEvent :: BatchCompleted . into( ) , RawEvent :: ProxyExecuted ( Ok ( ( ) ) ) . into( ) ] ) ;
228
- assert_noop ! ( Proxy :: proxy( Origin :: signed( 3 ) , 1 , None , call. clone( ) ) , Error :: <Test >:: Uncallable ) ;
226
+ assert_ok ! ( Proxy :: proxy( Origin :: signed( 3 ) , 1 , None , call. clone( ) ) ) ;
227
+ expect_event ( RawEvent :: ProxyExecuted ( Err ( DispatchError :: BadOrigin ) ) ) ;
229
228
assert_ok ! ( Proxy :: proxy( Origin :: signed( 4 ) , 1 , None , call. clone( ) ) ) ;
230
- expect_events ( vec ! [ UtilityEvent :: Uncallable ( 0 ) . into( ) , RawEvent :: ProxyExecuted ( Ok ( ( ) ) ) . into( ) ] ) ;
229
+ expect_events ( vec ! [
230
+ UtilityEvent :: BatchInterrupted ( 0 , DispatchError :: BadOrigin ) . into( ) ,
231
+ RawEvent :: ProxyExecuted ( Ok ( ( ) ) ) . into( ) ,
232
+ ] ) ;
231
233
232
234
let inner = Box :: new ( Call :: Proxy ( ProxyCall :: add_proxy ( 5 , ProxyType :: Any ) ) ) ;
233
235
let call = Box :: new ( Call :: Utility ( UtilityCall :: batch ( vec ! [ * inner] ) ) ) ;
234
236
assert_ok ! ( Proxy :: proxy( Origin :: signed( 2 ) , 1 , None , call. clone( ) ) ) ;
235
237
expect_events ( vec ! [ UtilityEvent :: BatchCompleted . into( ) , RawEvent :: ProxyExecuted ( Ok ( ( ) ) ) . into( ) ] ) ;
236
- assert_noop ! ( Proxy :: proxy( Origin :: signed( 3 ) , 1 , None , call. clone( ) ) , Error :: <Test >:: Uncallable ) ;
238
+ assert_ok ! ( Proxy :: proxy( Origin :: signed( 3 ) , 1 , None , call. clone( ) ) ) ;
239
+ expect_event ( RawEvent :: ProxyExecuted ( Err ( DispatchError :: BadOrigin ) ) ) ;
237
240
assert_ok ! ( Proxy :: proxy( Origin :: signed( 4 ) , 1 , None , call. clone( ) ) ) ;
238
- expect_events ( vec ! [ UtilityEvent :: Uncallable ( 0 ) . into( ) , RawEvent :: ProxyExecuted ( Ok ( ( ) ) ) . into( ) ] ) ;
241
+ expect_events ( vec ! [
242
+ UtilityEvent :: BatchInterrupted ( 0 , DispatchError :: BadOrigin ) . into( ) ,
243
+ RawEvent :: ProxyExecuted ( Ok ( ( ) ) ) . into( ) ,
244
+ ] ) ;
239
245
} ) ;
240
246
}
241
247
@@ -293,10 +299,12 @@ fn proxying_works() {
293
299
assert_eq ! ( Balances :: free_balance( 6 ) , 1 ) ;
294
300
295
301
let call = Box :: new ( Call :: System ( SystemCall :: set_code ( vec ! [ ] ) ) ) ;
296
- assert_noop ! ( Proxy :: proxy( Origin :: signed( 3 ) , 1 , None , call. clone( ) ) , Error :: <Test >:: Uncallable ) ;
302
+ assert_ok ! ( Proxy :: proxy( Origin :: signed( 3 ) , 1 , None , call. clone( ) ) ) ;
303
+ expect_event ( RawEvent :: ProxyExecuted ( Err ( DispatchError :: BadOrigin ) ) ) ;
297
304
298
305
let call = Box :: new ( Call :: Balances ( BalancesCall :: transfer_keep_alive ( 6 , 1 ) ) ) ;
299
- assert_noop ! ( Proxy :: proxy( Origin :: signed( 2 ) , 1 , None , call. clone( ) ) , Error :: <Test >:: Uncallable ) ;
306
+ assert_ok ! ( Call :: Proxy ( super :: Call :: proxy( 1 , None , call. clone( ) ) ) . dispatch( Origin :: signed( 2 ) ) ) ;
307
+ expect_event ( RawEvent :: ProxyExecuted ( Err ( DispatchError :: BadOrigin ) ) ) ;
300
308
assert_ok ! ( Proxy :: proxy( Origin :: signed( 3 ) , 1 , None , call. clone( ) ) ) ;
301
309
expect_event ( RawEvent :: ProxyExecuted ( Ok ( ( ) ) ) ) ;
302
310
assert_eq ! ( Balances :: free_balance( 6 ) , 2 ) ;
0 commit comments