-
Notifications
You must be signed in to change notification settings - Fork 374
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: add txtar driver for gnoland integration test #1117
Merged
Merged
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
ad175a8
feat: add txtar driver to gnoland
gfanton 9f4be75
chore: reload coverage
gfanton 686ae5f
fix: increase sleep before gnoland is ready
gfanton 76074e8
Merge branch 'master' into feat/gnoland-txtar-driver
gfanton 89420bc
feat: export gnoland integration function
gfanton f887613
feat: txtar log improvements
gfanton 30ba1de
fix: fixup render
gfanton cc1de0b
feat: add logger
gfanton b9d9156
chore: gno directory name definition
gfanton fc811ff
feat: upload logs as artifact
gfanton c0ed4b1
chore: lint
gfanton ed27557
Merge remote-tracking branch 'origin/master' into feat/gnoland-txtar-…
gfanton e808b91
fix: add sleep after addpkg command
gfanton 5a7f784
chore: add comment on app gnorootdir
gfanton 1b7d71c
chore: fix and update comments
gfanton a9687ca
Merge remote-tracking branch 'origin/master' into feat/gnoland-txtar-…
gfanton 8e2516a
Update gno.land/cmd/gnoland/integration_test.go
gfanton c776213
chore: remove useless (not used) config argument for gnoland integration
gfanton 9f82bcd
Merge branch 'master' into feat/gnoland-txtar-driver
gfanton 4b57cd5
chore: comments, capitalize, punctuation
gfanton 911320b
chore: correctly move sleep at the right place
gfanton bc08176
fix(docker): set GNOROOT in dockerfile instead of the docker integration
gfanton 18046ea
fix(test): use mutex in defer
gfanton 0cb9586
chore(log): set back %s instead of %+v
gfanton 8d0f2d9
fix(tempdir): use only one tempdir call
gfanton 221e216
feat: add `update_scripts` environment variable
gfanton 3544390
feat: add partial `doc.go`
gfanton 5f6f041
fix: remove sleep command inside testscripts
gfanton 2f17114
Update gno.land/pkg/integration/testing_integration.go
gfanton 0c589e2
fix: query reponse log
gfanton a265376
chore: centralize GuessGnoRootDir in gnoland
gfanton 97c8048
fix: correctly handle unknown gnoland subcommand
gfanton 348a410
fix: unused imports
gfanton 9ea0422
fix: node stop not correctly handled
gfanton ebb9fc2
feat: add UPDATE_SCRIPTS to test and sync gnoland integration
gfanton 358fbe2
chore: rename `CustomAppConfig` to `AppOptions` and `NewCustomApp` to…
gfanton aa253b3
chore: improve package doc.go
gfanton fbdf888
fix: check for first block, instead of sleepin
gfanton 9f3f52f
REMOVE_ME: ci test with count 50
gfanton d3624dd
fix: use event system for beter node start handling
gfanton 2436912
Revert "REMOVE_ME: ci test with count 50"
gfanton d66a4f6
chore: lint doc
gfanton c3ddec5
chore: add comment on `why a mutex will you say?`
gfanton f077906
chore: update doc.go
gfanton b8bd6b5
chore: add testing guide
gfanton 4b80e80
chore: guide fix
gfanton 977fe83
chore: minor fixes
gfanton c87a7a6
chore: use NewOptions instead of AppyDefault
gfanton 57497cf
chore: sync golden files
gfanton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ package gnoland | |
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
|
||
|
@@ -20,34 +22,62 @@ import ( | |
"github.com/gnolang/gno/tm2/pkg/store/iavl" | ||
) | ||
|
||
type AppOptions struct { | ||
DB dbm.DB | ||
// `gnoRootDir` should point to the local location of the gno repository. | ||
// It serves as the gno equivalent of GOROOT. | ||
GnoRootDir string | ||
gfanton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SkipFailingGenesisTxs bool | ||
Logger log.Logger | ||
MaxCycles int64 | ||
} | ||
|
||
func NewAppOptions() *AppOptions { | ||
return &AppOptions{ | ||
Logger: log.NewNopLogger(), | ||
DB: dbm.NewMemDB(), | ||
GnoRootDir: GuessGnoRootDir(), | ||
} | ||
} | ||
|
||
func (c *AppOptions) validate() error { | ||
if c.Logger == nil { | ||
return fmt.Errorf("no logger provided") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: this can be a regular Same nit for the other check in |
||
} | ||
|
||
if c.DB == nil { | ||
return fmt.Errorf("no db provided") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// NewApp creates the GnoLand application. | ||
func NewApp(rootDir string, skipFailingGenesisTxs bool, logger log.Logger, maxCycles int64) (abci.Application, error) { | ||
// Get main DB. | ||
db, err := dbm.NewDB("gnolang", dbm.GoLevelDBBackend, filepath.Join(rootDir, "data")) | ||
if err != nil { | ||
return nil, fmt.Errorf("error initializing database %q using path %q: %w", dbm.GoLevelDBBackend, rootDir, err) | ||
func NewAppWithOptions(cfg *AppOptions) (abci.Application, error) { | ||
if err := cfg.validate(); err != nil { | ||
return nil, err | ||
} | ||
|
||
// Capabilities keys. | ||
mainKey := store.NewStoreKey("main") | ||
baseKey := store.NewStoreKey("base") | ||
|
||
// Create BaseApp. | ||
baseApp := sdk.NewBaseApp("gnoland", logger, db, baseKey, mainKey) | ||
baseApp := sdk.NewBaseApp("gnoland", cfg.Logger, cfg.DB, baseKey, mainKey) | ||
baseApp.SetAppVersion("dev") | ||
|
||
// Set mounts for BaseApp's MultiStore. | ||
baseApp.MountStoreWithDB(mainKey, iavl.StoreConstructor, db) | ||
baseApp.MountStoreWithDB(baseKey, dbadapter.StoreConstructor, db) | ||
baseApp.MountStoreWithDB(mainKey, iavl.StoreConstructor, cfg.DB) | ||
baseApp.MountStoreWithDB(baseKey, dbadapter.StoreConstructor, cfg.DB) | ||
|
||
// Construct keepers. | ||
acctKpr := auth.NewAccountKeeper(mainKey, ProtoGnoAccount) | ||
bankKpr := bank.NewBankKeeper(acctKpr) | ||
stdlibsDir := filepath.Join("..", "gnovm", "stdlibs") | ||
vmKpr := vm.NewVMKeeper(baseKey, mainKey, acctKpr, bankKpr, stdlibsDir, maxCycles) | ||
stdlibsDir := filepath.Join(cfg.GnoRootDir, "gnovm", "stdlibs") | ||
gfanton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
vmKpr := vm.NewVMKeeper(baseKey, mainKey, acctKpr, bankKpr, stdlibsDir, cfg.MaxCycles) | ||
|
||
// Set InitChainer | ||
baseApp.SetInitChainer(InitChainer(baseApp, acctKpr, bankKpr, skipFailingGenesisTxs)) | ||
baseApp.SetInitChainer(InitChainer(baseApp, acctKpr, bankKpr, cfg.SkipFailingGenesisTxs)) | ||
|
||
// Set AnteHandler | ||
authOptions := auth.AnteOptions{ | ||
|
@@ -88,6 +118,23 @@ func NewApp(rootDir string, skipFailingGenesisTxs bool, logger log.Logger, maxCy | |
return baseApp, nil | ||
} | ||
|
||
// NewApp creates the GnoLand application. | ||
func NewApp(dataRootDir string, skipFailingGenesisTxs bool, logger log.Logger, maxCycles int64) (abci.Application, error) { | ||
var err error | ||
|
||
cfg := NewAppOptions() | ||
|
||
// Get main DB. | ||
cfg.DB, err = dbm.NewDB("gnolang", dbm.GoLevelDBBackend, filepath.Join(dataRootDir, "data")) | ||
if err != nil { | ||
return nil, fmt.Errorf("error initializing database %q using path %q: %w", dbm.GoLevelDBBackend, dataRootDir, err) | ||
} | ||
|
||
cfg.Logger = logger | ||
|
||
return NewAppWithOptions(cfg) | ||
} | ||
|
||
// InitChainer returns a function that can initialize the chain with genesis. | ||
func InitChainer(baseApp *sdk.BaseApp, acctKpr auth.AccountKeeperI, bankKpr bank.BankKeeperI, skipFailingGenesisTxs bool) func(sdk.Context, abci.RequestInitChain) abci.ResponseInitChain { | ||
return func(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { | ||
|
@@ -107,14 +154,15 @@ func InitChainer(baseApp *sdk.BaseApp, acctKpr auth.AccountKeeperI, bankKpr bank | |
for i, tx := range genState.Txs { | ||
res := baseApp.Deliver(tx) | ||
if res.IsErr() { | ||
fmt.Println("ERROR LOG:", res.Log) | ||
fmt.Println("#", i, string(amino.MustMarshalJSON(tx))) | ||
ctx.Logger().Error("LOG", res.Log) | ||
ctx.Logger().Error("#", i, string(amino.MustMarshalJSON(tx))) | ||
|
||
// NOTE: comment out to ignore. | ||
if !skipFailingGenesisTxs { | ||
panic(res.Error) | ||
} | ||
} else { | ||
fmt.Println("SUCCESS:", string(amino.MustMarshalJSON(tx))) | ||
ctx.Logger().Info("SUCCESS:", string(amino.MustMarshalJSON(tx))) | ||
} | ||
} | ||
// Done! | ||
|
@@ -146,3 +194,25 @@ func EndBlocker(vmk vm.VMKeeperI) func(ctx sdk.Context, req abci.RequestEndBlock | |
return abci.ResponseEndBlock{} | ||
} | ||
} | ||
|
||
func GuessGnoRootDir() string { | ||
var rootdir string | ||
|
||
// First try to get the root directory from the GNOROOT environment variable. | ||
if rootdir = os.Getenv("GNOROOT"); rootdir != "" { | ||
return filepath.Clean(rootdir) | ||
} | ||
|
||
if gobin, err := exec.LookPath("go"); err == nil { | ||
// If GNOROOT is not set, try to guess the root directory using the `go list` command. | ||
cmd := exec.Command(gobin, "list", "-m", "-mod=mod", "-f", "{{.Dir}}", "github.com/gnolang/gno") | ||
out, err := cmd.CombinedOutput() | ||
if err != nil { | ||
panic(fmt.Errorf("invalid gno directory %q: %w", rootdir, err)) | ||
} | ||
|
||
return strings.TrimSpace(string(out)) | ||
} | ||
|
||
panic("no go binary available, unable to determine gno root-dir path") | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Ideally, we should make all parameters optional with defaults:
-chainid
should always be set to "tendermint_test" since we only test this value in unit tests, not integration tests. I suggest setting the value by default and logging a warning if it differs.-broadcast
must be mandatory because we cannot combine the airgap-method with txtar.-gas-wanted
and-gas-fee
should remain unchanged, in my opinion, without default values.By implementing these changes, users can easily copy and paste commands from the terminal.
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.
thanks for the precision !
I totally agree on doing that, but can I do this in a next iteration? for now I only add default arguments on the root level of gnokey (common arguments), which contain only:
args like
chain-id
are ont a second level, which require checking the kind of subcommand, ignore potential user args and finally properly inject it at the right place (not that difficult to do, but a bit fastidious).If it's really mandatory for this PR to be merge I can take some time to add this.
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.
yep, let's keep for a next PR 👍
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 think it's better if we don't have special defaults when running tests with txtar; this way we can ensure that any command from the txtar tests can just be copy pasted into a terminal.
alternative idea: have a
GNOKEY_APPEND_FLAGS
env variable which adds its value as arguments, before passing ontopkg/commands
/ffcli
?(I agree on doing this in a next PR, just thought I'd point this out here as the discussion was already started)