Skip to content

Commit 5b8f187

Browse files
committed
genutil tests
1 parent 6e59ad0 commit 5b8f187

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

tests/systemtests/export_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//go:build system_test
2+
3+
package systemtests
4+
5+
import (
6+
"fmt"
7+
"os"
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
"github.com/stretchr/testify/require"
12+
"github.com/tidwall/gjson"
13+
)
14+
15+
func TestExportCmd(t *testing.T) {
16+
// scenario: test bank send command
17+
// given a running chain
18+
19+
sut.ResetChain(t)
20+
cli := NewCLIWrapper(t, sut, verbose)
21+
exportFile := "foobar.json"
22+
23+
sut.StartChain(t)
24+
25+
testCases := []struct {
26+
name string
27+
args []string
28+
expErr bool
29+
errMsg string
30+
expZeroHeight bool
31+
}{
32+
{"invalid home dir", []string{"genesis", "export", "--home=foo"}, true, "no such file or directory", false},
33+
{"should export correct height", []string{"genesis", "export"}, false, "", false},
34+
{"should export correct height with --height", []string{"genesis", "export", "--height=5"}, false, "", false},
35+
{"should export height 0 with --for-zero-height", []string{"genesis", "export", "--for-zero-height=true"}, false, "", true},
36+
{"should export state to the specified file", []string{"genesis", "export", fmt.Sprintf("--output-document=%s", exportFile)}, false, "", false},
37+
}
38+
39+
for _, tc := range testCases {
40+
41+
// fmt.Println(tc.name, res)
42+
if tc.expErr {
43+
assertOutput := func(_ assert.TestingT, gotErr error, gotOutputs ...interface{}) bool {
44+
require.Contains(t, gotOutputs[0], tc.errMsg)
45+
return false
46+
}
47+
cli.WithRunErrorMatcher(assertOutput).RunCommandWithArgs(tc.args...)
48+
} else {
49+
res := cli.RunCommandWithArgs(tc.args...)
50+
if res == "" {
51+
require.FileExists(t, exportFile)
52+
os.Remove(exportFile)
53+
} else {
54+
height := gjson.Get(res, "initial_height").Int()
55+
if tc.expZeroHeight {
56+
require.Equal(t, height, int64(0))
57+
} else {
58+
require.Greater(t, height, int64(0))
59+
}
60+
61+
// Check consensus params of exported state
62+
maxGas := gjson.Get(res, "consensus.params.block.max_gas").Int()
63+
require.Equal(t, maxGas, int64(MaxGas))
64+
}
65+
}
66+
}
67+
}

tests/systemtests/system.go

Lines changed: 3 additions & 1 deletion
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)