Refactor as_sub to make things clearer. (#6503)

* Refactor as_sub to make things clearer.

- `as_sub` becomes `as_alternative`
- `as_sub_limited` becomes `as_derivative`
- `as_alternative` and `as_derivative` generate a mutually exclusive set of accounts.

* Test fix

* Add test

* Fix test

* Remove `as_alternative`.

* Docs.
This commit is contained in:
Gavin Wood
2020-06-26 11:03:02 +02:00
committed by GitHub
parent 39c3d1c026
commit 0532db6b86
4 changed files with 27 additions and 59 deletions
+3 -11
View File
@@ -201,19 +201,11 @@ fn filtering_works() {
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
expect_event(RawEvent::ProxyExecuted(Err(DispatchError::BadOrigin)));
let sub_id = Utility::sub_account_id(1, 0);
Balances::mutate_account(&sub_id, |a| a.free = 1000);
let derivative_id = Utility::derivative_account_id(1, 0);
Balances::mutate_account(&derivative_id, |a| a.free = 1000);
let inner = Box::new(Call::Balances(BalancesCall::transfer(6, 1)));
let call = Box::new(Call::Utility(UtilityCall::as_sub(0, inner.clone())));
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
expect_event(RawEvent::ProxyExecuted(Ok(())));
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
expect_event(RawEvent::ProxyExecuted(Err(DispatchError::BadOrigin)));
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
expect_event(RawEvent::ProxyExecuted(Ok(())));
let call = Box::new(Call::Utility(UtilityCall::as_limited_sub(0, inner.clone())));
let call = Box::new(Call::Utility(UtilityCall::as_derivative(0, inner.clone())));
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
expect_event(RawEvent::ProxyExecuted(Ok(())));
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));