-
Notifications
You must be signed in to change notification settings - Fork 384
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
feat(gnovm): add 'gno test -print-events' + cleanup machine between tests #2975
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2975 +/- ##
==========================================
+ Coverage 63.39% 63.40% +0.01%
==========================================
Files 565 565
Lines 79390 79454 +64
==========================================
+ Hits 50326 50377 +51
- Misses 25674 25682 +8
- Partials 3390 3395 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
…ests Signed-off-by: moul <[email protected]>
dd4fb02
to
68ca01d
Compare
Signed-off-by: moul <[email protected]>
Signed-off-by: moul <[email protected]>
Signed-off-by: moul <[email protected]>
Signed-off-by: moul <[email protected]>
Signed-off-by: moul <[email protected]>
There's a PR for this, although it hasn't been merged for some time. |
|
||
// No events yet | ||
events = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer required, no?
gnovm/cmd/gno/test.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this. What if we had something like testing.Events()
to get the list of events which were emitted, which then can be printed by the test?
This way, we also have a way to programmatically verify the tests, rather than having to pass -print-events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See consideration at bottom of #2007
This would definitely be something needed, it's standard in other blockchain ecosystems. Ideally, we could actually do type checking on event objects down the line, but for now I guess testing.Events()
would return a string of events or similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testing.Events
appears to be a valuable enhancement, particularly for unit testing. However, print-events
allows for event printing in existing flows, regardless of whether they have been tested or modified. In my case, I wanted to understand what was happening in some multiphase test flows. At another time, I aimed to identify all the tests that triggered a specific std.Emit
, including those from realms that import the emitter indirectly.
I believe it makes sense to keep both options. The one in this PR functions like a specialized logging engine. Additionally, events
serve as an alternative stdout in some ways.
Once we have the testing.Events()
helper, I'm definitely open to removing the -print-events
flag for the sake of simplification. Let's discuss when it will take place.
! stdout .+ | ||
stderr 'EVENTS: \[{\"type\":\"EventA\",\"attrs\":\[\],\"pkg_path\":\"gno.land/r/.*\",\"func\":\"TestA\"}\]' | ||
stderr 'EVENTS: \[{\"type\":\"EventB\",\"attrs\":\[{\"key\":\"keyA\",\"value\":\"valA\"}\],\"pkg_path\":\"gno.land/r/.*\",\"func\":\"TestB\"},{\"type\":\"EventC\",\"attrs\":\[{\"key\":\"keyD\",\"value\":\"valD\"}\],\"pkg_path\":\"gno.land/r/.*\",\"func\":\"TestB\"}\]' | ||
stderr 'ok \. \d\.\d\ds' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if maybe it would be nicer to have a more human-readable format when printing. 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current mode is to provide the same JSON output on the WebSocket, during the maketx
call, and in unit tests. Essentially, events are to be intercepted by machines, so I believe it is beneficial to have the exact same representation, which is also copy-paste friendly.
We can reconsider.
gno test -print-events
flag for unit tests.Props to @r3v4s for his work on feat(gno): use
verbose
flag to print emitted events #2071// Events:
support in_filetests.gno
.gno.Machine
between unit tests (\o/) .Fixes #1982
Closes #2071
Addresses #2007