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:
Shaun Wang
2021-05-13 00:17:03 +12:00
committed by GitHub
parent d89a01cd96
commit ad584733e9
18 changed files with 85 additions and 206 deletions
+12
View File
@@ -1449,6 +1449,18 @@ impl<T: Config> Pallet<T> {
<EventTopics<T>>::remove_all();
}
/// Assert the given `event` exists.
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
pub fn assert_has_event(event: T::Event) {
assert!(Self::events().iter().any(|record| record.event == event))
}
/// Assert the last event equal to the given `event`.
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
pub fn assert_last_event(event: T::Event) {
assert_eq!(Self::events().last().expect("events expected").event, event);
}
/// Return the chain's current runtime version.
pub fn runtime_version() -> RuntimeVersion { T::Version::get() }
+11
View File
@@ -374,6 +374,17 @@ fn deposit_event_topics() {
});
}
#[test]
fn event_util_functions_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
System::deposit_event(SysEvent::CodeUpdated);
System::assert_has_event(SysEvent::CodeUpdated.into());
System::assert_last_event(SysEvent::CodeUpdated.into());
});
}
#[test]
fn prunes_block_hash_mappings() {
new_test_ext().execute_with(|| {