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

test: migrate e2e/genutil to systemtest (backport #22325) #22366

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
232 changes: 0 additions & 232 deletions tests/e2e/genutil/export_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ require (
github.com/google/gofuzz v1.2.0
github.com/jhump/protoreflect v1.17.0
github.com/rs/zerolog v1.33.0
github.com/spf13/cobra v1.8.1
github.com/spf13/cobra v1.8.1 // indirect
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
google.golang.org/grpc v1.67.1
Expand Down
88 changes: 88 additions & 0 deletions tests/systemtests/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//go:build system_test

package systemtests

import (
"fmt"
"os"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"
)

func TestExportCmd_WithHeight(t *testing.T) {
sut.ResetChain(t)
cli := NewCLIWrapper(t, sut, verbose)

sut.StartChain(t)

// Wait 10s for producing blocks
time.Sleep(10 * time.Second)

sut.StopChain()

testCases := []struct {
name string
args []string
expZeroHeight bool
}{
{"should export correct height", []string{"genesis", "export", "--home", sut.nodePath(0)}, false},
{"should export correct height with --height", []string{"genesis", "export", "--height=5", "--home", sut.nodePath(0), "--log_level=disabled"}, false},
{"should export height 0 with --for-zero-height", []string{"genesis", "export", "--for-zero-height=true", "--home", sut.nodePath(0)}, true},
}

for _, tc := range testCases {
res := cli.RunCommandWithArgs(tc.args...)
height := gjson.Get(res, "initial_height").Int()
if tc.expZeroHeight {
require.Equal(t, height, int64(0))
} else {
require.Greater(t, height, int64(0))
}

// Check consensus params of exported state
maxGas := gjson.Get(res, "consensus.params.block.max_gas").Int()
require.Equal(t, maxGas, int64(MaxGas))
}
}

func TestExportCmd_WithFileFlag(t *testing.T) {
sut.ResetChain(t)
cli := NewCLIWrapper(t, sut, verbose)
exportFile := "foobar.json"

sut.StartChain(t)

// Wait 10s for producing blocks
time.Sleep(10 * time.Second)

sut.StopChain()

testCases := []struct {
name string
args []string
expErr bool
errMsg string
}{
{"invalid home dir", []string{"genesis", "export", "--home=foo"}, true, "no such file or directory"},
{"should export state to the specified file", []string{"genesis", "export", fmt.Sprintf("--output-document=%s", exportFile), "--home", sut.nodePath(0)}, false, ""},
}

for _, tc := range testCases {
if tc.expErr {
assertOutput := func(_ assert.TestingT, gotErr error, gotOutputs ...interface{}) bool {
require.Contains(t, gotOutputs[0], tc.errMsg)
return false
}
cli.WithRunErrorMatcher(assertOutput).RunCommandWithArgs(tc.args...)
} else {
cli.RunCommandWithArgs(tc.args...)
require.FileExists(t, exportFile)
err := os.Remove(exportFile)
require.NoError(t, err)
}
}
}
4 changes: 3 additions & 1 deletion tests/systemtests/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ var (

// ExecBinaryUnversionedRegExp regular expression to extract the unversioned binary name
ExecBinaryUnversionedRegExp = regexp.MustCompile(`^(\w+)-?.*$`)

MaxGas = 10_000_000
)

type TestnetInitializer interface {
Expand Down Expand Up @@ -130,7 +132,7 @@ func (s *SystemUnderTest) SetupChain() {
panic(fmt.Sprintf("failed to load genesis: %s", err))
}

genesisBz, err = sjson.SetRawBytes(genesisBz, "consensus.params.block.max_gas", []byte(fmt.Sprintf(`"%d"`, 10_000_000)))
genesisBz, err = sjson.SetRawBytes(genesisBz, "consensus.params.block.max_gas", []byte(fmt.Sprintf(`"%d"`, MaxGas)))
if err != nil {
panic(fmt.Sprintf("failed to set block max gas: %s", err))
}
Expand Down
Loading