Unverified Commit 2ba03515 authored by Andrew Jones's avatar Andrew Jones Committed by GitHub

[lang] remove EnvAccess inherent emit_event to avoid override (#378)

* Rename EnvAccess direct emit_event method to avoid override

* Remove EmitEvent trait import

* Add test for decoding Transfer Event

* Only provide test Event alias when there are events

* Fmt

* Revert "Remove EmitEvent trait import"

This reverts commit 078fb09f

* Rename emit_event_inner to emit_event_generic

* Be more explicit calling emit_event

* Be more explicit calling emit_event

* Rename to emit_generic_event

* Remove EnvAccess method entirely
parent c9765ed8
Pipeline #88424 passed with stages
in 13 minutes and 32 seconds
......@@ -155,8 +155,18 @@ mod erc20 {
fn new_works() {
// Constructor works.
let _erc20 = Erc20::new(100);
// Transfer event triggered during initial contruction.
assert_eq!(1, env::test::recorded_events().count());
let emitted_events = env::test::recorded_events().collect::<Vec<_>>();
assert_eq!(1, emitted_events.len());
let raw_event = emitted_events.first().unwrap();
let event = <Event as scale::Decode>::decode(&mut &raw_event.data[..])
.expect("Invalid contract Event");
if let Event::Transfer(transfer) = event {
assert_eq!(100, transfer.value);
} else {
panic!("Expected a Transfer Event")
}
}
/// The total supply was applied.
......
......@@ -69,6 +69,15 @@ impl GenerateCode for ContractModule<'_> {
let cross_calling = self.generate_code_using::<CrossCalling>();
let non_ink_items = &self.contract.non_ink_items;
let test_event_alias = if !self.contract.events.is_empty() {
quote! {
#[cfg(all(test, feature = "test-env"))]
pub type Event = self::__ink_private::Event;
}
} else {
quote! {}
};
quote! {
mod #ident {
#env_types
......@@ -96,6 +105,8 @@ impl GenerateCode for ContractModule<'_> {
#[cfg(feature = "ink-as-dependency")]
pub type #storage_ident = self::__ink_private::StorageAsDependency;
#test_event_alias
#event_structs
#(
......
......@@ -119,7 +119,7 @@ impl EventHelpers<'_> {
where
E: Into<Self::Event>,
{
ink_lang::EnvAccess::<EnvTypes>::emit_event(self, event.into())
ink_core::env::emit_event::<EnvTypes, Self::Event>(event.into());
}
}
};
......@@ -135,7 +135,7 @@ impl EventHelpers<'_> {
.collect::<Vec<_>>();
quote! {
#[derive(scale::Encode)]
#[derive(scale::Encode, scale::Decode)]
pub enum Event {
#( #event_idents(#event_idents), )*
}
......@@ -182,7 +182,7 @@ impl EventHelpers<'_> {
///
/// - making all fields `pub`
/// - strip `#[ink(..)]` attributes
/// - add `#[derive(scale::Encode)]`
/// - add `#[derive(scale::Encode, scale::Decode)]`
///
/// # Note
///
......@@ -223,7 +223,7 @@ impl EventStructs<'_> {
quote_spanned!(span =>
#conflic_depedency_cfg
#(#attrs)*
#[derive(scale::Encode)]
#[derive(scale::Encode, scale::Decode)]
pub struct #ident
#fields
)
......
......@@ -23,7 +23,6 @@ use ink_core::{
},
EnvTypes,
Result,
Topics,
},
};
use ink_primitives::Key;
......@@ -185,18 +184,6 @@ where
env::tombstone_deposit::<T>().expect("couldn't decode tombstone deposits")
}
/// Emits an event with the given event data.
///
/// # Note
///
/// For more details visit: [`ink_core::env::emit_event`]
pub fn emit_event<Event>(self, event: Event)
where
Event: Topics<T> + scale::Encode,
{
env::emit_event::<T, Event>(event)
}
/// Sets the rent allowance of the executed contract to the new value.
///
/// # Note
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment