Skip to content

Commit aa4614e

Browse files
authored
test: migrate e2e/genutil to systemtest (#22325)
1 parent ec63f94 commit aa4614e

File tree

4 files changed

+92
-234
lines changed

4 files changed

+92
-234
lines changed

tests/e2e/genutil/export_test.go

-232
This file was deleted.

tests/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
// this version is not used as it is always replaced by the latest Cosmos SDK version
2323
github.com/cosmos/cosmos-sdk v0.53.0
2424
github.com/cosmos/gogoproto v1.7.0
25-
github.com/spf13/cobra v1.8.1
25+
github.com/spf13/cobra v1.8.1 // indirect
2626
github.com/stretchr/testify v1.9.0
2727
go.uber.org/mock v0.5.0
2828
google.golang.org/grpc v1.67.1

tests/systemtests/export_test.go

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//go:build system_test
2+
3+
package systemtests
4+
5+
import (
6+
"fmt"
7+
"os"
8+
"testing"
9+
"time"
10+
11+
"github.com/stretchr/testify/assert"
12+
"github.com/stretchr/testify/require"
13+
"github.com/tidwall/gjson"
14+
)
15+
16+
func TestExportCmd_WithHeight(t *testing.T) {
17+
sut.ResetChain(t)
18+
cli := NewCLIWrapper(t, sut, verbose)
19+
20+
sut.StartChain(t)
21+
22+
// Wait 10s for producing blocks
23+
time.Sleep(10 * time.Second)
24+
25+
sut.StopChain()
26+
27+
testCases := []struct {
28+
name string
29+
args []string
30+
expZeroHeight bool
31+
}{
32+
{"should export correct height", []string{"genesis", "export", "--home", sut.nodePath(0)}, false},
33+
{"should export correct height with --height", []string{"genesis", "export", "--height=5", "--home", sut.nodePath(0), "--log_level=disabled"}, false},
34+
{"should export height 0 with --for-zero-height", []string{"genesis", "export", "--for-zero-height=true", "--home", sut.nodePath(0)}, true},
35+
}
36+
37+
for _, tc := range testCases {
38+
res := cli.RunCommandWithArgs(tc.args...)
39+
height := gjson.Get(res, "initial_height").Int()
40+
if tc.expZeroHeight {
41+
require.Equal(t, height, int64(0))
42+
} else {
43+
require.Greater(t, height, int64(0))
44+
}
45+
46+
// Check consensus params of exported state
47+
maxGas := gjson.Get(res, "consensus.params.block.max_gas").Int()
48+
require.Equal(t, maxGas, int64(MaxGas))
49+
}
50+
}
51+
52+
func TestExportCmd_WithFileFlag(t *testing.T) {
53+
sut.ResetChain(t)
54+
cli := NewCLIWrapper(t, sut, verbose)
55+
exportFile := "foobar.json"
56+
57+
sut.StartChain(t)
58+
59+
// Wait 10s for producing blocks
60+
time.Sleep(10 * time.Second)
61+
62+
sut.StopChain()
63+
64+
testCases := []struct {
65+
name string
66+
args []string
67+
expErr bool
68+
errMsg string
69+
}{
70+
{"invalid home dir", []string{"genesis", "export", "--home=foo"}, true, "no such file or directory"},
71+
{"should export state to the specified file", []string{"genesis", "export", fmt.Sprintf("--output-document=%s", exportFile), "--home", sut.nodePath(0)}, false, ""},
72+
}
73+
74+
for _, tc := range testCases {
75+
if tc.expErr {
76+
assertOutput := func(_ assert.TestingT, gotErr error, gotOutputs ...interface{}) bool {
77+
require.Contains(t, gotOutputs[0], tc.errMsg)
78+
return false
79+
}
80+
cli.WithRunErrorMatcher(assertOutput).RunCommandWithArgs(tc.args...)
81+
} else {
82+
cli.RunCommandWithArgs(tc.args...)
83+
require.FileExists(t, exportFile)
84+
err := os.Remove(exportFile)
85+
require.NoError(t, err)
86+
}
87+
}
88+
}

tests/systemtests/system.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ var (
3535

3636
// ExecBinaryUnversionedRegExp regular expression to extract the unversioned binary name
3737
ExecBinaryUnversionedRegExp = regexp.MustCompile(`^(\w+)-?.*$`)
38+
39+
MaxGas = 10_000_000
3840
)
3941

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

133-
genesisBz, err = sjson.SetRawBytes(genesisBz, "consensus.params.block.max_gas", []byte(fmt.Sprintf(`"%d"`, 10_000_000)))
135+
genesisBz, err = sjson.SetRawBytes(genesisBz, "consensus.params.block.max_gas", []byte(fmt.Sprintf(`"%d"`, MaxGas)))
134136
if err != nil {
135137
panic(fmt.Sprintf("failed to set block max gas: %s", err))
136138
}

0 commit comments

Comments
 (0)