cosmos-sdk/x/genutil/client/testutil/validate_genesis.go
Aaron Craelius 3c65c3dacd
Make integration test suites reusable by apps (#6711)
* WIP on refactoring new integration tests.

* godocs

* godocs

* Fix ineff assign

* Updates

* Updates

* fix test

* refactor crisis, distr testsuites

* fix import issue

* refactor x/auth

* refactor x/authz

* refactor x/evidence

* refactor x/feegrant

* refactor x/genutil

* refactor x/gov

* refactor x/mint

* refactor x/params

* refactor x/{auth_vesting, slashing, staking}

* fix lint

* fix tests & lint

* fix lint

* fix tests

* lint

* lint

* fix lint memory

* add missing `norace` build flag

* update feegrant cfg

* fix lint

Co-authored-by: atheesh <atheesh@vitwit.com>
Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com>
2021-04-23 14:49:49 -04:00

103 lines
2.4 KiB
Go

package testutil
import (
"github.com/cosmos/cosmos-sdk/testutil"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
)
// An example exported genesis file from a 0.37 chain. Note that evidence
// parameters only contains `max_age`.
var v037Exported = `{
"app_hash": "",
"app_state": {},
"chain_id": "test",
"consensus_params": {
"block": {
"max_bytes": "22020096",
"max_gas": "-1",
"time_iota_ms": "1000"
},
"evidence": { "max_age": "100000" },
"validator": { "pub_key_types": ["ed25519"] }
},
"genesis_time": "2020-09-29T20:16:29.172362037Z",
"validators": []
}`
// An example exported genesis file that's 0.40 compatible.
// We added the following app_state:
//
// - x/gov: added votes to test ADR-037 split votes migration.
var v040Valid = `{
"app_hash": "",
"app_state": {
"gov": {
"starting_proposal_id": "0",
"deposits": [],
"votes": [
{
"proposal_id": "5",
"voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh",
"option": "VOTE_OPTION_YES"
}
],
"proposals": [],
"deposit_params": { "min_deposit": [], "max_deposit_period": "0s" },
"voting_params": { "voting_period": "0s" },
"tally_params": { "quorum": "0", "threshold": "0", "veto_threshold": "0" }
}
},
"chain_id": "test",
"consensus_params": {
"block": {
"max_bytes": "22020096",
"max_gas": "-1",
"time_iota_ms": "1000"
},
"evidence": {
"max_age_num_blocks": "100000",
"max_age_duration": "172800000000000",
"max_bytes": "0"
},
"validator": { "pub_key_types": ["ed25519"] }
},
"genesis_time": "2020-09-29T20:16:29.172362037Z",
"validators": []
}`
func (s *IntegrationTestSuite) TestValidateGenesis() {
val0 := s.network.Validators[0]
testCases := []struct {
name string
genesis string
expErr bool
}{
{
"exported 0.37 genesis file",
v037Exported,
true,
},
{
"valid 0.40 genesis file",
v040Valid,
false,
},
}
for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
genesisFile := testutil.WriteToNewTempFile(s.T(), tc.genesis)
_, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cli.ValidateGenesisCmd(nil), []string{genesisFile.Name()})
if tc.expErr {
s.Require().Contains(err.Error(), "Make sure that you have correctly migrated all Tendermint consensus params")
} else {
s.Require().NoError(err)
}
})
}
}