mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 04:07:57 +00:00
BREAKING: Rename Origin (#12258)
* BREAKING: Rename Origin * more renaming * a bit more renaming * fix * more fixing * fix in frame_support * even more fixes * fix * small fix * ... * update .stderr * docs * update docs * update docs * docs
This commit is contained in:
@@ -113,7 +113,7 @@ pub mod pallet {
|
||||
|
||||
/// The overarching call type.
|
||||
type RuntimeCall: Parameter
|
||||
+ Dispatchable<Origin = Self::Origin>
|
||||
+ Dispatchable<RuntimeOrigin = Self::RuntimeOrigin>
|
||||
+ GetDispatchInfo
|
||||
+ From<frame_system::Call<Self>>
|
||||
+ IsSubType<Call<Self>>
|
||||
@@ -819,7 +819,7 @@ impl<T: Config> Pallet<T> {
|
||||
call: <T as Config>::RuntimeCall,
|
||||
) {
|
||||
// This is a freshly authenticated new account, the origin restrictions doesn't apply.
|
||||
let mut origin: T::Origin = frame_system::RawOrigin::Signed(real).into();
|
||||
let mut origin: T::RuntimeOrigin = frame_system::RawOrigin::Signed(real).into();
|
||||
origin.add_filter(move |c: &<T as frame_system::Config>::RuntimeCall| {
|
||||
let c = <T as Config>::RuntimeCall::from_ref(c);
|
||||
// We make sure the proxy call does access this pallet to change modify proxies.
|
||||
|
||||
@@ -61,7 +61,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
@@ -204,7 +204,7 @@ fn call_transfer(dest: u64, value: u64) -> RuntimeCall {
|
||||
#[test]
|
||||
fn announcement_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Proxy::add_proxy(Origin::signed(1), 3, ProxyType::Any, 1));
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(1), 3, ProxyType::Any, 1));
|
||||
System::assert_last_event(
|
||||
ProxyEvent::ProxyAdded {
|
||||
delegator: 1,
|
||||
@@ -214,10 +214,10 @@ fn announcement_works() {
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
assert_ok!(Proxy::add_proxy(Origin::signed(2), 3, ProxyType::Any, 1));
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(2), 3, ProxyType::Any, 1));
|
||||
assert_eq!(Balances::reserved_balance(3), 0);
|
||||
|
||||
assert_ok!(Proxy::announce(Origin::signed(3), 1, [1; 32].into()));
|
||||
assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 1, [1; 32].into()));
|
||||
let announcements = Announcements::<Test>::get(3);
|
||||
assert_eq!(
|
||||
announcements.0,
|
||||
@@ -225,7 +225,7 @@ fn announcement_works() {
|
||||
);
|
||||
assert_eq!(Balances::reserved_balance(3), announcements.1);
|
||||
|
||||
assert_ok!(Proxy::announce(Origin::signed(3), 2, [2; 32].into()));
|
||||
assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 2, [2; 32].into()));
|
||||
let announcements = Announcements::<Test>::get(3);
|
||||
assert_eq!(
|
||||
announcements.0,
|
||||
@@ -236,20 +236,23 @@ fn announcement_works() {
|
||||
);
|
||||
assert_eq!(Balances::reserved_balance(3), announcements.1);
|
||||
|
||||
assert_noop!(Proxy::announce(Origin::signed(3), 2, [3; 32].into()), Error::<Test>::TooMany);
|
||||
assert_noop!(
|
||||
Proxy::announce(RuntimeOrigin::signed(3), 2, [3; 32].into()),
|
||||
Error::<Test>::TooMany
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_announcement_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Proxy::add_proxy(Origin::signed(1), 3, ProxyType::Any, 1));
|
||||
assert_ok!(Proxy::add_proxy(Origin::signed(2), 3, ProxyType::Any, 1));
|
||||
assert_ok!(Proxy::announce(Origin::signed(3), 1, [1; 32].into()));
|
||||
assert_ok!(Proxy::announce(Origin::signed(3), 2, [2; 32].into()));
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(1), 3, ProxyType::Any, 1));
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(2), 3, ProxyType::Any, 1));
|
||||
assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 1, [1; 32].into()));
|
||||
assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 2, [2; 32].into()));
|
||||
let e = Error::<Test>::NotFound;
|
||||
assert_noop!(Proxy::remove_announcement(Origin::signed(3), 1, [0; 32].into()), e);
|
||||
assert_ok!(Proxy::remove_announcement(Origin::signed(3), 1, [1; 32].into()));
|
||||
assert_noop!(Proxy::remove_announcement(RuntimeOrigin::signed(3), 1, [0; 32].into()), e);
|
||||
assert_ok!(Proxy::remove_announcement(RuntimeOrigin::signed(3), 1, [1; 32].into()));
|
||||
let announcements = Announcements::<Test>::get(3);
|
||||
assert_eq!(
|
||||
announcements.0,
|
||||
@@ -262,15 +265,15 @@ fn remove_announcement_works() {
|
||||
#[test]
|
||||
fn reject_announcement_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Proxy::add_proxy(Origin::signed(1), 3, ProxyType::Any, 1));
|
||||
assert_ok!(Proxy::add_proxy(Origin::signed(2), 3, ProxyType::Any, 1));
|
||||
assert_ok!(Proxy::announce(Origin::signed(3), 1, [1; 32].into()));
|
||||
assert_ok!(Proxy::announce(Origin::signed(3), 2, [2; 32].into()));
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(1), 3, ProxyType::Any, 1));
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(2), 3, ProxyType::Any, 1));
|
||||
assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 1, [1; 32].into()));
|
||||
assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 2, [2; 32].into()));
|
||||
let e = Error::<Test>::NotFound;
|
||||
assert_noop!(Proxy::reject_announcement(Origin::signed(1), 3, [0; 32].into()), e);
|
||||
assert_noop!(Proxy::reject_announcement(RuntimeOrigin::signed(1), 3, [0; 32].into()), e);
|
||||
let e = Error::<Test>::NotFound;
|
||||
assert_noop!(Proxy::reject_announcement(Origin::signed(4), 3, [1; 32].into()), e);
|
||||
assert_ok!(Proxy::reject_announcement(Origin::signed(1), 3, [1; 32].into()));
|
||||
assert_noop!(Proxy::reject_announcement(RuntimeOrigin::signed(4), 3, [1; 32].into()), e);
|
||||
assert_ok!(Proxy::reject_announcement(RuntimeOrigin::signed(1), 3, [1; 32].into()));
|
||||
let announcements = Announcements::<Test>::get(3);
|
||||
assert_eq!(
|
||||
announcements.0,
|
||||
@@ -283,41 +286,44 @@ fn reject_announcement_works() {
|
||||
#[test]
|
||||
fn announcer_must_be_proxy() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(Proxy::announce(Origin::signed(2), 1, H256::zero()), Error::<Test>::NotProxy);
|
||||
assert_noop!(
|
||||
Proxy::announce(RuntimeOrigin::signed(2), 1, H256::zero()),
|
||||
Error::<Test>::NotProxy
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delayed_requires_pre_announcement() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Proxy::add_proxy(Origin::signed(1), 2, ProxyType::Any, 1));
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(1), 2, ProxyType::Any, 1));
|
||||
let call = Box::new(call_transfer(6, 1));
|
||||
let e = Error::<Test>::Unannounced;
|
||||
assert_noop!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()), e);
|
||||
assert_noop!(Proxy::proxy(RuntimeOrigin::signed(2), 1, None, call.clone()), e);
|
||||
let e = Error::<Test>::Unannounced;
|
||||
assert_noop!(Proxy::proxy_announced(Origin::signed(0), 2, 1, None, call.clone()), e);
|
||||
assert_noop!(Proxy::proxy_announced(RuntimeOrigin::signed(0), 2, 1, None, call.clone()), e);
|
||||
let call_hash = BlakeTwo256::hash_of(&call);
|
||||
assert_ok!(Proxy::announce(Origin::signed(2), 1, call_hash));
|
||||
assert_ok!(Proxy::announce(RuntimeOrigin::signed(2), 1, call_hash));
|
||||
system::Pallet::<Test>::set_block_number(2);
|
||||
assert_ok!(Proxy::proxy_announced(Origin::signed(0), 2, 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy_announced(RuntimeOrigin::signed(0), 2, 1, None, call.clone()));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn proxy_announced_removes_announcement_and_returns_deposit() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Proxy::add_proxy(Origin::signed(1), 3, ProxyType::Any, 1));
|
||||
assert_ok!(Proxy::add_proxy(Origin::signed(2), 3, ProxyType::Any, 1));
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(1), 3, ProxyType::Any, 1));
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(2), 3, ProxyType::Any, 1));
|
||||
let call = Box::new(call_transfer(6, 1));
|
||||
let call_hash = BlakeTwo256::hash_of(&call);
|
||||
assert_ok!(Proxy::announce(Origin::signed(3), 1, call_hash));
|
||||
assert_ok!(Proxy::announce(Origin::signed(3), 2, call_hash));
|
||||
assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 1, call_hash));
|
||||
assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 2, call_hash));
|
||||
// Too early to execute announced call
|
||||
let e = Error::<Test>::Unannounced;
|
||||
assert_noop!(Proxy::proxy_announced(Origin::signed(0), 3, 1, None, call.clone()), e);
|
||||
assert_noop!(Proxy::proxy_announced(RuntimeOrigin::signed(0), 3, 1, None, call.clone()), e);
|
||||
|
||||
system::Pallet::<Test>::set_block_number(2);
|
||||
assert_ok!(Proxy::proxy_announced(Origin::signed(0), 3, 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy_announced(RuntimeOrigin::signed(0), 3, 1, None, call.clone()));
|
||||
let announcements = Announcements::<Test>::get(3);
|
||||
assert_eq!(announcements.0, vec![Announcement { real: 2, call_hash, height: 1 }]);
|
||||
assert_eq!(Balances::reserved_balance(3), announcements.1);
|
||||
@@ -328,16 +334,16 @@ fn proxy_announced_removes_announcement_and_returns_deposit() {
|
||||
fn filtering_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(Balances::mutate_account(&1, |a| a.free = 1000).is_ok());
|
||||
assert_ok!(Proxy::add_proxy(Origin::signed(1), 2, ProxyType::Any, 0));
|
||||
assert_ok!(Proxy::add_proxy(Origin::signed(1), 3, ProxyType::JustTransfer, 0));
|
||||
assert_ok!(Proxy::add_proxy(Origin::signed(1), 4, ProxyType::JustUtility, 0));
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(1), 2, ProxyType::Any, 0));
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(1), 3, ProxyType::JustTransfer, 0));
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(1), 4, ProxyType::JustUtility, 0));
|
||||
|
||||
let call = Box::new(call_transfer(6, 1));
|
||||
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(2), 1, None, call.clone()));
|
||||
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into());
|
||||
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(3), 1, None, call.clone()));
|
||||
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into());
|
||||
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(4), 1, None, call.clone()));
|
||||
System::assert_last_event(
|
||||
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
|
||||
);
|
||||
@@ -350,28 +356,28 @@ fn filtering_works() {
|
||||
index: 0,
|
||||
call: inner.clone(),
|
||||
}));
|
||||
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(2), 1, None, call.clone()));
|
||||
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into());
|
||||
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(3), 1, None, call.clone()));
|
||||
System::assert_last_event(
|
||||
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
|
||||
);
|
||||
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(4), 1, None, call.clone()));
|
||||
System::assert_last_event(
|
||||
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
|
||||
);
|
||||
|
||||
let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { calls: vec![*inner] }));
|
||||
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(2), 1, None, call.clone()));
|
||||
expect_events(vec![
|
||||
UtilityEvent::BatchCompleted.into(),
|
||||
ProxyEvent::ProxyExecuted { result: Ok(()) }.into(),
|
||||
]);
|
||||
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(3), 1, None, call.clone()));
|
||||
System::assert_last_event(
|
||||
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
|
||||
);
|
||||
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(4), 1, None, call.clone()));
|
||||
expect_events(vec![
|
||||
UtilityEvent::BatchInterrupted { index: 0, error: SystemError::CallFiltered.into() }
|
||||
.into(),
|
||||
@@ -384,16 +390,16 @@ fn filtering_works() {
|
||||
0,
|
||||
)));
|
||||
let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { calls: vec![*inner] }));
|
||||
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(2), 1, None, call.clone()));
|
||||
expect_events(vec![
|
||||
UtilityEvent::BatchCompleted.into(),
|
||||
ProxyEvent::ProxyExecuted { result: Ok(()) }.into(),
|
||||
]);
|
||||
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(3), 1, None, call.clone()));
|
||||
System::assert_last_event(
|
||||
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
|
||||
);
|
||||
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(4), 1, None, call.clone()));
|
||||
expect_events(vec![
|
||||
UtilityEvent::BatchInterrupted { index: 0, error: SystemError::CallFiltered.into() }
|
||||
.into(),
|
||||
@@ -401,15 +407,15 @@ fn filtering_works() {
|
||||
]);
|
||||
|
||||
let call = Box::new(RuntimeCall::Proxy(ProxyCall::remove_proxies {}));
|
||||
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(3), 1, None, call.clone()));
|
||||
System::assert_last_event(
|
||||
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
|
||||
);
|
||||
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(4), 1, None, call.clone()));
|
||||
System::assert_last_event(
|
||||
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
|
||||
);
|
||||
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(2), 1, None, call.clone()));
|
||||
expect_events(vec![
|
||||
BalancesEvent::<Test>::Unreserved { who: 1, amount: 5 }.into(),
|
||||
ProxyEvent::ProxyExecuted { result: Ok(()) }.into(),
|
||||
@@ -420,27 +426,27 @@ fn filtering_works() {
|
||||
#[test]
|
||||
fn add_remove_proxies_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Proxy::add_proxy(Origin::signed(1), 2, ProxyType::Any, 0));
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(1), 2, ProxyType::Any, 0));
|
||||
assert_noop!(
|
||||
Proxy::add_proxy(Origin::signed(1), 2, ProxyType::Any, 0),
|
||||
Proxy::add_proxy(RuntimeOrigin::signed(1), 2, ProxyType::Any, 0),
|
||||
Error::<Test>::Duplicate
|
||||
);
|
||||
assert_eq!(Balances::reserved_balance(1), 2);
|
||||
assert_ok!(Proxy::add_proxy(Origin::signed(1), 2, ProxyType::JustTransfer, 0));
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(1), 2, ProxyType::JustTransfer, 0));
|
||||
assert_eq!(Balances::reserved_balance(1), 3);
|
||||
assert_ok!(Proxy::add_proxy(Origin::signed(1), 3, ProxyType::Any, 0));
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(1), 3, ProxyType::Any, 0));
|
||||
assert_eq!(Balances::reserved_balance(1), 4);
|
||||
assert_ok!(Proxy::add_proxy(Origin::signed(1), 4, ProxyType::JustUtility, 0));
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(1), 4, ProxyType::JustUtility, 0));
|
||||
assert_eq!(Balances::reserved_balance(1), 5);
|
||||
assert_noop!(
|
||||
Proxy::add_proxy(Origin::signed(1), 4, ProxyType::Any, 0),
|
||||
Proxy::add_proxy(RuntimeOrigin::signed(1), 4, ProxyType::Any, 0),
|
||||
Error::<Test>::TooMany
|
||||
);
|
||||
assert_noop!(
|
||||
Proxy::remove_proxy(Origin::signed(1), 3, ProxyType::JustTransfer, 0),
|
||||
Proxy::remove_proxy(RuntimeOrigin::signed(1), 3, ProxyType::JustTransfer, 0),
|
||||
Error::<Test>::NotFound
|
||||
);
|
||||
assert_ok!(Proxy::remove_proxy(Origin::signed(1), 4, ProxyType::JustUtility, 0));
|
||||
assert_ok!(Proxy::remove_proxy(RuntimeOrigin::signed(1), 4, ProxyType::JustUtility, 0));
|
||||
System::assert_last_event(
|
||||
ProxyEvent::ProxyRemoved {
|
||||
delegator: 1,
|
||||
@@ -451,7 +457,7 @@ fn add_remove_proxies_works() {
|
||||
.into(),
|
||||
);
|
||||
assert_eq!(Balances::reserved_balance(1), 4);
|
||||
assert_ok!(Proxy::remove_proxy(Origin::signed(1), 3, ProxyType::Any, 0));
|
||||
assert_ok!(Proxy::remove_proxy(RuntimeOrigin::signed(1), 3, ProxyType::Any, 0));
|
||||
assert_eq!(Balances::reserved_balance(1), 3);
|
||||
System::assert_last_event(
|
||||
ProxyEvent::ProxyRemoved {
|
||||
@@ -462,7 +468,7 @@ fn add_remove_proxies_works() {
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
assert_ok!(Proxy::remove_proxy(Origin::signed(1), 2, ProxyType::Any, 0));
|
||||
assert_ok!(Proxy::remove_proxy(RuntimeOrigin::signed(1), 2, ProxyType::Any, 0));
|
||||
assert_eq!(Balances::reserved_balance(1), 2);
|
||||
System::assert_last_event(
|
||||
ProxyEvent::ProxyRemoved {
|
||||
@@ -473,7 +479,7 @@ fn add_remove_proxies_works() {
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
assert_ok!(Proxy::remove_proxy(Origin::signed(1), 2, ProxyType::JustTransfer, 0));
|
||||
assert_ok!(Proxy::remove_proxy(RuntimeOrigin::signed(1), 2, ProxyType::JustTransfer, 0));
|
||||
assert_eq!(Balances::reserved_balance(1), 0);
|
||||
System::assert_last_event(
|
||||
ProxyEvent::ProxyRemoved {
|
||||
@@ -485,7 +491,7 @@ fn add_remove_proxies_works() {
|
||||
.into(),
|
||||
);
|
||||
assert_noop!(
|
||||
Proxy::add_proxy(Origin::signed(1), 1, ProxyType::Any, 0),
|
||||
Proxy::add_proxy(RuntimeOrigin::signed(1), 1, ProxyType::Any, 0),
|
||||
Error::<Test>::NoSelfProxy
|
||||
);
|
||||
});
|
||||
@@ -494,10 +500,10 @@ fn add_remove_proxies_works() {
|
||||
#[test]
|
||||
fn cannot_add_proxy_without_balance() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Proxy::add_proxy(Origin::signed(5), 3, ProxyType::Any, 0));
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(5), 3, ProxyType::Any, 0));
|
||||
assert_eq!(Balances::reserved_balance(5), 2);
|
||||
assert_noop!(
|
||||
Proxy::add_proxy(Origin::signed(5), 4, ProxyType::Any, 0),
|
||||
Proxy::add_proxy(RuntimeOrigin::signed(5), 4, ProxyType::Any, 0),
|
||||
BalancesError::<Test, _>::InsufficientBalance
|
||||
);
|
||||
});
|
||||
@@ -506,24 +512,24 @@ fn cannot_add_proxy_without_balance() {
|
||||
#[test]
|
||||
fn proxying_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Proxy::add_proxy(Origin::signed(1), 2, ProxyType::JustTransfer, 0));
|
||||
assert_ok!(Proxy::add_proxy(Origin::signed(1), 3, ProxyType::Any, 0));
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(1), 2, ProxyType::JustTransfer, 0));
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(1), 3, ProxyType::Any, 0));
|
||||
|
||||
let call = Box::new(call_transfer(6, 1));
|
||||
assert_noop!(
|
||||
Proxy::proxy(Origin::signed(4), 1, None, call.clone()),
|
||||
Proxy::proxy(RuntimeOrigin::signed(4), 1, None, call.clone()),
|
||||
Error::<Test>::NotProxy
|
||||
);
|
||||
assert_noop!(
|
||||
Proxy::proxy(Origin::signed(2), 1, Some(ProxyType::Any), call.clone()),
|
||||
Proxy::proxy(RuntimeOrigin::signed(2), 1, Some(ProxyType::Any), call.clone()),
|
||||
Error::<Test>::NotProxy
|
||||
);
|
||||
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(2), 1, None, call.clone()));
|
||||
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into());
|
||||
assert_eq!(Balances::free_balance(6), 1);
|
||||
|
||||
let call = Box::new(RuntimeCall::System(SystemCall::set_code { code: vec![] }));
|
||||
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(3), 1, None, call.clone()));
|
||||
System::assert_last_event(
|
||||
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
|
||||
);
|
||||
@@ -533,11 +539,11 @@ fn proxying_works() {
|
||||
value: 1,
|
||||
}));
|
||||
assert_ok!(RuntimeCall::Proxy(super::Call::new_call_variant_proxy(1, None, call.clone()))
|
||||
.dispatch(Origin::signed(2)));
|
||||
.dispatch(RuntimeOrigin::signed(2)));
|
||||
System::assert_last_event(
|
||||
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
|
||||
);
|
||||
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(3), 1, None, call.clone()));
|
||||
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into());
|
||||
assert_eq!(Balances::free_balance(6), 2);
|
||||
});
|
||||
@@ -546,7 +552,7 @@ fn proxying_works() {
|
||||
#[test]
|
||||
fn anonymous_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Proxy::anonymous(Origin::signed(1), ProxyType::Any, 0, 0));
|
||||
assert_ok!(Proxy::anonymous(RuntimeOrigin::signed(1), ProxyType::Any, 0, 0));
|
||||
let anon = Proxy::anonymous_account(&1, &ProxyType::Any, 0, None);
|
||||
System::assert_last_event(
|
||||
ProxyEvent::AnonymousCreated {
|
||||
@@ -559,23 +565,23 @@ fn anonymous_works() {
|
||||
);
|
||||
|
||||
// other calls to anonymous allowed as long as they're not exactly the same.
|
||||
assert_ok!(Proxy::anonymous(Origin::signed(1), ProxyType::JustTransfer, 0, 0));
|
||||
assert_ok!(Proxy::anonymous(Origin::signed(1), ProxyType::Any, 0, 1));
|
||||
assert_ok!(Proxy::anonymous(RuntimeOrigin::signed(1), ProxyType::JustTransfer, 0, 0));
|
||||
assert_ok!(Proxy::anonymous(RuntimeOrigin::signed(1), ProxyType::Any, 0, 1));
|
||||
let anon2 = Proxy::anonymous_account(&2, &ProxyType::Any, 0, None);
|
||||
assert_ok!(Proxy::anonymous(Origin::signed(2), ProxyType::Any, 0, 0));
|
||||
assert_ok!(Proxy::anonymous(RuntimeOrigin::signed(2), ProxyType::Any, 0, 0));
|
||||
assert_noop!(
|
||||
Proxy::anonymous(Origin::signed(1), ProxyType::Any, 0, 0),
|
||||
Proxy::anonymous(RuntimeOrigin::signed(1), ProxyType::Any, 0, 0),
|
||||
Error::<Test>::Duplicate
|
||||
);
|
||||
System::set_extrinsic_index(1);
|
||||
assert_ok!(Proxy::anonymous(Origin::signed(1), ProxyType::Any, 0, 0));
|
||||
assert_ok!(Proxy::anonymous(RuntimeOrigin::signed(1), ProxyType::Any, 0, 0));
|
||||
System::set_extrinsic_index(0);
|
||||
System::set_block_number(2);
|
||||
assert_ok!(Proxy::anonymous(Origin::signed(1), ProxyType::Any, 0, 0));
|
||||
assert_ok!(Proxy::anonymous(RuntimeOrigin::signed(1), ProxyType::Any, 0, 0));
|
||||
|
||||
let call = Box::new(call_transfer(6, 1));
|
||||
assert_ok!(Balances::transfer(Origin::signed(3), anon, 5));
|
||||
assert_ok!(Proxy::proxy(Origin::signed(1), anon, None, call));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(3), anon, 5));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(1), anon, None, call));
|
||||
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into());
|
||||
assert_eq!(Balances::free_balance(6), 1);
|
||||
|
||||
@@ -586,18 +592,18 @@ fn anonymous_works() {
|
||||
1,
|
||||
0,
|
||||
)));
|
||||
assert_ok!(Proxy::proxy(Origin::signed(2), anon2, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(2), anon2, None, call.clone()));
|
||||
let de = DispatchError::from(Error::<Test>::NoPermission).stripped();
|
||||
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Err(de) }.into());
|
||||
assert_noop!(
|
||||
Proxy::kill_anonymous(Origin::signed(1), 1, ProxyType::Any, 0, 1, 0),
|
||||
Proxy::kill_anonymous(RuntimeOrigin::signed(1), 1, ProxyType::Any, 0, 1, 0),
|
||||
Error::<Test>::NoPermission
|
||||
);
|
||||
assert_eq!(Balances::free_balance(1), 0);
|
||||
assert_ok!(Proxy::proxy(Origin::signed(1), anon, None, call.clone()));
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(1), anon, None, call.clone()));
|
||||
assert_eq!(Balances::free_balance(1), 2);
|
||||
assert_noop!(
|
||||
Proxy::proxy(Origin::signed(1), anon, None, call.clone()),
|
||||
Proxy::proxy(RuntimeOrigin::signed(1), anon, None, call.clone()),
|
||||
Error::<Test>::NotProxy
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user