From d7178729ac726cf969ece8698b075cfc11d4d9d6 Mon Sep 17 00:00:00 2001 From: deelawn Date: Tue, 7 Nov 2023 13:14:00 -0800 Subject: [PATCH 1/7] load full node config --- gno.land/pkg/integration/testing_integration.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gno.land/pkg/integration/testing_integration.go b/gno.land/pkg/integration/testing_integration.go index b773317513f..fd6fadda475 100644 --- a/gno.land/pkg/integration/testing_integration.go +++ b/gno.land/pkg/integration/testing_integration.go @@ -125,7 +125,7 @@ func SetupGnolandTestScript(t *testing.T, txtarDir string) testscript.Params { t := TSTestingT(ts) // Generate config and node - cfg := TestingMinimalNodeConfig(t, gnoRootDir) + cfg, _ := TestingNodeConfig(t, gnoRootDir) n, remoteAddr := TestingInMemoryNode(t, logger, cfg) // Register cleanup From b20865e5d53d74699bcb88f24878047af41ebd77 Mon Sep 17 00:00:00 2001 From: deelawn Date: Tue, 7 Nov 2023 13:28:28 -0800 Subject: [PATCH 2/7] added test --- gno.land/cmd/gnoland/testdata/import.txtar | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 gno.land/cmd/gnoland/testdata/import.txtar diff --git a/gno.land/cmd/gnoland/testdata/import.txtar b/gno.land/cmd/gnoland/testdata/import.txtar new file mode 100644 index 00000000000..9f345737030 --- /dev/null +++ b/gno.land/cmd/gnoland/testdata/import.txtar @@ -0,0 +1,28 @@ +# test that the example packages directory is loaded and usable. + +## 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/importtest -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +stdout OK! + +## execute Render +gnokey maketx call -pkgpath gno.land/r/importtest -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -args '' -broadcast -chainid=tendermint_test test1 +stdout '("92054" string)' +stdout OK! + +-- gno.mod -- +module gno.land/r/importtest + +-- bar.gno -- +package importtest + +import ( + "gno.land/p/demo/ufmt" +) + +func Render(_ string) string { + return ufmt.Sprintf("%d", 92054) +} + From 8e527c080512019648c34d55eccf497d58c134ee Mon Sep 17 00:00:00 2001 From: deelawn Date: Tue, 7 Nov 2023 13:44:17 -0800 Subject: [PATCH 3/7] removed erroneous comment --- gno.land/cmd/gnoland/testdata/import.txtar | 1 - 1 file changed, 1 deletion(-) diff --git a/gno.land/cmd/gnoland/testdata/import.txtar b/gno.land/cmd/gnoland/testdata/import.txtar index 9f345737030..9c8e6480e4d 100644 --- a/gno.land/cmd/gnoland/testdata/import.txtar +++ b/gno.land/cmd/gnoland/testdata/import.txtar @@ -3,7 +3,6 @@ ## 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/importtest -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 stdout OK! From 5b3f5bba6a0d5d77100c12cad3c3a5a0dc317da8 Mon Sep 17 00:00:00 2001 From: deelawn Date: Tue, 7 Nov 2023 14:09:44 -0800 Subject: [PATCH 4/7] rename for clarity --- gno.land/cmd/gnoland/testdata/import.txtar | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gno.land/cmd/gnoland/testdata/import.txtar b/gno.land/cmd/gnoland/testdata/import.txtar index 9c8e6480e4d..3ad070654cf 100644 --- a/gno.land/cmd/gnoland/testdata/import.txtar +++ b/gno.land/cmd/gnoland/testdata/import.txtar @@ -14,7 +14,7 @@ stdout OK! -- gno.mod -- module gno.land/r/importtest --- bar.gno -- +-- import.gno -- package importtest import ( From bba6793968189b6df0728d4558f90e5727bac059 Mon Sep 17 00:00:00 2001 From: gfanton <8671905+gfanton@users.noreply.github.com> Date: Wed, 8 Nov 2023 16:15:15 +0100 Subject: [PATCH 5/7] fix: use in memory db provider for in memory node Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com> --- gno.land/pkg/gnoland/node_inmemory.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gno.land/pkg/gnoland/node_inmemory.go b/gno.land/pkg/gnoland/node_inmemory.go index a0ab6a51e82..0edef304281 100644 --- a/gno.land/pkg/gnoland/node_inmemory.go +++ b/gno.land/pkg/gnoland/node_inmemory.go @@ -128,9 +128,9 @@ func NewInMemoryNode(logger log.Logger, cfg *InMemoryNodeConfig) (*node.Node, er ) // Create genesis factory - genProvider := func() (*bft.GenesisDoc, error) { - return cfg.Genesis, nil - } + genProvider := func() (*bft.GenesisDoc, error) { return cfg.Genesis, nil } + + dbProvider := func(*node.DBContext) (db.DB, error) { return db.NewMemDB(), nil } // generate p2p node identity // XXX: do we need to configur @@ -141,7 +141,7 @@ func NewInMemoryNode(logger log.Logger, cfg *InMemoryNodeConfig) (*node.Node, er cfg.PrivValidator, nodekey, appClientCreator, genProvider, - node.DefaultDBProvider, + dbProvider, logger, ) } From f9f4465ef2445a13c6fba5abce5b84f3abb8a46d Mon Sep 17 00:00:00 2001 From: gfanton <8671905+gfanton@users.noreply.github.com> Date: Wed, 8 Nov 2023 16:16:17 +0100 Subject: [PATCH 6/7] fix: disable parallelism on gnoland testscripts tests Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com> --- gno.land/cmd/gnoland/integration_test.go | 3 +- gno.land/pkg/integration/integration_test.go | 4 +- .../pkg/integration/testing_integration.go | 49 ++++++++++++------- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/gno.land/cmd/gnoland/integration_test.go b/gno.land/cmd/gnoland/integration_test.go index 78c8e94fa09..37451df9704 100644 --- a/gno.land/cmd/gnoland/integration_test.go +++ b/gno.land/cmd/gnoland/integration_test.go @@ -4,9 +4,8 @@ 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")) + integration.RunGnolandTestscripts(t, "testdata") } diff --git a/gno.land/pkg/integration/integration_test.go b/gno.land/pkg/integration/integration_test.go index 3c22a190d64..a474791de2e 100644 --- a/gno.land/pkg/integration/integration_test.go +++ b/gno.land/pkg/integration/integration_test.go @@ -2,10 +2,8 @@ package integration import ( "testing" - - "github.com/rogpeppe/go-internal/testscript" ) func TestTestdata(t *testing.T) { - testscript.Run(t, SetupGnolandTestScript(t, "testdata")) + RunGnolandTestscripts(t, "testdata") } diff --git a/gno.land/pkg/integration/testing_integration.go b/gno.land/pkg/integration/testing_integration.go index fd6fadda475..9ecf001b2eb 100644 --- a/gno.land/pkg/integration/testing_integration.go +++ b/gno.land/pkg/integration/testing_integration.go @@ -8,7 +8,6 @@ import ( "path/filepath" "strconv" "strings" - "sync" "testing" "github.com/gnolang/gno/gno.land/pkg/gnoland" @@ -20,21 +19,42 @@ import ( "github.com/rogpeppe/go-internal/testscript" ) +type tSeqShim struct{ *testing.T } + +// noop Parallel method allow us to run test sequentially +func (tSeqShim) Parallel() {} + +func (t tSeqShim) Run(name string, f func(testscript.T)) { + t.T.Run(name, func(t *testing.T) { + f(tSeqShim{t}) + }) +} + +func (t tSeqShim) Verbose() bool { + return testing.Verbose() +} + +// RunGnolandTestscripts sets up and runs txtar integration tests for gnoland nodes. +// It prepares an in-memory gnoland node and initializes the necessary environment and custom commands. +// The function adapts the test setup for use with the testscript package, enabling +// the execution of gnoland and gnokey commands within txtar scripts. +// +// Refer to package documentation in doc.go for more information on commands and example txtar scripts. +func RunGnolandTestscripts(t *testing.T, txtarDir string) { + p := setupGnolandTestScript(t, txtarDir) + if deadline, ok := t.Deadline(); ok && p.Deadline.IsZero() { + p.Deadline = deadline + } + + testscript.RunT(tSeqShim{t}, p) +} + type testNode struct { *node.Node nGnoKeyExec uint // Counter for execution of gnokey. } -// SetupGnolandTestScript prepares the test environment to execute txtar tests -// using a partial InMemory gnoland node. It initializes key storage, sets up the gnoland node, -// and provides custom commands like "gnoland" and "gnokey" for txtar script execution. -// -// The function returns testscript.Params which contain the test setup and command -// executions to be used with the testscript package. -// -// For a detailed explanation of the commands and their behaviors, as well as -// example txtar scripts, refer to the package documentation in doc.go. -func SetupGnolandTestScript(t *testing.T, txtarDir string) testscript.Params { +func setupGnolandTestScript(t *testing.T, txtarDir string) testscript.Params { t.Helper() tmpdir := t.TempDir() @@ -47,7 +67,6 @@ func SetupGnolandTestScript(t *testing.T, txtarDir string) testscript.Params { gnoHomeDir := filepath.Join(tmpdir, "gno") // Testscripts run concurrently by default, so we need to be prepared for that. - var muNodes sync.Mutex nodes := map[string]*testNode{} updateScripts, _ := strconv.ParseBool(os.Getenv("UPDATE_SCRIPTS")) @@ -99,9 +118,6 @@ func SetupGnolandTestScript(t *testing.T, txtarDir string) testscript.Params { }, Cmds: map[string]func(ts *testscript.TestScript, neg bool, args []string){ "gnoland": func(ts *testscript.TestScript, neg bool, args []string) { - muNodes.Lock() - defer muNodes.Unlock() - if len(args) == 0 { tsValidateError(ts, "gnoland", neg, fmt.Errorf("syntax: gnoland [start|stop]")) return @@ -156,9 +172,6 @@ func SetupGnolandTestScript(t *testing.T, txtarDir string) testscript.Params { tsValidateError(ts, "gnoland "+cmd, neg, err) }, "gnokey": func(ts *testscript.TestScript, neg bool, args []string) { - muNodes.Lock() - defer muNodes.Unlock() - logger := ts.Value("_logger").(log.Logger) // grab logger sid := ts.Getenv("SID") // grab session id From f88c1962da30693626a3e7cc08b259768b669541 Mon Sep 17 00:00:00 2001 From: gfanton <8671905+gfanton@users.noreply.github.com> Date: Wed, 8 Nov 2023 16:30:13 +0100 Subject: [PATCH 7/7] chore: lint Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com> --- gno.land/pkg/integration/testing_integration.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gno.land/pkg/integration/testing_integration.go b/gno.land/pkg/integration/testing_integration.go index 9ecf001b2eb..b10686b0105 100644 --- a/gno.land/pkg/integration/testing_integration.go +++ b/gno.land/pkg/integration/testing_integration.go @@ -41,6 +41,8 @@ func (t tSeqShim) Verbose() bool { // // Refer to package documentation in doc.go for more information on commands and example txtar scripts. func RunGnolandTestscripts(t *testing.T, txtarDir string) { + t.Helper() + p := setupGnolandTestScript(t, txtarDir) if deadline, ok := t.Deadline(); ok && p.Deadline.IsZero() { p.Deadline = deadline