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

fix(gno.land): improve test speed #3396

Merged
merged 31 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
46af920
fix: rework and speed gnovm integration tests
gfanton Dec 20, 2024
e74adaa
fix: gno.land config integration
gfanton Dec 20, 2024
e01d185
fix(gnoland): speed test & rework directory
gfanton Dec 20, 2024
9586dfe
wip: fork
gfanton Dec 20, 2024
bcb44c8
wip: poc fork node
gfanton Dec 20, 2024
ddef133
fix: test pk
gfanton Dec 20, 2024
eb3702a
fix: increase timeout
gfanton Dec 20, 2024
de031ca
fix: increase timeout 2
gfanton Dec 20, 2024
a9bde35
wip: use db dir
gfanton Dec 20, 2024
d3717e4
wip: verbose mode
gfanton Dec 20, 2024
7ac95fe
fix: set fork test sequential
gfanton Dec 21, 2024
5dd2a66
fix: improve gno.land/gnoclient integration tests speed
gfanton Dec 21, 2024
cafdbbf
wip: fix gnolang integration test
gfanton Dec 21, 2024
bfafba6
wip: test without integ
gfanton Dec 21, 2024
c163a48
wip: integ
gfanton Dec 21, 2024
a3b76d4
fix: rename and update cmd -> process
gfanton Dec 27, 2024
a9b8e42
wip: cleanup
gfanton Dec 27, 2024
680180e
chore: cleanup
gfanton Dec 27, 2024
198af81
feat: command kind
gfanton Dec 29, 2024
20a2a76
chore: lint
gfanton Dec 29, 2024
f9a9b2f
chore: lint
gfanton Dec 29, 2024
c2064c0
chore: rename some files
gfanton Dec 29, 2024
54a776b
fix: make coverage works
gfanton Dec 29, 2024
ee516b8
Merge branch 'master' into fix/gnland/test-speed
gfanton Dec 29, 2024
c6af61d
chore: remove logger
gfanton Dec 30, 2024
b3c3a83
Merge branch 'master' into fix/gnland/test-speed
gfanton Jan 5, 2025
d19d089
chore: doc integration command and cleanup
gfanton Jan 6, 2025
e530049
fix: make coverage happy
gfanton Jan 6, 2025
2d9e101
chore: cleanup lefthover file
gfanton Jan 6, 2025
dfe212b
fix: inmemory db cleanup
gfanton Jan 6, 2025
45b5921
chore: lint
gfanton Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 62 additions & 10 deletions gno.land/pkg/gnoclient/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package gnoclient

import (
"path/filepath"
"testing"

"github.com/gnolang/gno/gnovm/pkg/gnolang"

"github.com/gnolang/gno/gno.land/pkg/gnoland"
"github.com/gnolang/gno/gno.land/pkg/gnoland/ugnot"
"github.com/gnolang/gno/gno.land/pkg/integration"
"github.com/gnolang/gno/gno.land/pkg/sdk/vm"
Expand All @@ -21,8 +23,14 @@ import (
)

func TestCallSingle_Integration(t *testing.T) {
// Set up in-memory node
config, _ := integration.TestingNodeConfig(t, gnoenv.RootDir())
// Setup packages
rootdir := gnoenv.RootDir()
config := integration.TestingMinimalNodeConfig(gnoenv.RootDir())
meta := loadpkgs(t, rootdir, "gno.land/r/demo/deep/very/deep")
gfanton marked this conversation as resolved.
Show resolved Hide resolved
state := config.Genesis.AppState.(gnoland.GnoGenesisState)
state.Txs = append(state.Txs, meta...)
config.Genesis.AppState = state

node, remoteAddr := integration.TestingInMemoryNode(t, log.NewNoopLogger(), config)
defer node.Stop()

Expand Down Expand Up @@ -74,8 +82,14 @@ func TestCallSingle_Integration(t *testing.T) {
}

func TestCallMultiple_Integration(t *testing.T) {
// Set up in-memory node
config, _ := integration.TestingNodeConfig(t, gnoenv.RootDir())
// Setup packages
rootdir := gnoenv.RootDir()
config := integration.TestingMinimalNodeConfig(gnoenv.RootDir())
meta := loadpkgs(t, rootdir, "gno.land/r/demo/deep/very/deep")
state := config.Genesis.AppState.(gnoland.GnoGenesisState)
state.Txs = append(state.Txs, meta...)
config.Genesis.AppState = state

node, remoteAddr := integration.TestingInMemoryNode(t, log.NewNoopLogger(), config)
defer node.Stop()

Expand Down Expand Up @@ -137,7 +151,7 @@ func TestCallMultiple_Integration(t *testing.T) {

func TestSendSingle_Integration(t *testing.T) {
// Set up in-memory node
config, _ := integration.TestingNodeConfig(t, gnoenv.RootDir())
config := integration.TestingMinimalNodeConfig(gnoenv.RootDir())
node, remoteAddr := integration.TestingInMemoryNode(t, log.NewNoopLogger(), config)
defer node.Stop()

Expand Down Expand Up @@ -201,7 +215,7 @@ func TestSendSingle_Integration(t *testing.T) {

func TestSendMultiple_Integration(t *testing.T) {
// Set up in-memory node
config, _ := integration.TestingNodeConfig(t, gnoenv.RootDir())
config := integration.TestingMinimalNodeConfig(gnoenv.RootDir())
node, remoteAddr := integration.TestingInMemoryNode(t, log.NewNoopLogger(), config)
defer node.Stop()

Expand Down Expand Up @@ -273,8 +287,15 @@ func TestSendMultiple_Integration(t *testing.T) {

// Run tests
func TestRunSingle_Integration(t *testing.T) {
// Setup packages
rootdir := gnoenv.RootDir()
config := integration.TestingMinimalNodeConfig(gnoenv.RootDir())
meta := loadpkgs(t, rootdir, "gno.land/p/demo/ufmt", "gno.land/r/demo/tests")
gfanton marked this conversation as resolved.
Show resolved Hide resolved
state := config.Genesis.AppState.(gnoland.GnoGenesisState)
state.Txs = append(state.Txs, meta...)
config.Genesis.AppState = state

// Set up in-memory node
config, _ := integration.TestingNodeConfig(t, gnoenv.RootDir())
node, remoteAddr := integration.TestingInMemoryNode(t, log.NewNoopLogger(), config)
defer node.Stop()

Expand Down Expand Up @@ -342,7 +363,17 @@ func main() {
// Run tests
func TestRunMultiple_Integration(t *testing.T) {
// Set up in-memory node
config, _ := integration.TestingNodeConfig(t, gnoenv.RootDir())
rootdir := gnoenv.RootDir()
config := integration.TestingMinimalNodeConfig(rootdir)
meta := loadpkgs(t, rootdir,
"gno.land/p/demo/ufmt",
"gno.land/r/demo/tests",
"gno.land/r/demo/deep/very/deep",
)
state := config.Genesis.AppState.(gnoland.GnoGenesisState)
state.Txs = append(state.Txs, meta...)
config.Genesis.AppState = state

node, remoteAddr := integration.TestingInMemoryNode(t, log.NewNoopLogger(), config)
defer node.Stop()

Expand Down Expand Up @@ -434,7 +465,7 @@ func main() {

func TestAddPackageSingle_Integration(t *testing.T) {
// Set up in-memory node
config, _ := integration.TestingNodeConfig(t, gnoenv.RootDir())
config := integration.TestingMinimalNodeConfig(gnoenv.RootDir())
node, remoteAddr := integration.TestingInMemoryNode(t, log.NewNoopLogger(), config)
defer node.Stop()

Expand Down Expand Up @@ -519,7 +550,7 @@ func Echo(str string) string {

func TestAddPackageMultiple_Integration(t *testing.T) {
// Set up in-memory node
config, _ := integration.TestingNodeConfig(t, gnoenv.RootDir())
config := integration.TestingMinimalNodeConfig(gnoenv.RootDir())
node, remoteAddr := integration.TestingInMemoryNode(t, log.NewNoopLogger(), config)
defer node.Stop()

Expand Down Expand Up @@ -670,3 +701,24 @@ func newInMemorySigner(t *testing.T, chainid string) *SignerFromKeybase {
ChainID: chainid, // Chain ID for transaction signing
}
}

func loadpkgs(t *testing.T, rootdir string, paths ...string) []gnoland.TxWithMetadata {
t.Helper()

loader := integration.NewPkgsLoader()
examplesDir := filepath.Join(rootdir, "examples")
for _, path := range paths {
path = filepath.Clean(path)
path = filepath.Join(examplesDir, path)
err := loader.LoadPackage(examplesDir, path, "")
require.NoErrorf(t, err, "`loadpkg` unable to load package(s) from %q: %s", path, err)
}

creator := crypto.MustAddressFromString(integration.DefaultAccount_Address)
defaultFee := std.NewFee(50000, std.MustParseCoin(ugnot.ValueString(1000000)))

meta, err := loader.LoadPackages(creator, defaultFee, nil)
require.NoError(t, err)

return meta
}
4 changes: 2 additions & 2 deletions gno.land/pkg/gnoland/node_inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type InMemoryNodeConfig struct {
PrivValidator bft.PrivValidator // identity of the validator
Genesis *bft.GenesisDoc
TMConfig *tmcfg.Config
DB *memdb.MemDB // will be initialized if nil
VMOutput io.Writer // optional
DB db.DB // will be initialized if nil
VMOutput io.Writer // optional

// If StdlibDir not set, then it's filepath.Join(TMConfig.RootDir, "gnovm", "stdlibs")
InitChainerConfig
Expand Down
7 changes: 0 additions & 7 deletions gno.land/pkg/integration/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@
//
// Input:
//
// - LOG_LEVEL:
// The logging level to be used, which can be one of "error", "debug", "info", or an empty string.
// If empty, the log level defaults to "debug".
//
// - LOG_DIR:
// If set, logs will be directed to the specified directory.
//
// - TESTWORK:
// A boolean that, when enabled, retains working directories after tests for
// inspection. If enabled, gnoland logs will be persisted inside this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestingInMemoryNode(t TestingTS, logger *slog.Logger, config *gnoland.InMem
// with default packages and genesis transactions already loaded.
// It will return the default creator address of the loaded packages.
func TestingNodeConfig(t TestingTS, gnoroot string, additionalTxs ...gnoland.TxWithMetadata) (*gnoland.InMemoryNodeConfig, bft.Address) {
cfg := TestingMinimalNodeConfig(t, gnoroot)
cfg := TestingMinimalNodeConfig(gnoroot)

creator := crypto.MustAddressFromString(DefaultAccount_Address) // test1

Expand All @@ -65,24 +65,24 @@ func TestingNodeConfig(t TestingTS, gnoroot string, additionalTxs ...gnoland.TxW
txs = append(txs, LoadDefaultPackages(t, creator, gnoroot)...)
txs = append(txs, additionalTxs...)

ggs := cfg.Genesis.AppState.(gnoland.GnoGenesisState)
ggs.Balances = balances
ggs.Txs = txs
ggs.Params = params
cfg.Genesis.AppState = ggs
cfg.Genesis.AppState = gnoland.GnoGenesisState{
Balances: balances,
Txs: txs,
Params: params,
}

return cfg, creator
}

// TestingMinimalNodeConfig constructs the default minimal in-memory node configuration for testing.
func TestingMinimalNodeConfig(t TestingTS, gnoroot string) *gnoland.InMemoryNodeConfig {
func TestingMinimalNodeConfig(gnoroot string) *gnoland.InMemoryNodeConfig {
tmconfig := DefaultTestingTMConfig(gnoroot)

// Create Mocked Identity
pv := gnoland.NewMockedPrivValidator()

// Generate genesis config
genesis := DefaultTestingGenesisConfig(t, gnoroot, pv.GetPubKey(), tmconfig)
genesis := DefaultTestingGenesisConfig(gnoroot, pv.GetPubKey(), tmconfig)

return &gnoland.InMemoryNodeConfig{
PrivValidator: pv,
Expand All @@ -96,16 +96,7 @@ func TestingMinimalNodeConfig(t TestingTS, gnoroot string) *gnoland.InMemoryNode
}
}

func DefaultTestingGenesisConfig(t TestingTS, gnoroot string, self crypto.PubKey, tmconfig *tmcfg.Config) *bft.GenesisDoc {
genState := gnoland.DefaultGenState()
genState.Balances = []gnoland.Balance{
{
Address: crypto.MustAddressFromString(DefaultAccount_Address),
Amount: std.MustParseCoins(ugnot.ValueString(10000000000000)),
},
}
genState.Txs = []gnoland.TxWithMetadata{}
genState.Params = []gnoland.Param{}
func DefaultTestingGenesisConfig(gnoroot string, self crypto.PubKey, tmconfig *tmcfg.Config) *bft.GenesisDoc {
return &bft.GenesisDoc{
GenesisTime: time.Now(),
ChainID: tmconfig.ChainID(),
Expand All @@ -125,7 +116,16 @@ func DefaultTestingGenesisConfig(t TestingTS, gnoroot string, self crypto.PubKey
Name: "self",
},
},
AppState: genState,
AppState: gnoland.GnoGenesisState{
Balances: []gnoland.Balance{
{
Address: crypto.MustAddressFromString(DefaultAccount_Address),
Amount: std.MustParseCoins(ugnot.ValueString(10_000_000_000_000)),
},
},
Txs: []gnoland.TxWithMetadata{},
Params: []gnoland.Param{},
},
}
}

Expand Down Expand Up @@ -178,8 +178,9 @@ func DefaultTestingTMConfig(gnoroot string) *tmcfg.Config {

tmconfig := tmcfg.TestConfig().SetRootDir(gnoroot)
tmconfig.Consensus.WALDisabled = true
tmconfig.Consensus.SkipTimeoutCommit = true
tmconfig.Consensus.CreateEmptyBlocks = true
tmconfig.Consensus.CreateEmptyBlocksInterval = time.Duration(0)
tmconfig.Consensus.CreateEmptyBlocksInterval = time.Millisecond * 100
gfanton marked this conversation as resolved.
Show resolved Hide resolved
tmconfig.RPC.ListenAddress = defaultListner
tmconfig.P2P.ListenAddress = defaultListner
return tmconfig
Expand Down
Loading
Loading