Remove migration scripts <=0.38 (#9291)
* Remove migration scripts <=0.38 * Add changelog * remove more * remove more stuff * Fix test * Relase wording * Add comment * Include migratio wording
This commit is contained in:
parent
300d2a7fd4
commit
56c0595f32
|
@ -67,6 +67,7 @@ if input key is empty, or input data contains empty key.
|
|||
* via `ServiceMsg` TypeURLs (e.g. `message.action='/cosmos.bank.v1beta1.Msg/Send'`) does not work anymore,
|
||||
* via legacy `msg.Type()` (e.g. `message.action='send'`) is being deprecated, new `Msg`s won't emit these events.
|
||||
* Please use concrete `Msg` TypeURLs instead (e.g. `message.action='/cosmos.bank.v1beta1.MsgSend'`).
|
||||
* [\#9291](https://github.com/cosmos/cosmos-sdk/pull/9291) Migration scripts prior to v0.38 have been removed from the CLI `migrate` command. The oldest supported migration is v0.39->v0.42.
|
||||
|
||||
### API Breaking Changes
|
||||
|
||||
|
|
|
@ -4,19 +4,16 @@
|
|||
|
||||
Only the following release series are currently supported and receive bug fixes:
|
||||
|
||||
The `0.37.x` release series will continue receiving bug fixes until the Cosmos Hub
|
||||
migrates to a newer release of the Cosmos-SDK.
|
||||
* **0.39 «Launchpad»** will be supported until 6 months after **0.42.0** is published. A fairly strict **bugfix-only** rule applies to pull requests that are requested to be included into a stable point-release.
|
||||
* **0.42 «Stargate»** is the latest stable release.
|
||||
|
||||
* **0.37** will continue receiving bug fixes until the Cosmos Hub migrates to a newer release series of the Cosmos-SDK.
|
||||
* **0.39 «Launchpad»** will be supported until 6 months after **0.40.0** is published. A fairly strict **bugfix-only** rule applies to pull requests that are requested to be included into a stable point-release.
|
||||
|
||||
The **0.39 «Launchpad»** release series is maintained in compliance with the **Stable Release Policy** as described in this document.
|
||||
The **0.42 «Stargate»** release series is maintained in compliance with the **Stable Release Policy** as described in this document.
|
||||
|
||||
## Stable Release Policy
|
||||
|
||||
This policy presently applies *only* to the following release series:
|
||||
|
||||
* **0.39 «Launchpad»**
|
||||
* **0.42 «Stargate»**
|
||||
|
||||
### Point Releases
|
||||
|
||||
|
@ -48,6 +45,10 @@ priority is to minimise the risk caused by changes that are not strictly require
|
|||
be correlated with minimising the size of such changes. As such, the same bug may need to be fixed in different
|
||||
ways in stable releases and `master` branch.
|
||||
|
||||
### Migrations
|
||||
|
||||
To smoothen the update to the latest stable release, the SDK includes a set of CLI commands for managing migrations between SDK versions, under the `migrate` subcommand. Only migration scripts between stable releases are included. For the current release, **0.39 «Launchpad»** and later migrations are supported.
|
||||
|
||||
### What qualifies as a Stable Release Update (SRU)
|
||||
|
||||
* **High-impact bugs**
|
||||
|
@ -86,12 +87,12 @@ As rule of thumb, the following changes will **NOT** be automatically accepted i
|
|||
|
||||
## Stable Release Exception - Procedure
|
||||
|
||||
1. Check that the bug is either fixed or not reproducible in `master`. It is, in general, not appropriate to release bug fixes for stable releases without first testing them in `master`. Please apply the label [0.39 «Launchpad»](https://github.com/cosmos/cosmos-sdk/labels/0.39%20LTS%20%28Launchpad%29) to the issue.
|
||||
1. Check that the bug is either fixed or not reproducible in `master`. It is, in general, not appropriate to release bug fixes for stable releases without first testing them in `master`. Please apply the label [0.42 «Stargate»](https://github.com/cosmos/cosmos-sdk/labels/0.42%20LTS%20%28Stargate%29) to the issue.
|
||||
2. Add a comment to the issue and ensure it contains the following information (see the bug template below):
|
||||
* **[Impact]** An explanation of the bug on users and justification for backporting the fix to the stable release.
|
||||
* A **[Test Case]** section containing detailed instructions on how to reproduce the bug.
|
||||
* A **[Regression Potential]** section with a clear assessment on how regressions are most likely to manifest as a result of the pull request that aims to fix the bug in the target stable release.
|
||||
3. **Stable Release Managers** will review and discuss the PR. Once *consensus* surrounding the rationale has been reached and the technical review has successfully concluded, the pull request will be merged in the respective point-release target branch (e.g. `release/launchpad/0.39.X` being `X` the Launchpad's upcoming point-release) and the PR included in the point-release's respective milestone (e.g. `0.39.5`).
|
||||
3. **Stable Release Managers** will review and discuss the PR. Once *consensus* surrounding the rationale has been reached and the technical review has successfully concluded, the pull request will be merged in the respective point-release target branch (e.g. `release/v0.42.x`) and the PR included in the point-release's respective milestone (e.g. `0.42.5`).
|
||||
|
||||
### Stable Release Exception - Bug template
|
||||
|
||||
|
@ -102,7 +103,7 @@ Brief xplanation of the effects of the bug on users and a justification for back
|
|||
|
||||
#### Test Case
|
||||
|
||||
Detailed instructions on how to reproduce the bug on Launchpad's most recently published point-release.
|
||||
Detailed instructions on how to reproduce the bug on Stargate's most recently published point-release.
|
||||
|
||||
#### Regression Potential
|
||||
|
||||
|
@ -124,8 +125,7 @@ Their responsibilites include:
|
|||
|
||||
The Stable Release Managers are appointed by the Interchain Foundation.
|
||||
|
||||
*Stable Release Managers* for the **0.39 «Launchpad»** release series follow:
|
||||
*Stable Release Managers* for the **0.42 «Stargate»** release series follow:
|
||||
|
||||
* @alessio - Alessio Treglia
|
||||
* @clevinson - Cory Levinson-
|
||||
* @ethanfrey - Ethan Frey
|
||||
* @clevinson - Cory Levinson
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// Package v034 is used for legacy migration scripts. Actual migration scripts
|
||||
// for v034 have been removed, but the v039->v042 migration script still
|
||||
// references types from this file, so we're keeping it for now.
|
||||
// DONTCOVER
|
||||
package v034
|
||||
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
// DONTCOVER
|
||||
package v036
|
||||
|
||||
import (
|
||||
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v034"
|
||||
)
|
||||
|
||||
// Migrate accepts exported genesis state from v0.34 and migrates it to v0.36
|
||||
// genesis state. This migration removes the CollectedFees coins from the old
|
||||
// FeeCollectorKeeper.
|
||||
func Migrate(oldGenState v034auth.GenesisState) GenesisState {
|
||||
return NewGenesisState(oldGenState.Params)
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package v036
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v034"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestMigrate(t *testing.T) {
|
||||
var genesisState GenesisState
|
||||
require.NotPanics(t, func() {
|
||||
genesisState = Migrate(v034auth.GenesisState{
|
||||
CollectedFees: types.Coins{
|
||||
{
|
||||
Amount: types.NewInt(10),
|
||||
Denom: "stake",
|
||||
},
|
||||
},
|
||||
Params: v034auth.Params{}, // forwarded structure: filling and checking will be testing a no-op
|
||||
})
|
||||
})
|
||||
require.Equal(t, genesisState, GenesisState{Params: v034auth.Params{}})
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
// DONTCOVER
|
||||
package v036
|
||||
|
||||
import v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v034"
|
||||
|
||||
const (
|
||||
ModuleName = "auth"
|
||||
)
|
||||
|
||||
type (
|
||||
GenesisState struct {
|
||||
Params v034auth.Params `json:"params"`
|
||||
}
|
||||
)
|
||||
|
||||
func NewGenesisState(params v034auth.Params) GenesisState {
|
||||
return GenesisState{params}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package v038
|
||||
|
||||
import (
|
||||
v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v036"
|
||||
v036genaccounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v036"
|
||||
)
|
||||
|
||||
// Migrate accepts exported genesis state from v0.34 and migrates it to v0.38
|
||||
// genesis state.
|
||||
func Migrate(authGenState v036auth.GenesisState, genAccountsGenState v036genaccounts.GenesisState) GenesisState {
|
||||
accounts := make(GenesisAccounts, len(genAccountsGenState))
|
||||
|
||||
for i, acc := range genAccountsGenState {
|
||||
var genAccount GenesisAccount
|
||||
|
||||
baseAccount := NewBaseAccount(acc.Address, acc.Coins.Sort(), nil, acc.AccountNumber, acc.Sequence)
|
||||
|
||||
switch {
|
||||
case !acc.OriginalVesting.IsZero():
|
||||
baseVestingAccount := NewBaseVestingAccount(
|
||||
baseAccount, acc.OriginalVesting.Sort(), acc.DelegatedFree.Sort(),
|
||||
acc.DelegatedVesting.Sort(), acc.EndTime,
|
||||
)
|
||||
|
||||
if acc.StartTime != 0 && acc.EndTime != 0 {
|
||||
// continuous vesting account type
|
||||
genAccount = NewContinuousVestingAccountRaw(baseVestingAccount, acc.StartTime)
|
||||
} else if acc.EndTime != 0 {
|
||||
// delayed vesting account type
|
||||
genAccount = NewDelayedVestingAccountRaw(baseVestingAccount)
|
||||
}
|
||||
|
||||
case acc.ModuleName != "":
|
||||
// module account type
|
||||
genAccount = NewModuleAccount(baseAccount, acc.ModuleName, acc.ModulePermissions...)
|
||||
|
||||
default:
|
||||
// standard account type
|
||||
genAccount = baseAccount
|
||||
}
|
||||
|
||||
accounts[i] = genAccount
|
||||
}
|
||||
|
||||
accounts = SanitizeGenesisAccounts(accounts)
|
||||
|
||||
if err := ValidateGenAccounts(accounts); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return NewGenesisState(authGenState.Params, accounts)
|
||||
}
|
|
@ -1,159 +0,0 @@
|
|||
package v038
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v034"
|
||||
v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v036"
|
||||
v036genaccounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v036"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func accAddressFromBech32(t *testing.T, addrStr string) sdk.AccAddress {
|
||||
addr, err := sdk.AccAddressFromBech32(addrStr)
|
||||
require.NoError(t, err)
|
||||
return addr
|
||||
}
|
||||
|
||||
func TestMigrate(t *testing.T) {
|
||||
var genesisState GenesisState
|
||||
|
||||
params := v034auth.Params{
|
||||
MaxMemoCharacters: 10,
|
||||
TxSigLimit: 10,
|
||||
TxSizeCostPerByte: 10,
|
||||
SigVerifyCostED25519: 10,
|
||||
SigVerifyCostSecp256k1: 10,
|
||||
}
|
||||
|
||||
acc1 := v036genaccounts.GenesisAccount{
|
||||
Address: accAddressFromBech32(t, "cosmos1f9xjhxm0plzrh9cskf4qee4pc2xwp0n0556gh0"),
|
||||
Coins: sdk.NewCoins(sdk.NewInt64Coin("stake", 400000)),
|
||||
Sequence: 1,
|
||||
AccountNumber: 1,
|
||||
}
|
||||
acc2 := v036genaccounts.GenesisAccount{
|
||||
Address: accAddressFromBech32(t, "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"),
|
||||
Coins: sdk.NewCoins(sdk.NewInt64Coin("stake", 400000000)),
|
||||
Sequence: 4,
|
||||
AccountNumber: 2,
|
||||
ModuleName: "bonded_tokens_pool",
|
||||
ModulePermissions: []string{"burner", "staking"},
|
||||
}
|
||||
acc3 := v036genaccounts.GenesisAccount{
|
||||
Address: accAddressFromBech32(t, "cosmos17n9sztlhx32tfy0tg0zc2ttmkeeth50yyuv9he"),
|
||||
Coins: sdk.NewCoins(sdk.NewInt64Coin("stake", 10000205)),
|
||||
OriginalVesting: sdk.NewCoins(sdk.NewInt64Coin("stake", 10000205)),
|
||||
StartTime: time.Now().Unix(),
|
||||
EndTime: time.Now().Add(48 * time.Hour).Unix(),
|
||||
Sequence: 5,
|
||||
AccountNumber: 3,
|
||||
}
|
||||
acc4 := v036genaccounts.GenesisAccount{
|
||||
Address: accAddressFromBech32(t, "cosmos1fmk5elg4r62mlexd36tqjcwyafs7mek0js5m4d"),
|
||||
Coins: sdk.NewCoins(sdk.NewInt64Coin("stake", 10000205)),
|
||||
OriginalVesting: sdk.NewCoins(sdk.NewInt64Coin("stake", 10000205)),
|
||||
EndTime: time.Now().Add(48 * time.Hour).Unix(),
|
||||
Sequence: 15,
|
||||
AccountNumber: 4,
|
||||
}
|
||||
|
||||
require.NotPanics(t, func() {
|
||||
genesisState = Migrate(
|
||||
v036auth.GenesisState{
|
||||
Params: params,
|
||||
},
|
||||
v036genaccounts.GenesisState{acc1, acc2, acc3, acc4},
|
||||
)
|
||||
})
|
||||
|
||||
expectedAcc1 := NewBaseAccount(acc1.Address, acc1.Coins, nil, acc1.AccountNumber, acc1.Sequence)
|
||||
expectedAcc2 := NewModuleAccount(
|
||||
NewBaseAccount(acc2.Address, acc2.Coins, nil, acc2.AccountNumber, acc2.Sequence),
|
||||
acc2.ModuleName, acc2.ModulePermissions...,
|
||||
)
|
||||
expectedAcc3 := NewContinuousVestingAccountRaw(
|
||||
NewBaseVestingAccount(
|
||||
NewBaseAccount(acc3.Address, acc3.Coins, nil, acc3.AccountNumber, acc3.Sequence),
|
||||
acc3.OriginalVesting, acc3.DelegatedFree, acc3.DelegatedVesting, acc3.EndTime,
|
||||
),
|
||||
acc3.StartTime,
|
||||
)
|
||||
expectedAcc4 := NewDelayedVestingAccountRaw(
|
||||
NewBaseVestingAccount(
|
||||
NewBaseAccount(acc4.Address, acc4.Coins, nil, acc4.AccountNumber, acc4.Sequence),
|
||||
acc4.OriginalVesting, acc4.DelegatedFree, acc4.DelegatedVesting, acc4.EndTime,
|
||||
),
|
||||
)
|
||||
|
||||
require.Equal(
|
||||
t, genesisState, GenesisState{
|
||||
Params: params,
|
||||
Accounts: GenesisAccounts{expectedAcc1, expectedAcc2, expectedAcc3, expectedAcc4},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestMigrateInvalid(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
acc v036genaccounts.GenesisAccount
|
||||
}{
|
||||
{
|
||||
"module account with invalid name",
|
||||
v036genaccounts.GenesisAccount{
|
||||
Address: accAddressFromBech32(t, "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"),
|
||||
Coins: sdk.NewCoins(sdk.NewInt64Coin("stake", 400000000)),
|
||||
Sequence: 4,
|
||||
AccountNumber: 2,
|
||||
ModuleName: " ",
|
||||
ModulePermissions: []string{"burner", "staking"},
|
||||
},
|
||||
},
|
||||
{
|
||||
"module account with invalid permissions",
|
||||
v036genaccounts.GenesisAccount{
|
||||
Address: accAddressFromBech32(t, "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"),
|
||||
Coins: sdk.NewCoins(sdk.NewInt64Coin("stake", 400000000)),
|
||||
Sequence: 4,
|
||||
AccountNumber: 2,
|
||||
ModuleName: "bonded_tokens_pool",
|
||||
ModulePermissions: []string{""},
|
||||
},
|
||||
},
|
||||
{
|
||||
"module account with invalid address",
|
||||
v036genaccounts.GenesisAccount{
|
||||
Address: accAddressFromBech32(t, "cosmos17n9sztlhx32tfy0tg0zc2ttmkeeth50yyuv9he"),
|
||||
Coins: sdk.NewCoins(sdk.NewInt64Coin("stake", 400000000)),
|
||||
Sequence: 4,
|
||||
AccountNumber: 2,
|
||||
ModuleName: "bonded_tokens_pool",
|
||||
ModulePermissions: []string{"burner", "staking"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
require.Panics(t, func() {
|
||||
Migrate(
|
||||
v036auth.GenesisState{
|
||||
Params: v034auth.Params{
|
||||
MaxMemoCharacters: 10,
|
||||
TxSigLimit: 10,
|
||||
TxSizeCostPerByte: 10,
|
||||
SigVerifyCostED25519: 10,
|
||||
SigVerifyCostSecp256k1: 10,
|
||||
},
|
||||
},
|
||||
v036genaccounts.GenesisState{tc.acc},
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,3 +1,6 @@
|
|||
// Package v038 is used for legacy migration scripts. Actual migration scripts
|
||||
// for v038 have been removed, but the v039->v042 migration script still
|
||||
// references types from this file, so we're keeping it for now.
|
||||
package v038
|
||||
|
||||
// DONTCOVER
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
package v039
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v038"
|
||||
)
|
||||
|
||||
// Migrate accepts exported genesis state from v0.38 and migrates it to v0.39
|
||||
// genesis state.
|
||||
func Migrate(oldAuthGenState v038auth.GenesisState) GenesisState {
|
||||
accounts := make(v038auth.GenesisAccounts, len(oldAuthGenState.Accounts))
|
||||
|
||||
for i, acc := range oldAuthGenState.Accounts {
|
||||
switch t := acc.(type) {
|
||||
case *v038auth.BaseAccount:
|
||||
accounts[i] = NewBaseAccount(t.Address, t.Coins, t.PubKey, t.AccountNumber, t.Sequence)
|
||||
|
||||
case *v038auth.BaseVestingAccount:
|
||||
accounts[i] = NewBaseVestingAccount(
|
||||
NewBaseAccount(t.Address, t.Coins, t.PubKey, t.AccountNumber, t.Sequence),
|
||||
t.OriginalVesting, t.DelegatedFree, t.DelegatedVesting, t.EndTime,
|
||||
)
|
||||
|
||||
case *v038auth.ContinuousVestingAccount:
|
||||
accounts[i] = NewContinuousVestingAccountRaw(
|
||||
NewBaseVestingAccount(
|
||||
NewBaseAccount(t.Address, t.Coins, t.PubKey, t.AccountNumber, t.Sequence),
|
||||
t.OriginalVesting, t.DelegatedFree, t.DelegatedVesting, t.EndTime,
|
||||
),
|
||||
t.StartTime,
|
||||
)
|
||||
|
||||
case *v038auth.DelayedVestingAccount:
|
||||
accounts[i] = NewDelayedVestingAccountRaw(
|
||||
NewBaseVestingAccount(
|
||||
NewBaseAccount(t.Address, t.Coins, t.PubKey, t.AccountNumber, t.Sequence),
|
||||
t.OriginalVesting, t.DelegatedFree, t.DelegatedVesting, t.EndTime,
|
||||
),
|
||||
)
|
||||
|
||||
case *v038auth.ModuleAccount:
|
||||
accounts[i] = NewModuleAccount(
|
||||
NewBaseAccount(t.Address, t.Coins, t.PubKey, t.AccountNumber, t.Sequence),
|
||||
t.Name, t.Permissions...,
|
||||
)
|
||||
|
||||
default:
|
||||
panic(fmt.Sprintf("unexpected account type: %T", acc))
|
||||
}
|
||||
}
|
||||
|
||||
accounts = v038auth.SanitizeGenesisAccounts(accounts)
|
||||
|
||||
if err := v038auth.ValidateGenAccounts(accounts); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return NewGenesisState(oldAuthGenState.Params, accounts)
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
package v039_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v038"
|
||||
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v039"
|
||||
)
|
||||
|
||||
func TestMigrate(t *testing.T) {
|
||||
aminoCdc := codec.NewLegacyAmino()
|
||||
v039auth.RegisterLegacyAminoCodec(aminoCdc)
|
||||
|
||||
pub1 := ed25519.GenPrivKeyFromSecret([]byte("acc1")).PubKey()
|
||||
pub2 := secp256k1.GenPrivKeyFromSecret([]byte("acc2")).PubKey()
|
||||
|
||||
acc1 := v038auth.BaseAccount{
|
||||
Address: sdk.AccAddress(pub1.Address()),
|
||||
Coins: sdk.NewCoins(sdk.NewInt64Coin("stake", 400000)),
|
||||
Sequence: 1,
|
||||
AccountNumber: 1,
|
||||
PubKey: pub1,
|
||||
}
|
||||
acc2 := v038auth.BaseAccount{
|
||||
Address: sdk.AccAddress(pub2.Address()),
|
||||
Coins: sdk.NewCoins(sdk.NewInt64Coin("stake", 400000)),
|
||||
Sequence: 2,
|
||||
AccountNumber: 2,
|
||||
PubKey: pub2,
|
||||
}
|
||||
|
||||
migrated := v039auth.Migrate(
|
||||
v038auth.GenesisState{
|
||||
Accounts: v038auth.GenesisAccounts{&acc1, &acc2},
|
||||
},
|
||||
)
|
||||
|
||||
expectedAcc1 := v039auth.NewBaseAccount(acc1.Address, acc1.Coins, acc1.PubKey, acc1.AccountNumber, acc1.Sequence)
|
||||
expectedAcc2 := v039auth.NewBaseAccount(acc2.Address, acc2.Coins, acc2.PubKey, acc2.AccountNumber, acc2.Sequence)
|
||||
|
||||
require.Equal(
|
||||
t, migrated, v039auth.GenesisState{
|
||||
Accounts: v038auth.GenesisAccounts{expectedAcc1, expectedAcc2},
|
||||
},
|
||||
)
|
||||
|
||||
json, err := aminoCdc.MarshalJSONIndent(migrated, "", " ")
|
||||
require.NoError(t, err)
|
||||
|
||||
expectedJSON := `{
|
||||
"params": {
|
||||
"max_memo_characters": "0",
|
||||
"tx_sig_limit": "0",
|
||||
"tx_size_cost_per_byte": "0",
|
||||
"sig_verify_cost_ed25519": "0",
|
||||
"sig_verify_cost_secp256k1": "0"
|
||||
},
|
||||
"accounts": [
|
||||
{
|
||||
"type": "cosmos-sdk/Account",
|
||||
"value": {
|
||||
"address": "cosmos1j7skdhh9raxdmfhmcy2gxz8hgn0jnhfmujjsfe",
|
||||
"coins": [
|
||||
{
|
||||
"denom": "stake",
|
||||
"amount": "400000"
|
||||
}
|
||||
],
|
||||
"public_key": {
|
||||
"type": "tendermint/PubKeyEd25519",
|
||||
"value": "eB0AcLMLKFRNFfh4XAAMstexfAIUQQCDnfjLZ2KJg+A="
|
||||
},
|
||||
"account_number": "1",
|
||||
"sequence": "1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "cosmos-sdk/Account",
|
||||
"value": {
|
||||
"address": "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h",
|
||||
"coins": [
|
||||
{
|
||||
"denom": "stake",
|
||||
"amount": "400000"
|
||||
}
|
||||
],
|
||||
"public_key": {
|
||||
"type": "tendermint/PubKeySecp256k1",
|
||||
"value": "AruDygh5HprMOpHOEato85dLgAsybMJVyxBGUa3KuWCr"
|
||||
},
|
||||
"account_number": "2",
|
||||
"sequence": "2"
|
||||
}
|
||||
}
|
||||
]
|
||||
}`
|
||||
require.Equal(t, expectedJSON, string(json))
|
||||
}
|
|
@ -1,3 +1,6 @@
|
|||
// Package v036 is used for legacy migration scripts. Actual migration scripts
|
||||
// for v036 have been removed, but the v039->v042 migration script still
|
||||
// references types from this file, so we're keeping it for now.
|
||||
// DONTCOVER
|
||||
package v036
|
||||
|
||||
|
@ -12,9 +15,3 @@ type (
|
|||
Supply sdk.Coins `json:"supply" yaml:"supply"`
|
||||
}
|
||||
)
|
||||
|
||||
func EmptyGenesisState() GenesisState {
|
||||
return GenesisState{
|
||||
Supply: sdk.NewCoins(), // leave this empty as it's filled on initialization
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// Package v038 is used for legacy migration scripts. Actual migration scripts
|
||||
// for v038 have been removed, but the v039->v042 migration script still
|
||||
// references types from this file, so we're keeping it for now.
|
||||
package v038
|
||||
|
||||
// DONTCOVER
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// Package v034 is used for legacy migration scripts. Actual migration scripts
|
||||
// for v034 have been removed, but the v039->v042 migration script still
|
||||
// references types from this file, so we're keeping it for now.
|
||||
// DONTCOVER
|
||||
package v034
|
||||
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
package v036
|
||||
|
||||
import (
|
||||
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v034"
|
||||
)
|
||||
|
||||
// Migrate accepts exported genesis state from v0.34 and migrates it to v0.36
|
||||
// genesis state. All entries are identical except for validator slashing events
|
||||
// which now include the period.
|
||||
func Migrate(oldGenState v034distr.GenesisState) GenesisState {
|
||||
// migrate slash events which now have the period included
|
||||
slashEvents := make([]ValidatorSlashEventRecord, len(oldGenState.ValidatorSlashEvents))
|
||||
for i, se := range oldGenState.ValidatorSlashEvents {
|
||||
slashEvents[i] = ValidatorSlashEventRecord{
|
||||
ValidatorAddress: se.ValidatorAddress,
|
||||
Height: se.Height,
|
||||
Period: se.Event.ValidatorPeriod,
|
||||
Event: se.Event,
|
||||
}
|
||||
}
|
||||
|
||||
return NewGenesisState(
|
||||
oldGenState.FeePool, oldGenState.CommunityTax, oldGenState.BaseProposerReward,
|
||||
oldGenState.BonusProposerReward, oldGenState.WithdrawAddrEnabled,
|
||||
oldGenState.DelegatorWithdrawInfos, oldGenState.PreviousProposer,
|
||||
oldGenState.OutstandingRewards, oldGenState.ValidatorAccumulatedCommissions,
|
||||
oldGenState.ValidatorHistoricalRewards, oldGenState.ValidatorCurrentRewards,
|
||||
oldGenState.DelegatorStartingInfos, slashEvents,
|
||||
)
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package v036
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v034"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var (
|
||||
priv = secp256k1.GenPrivKey()
|
||||
addr = types.AccAddress(priv.PubKey().Address())
|
||||
valAddr, _ = types.ValAddressFromBech32(addr.String())
|
||||
|
||||
event = v034distr.ValidatorSlashEvent{
|
||||
ValidatorPeriod: 1,
|
||||
Fraction: types.Dec{},
|
||||
}
|
||||
)
|
||||
|
||||
func TestMigrate(t *testing.T) {
|
||||
var genesisState GenesisState
|
||||
require.NotPanics(t, func() {
|
||||
genesisState = Migrate(v034distr.GenesisState{
|
||||
ValidatorSlashEvents: []v034distr.ValidatorSlashEventRecord{
|
||||
{
|
||||
ValidatorAddress: valAddr,
|
||||
Height: 1,
|
||||
Event: event,
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
require.Equal(t, genesisState.ValidatorSlashEvents[0], ValidatorSlashEventRecord{
|
||||
ValidatorAddress: valAddr,
|
||||
Height: 1,
|
||||
Period: event.ValidatorPeriod,
|
||||
Event: event,
|
||||
})
|
||||
}
|
||||
|
||||
func TestMigrateEmptyRecord(t *testing.T) {
|
||||
var genesisState GenesisState
|
||||
|
||||
require.NotPanics(t, func() {
|
||||
genesisState = Migrate(v034distr.GenesisState{
|
||||
ValidatorSlashEvents: []v034distr.ValidatorSlashEventRecord{{}},
|
||||
})
|
||||
})
|
||||
|
||||
require.Equal(t, genesisState.ValidatorSlashEvents[0], ValidatorSlashEventRecord{
|
||||
ValidatorAddress: valAddr,
|
||||
Height: 0,
|
||||
Period: 0,
|
||||
Event: v034distr.ValidatorSlashEvent{
|
||||
ValidatorPeriod: 0,
|
||||
Fraction: types.Dec{},
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,3 +1,6 @@
|
|||
// Package v036 is used for legacy migration scripts. Actual migration scripts
|
||||
// for v036 have been removed, but the v039->v042 migration script still
|
||||
// references types from this file, so we're keeping it for now.
|
||||
// DONTCOVER
|
||||
package v036
|
||||
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
package v038
|
||||
|
||||
// DONTCOVER
|
||||
|
||||
import (
|
||||
v036distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v036"
|
||||
)
|
||||
|
||||
// Migrate accepts exported genesis state from v0.36 or v0.37 and migrates it to
|
||||
// v0.38 genesis state. All entries are identical except for parameters.
|
||||
func Migrate(oldGenState v036distr.GenesisState) GenesisState {
|
||||
params := Params{
|
||||
CommunityTax: oldGenState.CommunityTax,
|
||||
BaseProposerReward: oldGenState.BaseProposerReward,
|
||||
BonusProposerReward: oldGenState.BonusProposerReward,
|
||||
WithdrawAddrEnabled: oldGenState.WithdrawAddrEnabled,
|
||||
}
|
||||
|
||||
return NewGenesisState(
|
||||
params, oldGenState.FeePool,
|
||||
oldGenState.DelegatorWithdrawInfos, oldGenState.PreviousProposer,
|
||||
oldGenState.OutstandingRewards, oldGenState.ValidatorAccumulatedCommissions,
|
||||
oldGenState.ValidatorHistoricalRewards, oldGenState.ValidatorCurrentRewards,
|
||||
oldGenState.DelegatorStartingInfos, oldGenState.ValidatorSlashEvents,
|
||||
)
|
||||
}
|
|
@ -1,3 +1,6 @@
|
|||
// Package v038 is used for legacy migration scripts. Actual migration scripts
|
||||
// for v038 have been removed, but the v039->v042 migration script still
|
||||
// references types from this file, so we're keeping it for now.
|
||||
package v038
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// Package v038 is used for legacy migration scripts. Actual migration scripts
|
||||
// for v038 have been removed, but the v039->v042 migration script still
|
||||
// references types from this file, so we're keeping it for now.
|
||||
package v038
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
/*
|
||||
Package genaccounts is now deprecated.
|
||||
|
||||
IMPORTANT: This module has been replaced by ADR 011: Generalize Module Accounts.
|
||||
The ADR can be found here: https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-011-generalize-genesis-accounts.md.
|
||||
|
||||
Genesis accounts that existed in the genesis application state under `app_state.accounts`
|
||||
now exists under the x/auth module's genesis state under the `app_state.auth.accounts` key.
|
||||
Migration can be performed via x/auth/legacy/v038/migrate.go. In addition, because genesis
|
||||
accounts are now generalized via an interface, it is now up to the application to
|
||||
define the concrete types and the respective client logic to add them to a genesis
|
||||
state/file. For an example implementation of the `add-genesis-account` command please
|
||||
refer to https://github.com/cosmos/gaia/pull/122.
|
||||
*/
|
||||
package genaccounts
|
|
@ -1,27 +0,0 @@
|
|||
// DONTCOVER
|
||||
package v034
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
const (
|
||||
ModuleName = "accounts"
|
||||
)
|
||||
|
||||
type (
|
||||
GenesisAccount struct {
|
||||
Address sdk.AccAddress `json:"address"`
|
||||
Coins sdk.Coins `json:"coins"`
|
||||
Sequence uint64 `json:"sequence_number"`
|
||||
AccountNumber uint64 `json:"account_number"`
|
||||
|
||||
OriginalVesting sdk.Coins `json:"original_vesting"`
|
||||
DelegatedFree sdk.Coins `json:"delegated_free"`
|
||||
DelegatedVesting sdk.Coins `json:"delegated_vesting"`
|
||||
StartTime int64 `json:"start_time"`
|
||||
EndTime int64 `json:"end_time"`
|
||||
}
|
||||
|
||||
GenesisState []GenesisAccount
|
||||
)
|
|
@ -1,179 +0,0 @@
|
|||
// DONTCOVER
|
||||
// nolint
|
||||
package v036
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v034"
|
||||
v034accounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v034"
|
||||
v034gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v034"
|
||||
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v034"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
)
|
||||
|
||||
const (
|
||||
notBondedPoolName = "not_bonded_tokens_pool"
|
||||
bondedPoolName = "bonded_tokens_pool"
|
||||
feeCollectorName = "fee_collector"
|
||||
mintModuleName = "mint"
|
||||
|
||||
basic = "basic"
|
||||
minter = "minter"
|
||||
burner = "burner"
|
||||
staking = "staking"
|
||||
)
|
||||
|
||||
// Migrate accepts exported genesis state from v0.34 and migrates it to v0.36
|
||||
// genesis state. It deletes the governance base accounts and creates the new module accounts.
|
||||
// The remaining accounts are updated to the new GenesisAccount type from 0.36
|
||||
func Migrate(
|
||||
oldGenState v034accounts.GenesisState, fees sdk.Coins, communityPool sdk.DecCoins,
|
||||
deposits []v034gov.DepositWithMetadata, vals v034staking.Validators, ubds []v034staking.UnbondingDelegation,
|
||||
valOutRewards []v034distr.ValidatorOutstandingRewardsRecord, bondDenom, distrModuleName, govModuleName string,
|
||||
) GenesisState {
|
||||
|
||||
depositedCoinsAccAddr := sdk.AccAddress(crypto.AddressHash([]byte("govDepositedCoins")))
|
||||
burnedDepositCoinsAccAddr := sdk.AccAddress(crypto.AddressHash([]byte("govBurnedDepositCoins")))
|
||||
|
||||
bondedAmt := sdk.ZeroInt()
|
||||
notBondedAmt := sdk.ZeroInt()
|
||||
|
||||
// remove the two previous governance base accounts for deposits and burned
|
||||
// coins from rejected proposals add six new module accounts:
|
||||
// distribution, gov, mint, fee collector, bonded and not bonded pool
|
||||
var (
|
||||
newGenState GenesisState
|
||||
govCoins sdk.Coins
|
||||
extraAccounts = 6
|
||||
)
|
||||
|
||||
for _, acc := range oldGenState {
|
||||
switch {
|
||||
case acc.Address.Equals(depositedCoinsAccAddr):
|
||||
// remove gov deposits base account
|
||||
govCoins = acc.Coins
|
||||
extraAccounts -= 1
|
||||
|
||||
case acc.Address.Equals(burnedDepositCoinsAccAddr):
|
||||
// remove gov burned deposits base account
|
||||
extraAccounts -= 1
|
||||
|
||||
default:
|
||||
newGenState = append(
|
||||
newGenState,
|
||||
NewGenesisAccount(
|
||||
acc.Address, acc.Coins, acc.Sequence,
|
||||
acc.OriginalVesting, acc.DelegatedFree, acc.DelegatedVesting,
|
||||
acc.StartTime, acc.EndTime, "", []string{},
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
var expDeposits sdk.Coins
|
||||
for _, deposit := range deposits {
|
||||
expDeposits = expDeposits.Add(deposit.Deposit.Amount...)
|
||||
}
|
||||
|
||||
if !expDeposits.IsEqual(govCoins) {
|
||||
panic(
|
||||
fmt.Sprintf(
|
||||
"pre migration deposit base account coins ≠ stored deposits coins (%s ≠ %s)",
|
||||
expDeposits.String(), govCoins.String(),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
// get staking module accounts coins
|
||||
for _, validator := range vals {
|
||||
switch validator.Status {
|
||||
case v034staking.Bonded:
|
||||
bondedAmt = bondedAmt.Add(validator.Tokens)
|
||||
|
||||
case v034staking.Unbonding, v034staking.Unbonded:
|
||||
notBondedAmt = notBondedAmt.Add(validator.Tokens)
|
||||
|
||||
default:
|
||||
panic("invalid validator status")
|
||||
}
|
||||
}
|
||||
|
||||
for _, ubd := range ubds {
|
||||
for _, entry := range ubd.Entries {
|
||||
notBondedAmt = notBondedAmt.Add(entry.Balance)
|
||||
}
|
||||
}
|
||||
|
||||
bondedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, bondedAmt))
|
||||
notBondedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, notBondedAmt))
|
||||
|
||||
// get distr module account coins
|
||||
var distrDecCoins sdk.DecCoins
|
||||
for _, reward := range valOutRewards {
|
||||
distrDecCoins = distrDecCoins.Add(reward.OutstandingRewards...)
|
||||
}
|
||||
|
||||
distrCoins, _ := distrDecCoins.Add(communityPool...).TruncateDecimal()
|
||||
|
||||
// get module account addresses
|
||||
feeCollectorAddr := sdk.AccAddress(crypto.AddressHash([]byte(feeCollectorName)))
|
||||
govAddr := sdk.AccAddress(crypto.AddressHash([]byte(govModuleName)))
|
||||
bondedAddr := sdk.AccAddress(crypto.AddressHash([]byte(bondedPoolName)))
|
||||
notBondedAddr := sdk.AccAddress(crypto.AddressHash([]byte(notBondedPoolName)))
|
||||
distrAddr := sdk.AccAddress(crypto.AddressHash([]byte(distrModuleName)))
|
||||
mintAddr := sdk.AccAddress(crypto.AddressHash([]byte(mintModuleName)))
|
||||
|
||||
// create module genesis accounts
|
||||
feeCollectorModuleAcc := NewGenesisAccount(
|
||||
feeCollectorAddr, fees, 0,
|
||||
sdk.Coins{}, sdk.Coins{}, sdk.Coins{},
|
||||
0, 0, feeCollectorName, []string{basic},
|
||||
)
|
||||
govModuleAcc := NewGenesisAccount(
|
||||
govAddr, govCoins, 0,
|
||||
sdk.Coins{}, sdk.Coins{}, sdk.Coins{},
|
||||
0, 0, govModuleName, []string{burner},
|
||||
)
|
||||
distrModuleAcc := NewGenesisAccount(
|
||||
distrAddr, distrCoins, 0,
|
||||
sdk.Coins{}, sdk.Coins{}, sdk.Coins{},
|
||||
0, 0, distrModuleName, []string{basic},
|
||||
)
|
||||
bondedModuleAcc := NewGenesisAccount(
|
||||
bondedAddr, bondedCoins, 0,
|
||||
sdk.Coins{}, sdk.Coins{}, sdk.Coins{},
|
||||
0, 0, bondedPoolName, []string{burner, staking},
|
||||
)
|
||||
notBondedModuleAcc := NewGenesisAccount(
|
||||
notBondedAddr, notBondedCoins, 0,
|
||||
sdk.Coins{}, sdk.Coins{}, sdk.Coins{},
|
||||
0, 0, notBondedPoolName, []string{burner, staking},
|
||||
)
|
||||
mintModuleAcc := NewGenesisAccount(
|
||||
mintAddr, sdk.Coins{}, 0,
|
||||
sdk.Coins{}, sdk.Coins{}, sdk.Coins{},
|
||||
0, 0, mintModuleName, []string{minter},
|
||||
)
|
||||
|
||||
newGenState = append(
|
||||
newGenState,
|
||||
[]GenesisAccount{
|
||||
feeCollectorModuleAcc, govModuleAcc, distrModuleAcc,
|
||||
bondedModuleAcc, notBondedModuleAcc, mintModuleAcc,
|
||||
}...,
|
||||
)
|
||||
|
||||
// verify the total number of accounts is correct
|
||||
if len(newGenState) != len(oldGenState)+extraAccounts {
|
||||
panic(
|
||||
fmt.Sprintf(
|
||||
"invalid total number of genesis accounts; got: %d, expected: %d",
|
||||
len(newGenState), len(oldGenState)+extraAccounts),
|
||||
)
|
||||
}
|
||||
|
||||
return newGenState
|
||||
}
|
|
@ -1,126 +0,0 @@
|
|||
package v036
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v034"
|
||||
v034accounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v034"
|
||||
v034gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v034"
|
||||
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v034"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var (
|
||||
priv = secp256k1.GenPrivKey()
|
||||
addr = types.AccAddress(priv.PubKey().Address())
|
||||
depositedCoinsAccAddr = types.AccAddress(crypto.AddressHash([]byte("govDepositedCoins")))
|
||||
burnedDepositCoinsAccAddr = types.AccAddress(crypto.AddressHash([]byte("govBurnedDepositCoins")))
|
||||
|
||||
coins = types.Coins{types.NewInt64Coin(types.DefaultBondDenom, 10)}
|
||||
halfCoins = types.Coins{types.NewInt64Coin(types.DefaultBondDenom, 5)}
|
||||
|
||||
accountDeposited = v034accounts.GenesisAccount{
|
||||
Address: depositedCoinsAccAddr,
|
||||
Coins: coins,
|
||||
Sequence: 1,
|
||||
AccountNumber: 1,
|
||||
|
||||
OriginalVesting: coins,
|
||||
DelegatedFree: coins,
|
||||
DelegatedVesting: coins,
|
||||
StartTime: 0,
|
||||
EndTime: 0,
|
||||
}
|
||||
|
||||
accountBurned = v034accounts.GenesisAccount{
|
||||
Address: burnedDepositCoinsAccAddr,
|
||||
Coins: coins,
|
||||
Sequence: 2,
|
||||
AccountNumber: 2,
|
||||
|
||||
OriginalVesting: coins,
|
||||
DelegatedFree: coins,
|
||||
DelegatedVesting: coins,
|
||||
StartTime: 0,
|
||||
EndTime: 0,
|
||||
}
|
||||
|
||||
deposit = v034gov.DepositWithMetadata{
|
||||
ProposalID: 1,
|
||||
Deposit: v034gov.Deposit{
|
||||
ProposalID: 1,
|
||||
Depositor: addr,
|
||||
Amount: coins,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func TestMigrateEmptyRecord(t *testing.T) {
|
||||
|
||||
type args struct {
|
||||
accounts v034accounts.GenesisState
|
||||
deposits []v034gov.DepositWithMetadata
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
}{
|
||||
{"No Accounts", args{v034accounts.GenesisState{}, []v034gov.DepositWithMetadata{}}},
|
||||
{"Deposited account", args{v034accounts.GenesisState{accountDeposited}, []v034gov.DepositWithMetadata{deposit}}},
|
||||
{"Burned account", args{v034accounts.GenesisState{accountBurned}, []v034gov.DepositWithMetadata{}}},
|
||||
{"Burned and deposited accounts", args{v034accounts.GenesisState{accountDeposited, accountBurned}, []v034gov.DepositWithMetadata{deposit}}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
require.NotPanics(t, func() {
|
||||
Migrate(
|
||||
tt.args.accounts,
|
||||
types.Coins{},
|
||||
types.DecCoins{},
|
||||
tt.args.deposits,
|
||||
v034staking.Validators{},
|
||||
[]v034staking.UnbondingDelegation{},
|
||||
[]v034distr.ValidatorOutstandingRewardsRecord{},
|
||||
types.DefaultBondDenom,
|
||||
v034distr.ModuleName,
|
||||
v034gov.ModuleName,
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateWrongDeposit(t *testing.T) {
|
||||
require.Panics(t, func() {
|
||||
Migrate(
|
||||
v034accounts.GenesisState{
|
||||
accountDeposited,
|
||||
accountBurned,
|
||||
},
|
||||
types.Coins{},
|
||||
types.DecCoins{},
|
||||
[]v034gov.DepositWithMetadata{
|
||||
{
|
||||
ProposalID: 1,
|
||||
Deposit: v034gov.Deposit{
|
||||
ProposalID: 1,
|
||||
Depositor: addr,
|
||||
Amount: halfCoins,
|
||||
},
|
||||
},
|
||||
},
|
||||
v034staking.Validators{},
|
||||
[]v034staking.UnbondingDelegation{},
|
||||
[]v034distr.ValidatorOutstandingRewardsRecord{},
|
||||
types.DefaultBondDenom,
|
||||
v034distr.ModuleName,
|
||||
v034gov.ModuleName,
|
||||
)
|
||||
})
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
// DONTCOVER
|
||||
package v036
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
const (
|
||||
ModuleName = "accounts"
|
||||
)
|
||||
|
||||
type (
|
||||
GenesisAccount struct {
|
||||
Address sdk.AccAddress `json:"address" yaml:"address"`
|
||||
Coins sdk.Coins `json:"coins" yaml:"coins"`
|
||||
Sequence uint64 `json:"sequence_number" yaml:"sequence_number"`
|
||||
AccountNumber uint64 `json:"account_number" yaml:"account_number"`
|
||||
|
||||
OriginalVesting sdk.Coins `json:"original_vesting" yaml:"original_vesting"`
|
||||
DelegatedFree sdk.Coins `json:"delegated_free" yaml:"delegated_free"`
|
||||
DelegatedVesting sdk.Coins `json:"delegated_vesting" yaml:"delegated_vesting"`
|
||||
StartTime int64 `json:"start_time" yaml:"start_time"`
|
||||
EndTime int64 `json:"end_time" yaml:"end_time"`
|
||||
|
||||
ModuleName string `json:"module_name" yaml:"module_name"`
|
||||
ModulePermissions []string `json:"module_permissions" yaml:"module_permissions"`
|
||||
}
|
||||
|
||||
GenesisState []GenesisAccount
|
||||
)
|
||||
|
||||
// NewGenesisAccount creates a new GenesisAccount object
|
||||
func NewGenesisAccount(
|
||||
address sdk.AccAddress, coins sdk.Coins, sequence uint64,
|
||||
vestingAmount, delFree, delVesting sdk.Coins, vestingStartTime, vestingEndTime int64,
|
||||
module string, permissions []string,
|
||||
) GenesisAccount {
|
||||
|
||||
return GenesisAccount{
|
||||
Address: address,
|
||||
Coins: coins,
|
||||
Sequence: sequence,
|
||||
AccountNumber: 0, // ignored set by the account keeper during InitGenesis
|
||||
OriginalVesting: vestingAmount,
|
||||
DelegatedFree: delFree,
|
||||
DelegatedVesting: delVesting,
|
||||
StartTime: vestingStartTime,
|
||||
EndTime: vestingEndTime,
|
||||
ModuleName: module,
|
||||
ModulePermissions: permissions,
|
||||
}
|
||||
}
|
|
@ -14,9 +14,6 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
v036 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v036"
|
||||
v038 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v038"
|
||||
v039 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v039"
|
||||
v040 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v040"
|
||||
v043 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v043"
|
||||
"github.com/cosmos/cosmos-sdk/x/genutil/types"
|
||||
|
@ -28,9 +25,6 @@ const flagGenesisTime = "genesis-time"
|
|||
//
|
||||
// Ref: https://github.com/cosmos/cosmos-sdk/issues/5041
|
||||
var migrationMap = types.MigrationMap{
|
||||
"v0.36": v036.Migrate,
|
||||
"v0.38": v038.Migrate, // NOTE: v0.37 and v0.38 are genesis compatible.
|
||||
"v0.39": v039.Migrate,
|
||||
"v0.42": v040.Migrate, // NOTE: v0.40, v0.41 and v0.42 are genesis compatible.
|
||||
"v0.43": v043.Migrate,
|
||||
}
|
||||
|
|
|
@ -27,12 +27,6 @@ func (s *IntegrationTestSuite) TestMigrateGenesis() {
|
|||
expErrMsg string
|
||||
check func(jsonOut string)
|
||||
}{
|
||||
{
|
||||
"migrate 0.34 to 0.36",
|
||||
`{"chain_id":"test","app_state":{}}`,
|
||||
"v0.36",
|
||||
false, "", func(_ string) {},
|
||||
},
|
||||
{
|
||||
"migrate 0.37 to 0.42",
|
||||
v037Exported,
|
||||
|
|
|
@ -1,101 +0,0 @@
|
|||
package v036
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v034"
|
||||
v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v036"
|
||||
v036bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v036"
|
||||
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v034"
|
||||
v036distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v036"
|
||||
v034genAccounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v034"
|
||||
v036genAccounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v036"
|
||||
"github.com/cosmos/cosmos-sdk/x/genutil/types"
|
||||
v034gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v034"
|
||||
v036gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v036"
|
||||
v036params "github.com/cosmos/cosmos-sdk/x/params/legacy/v036"
|
||||
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v034"
|
||||
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v036"
|
||||
)
|
||||
|
||||
// Migrate migrates exported state from v0.34 to a v0.36 genesis state.
|
||||
func Migrate(appState types.AppMap, _ client.Context) types.AppMap {
|
||||
v034Codec := codec.NewLegacyAmino()
|
||||
cryptocodec.RegisterCrypto(v034Codec)
|
||||
v034gov.RegisterLegacyAminoCodec(v034Codec)
|
||||
|
||||
v036Codec := codec.NewLegacyAmino()
|
||||
cryptocodec.RegisterCrypto(v036Codec)
|
||||
v036gov.RegisterLegacyAminoCodec(v036Codec)
|
||||
v036distr.RegisterLegacyAminoCodec(v036Codec)
|
||||
v036params.RegisterLegacyAminoCodec(v036Codec)
|
||||
|
||||
// migrate genesis accounts state
|
||||
if appState[v034genAccounts.ModuleName] != nil {
|
||||
var genAccs v034genAccounts.GenesisState
|
||||
v034Codec.MustUnmarshalJSON(appState[v034genAccounts.ModuleName], &genAccs)
|
||||
|
||||
var authGenState v034auth.GenesisState
|
||||
v034Codec.MustUnmarshalJSON(appState[v034auth.ModuleName], &authGenState)
|
||||
|
||||
var govGenState v034gov.GenesisState
|
||||
v034Codec.MustUnmarshalJSON(appState[v034gov.ModuleName], &govGenState)
|
||||
|
||||
var distrGenState v034distr.GenesisState
|
||||
v034Codec.MustUnmarshalJSON(appState[v034distr.ModuleName], &distrGenState)
|
||||
|
||||
var stakingGenState v034staking.GenesisState
|
||||
v034Codec.MustUnmarshalJSON(appState[v034staking.ModuleName], &stakingGenState)
|
||||
|
||||
delete(appState, v034genAccounts.ModuleName) // delete old key in case the name changed
|
||||
appState[v036genAccounts.ModuleName] = v036Codec.MustMarshalJSON(
|
||||
v036genAccounts.Migrate(
|
||||
genAccs, authGenState.CollectedFees, distrGenState.FeePool.CommunityPool, govGenState.Deposits,
|
||||
stakingGenState.Validators, stakingGenState.UnbondingDelegations, distrGenState.OutstandingRewards,
|
||||
stakingGenState.Params.BondDenom, v036distr.ModuleName, v036gov.ModuleName,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
// migrate auth state
|
||||
if appState[v034auth.ModuleName] != nil {
|
||||
var authGenState v034auth.GenesisState
|
||||
v034Codec.MustUnmarshalJSON(appState[v034auth.ModuleName], &authGenState)
|
||||
|
||||
delete(appState, v034auth.ModuleName) // delete old key in case the name changed
|
||||
appState[v036auth.ModuleName] = v036Codec.MustMarshalJSON(v036auth.Migrate(authGenState))
|
||||
}
|
||||
|
||||
// migrate gov state
|
||||
if appState[v034gov.ModuleName] != nil {
|
||||
var govGenState v034gov.GenesisState
|
||||
v034Codec.MustUnmarshalJSON(appState[v034gov.ModuleName], &govGenState)
|
||||
|
||||
delete(appState, v034gov.ModuleName) // delete old key in case the name changed
|
||||
appState[v036gov.ModuleName] = v036Codec.MustMarshalJSON(v036gov.Migrate(govGenState))
|
||||
}
|
||||
|
||||
// migrate distribution state
|
||||
if appState[v034distr.ModuleName] != nil {
|
||||
var slashingGenState v034distr.GenesisState
|
||||
v034Codec.MustUnmarshalJSON(appState[v034distr.ModuleName], &slashingGenState)
|
||||
|
||||
delete(appState, v034distr.ModuleName) // delete old key in case the name changed
|
||||
appState[v036distr.ModuleName] = v036Codec.MustMarshalJSON(v036distr.Migrate(slashingGenState))
|
||||
}
|
||||
|
||||
// migrate staking state
|
||||
if appState[v034staking.ModuleName] != nil {
|
||||
var stakingGenState v034staking.GenesisState
|
||||
v034Codec.MustUnmarshalJSON(appState[v034staking.ModuleName], &stakingGenState)
|
||||
|
||||
delete(appState, v034staking.ModuleName) // delete old key in case the name changed
|
||||
appState[v036staking.ModuleName] = v036Codec.MustMarshalJSON(v036staking.Migrate(stakingGenState))
|
||||
}
|
||||
|
||||
// migrate supply state
|
||||
appState[v036bank.ModuleName] = v036Codec.MustMarshalJSON(v036bank.EmptyGenesisState())
|
||||
|
||||
return appState
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
package v036
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/x/genutil/types"
|
||||
)
|
||||
|
||||
var basic034Gov = []byte(`
|
||||
{
|
||||
"starting_proposal_id": "2",
|
||||
"deposits": [
|
||||
{
|
||||
"proposal_id": "1",
|
||||
"deposit": {
|
||||
"depositor": "cosmos1grgelyng2v6v3t8z87wu3sxgt9m5s03xvslewd",
|
||||
"proposal_id": "1",
|
||||
"amount": [
|
||||
{
|
||||
"denom": "uatom",
|
||||
"amount": "512000000"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"votes" : [
|
||||
{
|
||||
"proposal_id": "1",
|
||||
"vote": {
|
||||
"voter": "cosmos1lktjhnzkpkz3ehrg8psvmwhafg56kfss5597tg",
|
||||
"proposal_id": "1",
|
||||
"option": "Yes"
|
||||
}
|
||||
}
|
||||
],
|
||||
"proposals": [
|
||||
{
|
||||
"proposal_content": {
|
||||
"type": "gov/TextProposal",
|
||||
"value": {
|
||||
"title": "test",
|
||||
"description": "test"
|
||||
}
|
||||
},
|
||||
"proposal_id": "1",
|
||||
"proposal_status": "Passed",
|
||||
"final_tally_result": {
|
||||
"yes": "1",
|
||||
"abstain": "0",
|
||||
"no": "0",
|
||||
"no_with_veto": "0"
|
||||
},
|
||||
"submit_time": "2019-05-03T21:08:25.443199036Z",
|
||||
"deposit_end_time": "2019-05-17T21:08:25.443199036Z",
|
||||
"total_deposit": [
|
||||
{
|
||||
"denom": "uatom",
|
||||
"amount": "512000000"
|
||||
}
|
||||
],
|
||||
"voting_start_time": "2019-05-04T16:02:33.24680295Z",
|
||||
"voting_end_time": "2019-05-18T16:02:33.24680295Z"
|
||||
}
|
||||
],
|
||||
"deposit_params": {
|
||||
"min_deposit": [
|
||||
{
|
||||
"denom": "uatom",
|
||||
"amount": "512000000"
|
||||
}
|
||||
],
|
||||
"max_deposit_period": "1209600000000000"
|
||||
},
|
||||
"voting_params": {
|
||||
"voting_period": "1209600000000000"
|
||||
},
|
||||
"tally_params": {
|
||||
"quorum": "0.400000000000000000",
|
||||
"threshold": "0.500000000000000000",
|
||||
"veto": "0.334000000000000000"
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
func TestDummyGenesis(t *testing.T) {
|
||||
genesisDummy := types.AppMap{
|
||||
"foo": {},
|
||||
"bar": []byte(`{"custom": "module"}`),
|
||||
}
|
||||
migratedDummy := Migrate(genesisDummy, client.Context{})
|
||||
|
||||
// We should not touch custom modules in the map
|
||||
require.Equal(t, genesisDummy["foo"], migratedDummy["foo"])
|
||||
require.Equal(t, genesisDummy["bar"], migratedDummy["bar"])
|
||||
}
|
||||
|
||||
func TestGovGenesis(t *testing.T) {
|
||||
genesis := types.AppMap{
|
||||
"gov": basic034Gov,
|
||||
}
|
||||
|
||||
require.NotPanics(t, func() { Migrate(genesis, client.Context{}) })
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
package v038
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||
v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v036"
|
||||
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v038"
|
||||
v036distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v036"
|
||||
v038distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v038"
|
||||
v036genaccounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v036"
|
||||
"github.com/cosmos/cosmos-sdk/x/genutil/types"
|
||||
v036gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v036"
|
||||
v036params "github.com/cosmos/cosmos-sdk/x/params/legacy/v036"
|
||||
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v036"
|
||||
v038staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v038"
|
||||
v038upgrade "github.com/cosmos/cosmos-sdk/x/upgrade/legacy/v038"
|
||||
)
|
||||
|
||||
// Migrate migrates exported state from v0.36/v0.37 to a v0.38 genesis state.
|
||||
func Migrate(appState types.AppMap, _ client.Context) types.AppMap {
|
||||
v036Codec := codec.NewLegacyAmino()
|
||||
cryptocodec.RegisterCrypto(v036Codec)
|
||||
v036gov.RegisterLegacyAminoCodec(v036Codec)
|
||||
v036distr.RegisterLegacyAminoCodec(v036Codec)
|
||||
v036params.RegisterLegacyAminoCodec(v036Codec)
|
||||
|
||||
v038Codec := codec.NewLegacyAmino()
|
||||
v038auth.RegisterLegacyAminoCodec(v038Codec)
|
||||
v036gov.RegisterLegacyAminoCodec(v038Codec)
|
||||
v036distr.RegisterLegacyAminoCodec(v038Codec)
|
||||
v036params.RegisterLegacyAminoCodec(v038Codec)
|
||||
v038upgrade.RegisterLegacyAminoCodec(v038Codec)
|
||||
|
||||
if appState[v036genaccounts.ModuleName] != nil {
|
||||
// unmarshal relative source genesis application state
|
||||
var authGenState v036auth.GenesisState
|
||||
v036Codec.MustUnmarshalJSON(appState[v036auth.ModuleName], &authGenState)
|
||||
|
||||
var genAccountsGenState v036genaccounts.GenesisState
|
||||
v036Codec.MustUnmarshalJSON(appState[v036genaccounts.ModuleName], &genAccountsGenState)
|
||||
|
||||
// delete deprecated genaccounts genesis state
|
||||
delete(appState, v036genaccounts.ModuleName)
|
||||
|
||||
// Migrate relative source genesis application state and marshal it into
|
||||
// the respective key.
|
||||
appState[v038auth.ModuleName] = v038Codec.MustMarshalJSON(v038auth.Migrate(authGenState, genAccountsGenState))
|
||||
}
|
||||
|
||||
// migrate staking state
|
||||
if appState[v036staking.ModuleName] != nil {
|
||||
var stakingGenState v036staking.GenesisState
|
||||
v036Codec.MustUnmarshalJSON(appState[v036staking.ModuleName], &stakingGenState)
|
||||
|
||||
delete(appState, v036staking.ModuleName) // delete old key in case the name changed
|
||||
appState[v038staking.ModuleName] = v038Codec.MustMarshalJSON(v038staking.Migrate(stakingGenState))
|
||||
}
|
||||
|
||||
// migrate distribution state
|
||||
if appState[v036distr.ModuleName] != nil {
|
||||
var distrGenState v036distr.GenesisState
|
||||
v036Codec.MustUnmarshalJSON(appState[v036distr.ModuleName], &distrGenState)
|
||||
|
||||
delete(appState, v036distr.ModuleName) // delete old key in case the name changed
|
||||
appState[v038distr.ModuleName] = v038Codec.MustMarshalJSON(v038distr.Migrate(distrGenState))
|
||||
}
|
||||
|
||||
return appState
|
||||
}
|
|
@ -1,143 +0,0 @@
|
|||
package v038_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v036"
|
||||
v036genaccounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v036"
|
||||
v038 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v038"
|
||||
"github.com/cosmos/cosmos-sdk/x/genutil/types"
|
||||
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v036"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var genAccountsState = []byte(`[
|
||||
{
|
||||
"account_number": "0",
|
||||
"address": "cosmos1q7380u26f7ntke3facjmynajs4umlr329vr4ja",
|
||||
"coins": [
|
||||
{
|
||||
"amount": "1000000000",
|
||||
"denom": "node0token"
|
||||
},
|
||||
{
|
||||
"amount": "400000198",
|
||||
"denom": "stake"
|
||||
}
|
||||
],
|
||||
"delegated_free": [],
|
||||
"delegated_vesting": [],
|
||||
"end_time": "0",
|
||||
"module_name": "",
|
||||
"module_permissions": [],
|
||||
"original_vesting": [],
|
||||
"sequence_number": "1",
|
||||
"start_time": "0"
|
||||
},
|
||||
{
|
||||
"account_number": "0",
|
||||
"address": "cosmos1tygms3xhhs3yv487phx3dw4a95jn7t7lpm470r",
|
||||
"coins": [],
|
||||
"delegated_free": [],
|
||||
"delegated_vesting": [],
|
||||
"end_time": "0",
|
||||
"module_name": "not_bonded_tokens_pool",
|
||||
"module_permissions": [
|
||||
"burner",
|
||||
"staking"
|
||||
],
|
||||
"original_vesting": [],
|
||||
"sequence_number": "0",
|
||||
"start_time": "0"
|
||||
},
|
||||
{
|
||||
"account_number": "0",
|
||||
"address": "cosmos1m3h30wlvsf8llruxtpukdvsy0km2kum8g38c8q",
|
||||
"coins": [],
|
||||
"delegated_free": [],
|
||||
"delegated_vesting": [],
|
||||
"end_time": "0",
|
||||
"module_name": "mint",
|
||||
"module_permissions": [
|
||||
"minter"
|
||||
],
|
||||
"original_vesting": [],
|
||||
"sequence_number": "0",
|
||||
"start_time": "0"
|
||||
}
|
||||
]`)
|
||||
|
||||
var genAuthState = []byte(`{
|
||||
"params": {
|
||||
"max_memo_characters": "256",
|
||||
"sig_verify_cost_ed25519": "590",
|
||||
"sig_verify_cost_secp256k1": "1000",
|
||||
"tx_sig_limit": "7",
|
||||
"tx_size_cost_per_byte": "10"
|
||||
}
|
||||
}`)
|
||||
|
||||
var genStakingState = []byte(`{
|
||||
"delegations": [
|
||||
{
|
||||
"delegator_address": "cosmos1q7380u26f7ntke3facjmynajs4umlr329vr4ja",
|
||||
"shares": "100000000.000000000000000000",
|
||||
"validator_address": "cosmosvaloper1q7380u26f7ntke3facjmynajs4umlr32qchq7w"
|
||||
}
|
||||
],
|
||||
"exported": true,
|
||||
"last_total_power": "400",
|
||||
"last_validator_powers": [
|
||||
{
|
||||
"Address": "cosmosvaloper1q7380u26f7ntke3facjmynajs4umlr32qchq7w",
|
||||
"Power": "100"
|
||||
}
|
||||
],
|
||||
"params": {
|
||||
"bond_denom": "stake",
|
||||
"max_entries": 7,
|
||||
"max_validators": 100,
|
||||
"unbonding_time": "259200000000000"
|
||||
},
|
||||
"redelegations": null,
|
||||
"unbonding_delegations": null,
|
||||
"validators": [
|
||||
{
|
||||
"commission": {
|
||||
"commission_rates": {
|
||||
"max_change_rate": "0.000000000000000000",
|
||||
"max_rate": "0.000000000000000000",
|
||||
"rate": "0.000000000000000000"
|
||||
},
|
||||
"update_time": "2019-09-24T23:11:22.9692177Z"
|
||||
},
|
||||
"consensus_pubkey": "cosmosvalconspub1zcjduepqygqrt0saxf76lhsmp56rx52j0acdxyjvcdkq3tqvwrsmmm0ke28q36kh9h",
|
||||
"delegator_shares": "100000000.000000000000000000",
|
||||
"description": {
|
||||
"details": "",
|
||||
"identity": "",
|
||||
"moniker": "node0",
|
||||
"website": ""
|
||||
},
|
||||
"jailed": false,
|
||||
"min_self_delegation": "1",
|
||||
"operator_address": "cosmosvaloper1q7380u26f7ntke3facjmynajs4umlr32qchq7w",
|
||||
"status": 2,
|
||||
"tokens": "100000000",
|
||||
"unbonding_height": "0",
|
||||
"unbonding_time": "1970-01-01T00:00:00Z"
|
||||
}
|
||||
]
|
||||
}`)
|
||||
|
||||
func TestMigrate(t *testing.T) {
|
||||
genesis := types.AppMap{
|
||||
v036auth.ModuleName: genAuthState,
|
||||
v036genaccounts.ModuleName: genAccountsState,
|
||||
v036staking.ModuleName: genStakingState,
|
||||
}
|
||||
|
||||
require.NotPanics(t, func() { v038.Migrate(genesis, client.Context{}) })
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package v039
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v038"
|
||||
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v039"
|
||||
v036distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v036"
|
||||
"github.com/cosmos/cosmos-sdk/x/genutil/types"
|
||||
v036gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v036"
|
||||
v036params "github.com/cosmos/cosmos-sdk/x/params/legacy/v036"
|
||||
v038upgrade "github.com/cosmos/cosmos-sdk/x/upgrade/legacy/v038"
|
||||
)
|
||||
|
||||
// Migrate migrates exported state from v0.38 to a v0.39 genesis state.
|
||||
//
|
||||
// NOTE: No actual migration occurs since the types do not change, but JSON
|
||||
// serialization of accounts do change.
|
||||
func Migrate(appState types.AppMap, _ client.Context) types.AppMap {
|
||||
v038Codec := codec.NewLegacyAmino()
|
||||
v038auth.RegisterLegacyAminoCodec(v038Codec)
|
||||
v036gov.RegisterLegacyAminoCodec(v038Codec)
|
||||
v036distr.RegisterLegacyAminoCodec(v038Codec)
|
||||
v036params.RegisterLegacyAminoCodec(v038Codec)
|
||||
v038upgrade.RegisterLegacyAminoCodec(v038Codec)
|
||||
|
||||
v039Codec := codec.NewLegacyAmino()
|
||||
v039auth.RegisterLegacyAminoCodec(v039Codec)
|
||||
v036gov.RegisterLegacyAminoCodec(v039Codec)
|
||||
v036distr.RegisterLegacyAminoCodec(v039Codec)
|
||||
v036params.RegisterLegacyAminoCodec(v039Codec)
|
||||
v038upgrade.RegisterLegacyAminoCodec(v039Codec)
|
||||
|
||||
// migrate x/auth state (JSON serialization only)
|
||||
if appState[v038auth.ModuleName] != nil {
|
||||
var authGenState v038auth.GenesisState
|
||||
v038Codec.MustUnmarshalJSON(appState[v038auth.ModuleName], &authGenState)
|
||||
|
||||
delete(appState, v038auth.ModuleName) // delete old key in case the name changed
|
||||
appState[v039auth.ModuleName] = v039Codec.MustMarshalJSON(v039auth.Migrate(authGenState))
|
||||
}
|
||||
|
||||
return appState
|
||||
}
|
|
@ -1,121 +0,0 @@
|
|||
package v039_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v038"
|
||||
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v039"
|
||||
v039 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v039"
|
||||
"github.com/cosmos/cosmos-sdk/x/genutil/types"
|
||||
)
|
||||
|
||||
var genAuthState = []byte(`{
|
||||
"params": {
|
||||
"max_memo_characters": "10",
|
||||
"tx_sig_limit": "10",
|
||||
"tx_size_cost_per_byte": "10",
|
||||
"sig_verify_cost_ed25519": "10",
|
||||
"sig_verify_cost_secp256k1": "10"
|
||||
},
|
||||
"accounts": [
|
||||
{
|
||||
"type": "cosmos-sdk/Account",
|
||||
"value": {
|
||||
"address": "cosmos19hz3ee9e3lj9mne4jggj3v8hxjrpre22jukj9y",
|
||||
"coins": [
|
||||
{
|
||||
"denom": "stake",
|
||||
"amount": "400000"
|
||||
}
|
||||
],
|
||||
"public_key": "cosmospub1addwnpepqtezq4ajkevh724ls45zp72x70rj8mhszqf5pxcaahazm8trv490swlf404",
|
||||
"account_number": 1,
|
||||
"sequence": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "cosmos-sdk/ModuleAccount",
|
||||
"value": {
|
||||
"address": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh",
|
||||
"coins": [
|
||||
{
|
||||
"denom": "stake",
|
||||
"amount": "400000000"
|
||||
}
|
||||
],
|
||||
"public_key": "",
|
||||
"account_number": 2,
|
||||
"sequence": 4,
|
||||
"name": "bonded_tokens_pool",
|
||||
"permissions": [
|
||||
"burner",
|
||||
"staking"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "cosmos-sdk/ContinuousVestingAccount",
|
||||
"value": {
|
||||
"address": "cosmos1vtzxzyjv506dvhl9pa527xsugf5gez4fnqxq0n",
|
||||
"coins": [
|
||||
{
|
||||
"denom": "stake",
|
||||
"amount": "10000205"
|
||||
}
|
||||
],
|
||||
"public_key": "cosmospub1addwnpepqdxrk48q89xlmnzrr5nkssle05tkp73uknevzaavm53c02v26vlyzz6vcdh",
|
||||
"account_number": 3,
|
||||
"sequence": 5,
|
||||
"original_vesting": [
|
||||
{
|
||||
"denom": "stake",
|
||||
"amount": "10000205"
|
||||
}
|
||||
],
|
||||
"delegated_free": [],
|
||||
"delegated_vesting": [],
|
||||
"end_time": 1596125048,
|
||||
"start_time": 1595952248
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "cosmos-sdk/DelayedVestingAccount",
|
||||
"value": {
|
||||
"address": "cosmos1prxkcqclweqa0g28p7vmf6z78ghyeckm4qak30",
|
||||
"coins": [
|
||||
{
|
||||
"denom": "stake",
|
||||
"amount": "10000205"
|
||||
}
|
||||
],
|
||||
"public_key": "cosmospub1addwnpepqwewcad349e2yw3weatf8lzfyv5cd6am9jkk4ajach3f568k6gg47nls3p8",
|
||||
"account_number": 4,
|
||||
"sequence": 15,
|
||||
"original_vesting": [
|
||||
{
|
||||
"denom": "stake",
|
||||
"amount": "10000205"
|
||||
}
|
||||
],
|
||||
"delegated_free": [],
|
||||
"delegated_vesting": [],
|
||||
"end_time": 1596125048
|
||||
}
|
||||
}
|
||||
]
|
||||
}`)
|
||||
|
||||
var expectedGenAuthState = []byte(`{"params":{"max_memo_characters":"10","tx_sig_limit":"10","tx_size_cost_per_byte":"10","sig_verify_cost_ed25519":"10","sig_verify_cost_secp256k1":"10"},"accounts":[{"type":"cosmos-sdk/Account","value":{"address":"cosmos19hz3ee9e3lj9mne4jggj3v8hxjrpre22jukj9y","coins":[{"denom":"stake","amount":"400000"}],"public_key":{"type":"tendermint/PubKeySecp256k1","value":"AvIgV7K2WX8qv4VoIPlG88cj7vAQE0CbHe36LZ1jZUr4"},"account_number":"1","sequence":"1"}},{"type":"cosmos-sdk/ModuleAccount","value":{"address":"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh","coins":[{"denom":"stake","amount":"400000000"}],"public_key":"","account_number":"2","sequence":"4","name":"bonded_tokens_pool","permissions":["burner","staking"]}},{"type":"cosmos-sdk/ContinuousVestingAccount","value":{"address":"cosmos1vtzxzyjv506dvhl9pa527xsugf5gez4fnqxq0n","coins":[{"denom":"stake","amount":"10000205"}],"public_key":{"type":"tendermint/PubKeySecp256k1","value":"A0w7VOA5Tf3MQx0naEP5fRdg+jy08sF3rN0jh6mK0z5B"},"account_number":"3","sequence":"5","original_vesting":[{"denom":"stake","amount":"10000205"}],"delegated_free":[],"delegated_vesting":[],"end_time":"1596125048","start_time":"1595952248"}},{"type":"cosmos-sdk/DelayedVestingAccount","value":{"address":"cosmos1prxkcqclweqa0g28p7vmf6z78ghyeckm4qak30","coins":[{"denom":"stake","amount":"10000205"}],"public_key":{"type":"tendermint/PubKeySecp256k1","value":"A7LsdbGpcqI6Ls9Wk/xJIymG67ssrWr2XcXimmj20hFf"},"account_number":"4","sequence":"15","original_vesting":[{"denom":"stake","amount":"10000205"}],"delegated_free":[],"delegated_vesting":[],"end_time":"1596125048"}}]}`)
|
||||
|
||||
func TestMigrate(t *testing.T) {
|
||||
genesis := types.AppMap{
|
||||
v038auth.ModuleName: genAuthState,
|
||||
}
|
||||
|
||||
var migrated types.AppMap
|
||||
require.NotPanics(t, func() { migrated = v039.Migrate(genesis, client.Context{}) })
|
||||
require.Equal(t, string(expectedGenAuthState), string(migrated[v039auth.ModuleName]))
|
||||
}
|
|
@ -1,3 +1,6 @@
|
|||
// Package v034 is used for legacy migration scripts. Actual migration scripts
|
||||
// for v034 have been removed, but the v039->v042 migration script still
|
||||
// references types from this file, so we're keeping it for now.
|
||||
// DONTCOVER
|
||||
package v034
|
||||
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
package v036
|
||||
|
||||
import (
|
||||
v034gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v034"
|
||||
)
|
||||
|
||||
// Migrate accepts exported genesis state from v0.34 and migrates it to v0.36
|
||||
// genesis state. This migration flattens the deposits and votes and updates the
|
||||
// proposal content to the new
|
||||
func Migrate(oldGenState v034gov.GenesisState) GenesisState {
|
||||
deposits := make(v034gov.Deposits, len(oldGenState.Deposits))
|
||||
for i, deposit := range oldGenState.Deposits {
|
||||
deposits[i] = deposit.Deposit
|
||||
}
|
||||
|
||||
votes := make(v034gov.Votes, len(oldGenState.Votes))
|
||||
for i, vote := range oldGenState.Votes {
|
||||
votes[i] = vote.Vote
|
||||
}
|
||||
|
||||
proposals := make([]Proposal, len(oldGenState.Proposals))
|
||||
for i, proposal := range oldGenState.Proposals {
|
||||
proposals[i] = Proposal{
|
||||
Content: migrateContent(proposal.ProposalContent),
|
||||
ProposalID: proposal.ProposalID,
|
||||
Status: proposal.Status,
|
||||
FinalTallyResult: proposal.FinalTallyResult,
|
||||
SubmitTime: proposal.SubmitTime,
|
||||
DepositEndTime: proposal.DepositEndTime,
|
||||
TotalDeposit: proposal.TotalDeposit,
|
||||
VotingStartTime: proposal.VotingStartTime,
|
||||
VotingEndTime: proposal.VotingEndTime,
|
||||
}
|
||||
}
|
||||
|
||||
return NewGenesisState(
|
||||
oldGenState.StartingProposalID, deposits, votes, proposals,
|
||||
oldGenState.DepositParams, oldGenState.VotingParams, oldGenState.TallyParams,
|
||||
)
|
||||
}
|
||||
|
||||
func migrateContent(proposalContent v034gov.ProposalContent) (content Content) {
|
||||
switch proposalContent.ProposalType() {
|
||||
case v034gov.ProposalTypeText:
|
||||
return NewTextProposal(proposalContent.GetTitle(), proposalContent.GetDescription())
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
|
@ -1,3 +1,6 @@
|
|||
// Package v036 is used for legacy migration scripts. Actual migration scripts
|
||||
// for v036 have been removed, but the v039->v042 migration script still
|
||||
// references types from this file, so we're keeping it for now.
|
||||
// DONTCOVER
|
||||
package v036
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// Package v036 is used for legacy migration scripts. Actual migration scripts
|
||||
// for v036 have been removed, but the v039->v042 migration script still
|
||||
// references types from this file, so we're keeping it for now.
|
||||
package v036
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// Package v034 is used for legacy migration scripts. Actual migration scripts
|
||||
// for v034 have been removed, but the v039->v042 migration script still
|
||||
// references types from this file, so we're keeping it for now.
|
||||
// DONTCOVER
|
||||
package v034
|
||||
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
// DONTCOVER
|
||||
package v036
|
||||
|
||||
import (
|
||||
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v034"
|
||||
)
|
||||
|
||||
// Migrate accepts exported genesis state from v0.34 and migrates it to v0.36
|
||||
// genesis state. All entries are identical except for validator slashing events
|
||||
// which now include the period.
|
||||
func Migrate(oldGenState v034staking.GenesisState) GenesisState {
|
||||
return NewGenesisState(
|
||||
oldGenState.Params,
|
||||
oldGenState.LastTotalPower,
|
||||
oldGenState.LastValidatorPowers,
|
||||
migrateValidators(oldGenState.Validators),
|
||||
oldGenState.Delegations,
|
||||
oldGenState.UnbondingDelegations,
|
||||
oldGenState.Redelegations,
|
||||
oldGenState.Exported,
|
||||
)
|
||||
}
|
||||
|
||||
func migrateValidators(oldValidators v034staking.Validators) Validators {
|
||||
validators := make(Validators, len(oldValidators))
|
||||
|
||||
for i, val := range oldValidators {
|
||||
validators[i] = Validator{
|
||||
OperatorAddress: val.OperatorAddress,
|
||||
ConsPubKey: val.ConsPubKey,
|
||||
Jailed: val.Jailed,
|
||||
Status: val.Status,
|
||||
Tokens: val.Tokens,
|
||||
DelegatorShares: val.DelegatorShares,
|
||||
Description: val.Description,
|
||||
UnbondingHeight: val.UnbondingHeight,
|
||||
UnbondingCompletionTime: val.UnbondingCompletionTime,
|
||||
Commission: Commission{
|
||||
CommissionRates: CommissionRates{
|
||||
Rate: val.Commission.Rate,
|
||||
MaxRate: val.Commission.MaxRate,
|
||||
MaxChangeRate: val.Commission.MaxChangeRate,
|
||||
},
|
||||
UpdateTime: val.Commission.UpdateTime,
|
||||
},
|
||||
MinSelfDelegation: val.MinSelfDelegation,
|
||||
}
|
||||
}
|
||||
|
||||
return validators
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
package v036_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v034"
|
||||
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v036"
|
||||
)
|
||||
|
||||
func TestMigrate(t *testing.T) {
|
||||
aminoCdc := codec.NewLegacyAmino()
|
||||
consPubKeyEd := ed25519.GenPrivKeyFromSecret([]byte("val0")).PubKey()
|
||||
consPubKeySecp := secp256k1.GenPrivKeyFromSecret([]byte("val1")).PubKey()
|
||||
stakingGenState := v034staking.GenesisState{
|
||||
Validators: v034staking.Validators{
|
||||
v034staking.Validator{
|
||||
ConsPubKey: consPubKeyEd,
|
||||
Status: v034staking.Unbonded,
|
||||
}, v034staking.Validator{
|
||||
ConsPubKey: consPubKeySecp,
|
||||
Status: v034staking.Unbonded,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
migrated := v036staking.Migrate(stakingGenState)
|
||||
|
||||
json, err := aminoCdc.MarshalJSONIndent(migrated, "", " ")
|
||||
require.NoError(t, err)
|
||||
|
||||
expectedJSON := `{
|
||||
"params": {
|
||||
"unbonding_time": "0",
|
||||
"max_validators": 0,
|
||||
"max_entries": 0,
|
||||
"bond_denom": ""
|
||||
},
|
||||
"last_total_power": "0",
|
||||
"last_validator_powers": null,
|
||||
"validators": [
|
||||
{
|
||||
"operator_address": "",
|
||||
"consensus_pubkey": "cosmosvalconspub1zcjduepq9ymett3nlv6fytn7lqxzd3q3ckvd79eqlcf3wkhgamcl4rzghesq83ecpx",
|
||||
"jailed": false,
|
||||
"status": 0,
|
||||
"tokens": "0",
|
||||
"delegator_shares": "0",
|
||||
"description": {
|
||||
"moniker": "",
|
||||
"identity": "",
|
||||
"website": "",
|
||||
"details": ""
|
||||
},
|
||||
"unbonding_height": "0",
|
||||
"unbonding_time": "0001-01-01T00:00:00Z",
|
||||
"commission": {
|
||||
"commission_rates": {
|
||||
"rate": "0",
|
||||
"max_rate": "0",
|
||||
"max_change_rate": "0"
|
||||
},
|
||||
"update_time": "0001-01-01T00:00:00Z"
|
||||
},
|
||||
"min_self_delegation": "0"
|
||||
},
|
||||
{
|
||||
"operator_address": "",
|
||||
"consensus_pubkey": "cosmosvalconspub1addwnpepqwfxk5k5pugwz3quqyzvzupefm3589tw6x9dkzjdkuzn7hgpz33ag84e406",
|
||||
"jailed": false,
|
||||
"status": 0,
|
||||
"tokens": "0",
|
||||
"delegator_shares": "0",
|
||||
"description": {
|
||||
"moniker": "",
|
||||
"identity": "",
|
||||
"website": "",
|
||||
"details": ""
|
||||
},
|
||||
"unbonding_height": "0",
|
||||
"unbonding_time": "0001-01-01T00:00:00Z",
|
||||
"commission": {
|
||||
"commission_rates": {
|
||||
"rate": "0",
|
||||
"max_rate": "0",
|
||||
"max_change_rate": "0"
|
||||
},
|
||||
"update_time": "0001-01-01T00:00:00Z"
|
||||
},
|
||||
"min_self_delegation": "0"
|
||||
}
|
||||
],
|
||||
"delegations": null,
|
||||
"unbonding_delegations": null,
|
||||
"redelegations": null,
|
||||
"exported": false
|
||||
}`
|
||||
|
||||
require.Equal(t, expectedJSON, string(json))
|
||||
}
|
|
@ -1,3 +1,6 @@
|
|||
// Package v036 is used for legacy migration scripts. Actual migration scripts
|
||||
// for v036 have been removed, but the v039->v042 migration script still
|
||||
// references types from this file, so we're keeping it for now.
|
||||
// DONTCOVER
|
||||
package v036
|
||||
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
// DONTCOVER
|
||||
package v038
|
||||
|
||||
import (
|
||||
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v036"
|
||||
)
|
||||
|
||||
// Migrate accepts exported genesis state from v0.36 or v0.37 and migrates it to
|
||||
// v0.38 genesis state. All entries are identical except for validator descriptions
|
||||
// which now include a security contact.
|
||||
func Migrate(oldGenState v036staking.GenesisState) GenesisState {
|
||||
return NewGenesisState(
|
||||
oldGenState.Params,
|
||||
oldGenState.LastTotalPower,
|
||||
oldGenState.LastValidatorPowers,
|
||||
migrateValidators(oldGenState.Validators),
|
||||
oldGenState.Delegations,
|
||||
oldGenState.UnbondingDelegations,
|
||||
oldGenState.Redelegations,
|
||||
oldGenState.Exported,
|
||||
)
|
||||
}
|
||||
|
||||
func migrateValidators(oldValidators v036staking.Validators) Validators {
|
||||
validators := make(Validators, len(oldValidators))
|
||||
|
||||
for i, val := range oldValidators {
|
||||
validators[i] = Validator{
|
||||
OperatorAddress: val.OperatorAddress,
|
||||
ConsPubKey: val.ConsPubKey,
|
||||
Jailed: val.Jailed,
|
||||
Status: val.Status,
|
||||
Tokens: val.Tokens,
|
||||
DelegatorShares: val.DelegatorShares,
|
||||
Description: NewDescription(
|
||||
val.Description.Moniker,
|
||||
val.Description.Identity,
|
||||
val.Description.Website,
|
||||
"", // security contact field
|
||||
val.Description.Details,
|
||||
),
|
||||
UnbondingHeight: val.UnbondingHeight,
|
||||
UnbondingCompletionTime: val.UnbondingCompletionTime,
|
||||
Commission: val.Commission,
|
||||
MinSelfDelegation: val.MinSelfDelegation,
|
||||
}
|
||||
}
|
||||
|
||||
return validators
|
||||
}
|
|
@ -1,3 +1,6 @@
|
|||
// Package v038 is used for legacy migration scripts. Actual migration scripts
|
||||
// for v038 have been removed, but the v039->v042 migration script still
|
||||
// references types from this file, so we're keeping it for now.
|
||||
// DONTCOVER
|
||||
package v038
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// Package v038 is used for legacy migration scripts. Actual migration scripts
|
||||
// for v038 have been removed, but the v039->v042 migration script still
|
||||
// references types from this file, so we're keeping it for now.
|
||||
package v038
|
||||
|
||||
import (
|
||||
|
|
Loading…
Reference in New Issue