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

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

Open
leohhhn opened this issue Jun 12, 2024 · 1 comment
Open

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

leohhhn opened this issue Jun 12, 2024 · 1 comment

Comments

@leohhhn
Copy link
Contributor

leohhhn commented Jun 12, 2024

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
Copy link
Member

thehowl commented Jun 24, 2024

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.

type Context struct {
IsOrigin bool
CurrentRealm chain.Realm
Deposit chain.Coins
ChainID string
Height uint64
Time time.Time
Banker chain.Banker
Logger bool // TODO
}
func (c Context) Run(f func()) {
}

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Triage
Development

No branches or pull requests

2 participants