github.com/Finschia/finschia-sdk@v0.48.1/x/genutil/client/testutil/validate_genesis.go (about)

     1  package testutil
     2  
     3  import (
     4  	"github.com/Finschia/finschia-sdk/testutil"
     5  	clitestutil "github.com/Finschia/finschia-sdk/testutil/cli"
     6  	"github.com/Finschia/finschia-sdk/x/genutil/client/cli"
     7  )
     8  
     9  // An example exported genesis file from a 0.37 chain. Note that evidence
    10  // parameters only contains `max_age`.
    11  var v037Exported = `{
    12  	"app_hash": "",
    13  	"app_state": {},
    14  	"chain_id": "test",
    15  	"consensus_params": {
    16  		"block": {
    17  		"max_bytes": "22020096",
    18  		"max_gas": "-1",
    19  		"time_iota_ms": "1000"
    20  		},
    21  		"evidence": { "max_age": "100000" },
    22  		"validator": { "pub_key_types": ["ed25519"] }
    23  	},
    24  	"genesis_time": "2020-09-29T20:16:29.172362037Z",
    25  	"validators": []
    26  }`
    27  
    28  // An example exported genesis file that's 0.40 compatible.
    29  // We added the following app_state:
    30  //
    31  // - x/gov: added votes to test ADR-037 split votes migration.
    32  var v040Valid = `{
    33  	"app_hash": "",
    34  	"app_state": {
    35  		"gov": {
    36  			"starting_proposal_id": "0",
    37  			"deposits": [],
    38  			"votes": [
    39  			  {
    40  				"proposal_id": "5",
    41  				"voter": "link1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh",
    42  				"option": "VOTE_OPTION_YES"
    43  			  }
    44  			],
    45  			"proposals": [],
    46  			"deposit_params": { "min_deposit": [], "max_deposit_period": "0s" },
    47  			"voting_params": { "voting_period": "0s" },
    48  			"tally_params": { "quorum": "0", "threshold": "0", "veto_threshold": "0" }
    49  		}	  
    50  	},
    51  	"chain_id": "test",
    52  	"consensus_params": {
    53  		"block": {
    54  		"max_bytes": "22020096",
    55  		"max_gas": "-1",
    56  		"time_iota_ms": "1000"
    57  		},
    58  		"evidence": {
    59  			"max_age_num_blocks": "100000",
    60  			"max_age_duration": "172800000000000",
    61  			"max_bytes": "0"
    62  		},
    63  		"validator": { "pub_key_types": ["ed25519"] }
    64  	},
    65  	"genesis_time": "2020-09-29T20:16:29.172362037Z",
    66  	"validators": []
    67  }`
    68  
    69  func (s *IntegrationTestSuite) TestValidateGenesis() {
    70  	val0 := s.network.Validators[0]
    71  
    72  	testCases := []struct {
    73  		name    string
    74  		genesis string
    75  		expErr  bool
    76  	}{
    77  		{
    78  			"exported 0.37 genesis file",
    79  			v037Exported,
    80  			true,
    81  		},
    82  		{
    83  			"valid 0.40 genesis file",
    84  			v040Valid,
    85  			false,
    86  		},
    87  	}
    88  
    89  	for _, tc := range testCases {
    90  		tc := tc
    91  		s.Run(tc.name, func() {
    92  			genesisFile := testutil.WriteToNewTempFile(s.T(), tc.genesis)
    93  			_, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cli.ValidateGenesisCmd(nil), []string{genesisFile.Name()})
    94  			if tc.expErr {
    95  				s.Require().Contains(err.Error(), "Make sure that you have correctly migrated all Tendermint consensus params")
    96  			} else {
    97  				s.Require().NoError(err)
    98  			}
    99  		})
   100  	}
   101  }