Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 1f70226

Browse files
zjb0807bkchr
andauthored
Add debug info in assert_has_event and assert_last_event (#12979)
* improve debug info in assert_has_event and assert_last_event * Apply suggestions from code review Co-authored-by: Bastian Köcher <[email protected]> Co-authored-by: Bastian Köcher <[email protected]>
1 parent 79cb2e6 commit 1f70226

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

frame/system/src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,13 +1503,21 @@ impl<T: Config> Pallet<T> {
15031503
/// Assert the given `event` exists.
15041504
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
15051505
pub fn assert_has_event(event: T::RuntimeEvent) {
1506-
assert!(Self::events().iter().any(|record| record.event == event))
1506+
let events = Self::events();
1507+
assert!(
1508+
events.iter().any(|record| record.event == event),
1509+
"expected event {event:?} not found in events {events:?}",
1510+
);
15071511
}
15081512

15091513
/// Assert the last event equal to the given `event`.
15101514
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
15111515
pub fn assert_last_event(event: T::RuntimeEvent) {
1512-
assert_eq!(Self::events().last().expect("events expected").event, event);
1516+
let last_event = Self::events().last().expect("events expected").event.clone();
1517+
assert_eq!(
1518+
last_event, event,
1519+
"expected event {event:?} is not equal to the last event {last_event:?}",
1520+
);
15131521
}
15141522

15151523
/// Return the chain's current runtime version.

0 commit comments

Comments
 (0)