Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1453,10 +1453,6 @@ impl<T: Config> Pallet<T> {
/// NOTE: Events not registered at the genesis block and quietly omitted.
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
pub fn events() -> Vec<EventRecord<T::RuntimeEvent, T::Hash>> {
debug_assert!(
!Self::block_number().is_zero(),
"events not registered at the genesis block"
);
// Dereferencing the events here is fine since we are not in the
// memory-restricted runtime.
Self::read_events_no_consensus().map(|e| *e).collect()
Expand Down Expand Up @@ -1515,6 +1511,11 @@ impl<T: Config> Pallet<T> {
/// NOTE: Events not registered at the genesis block and quietly omitted.
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
pub fn assert_has_event(event: T::RuntimeEvent) {
debug_assert!(
!Self::block_number().is_zero(),
"events not registered at the genesis block"
);

let events = Self::events();
assert!(
events.iter().any(|record| record.event == event),
Expand All @@ -1527,6 +1528,11 @@ impl<T: Config> Pallet<T> {
/// NOTE: Events not registered at the genesis block and quietly omitted.
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
pub fn assert_last_event(event: T::RuntimeEvent) {
debug_assert!(
!Self::block_number().is_zero(),
"events not registered at the genesis block"
);

let last_event = Self::events().last().expect("events expected").event.clone();
assert_eq!(
last_event, event,
Expand Down