Skip to content

Commit e0b60eb

Browse files
committed
fix test
1 parent f07eaa1 commit e0b60eb

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

x/genutil/client/cli/validate_genesis_test.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package cli_test
22

33
import (
4+
"encoding/json"
45
"os"
56
"testing"
67

78
"github.com/stretchr/testify/require"
89

910
"github.com/cosmos/cosmos-sdk/client"
11+
"github.com/cosmos/cosmos-sdk/codec"
1012
"github.com/cosmos/cosmos-sdk/testutil"
1113
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
1214
"github.com/cosmos/cosmos-sdk/types/module"
13-
testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil"
14-
"github.com/cosmos/cosmos-sdk/x/genutil"
1515
"github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
16-
"github.com/cosmos/cosmos-sdk/x/staking"
1716
)
1817

1918
// An example exported genesis file from a 0.37 chain. Note that evidence
@@ -36,12 +35,11 @@ var v037Exported = `{
3635
}`
3736

3837
func TestValidateGenesis(t *testing.T) {
39-
cdc := testutilmod.MakeTestEncodingConfig(genutil.AppModule{}).Codec
4038
testCases := []struct {
41-
name string
42-
genesis string
43-
expErrStr string
44-
genMM module.BasicManager
39+
name string
40+
genesis string
41+
expErrStr string
42+
basicManager module.BasicManager
4543
}{
4644
{
4745
"invalid json",
@@ -58,7 +56,7 @@ func TestValidateGenesis(t *testing.T) {
5856
return string(bz)
5957
}(),
6058
"section is missing in the app_state",
61-
module.NewBasicManager(staking.NewAppModule(cdc, nil, nil, nil, nil)),
59+
module.NewBasicManager(mockModule{}),
6260
},
6361
{
6462
"exported 0.37 genesis file",
@@ -84,7 +82,7 @@ func TestValidateGenesis(t *testing.T) {
8482

8583
t.Run(tc.name, func(t *testing.T) {
8684
genesisFile := testutil.WriteToNewTempFile(t, tc.genesis)
87-
_, err := clitestutil.ExecTestCLICmd(client.Context{}, cli.ValidateGenesisCmd(tc.genMM), []string{genesisFile.Name()})
85+
_, err := clitestutil.ExecTestCLICmd(client.Context{}, cli.ValidateGenesisCmd(tc.basicManager), []string{genesisFile.Name()})
8886
if tc.expErrStr != "" {
8987
require.Contains(t, err.Error(), tc.expErrStr)
9088
} else {
@@ -93,3 +91,19 @@ func TestValidateGenesis(t *testing.T) {
9391
})
9492
}
9593
}
94+
95+
type mockModule struct {
96+
module.AppModuleBasic
97+
}
98+
99+
func (mockModule) Name() string {
100+
return "mock"
101+
}
102+
103+
func (mockModule) DefaultGenesis(codec.JSONCodec) json.RawMessage {
104+
return json.RawMessage(`{"foo": "bar"}`)
105+
}
106+
107+
func (mockModule) ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage) error {
108+
return nil
109+
}

0 commit comments

Comments
 (0)