-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(staking): Fix JSON genesis migration (#12140)
(cherry picked from commit 67a04a5)
- Loading branch information
1 parent
ecb219e
commit 0f39888
Showing
6 changed files
with
109 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package v043 | ||
|
||
const ( | ||
// ModuleName is the name of the module | ||
ModuleName = "staking" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package v046 | ||
|
||
import "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
|
||
// MigrateJSON accepts exported v0.43 x/stakinng genesis state and migrates it to | ||
// v0.46 x/staking genesis state. The migration includes: | ||
// | ||
// - Add MinCommissionRate param. | ||
func MigrateJSON(oldState types.GenesisState) (types.GenesisState, error) { | ||
oldState.Params.MinCommissionRate = types.DefaultMinCommissionRate | ||
|
||
return oldState, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package v046_test | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/simapp" | ||
v046 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v046" | ||
"github.com/cosmos/cosmos-sdk/x/staking/types" | ||
) | ||
|
||
func TestMigrateJSON(t *testing.T) { | ||
encodingConfig := simapp.MakeTestEncodingConfig() | ||
clientCtx := client.Context{}. | ||
WithInterfaceRegistry(encodingConfig.InterfaceRegistry). | ||
WithTxConfig(encodingConfig.TxConfig). | ||
WithCodec(encodingConfig.Codec) | ||
|
||
oldState := types.DefaultGenesisState() | ||
|
||
newState, err := v046.MigrateJSON(*oldState) | ||
require.NoError(t, err) | ||
|
||
bz, err := clientCtx.Codec.MarshalJSON(&newState) | ||
require.NoError(t, err) | ||
|
||
// Indent the JSON bz correctly. | ||
var jsonObj map[string]interface{} | ||
err = json.Unmarshal(bz, &jsonObj) | ||
require.NoError(t, err) | ||
indentedBz, err := json.MarshalIndent(jsonObj, "", "\t") | ||
require.NoError(t, err) | ||
|
||
// Make sure about new param MinCommissionRate. | ||
expected := `{ | ||
"delegations": [], | ||
"exported": false, | ||
"last_total_power": "0", | ||
"last_validator_powers": [], | ||
"params": { | ||
"bond_denom": "stake", | ||
"historical_entries": 10000, | ||
"max_entries": 7, | ||
"max_validators": 100, | ||
"min_commission_rate": "0.000000000000000000", | ||
"unbonding_time": "1814400s" | ||
}, | ||
"redelegations": [], | ||
"unbonding_delegations": [], | ||
"validators": [] | ||
}` | ||
|
||
require.Equal(t, expected, string(indentedBz)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package v046 | ||
|
||
const ( | ||
// ModuleName is the name of the module | ||
ModuleName = "staking" | ||
) |