In unit test, how to read module event? #380
-
Discord user ID0xaptos Describe your question in detail.Take my simple message board contract as an example, I create a message in an object, I emit an event, is there any way to read the event in my unit test? I think current workaround is we create another function like Ideally we can read the module event in unit test, so i can call the /// Create a new message
public entry fun craete_message(sender: &signer, content: String) {
let message_obj_constructor_ref = &object::create_object(@message_board_addr);
let message_obj_signer = &object::generate_signer(message_obj_constructor_ref);
let message = Message {
creator: signer::address_of(sender),
creation_timestamp: timestamp::now_seconds(),
content,
};
move_to(message_obj_signer, message);
event::emit(CreateMessageEvent {
message_obj: object::object_from_constructor_ref(message_obj_constructor_ref),
message,
});
} What error, if any, are you getting?No response What have you tried or looked at? Or how can we reproduce the error?No response Which operating system are you using?macOS Which SDK or tool are you using? (if any)TypeScript SDK Describe your environment or tooling in detailNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can use these test only functions to check emitted events. |
Beta Was this translation helpful? Give feedback.
You can use these test only functions to check emitted events.
https://github.com/aptos-labs/aptos-core/blob/main/aptos-move/framework/aptos-framework/sources/event.move#L21-L28