Skip to content

Commit

Permalink
Merge branch 'master' into migrate-pallet-slots-to-benchmarking-v2-sy…
Browse files Browse the repository at this point in the history
…ntax
  • Loading branch information
bkchr authored Jan 25, 2025
2 parents c9c06af + 17ae062 commit 8d6453c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions substrate/frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2062,23 +2062,41 @@ impl<T: Config> Pallet<T> {
///
/// NOTE: Events not registered at the genesis block and quietly omitted.
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
#[track_caller]
pub fn assert_has_event(event: T::RuntimeEvent) {
let warn = if Self::block_number().is_zero() {
"WARNING: block number is zero, and events are not registered at block number zero.\n"
} else {
""
};

let events = Self::events();
assert!(
events.iter().any(|record| record.event == event),
"expected event {event:?} not found in events {events:?}",
"{warn}expected event {event:?} not found in events {events:?}",
);
}

/// Assert the last event equal to the given `event`.
///
/// NOTE: Events not registered at the genesis block and quietly omitted.
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
#[track_caller]
pub fn assert_last_event(event: T::RuntimeEvent) {
let last_event = Self::events().last().expect("events expected").event.clone();
let warn = if Self::block_number().is_zero() {
"WARNING: block number is zero, and events are not registered at block number zero.\n"
} else {
""
};

let last_event = Self::events()
.last()
.expect(&alloc::format!("{warn}events expected"))
.event
.clone();
assert_eq!(
last_event, event,
"expected event {event:?} is not equal to the last event {last_event:?}",
"{warn}expected event {event:?} is not equal to the last event {last_event:?}",
);
}

Expand Down

0 comments on commit 8d6453c

Please sign in to comment.