forked from gnolang/gno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add txtar driver for gnoland integration test (gnolang#1117)
Resolves gnolang#1101. This PR establishes a base for creating `txtar` tests using a partial in-memory `gnoland` node. It supports: - `gnoland [start|stop]`: The node doesn't start automatically, which enables users to perform pre-configuration or pass custom arguments to the start command. - `gnokey`: Most of the commands should work. The `--remote`, `--insecure-password-stdin`, and `--home` flags are automatically set with the appropriate values to communicate with the node. - `sleep`: A simple helper to introduce a delay between actions, ensuring specific tasks complete before proceeding. Currently, only the "test1" user is automatically created in the default keybase directory (without a password). Default `gnoland` genesis balance and genesis transaction files are also load on start. You can find some examples of `txtar` in this directory: https://github.com/gfanton/gno/tree/feat/gnoland-txtar-driver/gno.land/cmd/gnoland/testdata `gnoland` logs aren't forwarded to stdout to avoid overwhelming informations in the tests. Instead, you can specify a log directory using the `LOG_DIR` environment variable or set `TESTWORK=true` to enable persistence in the `txtar` working directory. In either case, the path to the log file will be printed at the start if one of these environment variables is set. This also enables storing logs as artifacts on the CI for later examination. There is still a lot to do, but I believe this provides a good base for future iterations. <!-- please provide a detailed description of the changes made in this pull request. --> <details><summary>Contributors' checklist...</summary> - [ ] 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](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com> Co-authored-by: Manfred Touron <94029+moul@users.noreply.github.com> Co-authored-by: Morgan <git@howl.moe>
- Loading branch information
1 parent
8c0e6ee
commit 5824315
Showing
30 changed files
with
1,065 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Gnoland Testing Guide | ||
|
||
This guide provides an overview of our testing practices and conventions. While most of our testing aligns with typical Go practices, there are exceptions and specifics you should be aware of. | ||
|
||
## Standard Package Testing | ||
|
||
For most packages, tests are written and executed in the standard Go manner: | ||
|
||
- Tests are located alongside the code they test. | ||
- The `go test` command can be used to execute tests. | ||
|
||
However, as mentioned earlier, there are some exceptions. In the following sections, we will explore our specialized tests and how to work with them. | ||
|
||
## Gno Filetests | ||
|
||
**Location:** `gnovm/test/files` | ||
|
||
These are our custom file-based tests tailored specifically for this project. | ||
|
||
**Execution:** | ||
|
||
From the gnovm directory, There are two main commands to run Gno filetests: | ||
|
||
1. To test native files, use: | ||
``` | ||
make _test.gnolang.native | ||
``` | ||
|
||
2. To test standard libraries, use: | ||
``` | ||
make _test.gnolang.stdlibs | ||
``` | ||
|
||
**Golden Files Update:** | ||
|
||
Golden files are references for expected outputs. Sometimes, after certain updates, these need to be synchronized. To do so: | ||
|
||
1. For native tests: | ||
``` | ||
make _test.gnolang.native.sync | ||
``` | ||
|
||
2. For standard library tests: | ||
``` | ||
make _test.gnolang.stdlibs.sync | ||
``` | ||
|
||
## Integration Tests | ||
|
||
**Location:** `gno.land/**/testdata` | ||
|
||
From the gno.land directory, Integration tests are designed to ensure different parts of the project work cohesively. Specifically: | ||
|
||
1. **InMemory Node Integration Testing:** | ||
Found in `gno.land/cmd/gnoland/testdata`, these are dedicated to running integration tests against a genuine `gnoland` node. | ||
|
||
2. **Integration Features Testing:** | ||
Located in `gno.land/pkg/integration/testdata`, these tests target integrations specific commands. | ||
|
||
These integration tests utilize the `testscript` package and follow the `txtar` file specifications. | ||
|
||
**Documentation:** | ||
|
||
- For general `testscript` package documentation, refer to: [testscript documentation](https://github.com/rogpeppe/go-internal/blob/v1.11.0/testscript/doc.go) | ||
|
||
- For more specific details about our integration tests, consult our extended documentation: [gnoland integration documentation](https://github.com/gnolang/gno/blob/master/gno.land/pkg/integration/doc.go) | ||
|
||
**Execution:** | ||
|
||
To run the integration tests (alongside other packages): | ||
|
||
``` | ||
make _test.pkgs | ||
``` | ||
|
||
**Golden Files Update within txtar:** | ||
|
||
For tests utilizing the `cmp` command inside `txtar` files, golden files can be synchronized using: | ||
|
||
``` | ||
make _test.pkgs.sync | ||
``` | ||
|
||
--- | ||
|
||
As the project evolves, this guide might be updated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gnolang/gno/gno.land/pkg/integration" | ||
"github.com/rogpeppe/go-internal/testscript" | ||
) | ||
|
||
func TestTestdata(t *testing.T) { | ||
testscript.Run(t, integration.SetupGnolandTestScript(t, "testdata")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# test for add package | ||
|
||
## start a new node | ||
gnoland start | ||
|
||
## add bar.gno package located in $WORK directory as gno.land/r/foobar/bar | ||
gnokey maketx addpkg -pkgdir $WORK -pkgpath gno.land/r/foobar/bar -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
|
||
## execute Render | ||
gnokey maketx call -pkgpath gno.land/r/foobar/bar -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -args '' -broadcast -chainid=tendermint_test test1 | ||
|
||
## compare render | ||
cmp stdout stdout.golden | ||
|
||
-- bar.gno -- | ||
package bar | ||
|
||
func Render(path string) string { | ||
return "hello from foo" | ||
} | ||
|
||
-- stdout.golden -- | ||
("hello from foo" string) | ||
OK! | ||
GAS WANTED: 2000000 | ||
GAS USED: 69163 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.