mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 19:51:05 +00:00
frame system: add event util functions for tests. (#8734)
* frame system: add event util functions for tests. * URemove unused fn. * Apply review suggestions.
This commit is contained in:
@@ -20,17 +20,13 @@
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use super::*;
|
||||
use frame_system::{RawOrigin, EventRecord};
|
||||
use frame_system::RawOrigin;
|
||||
use frame_benchmarking::{benchmarks, account, whitelisted_caller, impl_benchmark_test_suite};
|
||||
|
||||
const SEED: u32 = 0;
|
||||
|
||||
fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
|
||||
let events = frame_system::Pallet::<T>::events();
|
||||
let system_event: <T as frame_system::Config>::Event = generic_event.into();
|
||||
// compare to the last event record
|
||||
let EventRecord { event, .. } = &events[events.len() - 1];
|
||||
assert_eq!(event, &system_event);
|
||||
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
|
||||
}
|
||||
|
||||
benchmarks! {
|
||||
|
||||
@@ -171,14 +171,6 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
ext
|
||||
}
|
||||
|
||||
fn last_event() -> Event {
|
||||
frame_system::Pallet::<Test>::events().pop().map(|e| e.event).expect("Event expected")
|
||||
}
|
||||
|
||||
fn expect_event<E: Into<Event>>(e: E) {
|
||||
assert_eq!(last_event(), e.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn as_derivative_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
@@ -313,7 +305,7 @@ fn batch_with_signed_filters() {
|
||||
Call::Balances(pallet_balances::Call::transfer_keep_alive(2, 1))
|
||||
]),
|
||||
);
|
||||
expect_event(utility::Event::BatchInterrupted(0, DispatchError::BadOrigin));
|
||||
System::assert_last_event(utility::Event::BatchInterrupted(0, DispatchError::BadOrigin).into());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -387,7 +379,7 @@ fn batch_handles_weight_refund() {
|
||||
let info = call.get_dispatch_info();
|
||||
let result = call.dispatch(Origin::signed(1));
|
||||
assert_ok!(result);
|
||||
expect_event(utility::Event::BatchInterrupted(1, DispatchError::Other("")));
|
||||
System::assert_last_event(utility::Event::BatchInterrupted(1, DispatchError::Other("")).into());
|
||||
// No weight is refunded
|
||||
assert_eq!(extract_actual_weight(&result, &info), info.weight);
|
||||
|
||||
@@ -400,7 +392,7 @@ fn batch_handles_weight_refund() {
|
||||
let info = call.get_dispatch_info();
|
||||
let result = call.dispatch(Origin::signed(1));
|
||||
assert_ok!(result);
|
||||
expect_event(utility::Event::BatchInterrupted(1, DispatchError::Other("")));
|
||||
System::assert_last_event(utility::Event::BatchInterrupted(1, DispatchError::Other("")).into());
|
||||
assert_eq!(extract_actual_weight(&result, &info), info.weight - diff * batch_len);
|
||||
|
||||
// Partial batch completion
|
||||
@@ -411,7 +403,7 @@ fn batch_handles_weight_refund() {
|
||||
let info = call.get_dispatch_info();
|
||||
let result = call.dispatch(Origin::signed(1));
|
||||
assert_ok!(result);
|
||||
expect_event(utility::Event::BatchInterrupted(1, DispatchError::Other("")));
|
||||
System::assert_last_event(utility::Event::BatchInterrupted(1, DispatchError::Other("")).into());
|
||||
assert_eq!(
|
||||
extract_actual_weight(&result, &info),
|
||||
// Real weight is 2 calls at end_weight
|
||||
|
||||
Reference in New Issue
Block a user