Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_key_string method to RuntimeEvent #1107

Conversation

cemozerr
Copy link
Member

Description

Added a get_key_string method to the <runtime>Event enum generated by the Event macro.

This method will eventually be used to replace the user-defined event keys currently utilized for accessing events in the database.

Additionally, added the Event macro to the demo_stf runtime, and an Event enum to the ValueSetter module for testing purposes.

Testing

Tested the new get_key_string method in derive_event.rs

@codecov
Copy link

codecov bot commented Oct 25, 2023

Codecov Report

Merging #1107 (5ae3ad9) into nightly (9995ada) will increase coverage by 0.0%.
The diff coverage is 100.0%.

Files Coverage Δ
module-system/sov-modules-macros/src/event.rs 100.0% <100.0%> (ø)

... and 2 files with indirect coverage changes

let _event = RuntimeEvent::<DefaultContext>::second(second_test_module::Event::SecondModuleEnum);
{
let event = RuntimeEvent::<DefaultContext>::first(first_test_module::Event::FirstModuleEnum1(10));
assert_eq!(event.get_key_string(), "first-FirstModuleEnum1");
Copy link
Member

@bkolad bkolad Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this generate an expected string even if Event is struct/tuple/array/nested enum instead of an enum type?


{
let event = RuntimeEvent::<DefaultContext>::first(first_test_module::Event::FirstModuleEnum3(vec![1; 3]));
assert_eq!(event.get_key_string(), "first-FirstModuleEnum3");
Copy link
Member

@bkolad bkolad Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To create the key string using the get_key_string function, we require a value of Event::FirstModuleEnum3(..). However, obtaining this value necessitates providing a Vec this is fine when we save to the db.

Now, let's consider a scenario where a user wishes to query the database using the first-FirstModuleEnum3 key. What will be the method for the user to calculate the first-FirstModuleEnum3? Since he doesn't have a value of the Event::FirstModuleEnum3(...) he can't call get_key_string(&self). We have to think about the cases where the enums contain arbitrary complex structures and possibly other nested enums.

@cemozerr
Copy link
Member Author

Closing in favor of: #1116

@cemozerr cemozerr closed this Oct 27, 2023
@cemozerr cemozerr deleted the addGetKeyStringToRuntimeEventEnum branch October 27, 2023 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants