Root origin always bypass all filter, other origin cannot bypass BaseCallFilter even when constructed from Root origin (#9948)

* improve root filter bypass

* improve doc

* fmt

* refactor test for more understandable flow

* Update frame/support/procedural/src/construct_runtime/expand/origin.rs

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* match

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
Guillaume Thiolliere
2021-10-07 17:46:06 +02:00
committed by GitHub
parent cec88b7144
commit e81a425241
3 changed files with 36 additions and 22 deletions
@@ -327,19 +327,31 @@ mod origin_test {
assert_eq!(Origin::from(super::nested::module3::Origin).filter_call(&rejected_call), false);
let mut origin = Origin::from(Some(0));
origin.add_filter(|c| matches!(c, Call::Module3(_)));
assert_eq!(origin.filter_call(&accepted_call), false);
assert_eq!(origin.filter_call(&rejected_call), false);
// Now test for root origin and filters:
let mut origin = Origin::from(Some(0));
origin.set_caller_from(Origin::root());
assert!(matches!(origin.caller, OriginCaller::system(super::system::RawOrigin::Root)));
assert_eq!(origin.filter_call(&accepted_call), false);
assert_eq!(origin.filter_call(&rejected_call), false);
origin.reset_filter();
// Root origin bypass all filter.
assert_eq!(origin.filter_call(&accepted_call), true);
assert_eq!(origin.filter_call(&rejected_call), true);
origin.set_caller_from(Origin::from(Some(0)));
// Back to another signed origin, the filtered are now effective again
assert_eq!(origin.filter_call(&accepted_call), true);
assert_eq!(origin.filter_call(&rejected_call), false);
origin.set_caller_from(Origin::root());
origin.reset_filter();
// Root origin bypass all filter, even when they are reset.
assert_eq!(origin.filter_call(&accepted_call), true);
assert_eq!(origin.filter_call(&rejected_call), true);
}
}