From 28b6b0bfd8b003ad316e4139888ed23c0312950a Mon Sep 17 00:00:00 2001 From: green Date: Thu, 6 Jul 2023 22:04:23 +0100 Subject: [PATCH 1/2] Usage of the crate includes defined there events --- integration-tests/events/event-def-unused/src/lib.rs | 6 ++++++ integration-tests/events/lib.rs | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/integration-tests/events/event-def-unused/src/lib.rs b/integration-tests/events/event-def-unused/src/lib.rs index 9fc3065ab82..cbf2d719fd8 100644 --- a/integration-tests/events/event-def-unused/src/lib.rs +++ b/integration-tests/events/event-def-unused/src/lib.rs @@ -1,5 +1,11 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] +#[ink::trait_definition] +pub trait FlipperTrait { + #[ink(message)] + fn flip(&mut self); +} + #[ink::event] pub struct EventDefUnused { #[ink(topic)] diff --git a/integration-tests/events/lib.rs b/integration-tests/events/lib.rs index aee5a60076e..975adb6a4ab 100644 --- a/integration-tests/events/lib.rs +++ b/integration-tests/events/lib.rs @@ -77,6 +77,13 @@ pub mod events { } } + impl event_def_unused::FlipperTrait for Events { + #[ink(message)] + fn flip(&mut self) { + self.value = !self.value; + } + } + #[cfg(test)] mod tests { use super::*; From d0aa0b167ea329b14bda14f1175413fcec962d9c Mon Sep 17 00:00:00 2001 From: green Date: Thu, 13 Jul 2023 19:49:47 +0100 Subject: [PATCH 2/2] Inclusion of the event from `event_def_unused` is expected --- integration-tests/events/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/integration-tests/events/lib.rs b/integration-tests/events/lib.rs index 975adb6a4ab..aa88c7af2f8 100644 --- a/integration-tests/events/lib.rs +++ b/integration-tests/events/lib.rs @@ -77,6 +77,8 @@ pub mod events { } } + /// Implementing the trait from the `event_def_unused` crate includes all defined + /// events there. impl event_def_unused::FlipperTrait for Events { #[ink(message)] fn flip(&mut self) { @@ -92,7 +94,7 @@ pub mod events { #[test] fn collects_specs_for_all_linked_and_used_events() { let event_specs = ink::metadata::collect_events(); - assert_eq!(6, event_specs.len()); + assert_eq!(7, event_specs.len()); assert!(event_specs .iter() @@ -113,7 +115,9 @@ pub mod events { .iter() .any(|evt| evt.label() == &"InlineAnonymousEvent")); - assert!(!event_specs + // The event is not used in the code by being included in the metadata + // because we implement trait form `event_def_unused` crate. + assert!(event_specs .iter() .any(|evt| evt.label() == &"EventDefUnused")); }