@@ -6,9 +6,16 @@ import (
66
77 "github.com/stretchr/testify/require"
88
9+ appmodulev2 "cosmossdk.io/core/appmodule/v2"
10+ "cosmossdk.io/x/staking"
11+
912 "github.com/cosmos/cosmos-sdk/client"
13+ codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
1014 "github.com/cosmos/cosmos-sdk/testutil"
1115 clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
16+ "github.com/cosmos/cosmos-sdk/types/module"
17+ testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil"
18+ "github.com/cosmos/cosmos-sdk/x/genutil"
1219 "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
1320)
1421
@@ -32,15 +39,37 @@ var v037Exported = `{
3239}`
3340
3441func TestValidateGenesis (t * testing.T ) {
42+ cdc := testutilmod .MakeTestEncodingConfig (codectestutil.CodecOptions {}, genutil.AppModule {}).Codec
3543 testCases := []struct {
36- name string
37- genesis string
38- expErr bool
44+ name string
45+ genesis string
46+ expErrStr string
47+ genMM * module.Manager
3948 }{
49+ {
50+ "invalid json" ,
51+ `{"app_state": {x,}}` ,
52+ "error at offset 16: invalid character" ,
53+ module .NewManagerFromMap (nil ),
54+ },
55+ {
56+ "invalid: missing module config in app_state" ,
57+ func () string {
58+ bz , err := os .ReadFile ("../../types/testdata/app_genesis.json" )
59+ require .NoError (t , err )
60+
61+ return string (bz )
62+ }(),
63+ "section is missing in the app_state" ,
64+ module .NewManagerFromMap (map [string ]appmodulev2.AppModule {
65+ "custommod" : staking .NewAppModule (cdc , nil , nil , nil ),
66+ }),
67+ },
4068 {
4169 "exported 0.37 genesis file" ,
4270 v037Exported ,
43- true ,
71+ "make sure that you have correctly migrated all CometBFT consensus params" ,
72+ module .NewManagerFromMap (nil ),
4473 },
4574 {
4675 "valid 0.50 genesis file" ,
@@ -50,7 +79,8 @@ func TestValidateGenesis(t *testing.T) {
5079
5180 return string (bz )
5281 }(),
53- false ,
82+ "" ,
83+ module .NewManagerFromMap (nil ),
5484 },
5585 }
5686
@@ -59,9 +89,9 @@ func TestValidateGenesis(t *testing.T) {
5989
6090 t .Run (tc .name , func (t * testing.T ) {
6191 genesisFile := testutil .WriteToNewTempFile (t , tc .genesis )
62- _ , err := clitestutil .ExecTestCLICmd (client.Context {}, cli .ValidateGenesisCmd (nil ), []string {genesisFile .Name ()})
63- if tc .expErr {
64- require .Contains (t , err .Error (), "make sure that you have correctly migrated all CometBFT consensus params" )
92+ _ , err := clitestutil .ExecTestCLICmd (client.Context {}, cli .ValidateGenesisCmd (tc . genMM ), []string {genesisFile .Name ()})
93+ if tc .expErrStr != "" {
94+ require .Contains (t , err .Error (), tc . expErrStr )
6595 } else {
6696 require .NoError (t , err )
6797 }
0 commit comments