gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + Gno.land: a blockchain for timeless code and fair open-source
https://gno.land/
Other
839 stars 342 forks source link

[Discussion/Request] Add a way to catch emitted events in `gno test` #2338

Open leohhhn opened 2 weeks ago

leohhhn commented 2 weeks ago

Description

We should be able to test events that are being emitted in gno test. Is this feasible having in mind the multiple layers that events work on?

A suggested approach for the UX could be having a expectEmit function somewhere. I like Foundry's approach.

It does not really fit into std, which makes an even stronger case for moving TestSetXYZ functions out of the std package and adding them to a new gno-specific testing package (or similar), and having such a function there.

@thehowl what do you think?

thehowl commented 1 day ago

I still need to scope the whole idea out, but I'm thinking about having a simple helper function in testing to replace the ExecContext with one passed in by the user at runtime, which is executed within a closure.

https://github.com/gnolang/gno/blob/ef3b26432523c331634f508bc33ba508b27b4609/gnovm/stdlibs/testing/context.gno#L9-L21

This is still WIP, but my idea here is that the user can essentially add a "mock" emitter and capture all emitted events, within the closure passed to Run.