Skip to content

Commit

Permalink
Resolve requests, fix import issue, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cemozerr committed Oct 29, 2023
1 parent 0444cb2 commit 7526a2d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 18 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/demo-rollup/provers/risc0/guest-mock/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions module-system/sov-modules-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ serde_json = { workspace = true, optional = true }
hex = { workspace = true }
clap = { workspace = true, optional = true }
schemars = { workspace = true, optional = true, features = [] }
tracing = { workspace = true }

ed25519-dalek = { version = "2.0.0", default-features = false, features = ["serde"] }
rand = { version = "0.8", optional = true }
Expand Down
3 changes: 2 additions & 1 deletion module-system/sov-modules-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ pub trait Module {

impl Event for () {
fn event_key(&self) -> &'static str {
unimplemented!("Event type for this module does not exist.")
tracing::warn!("Trying to get the event_key string for an undefined event.");
"NA-Event-Not-Defined"
}
}

Expand Down
11 changes: 6 additions & 5 deletions module-system/sov-modules-macros/src/runtime_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ impl<'a> StructDef<'a> {
let name = &field.ident;
let ty = &field.ty;

let doc: String = format!("An event emitted by the {} module", name.to_string());

quote::quote!(
#[doc = "Module event."]
#[doc = #doc]
#name(<#ty as ::sov_modules_api::Module>::Event),
)
})
Expand All @@ -38,10 +40,7 @@ impl<'a> StructDef<'a> {
let module_name_str = &field.ident.to_string();
quote::quote!(
#enum_ident::#module_name(inner)=>{
let enum_name: String = format!("{:?}", inner)
.split('(')
.collect::<Vec<&str>>()[0].to_string();
format!("{}-{}", #module_name_str, enum_name)
format!("{}-{}", #module_name_str, inner.event_key())
},
)
})
Expand All @@ -57,6 +56,8 @@ impl<'a> StructDef<'a> {

/// Returns a string that identifies both the module and the event type
pub fn get_key_string(&self) -> String {
use ::sov_modules_api::Event as _;

match self {
#(#match_legs)*
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod modules;
use modules::{first_test_module, second_test_module, third_test_module, fourth_test_module, fourth_test_module::MyStruct, fourth_test_module::MyNewStruct, fourth_test_module::NestedEnum};
use modules::{first_test_module, second_test_module,
third_test_module,
fourth_test_module, fourth_test_module::MyStruct, fourth_test_module::MyNewStruct, fourth_test_module::NestedEnum};
use sov_modules_api::default_context::DefaultContext;
use sov_modules_api::macros::DefaultRuntime;
use sov_modules_api::{
Expand All @@ -17,15 +19,24 @@ struct Runtime<C: Context>
}

fn main() {
// Check to see if the runtime events are getting initialized correctly
let _event = RuntimeEvent::<DefaultContext>::first(first_test_module::MyEvent::Variant1(10));
let _event = RuntimeEvent::<DefaultContext>::first(first_test_module::MyEvent::Variant2);
let _event = RuntimeEvent::<DefaultContext>::first(first_test_module::MyEvent::Variant3(vec![1; 3]));
let _event = RuntimeEvent::<DefaultContext>::second(second_test_module::MyEvent::Variant);
let _event = RuntimeEvent::<DefaultContext>::third(());
let _event = RuntimeEvent::<DefaultContext>::fourth(fourth_test_module::MyEvent::Variant1);
let _event = RuntimeEvent::<DefaultContext>::fourth(fourth_test_module::MyEvent::Variant2WithStruct(MyStruct { a: 10, b: "abc".to_string()}));
let _event = RuntimeEvent::<DefaultContext>::fourth(fourth_test_module::MyEvent::Variant3WithNewTypeStruct(MyNewStruct(10)));
let _event = RuntimeEvent::<DefaultContext>::fourth(fourth_test_module::MyEvent::Variant4WithUnnamedStruct { a: 10, b: "abc".to_string()});
let _event = RuntimeEvent::<DefaultContext>::fourth(fourth_test_module::MyEvent::Variant5WithNestedEnum(NestedEnum::Variant1));
let event = RuntimeEvent::<DefaultContext>::first(first_test_module::MyEvent::Variant1(10));
assert_eq!(event.get_key_string(), "first-Variant1");
let event = RuntimeEvent::<DefaultContext>::first(first_test_module::MyEvent::Variant2);
assert_eq!(event.get_key_string(), "first-Variant2");
let event = RuntimeEvent::<DefaultContext>::first(first_test_module::MyEvent::Variant3(vec![1; 3]));
assert_eq!(event.get_key_string(), "first-Variant3");
let event = RuntimeEvent::<DefaultContext>::second(second_test_module::MyEvent::Variant);
assert_eq!(event.get_key_string(), "second-Variant");
let event = RuntimeEvent::<DefaultContext>::third(());
assert_eq!(event.get_key_string(), "third-NA-Event-Not-Defined");
let event = RuntimeEvent::<DefaultContext>::fourth(fourth_test_module::MyEvent::Variant1);
assert_eq!(event.get_key_string(), "fourth-Variant1");
let event = RuntimeEvent::<DefaultContext>::fourth(fourth_test_module::MyEvent::Variant2WithStruct(MyStruct { a: 10, b: "abc".to_string()}));
assert_eq!(event.get_key_string(), "fourth-Variant2WithStruct");
let event = RuntimeEvent::<DefaultContext>::fourth(fourth_test_module::MyEvent::Variant3WithNewTypeStruct(MyNewStruct(10)));
assert_eq!(event.get_key_string(), "fourth-Variant3WithNewTypeStruct");
let event = RuntimeEvent::<DefaultContext>::fourth(fourth_test_module::MyEvent::Variant4WithUnnamedStruct { a: 10, b: "abc".to_string()});
assert_eq!(event.get_key_string(), "fourth-Variant4WithUnnamedStruct");
let event = RuntimeEvent::<DefaultContext>::fourth(fourth_test_module::MyEvent::Variant5WithNestedEnum(NestedEnum::Variant1));
assert_eq!(event.get_key_string(), "fourth-Variant5WithNestedEnum");
}

0 comments on commit 7526a2d

Please sign in to comment.