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

feat(gno): use verbose flag to print emitted events #2071

Closed

Conversation

r3v4s
Copy link
Contributor

@r3v4s r3v4s commented May 10, 2024

Closes half of #2007

Add print-events flag to print emitted events in gno -test.

Sample

// event.gno
package event

import (
	"std"
)

func Hello() string {
	std.Emit("hello", "emit_key", "emit_value")

	return "hello_return"
}
// event_test.gno
package event

import (
	"std"
	"testing"
)

func TestFunc(t *testing.T) {
	Hello()

	std.Emit("tEsTfUnC", "test key", "test value")
}

func TestOtherEvent(t *testing.T) {
	std.Emit("otherEvent", "test key", "test value")
}

Ouput

image
Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

@r3v4s r3v4s requested a review from leohhhn May 10, 2024 11:13
@r3v4s r3v4s self-assigned this May 10, 2024
@github-actions github-actions bot added 📦 🤖 gnovm Issues or PRs gnovm related 📦 🌐 tendermint v2 Issues or PRs tm2 related labels May 10, 2024
@r3v4s r3v4s added 🌱 feature New update to Gno and removed 📦 🤖 gnovm Issues or PRs gnovm related 📦 🌐 tendermint v2 Issues or PRs tm2 related labels May 10, 2024
Copy link

codecov bot commented May 10, 2024

Codecov Report

Attention: Patch coverage is 55.55556% with 8 lines in your changes missing coverage. Please review.

Project coverage is 60.99%. Comparing base (a2b4d4b) to head (984093b).
Report is 46 commits behind head on master.

Files with missing lines Patch % Lines
tm2/pkg/colors/colors.go 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2071      +/-   ##
==========================================
+ Coverage   60.95%   60.99%   +0.03%     
==========================================
  Files         564      564              
  Lines       75273    75290      +17     
==========================================
+ Hits        45885    45925      +40     
+ Misses      26018    25995      -23     
  Partials     3370     3370              
Flag Coverage Δ
contribs/gnodev 61.46% <ø> (ø)
contribs/gnofaucet 14.46% <ø> (ø)
gno.land 67.92% <ø> (ø)
gnovm 65.88% <100.00%> (+0.10%) ⬆️
misc/genstd 80.54% <ø> (ø)
misc/logos 20.23% <ø> (ø)
tm2 62.07% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@moul moul left a comment

Choose a reason for hiding this comment

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

Events printing should be as common as stdout. It should be the default on gnokey maketx and similar commands.

Regarding gnotest, I'm considering whether your approach is the best or if we should print nothing by default and only print everything (stdout and events) when using the -v option.

Blocking. We should wait for more feedback before making a decision.

@leohhhn
Copy link
Contributor

leohhhn commented May 12, 2024

Hey @moul, here is the issue with the discussion about this - TL;DR I am in favor of adding -print-events apart from -v, since the events might clog up the test output if there is lots of them, making the output unreadable. Maybe -print-events would have the same functionality that -v has, plus the added printing of events.

@github-actions github-actions bot added 📦 🤖 gnovm Issues or PRs gnovm related 📦 🌐 tendermint v2 Issues or PRs tm2 related labels May 14, 2024
Copy link
Member

@zivkovicmilos zivkovicmilos left a comment

Choose a reason for hiding this comment

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

I've left a few comments that need addressing before we can move forward, otherwise it looks good 💯

gnovm/cmd/gno/test.go Show resolved Hide resolved
tm2/pkg/colors/colors.go Show resolved Hide resolved
tm2/pkg/colors/colors.go Show resolved Hide resolved
res := gno.Call("runtest", testFuncStr)

eval := m.Eval(res) // NOTE: verbose prints get here
if printEvents {
Copy link
Member

Choose a reason for hiding this comment

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

I agree with @moul, I think we should print these events if the verbose flag is enabled, and not hide this functionality behind an additional flag we need to now maintain

The reasoning is that events are now an integral part of the Gno development lifecycle, and not a "feature" we can disable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reasoning is that events are now an integral part of the Gno development lifecycle

I totally understand, however for easier(or at least more readable) debugging flags needs to be separated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gnovm/cmd/gno/test.go Show resolved Hide resolved
gnovm/cmd/gno/test.go Show resolved Hide resolved
@r3v4s r3v4s force-pushed the feat/print-emit-during-gno-test branch from 875394f to 2cf4dec Compare September 19, 2024 07:43
@moul
Copy link
Member

moul commented Sep 21, 2024

If stdout is printed, events should also be printed if they exist. Currently, events should be considered as returned values of a contract, representing an outcome or consequence as the returned value (stdout).

Let's wait for a clear example to determine if events are too spammy. Initially, we should consider reducing the number of events. If they overwhelm users, it makes the contract's usage more implicit, which we aim to avoid.

We should always print events when stdout is printed and maintain our usual rule: strive for straightforward, explicit, and simple communication without hiding things as soon as they become complex; let's just remove the complex.

@zivkovicmilos
Copy link
Member

@r3v4s

Can you please check why the CI is failing and apply @moul's comment, so we can go ahead with merging this? 🙏

@r3v4s r3v4s changed the title feat(gno): add -print-events flag to gno test to print emitted events feat(gno): use verbose flag to print emitted events Oct 3, 2024
@r3v4s
Copy link
Contributor Author

r3v4s commented Oct 3, 2024

@zivkovicmilos
Removed new flag(print-events) and applied existing flag verbose` to print emitted events or not.

And CI fails on codecov against ColoredBytesOnlyAscii function, which I can't think of straightforward way to make it not to fail. Can you enlighten me?

@moul
Copy link
Member

moul commented Oct 23, 2024

Closed in favor of #2975. But thank you @r3v4s!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 🤖 gnovm Issues or PRs gnovm related 🌱 feature New update to Gno
Projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants