Add field names to pallet Event variants (#9993)

* convert pallet-assets events to struct types

* updated events of a couple pallets

* updated pallet event field names

* update pallet event field names

* updated events in test files

* cargo fmt

* minorfixes

* fix assertion error

* minor fix

* formatting fix

* fmt
This commit is contained in:
David Salami
2021-11-16 02:56:00 +01:00
committed by GitHub
parent fb3c7326c2
commit 120894fdb7
48 changed files with 1181 additions and 681 deletions
+9 -9
View File
@@ -86,7 +86,7 @@ benchmarks! {
let call: <T as Config>::Call = frame_system::Call::<T>::remark { remark: vec![] }.into();
}: _(RawOrigin::Signed(caller), real, Some(T::ProxyType::default()), Box::new(call))
verify {
assert_last_event::<T>(Event::ProxyExecuted(Ok(())).into())
assert_last_event::<T>(Event::ProxyExecuted { result: Ok(()) }.into())
}
proxy_announced {
@@ -107,7 +107,7 @@ benchmarks! {
add_announcements::<T>(a, Some(delegate.clone()), None)?;
}: _(RawOrigin::Signed(caller), delegate, real, Some(T::ProxyType::default()), Box::new(call))
verify {
assert_last_event::<T>(Event::ProxyExecuted(Ok(())).into())
assert_last_event::<T>(Event::ProxyExecuted { result: Ok(()) }.into())
}
remove_announcement {
@@ -165,7 +165,7 @@ benchmarks! {
let call_hash = T::CallHasher::hash_of(&call);
}: _(RawOrigin::Signed(caller.clone()), real.clone(), call_hash)
verify {
assert_last_event::<T>(Event::Announced(real, caller, call_hash).into());
assert_last_event::<T>(Event::Announced { real, proxy: caller, call_hash }.into());
}
add_proxy {
@@ -216,12 +216,12 @@ benchmarks! {
)
verify {
let anon_account = Pallet::<T>::anonymous_account(&caller, &T::ProxyType::default(), 0, None);
assert_last_event::<T>(Event::AnonymousCreated(
anon_account,
caller,
T::ProxyType::default(),
0,
).into());
assert_last_event::<T>(Event::AnonymousCreated {
anonymous: anon_account,
who: caller,
proxy_type: T::ProxyType::default(),
disambiguation_index: 0,
}.into());
}
kill_anonymous {
+29 -15
View File
@@ -327,7 +327,12 @@ pub mod pallet {
T::Currency::reserve(&who, deposit)?;
Proxies::<T>::insert(&anonymous, (bounded_proxies, deposit));
Self::deposit_event(Event::AnonymousCreated(anonymous, who, proxy_type, index));
Self::deposit_event(Event::AnonymousCreated {
anonymous,
who,
proxy_type,
disambiguation_index: index,
});
Ok(())
}
@@ -427,7 +432,7 @@ pub mod pallet {
})
.map(|d| *deposit = d)
})?;
Self::deposit_event(Event::Announced(real, who, call_hash));
Self::deposit_event(Event::Announced { real, proxy: who, call_hash });
Ok(())
}
@@ -547,16 +552,25 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// A proxy was executed correctly, with the given \[result\].
ProxyExecuted(DispatchResult),
/// A proxy was executed correctly, with the given.
ProxyExecuted { result: DispatchResult },
/// Anonymous account has been created by new proxy with given
/// disambiguation index and proxy type. \[anonymous, who, proxy_type,
/// disambiguation_index\]
AnonymousCreated(T::AccountId, T::AccountId, T::ProxyType, u16),
/// An announcement was placed to make a call in the future. \[real, proxy, call_hash\]
Announced(T::AccountId, T::AccountId, CallHashOf<T>),
/// A proxy was added. \[delegator, delegatee, proxy_type, delay\]
ProxyAdded(T::AccountId, T::AccountId, T::ProxyType, T::BlockNumber),
/// disambiguation index and proxy type.
AnonymousCreated {
anonymous: T::AccountId,
who: T::AccountId,
proxy_type: T::ProxyType,
disambiguation_index: u16,
},
/// An announcement was placed to make a call in the future.
Announced { real: T::AccountId, proxy: T::AccountId, call_hash: CallHashOf<T> },
/// A proxy was added.
ProxyAdded {
delegator: T::AccountId,
delegatee: T::AccountId,
proxy_type: T::ProxyType,
delay: T::BlockNumber,
},
}
/// Old name generated by `decl_event`.
@@ -672,12 +686,12 @@ impl<T: Config> Pallet<T> {
T::Currency::unreserve(delegator, *deposit - new_deposit);
}
*deposit = new_deposit;
Self::deposit_event(Event::<T>::ProxyAdded(
delegator.clone(),
Self::deposit_event(Event::<T>::ProxyAdded {
delegator: delegator.clone(),
delegatee,
proxy_type,
delay,
));
});
Ok(())
})
}
@@ -800,6 +814,6 @@ impl<T: Config> Pallet<T> {
}
});
let e = call.dispatch(origin);
Self::deposit_event(Event::ProxyExecuted(e.map(|_| ()).map_err(|e| e.error)));
Self::deposit_event(Event::ProxyExecuted { result: e.map(|_| ()).map_err(|e| e.error) });
}
}
+38 -24
View File
@@ -211,7 +211,15 @@ fn call_transfer(dest: u64, value: u64) -> Call {
fn announcement_works() {
new_test_ext().execute_with(|| {
assert_ok!(Proxy::add_proxy(Origin::signed(1), 3, ProxyType::Any, 1));
System::assert_last_event(ProxyEvent::ProxyAdded(1, 3, ProxyType::Any, 1).into());
System::assert_last_event(
ProxyEvent::ProxyAdded {
delegator: 1,
delegatee: 3,
proxy_type: ProxyType::Any,
delay: 1,
}
.into(),
);
assert_ok!(Proxy::add_proxy(Origin::signed(2), 3, ProxyType::Any, 1));
assert_eq!(Balances::reserved_balance(3), 0);
@@ -332,12 +340,12 @@ fn filtering_works() {
let call = Box::new(call_transfer(6, 1));
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
System::assert_last_event(ProxyEvent::ProxyExecuted(Ok(())).into());
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into());
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
System::assert_last_event(ProxyEvent::ProxyExecuted(Ok(())).into());
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into());
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
System::assert_last_event(
ProxyEvent::ProxyExecuted(Err(SystemError::CallFiltered.into())).into(),
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
);
let derivative_id = Utility::derivative_account_id(1, 0);
@@ -347,31 +355,31 @@ fn filtering_works() {
let call =
Box::new(Call::Utility(UtilityCall::as_derivative { index: 0, call: inner.clone() }));
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
System::assert_last_event(ProxyEvent::ProxyExecuted(Ok(())).into());
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into());
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
System::assert_last_event(
ProxyEvent::ProxyExecuted(Err(SystemError::CallFiltered.into())).into(),
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
);
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
System::assert_last_event(
ProxyEvent::ProxyExecuted(Err(SystemError::CallFiltered.into())).into(),
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
);
let call = Box::new(Call::Utility(UtilityCall::batch { calls: vec![*inner] }));
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
expect_events(vec![
UtilityEvent::BatchCompleted.into(),
ProxyEvent::ProxyExecuted(Ok(())).into(),
ProxyEvent::ProxyExecuted { result: Ok(()) }.into(),
]);
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
System::assert_last_event(
ProxyEvent::ProxyExecuted(Err(SystemError::CallFiltered.into())).into(),
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
);
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
expect_events(vec![
UtilityEvent::BatchInterrupted { index: 0, error: SystemError::CallFiltered.into() }
.into(),
ProxyEvent::ProxyExecuted(Ok(())).into(),
ProxyEvent::ProxyExecuted { result: Ok(()) }.into(),
]);
let inner =
@@ -380,32 +388,32 @@ fn filtering_works() {
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
expect_events(vec![
UtilityEvent::BatchCompleted.into(),
ProxyEvent::ProxyExecuted(Ok(())).into(),
ProxyEvent::ProxyExecuted { result: Ok(()) }.into(),
]);
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
System::assert_last_event(
ProxyEvent::ProxyExecuted(Err(SystemError::CallFiltered.into())).into(),
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
);
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
expect_events(vec![
UtilityEvent::BatchInterrupted { index: 0, error: SystemError::CallFiltered.into() }
.into(),
ProxyEvent::ProxyExecuted(Ok(())).into(),
ProxyEvent::ProxyExecuted { result: Ok(()) }.into(),
]);
let call = Box::new(Call::Proxy(ProxyCall::remove_proxies {}));
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
System::assert_last_event(
ProxyEvent::ProxyExecuted(Err(SystemError::CallFiltered.into())).into(),
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
);
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
System::assert_last_event(
ProxyEvent::ProxyExecuted(Err(SystemError::CallFiltered.into())).into(),
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
);
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
expect_events(vec![
BalancesEvent::<Test>::Unreserved(1, 5).into(),
ProxyEvent::ProxyExecuted(Ok(())).into(),
BalancesEvent::<Test>::Unreserved { who: 1, amount: 5 }.into(),
ProxyEvent::ProxyExecuted { result: Ok(()) }.into(),
]);
});
}
@@ -476,13 +484,13 @@ fn proxying_works() {
Error::<Test>::NotProxy
);
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
System::assert_last_event(ProxyEvent::ProxyExecuted(Ok(())).into());
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into());
assert_eq!(Balances::free_balance(6), 1);
let call = Box::new(Call::System(SystemCall::set_code { code: vec![] }));
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
System::assert_last_event(
ProxyEvent::ProxyExecuted(Err(SystemError::CallFiltered.into())).into(),
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
);
let call =
@@ -490,10 +498,10 @@ fn proxying_works() {
assert_ok!(Call::Proxy(super::Call::new_call_variant_proxy(1, None, call.clone()))
.dispatch(Origin::signed(2)));
System::assert_last_event(
ProxyEvent::ProxyExecuted(Err(SystemError::CallFiltered.into())).into(),
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
);
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
System::assert_last_event(ProxyEvent::ProxyExecuted(Ok(())).into());
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into());
assert_eq!(Balances::free_balance(6), 2);
});
}
@@ -504,7 +512,13 @@ fn anonymous_works() {
assert_ok!(Proxy::anonymous(Origin::signed(1), ProxyType::Any, 0, 0));
let anon = Proxy::anonymous_account(&1, &ProxyType::Any, 0, None);
System::assert_last_event(
ProxyEvent::AnonymousCreated(anon.clone(), 1, ProxyType::Any, 0).into(),
ProxyEvent::AnonymousCreated {
anonymous: anon.clone(),
who: 1,
proxy_type: ProxyType::Any,
disambiguation_index: 0,
}
.into(),
);
// other calls to anonymous allowed as long as they're not exactly the same.
@@ -525,7 +539,7 @@ fn anonymous_works() {
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));
System::assert_last_event(ProxyEvent::ProxyExecuted(Ok(())).into());
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into());
assert_eq!(Balances::free_balance(6), 1);
let call = Box::new(Call::Proxy(ProxyCall::new_call_variant_kill_anonymous(
@@ -537,7 +551,7 @@ fn anonymous_works() {
)));
assert_ok!(Proxy::proxy(Origin::signed(2), anon2, None, call.clone()));
let de = DispatchError::from(Error::<Test>::NoPermission).stripped();
System::assert_last_event(ProxyEvent::ProxyExecuted(Err(de)).into());
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Err(de) }.into());
assert_noop!(
Proxy::kill_anonymous(Origin::signed(1), 1, ProxyType::Any, 0, 1, 0),
Error::<Test>::NoPermission