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

Improve txtar DX #1269

Open
moul opened this issue Oct 20, 2023 · 5 comments
Open

Improve txtar DX #1269

moul opened this issue Oct 20, 2023 · 5 comments

Comments

@moul
Copy link
Member

moul commented Oct 20, 2023

Since we're increasingly using txtar, both as an integration test system and a means of sharing self-contained complex examples (#1262), I propose enhancing the txtar experience for developers. Here are some suggestions:

  • Explore a suitable .gitattributes linguist language from this resource: https://gist.github.com/moul/113c2cc8bb27ce80969995192ddb4c7f.
  • Consider configuring .editorconfig or sharing code snippets in CONTRIBUTING.md.
  • In any case, update CONTRIBUTING.md to provide context and examples. For instance, highlight the effectiveness of running a specific txtar that delivers exceptional speed.
  • Are there any other ideas worth considering?

cc @gfanton

@moul
Copy link
Member Author

moul commented Nov 10, 2023

  • Allow having txtar files alongside .gno files in examples/ folder.
  • Add more test addresses by default (test2, test3, test4), and make it easy to use them.

@gfanton
Copy link
Member

gfanton commented Nov 13, 2023

Explore a suitable .gitattributes linguist language from this resource.

I didn't examine in detail, but we can likely add a linguist directly to GitHub to support these files. It appears we need at least 200 unique repositories using this extension to submit a new one, which might already be possible given the fact that txtar was existing before gno.
In any case we can temporarily use one of the linguists you suggest.

Allow having txtar files alongside .gno files in the examples/ folder.

I actually like the idea of having a specific testdata directory as a subfolder of the current working directory. However, we might not enforce this. Instead, I suggest we create a gno testscripts command that can accept folders/files as arguments, similar to the go test command.

Based on recent experiences, I am exploring better ways to configure gnoland node from txtar. One idea is to start the node automatically with some sane defaults, but also allow explicit configuration using files like .env or config.json, or both, directly inside the .txtar:

# The node is already started.

# Execute some commands.
gnokey addpkg ...

-- myrealm.gno --
package hello

func Render(path string) string {
    return "hello world"
}

-- .env --
# gnoland config
GNOLAND_START_MINIMAL=true

# balance
GNOLAND_BALANCE_USER_test2=100000ugnot
GNOLAND_BALANCE_USER_test3=100000ugnot
...

With this approach, we can easily create users directly or update configurations as needed.

moul added a commit that referenced this issue Dec 7, 2023
This PR presents a GNOT wrapper that conforms to the GRC20 interface.

Optimally, the txtar file should be relocated to the wugnot directory,
pending resolution of [issue
#1269](#1269 (comment)).

Enabling the use of `gnokey maketx call -func WUGNOT.Transfer` over
`-func Transfer` would streamline the wrapper, reducing it to just the
initial 55 lines.

<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [x] Provided any useful hints for running manual tests
- [x] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>

---------

Signed-off-by: moul <94029+moul@users.noreply.github.com>
@jaekwon
Copy link
Contributor

jaekwon commented Jan 8, 2024

I would avoid using environment variables for input, and discourage its usage by not supporting it where at all possible.
Environment variables are prime candidate for hacking due to random behavior from various bash systems.
It's like the global of globals, and it's already full of other shit.

I much prefer explicit --flags, or files. Anything but environment variables.

My main thing with tests is this:

I just want "make test" to work as expected, at the root, and at the individual project levels. At the root it should just pass any options and call make test individually.

Anyone who pulls the codebase should be able to get make test passing, and go test ./... should all work as expected too.
Anything else and it fails from a developer UX perspective.

@jaekwon
Copy link
Contributor

jaekwon commented Jan 8, 2024

The test data should not be compiled into the same binary as the gnoland binary.
They should be built completely independently. Any association will lead to security issues.
Testing must never compile into the production build.
Can these integration tests be instead implemented as regular Test*() tests?

@gfanton
Copy link
Member

gfanton commented Jan 9, 2024

Can these integration tests be instead implemented as regular Test*() tests?

They already are, and for now, they are not part of the gnoland binary. Even though it might look like bash, txtar is different and should not be compared to it, as it runs on the golang runtime with its own specifications. Its aim is to be simple; you cannot use if, &&, |, ;, etc.

Anyone who pulls the codebase should be able to get make test passing, and go test ./... should all work as expected too. Anything else fails from a developer UX perspective.

I totally agree with this. txtar is actually running inside the Golang standard test, so running go test ./... already works without any additional configuration.

The test data should not be compiled into the same binary as the gnoland binary.

That's fine. The gno testscripts I suggest could be moved to a gnodev binary (or something else in the contribs folder). I just want a way for people to easily run txtar files from outside the gno repository.

I would avoid using environment variables for input, and discourage its usage by not supporting it where at all possible.

It's not yet implemented, but I intended to use environment variables to create something that users can easily copy and paste in a bash environment. I understand that we shouldn't use this in production, but it can be handy in a testing environment. I don't mind using something else, like flags.

gfanton pushed a commit to moul/gno that referenced this issue Jan 18, 2024
This PR presents a GNOT wrapper that conforms to the GRC20 interface.

Optimally, the txtar file should be relocated to the wugnot directory,
pending resolution of [issue
gnolang#1269](gnolang#1269 (comment)).

Enabling the use of `gnokey maketx call -func WUGNOT.Transfer` over
`-func Transfer` would streamline the wrapper, reducing it to just the
initial 55 lines.

<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [x] Provided any useful hints for running manual tests
- [x] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>

---------

Signed-off-by: moul <94029+moul@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📥 Inbox
Status: 🔵 Not Needed for Launch
Development

No branches or pull requests

3 participants