github.com/cosmos/cosmos-sdk@v0.50.10/x/staking/migrations/v3/json_test.go (about)

     1  package v3_test
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  
     9  	"github.com/cosmos/cosmos-sdk/client"
    10  	moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
    11  	v3 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v3"
    12  	"github.com/cosmos/cosmos-sdk/x/staking/types"
    13  )
    14  
    15  func TestMigrateJSON(t *testing.T) {
    16  	encodingConfig := moduletestutil.MakeTestEncodingConfig()
    17  	clientCtx := client.Context{}.
    18  		WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
    19  		WithTxConfig(encodingConfig.TxConfig).
    20  		WithCodec(encodingConfig.Codec)
    21  
    22  	oldState := types.DefaultGenesisState()
    23  
    24  	newState, err := v3.MigrateJSON(*oldState)
    25  	require.NoError(t, err)
    26  
    27  	bz, err := clientCtx.Codec.MarshalJSON(&newState)
    28  	require.NoError(t, err)
    29  
    30  	// Indent the JSON bz correctly.
    31  	var jsonObj map[string]interface{}
    32  	err = json.Unmarshal(bz, &jsonObj)
    33  	require.NoError(t, err)
    34  	indentedBz, err := json.MarshalIndent(jsonObj, "", "\t")
    35  	require.NoError(t, err)
    36  
    37  	// Make sure about new param MinCommissionRate.
    38  	expected := `{
    39  	"delegations": [],
    40  	"exported": false,
    41  	"last_total_power": "0",
    42  	"last_validator_powers": [],
    43  	"params": {
    44  		"bond_denom": "stake",
    45  		"historical_entries": 10000,
    46  		"max_entries": 7,
    47  		"max_validators": 100,
    48  		"min_commission_rate": "0.000000000000000000",
    49  		"unbonding_time": "1814400s"
    50  	},
    51  	"redelegations": [],
    52  	"unbonding_delegations": [],
    53  	"validators": []
    54  }`
    55  
    56  	require.Equal(t, expected, string(indentedBz))
    57  }