2022-04-21 20:16:28 +00:00
|
|
|
package v0_17
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2022-04-22 16:22:20 +00:00
|
|
|
bridgetypes "github.com/kava-labs/kava-bridge/x/bridge/types"
|
2022-04-21 20:16:28 +00:00
|
|
|
"github.com/kava-labs/kava/app"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2022-04-22 16:22:20 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2022-04-22 15:58:55 +00:00
|
|
|
authz "github.com/cosmos/cosmos-sdk/x/authz"
|
2022-04-21 20:16:28 +00:00
|
|
|
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
|
|
|
|
tmjson "github.com/tendermint/tendermint/libs/json"
|
|
|
|
tmtypes "github.com/tendermint/tendermint/types"
|
|
|
|
evmtypes "github.com/tharsis/ethermint/x/evm/types"
|
|
|
|
feemarkettypes "github.com/tharsis/ethermint/x/feemarket/types"
|
|
|
|
|
2022-04-22 18:36:05 +00:00
|
|
|
auctiontypes "github.com/kava-labs/kava/x/auction/types"
|
2022-04-21 20:16:28 +00:00
|
|
|
evmutiltypes "github.com/kava-labs/kava/x/evmutil/types"
|
2022-04-22 23:30:09 +00:00
|
|
|
incentivetypes "github.com/kava-labs/kava/x/incentive/types"
|
2022-04-25 19:48:59 +00:00
|
|
|
savingstypes "github.com/kava-labs/kava/x/savings/types"
|
2022-04-21 20:16:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMigrateGenesisDoc(t *testing.T) {
|
|
|
|
expected := getTestDataJSON("genesis-v17.json")
|
|
|
|
genDoc, err := tmtypes.GenesisDocFromFile(filepath.Join("testdata", "genesis-v16.json"))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
actualGenDoc, err := Migrate(genDoc, newClientContext())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
actualJson, err := tmjson.Marshal(actualGenDoc)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.JSONEq(t, expected, string(actualJson))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMigrateEvmUtil(t *testing.T) {
|
2022-04-22 15:58:55 +00:00
|
|
|
appMap, ctx := migrateToV17AndGetAppMap(t)
|
2022-04-21 20:16:28 +00:00
|
|
|
var genstate evmutiltypes.GenesisState
|
|
|
|
err := ctx.Codec.UnmarshalJSON(appMap[evmutiltypes.ModuleName], &genstate)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, genstate.Accounts, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMigrateEvm(t *testing.T) {
|
2022-04-22 15:58:55 +00:00
|
|
|
appMap, ctx := migrateToV17AndGetAppMap(t)
|
2022-04-21 20:16:28 +00:00
|
|
|
var genstate evmtypes.GenesisState
|
|
|
|
err := ctx.Codec.UnmarshalJSON(appMap[evmtypes.ModuleName], &genstate)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, genstate.Accounts, 0)
|
|
|
|
assert.Equal(t, genstate.Params, evmtypes.Params{
|
|
|
|
EvmDenom: "akava",
|
|
|
|
EnableCreate: true,
|
|
|
|
EnableCall: true,
|
|
|
|
ChainConfig: evmtypes.DefaultChainConfig(),
|
|
|
|
ExtraEIPs: []int64{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-04-22 23:30:09 +00:00
|
|
|
func TestMigrateAuction(t *testing.T) {
|
2022-04-22 18:36:05 +00:00
|
|
|
appMap, ctx := migrateToV17AndGetAppMap(t)
|
|
|
|
var genstate auctiontypes.GenesisState
|
|
|
|
err := ctx.Codec.UnmarshalJSON(appMap[auctiontypes.ModuleName], &genstate)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, genstate.Auctions, 3)
|
|
|
|
}
|
|
|
|
|
2022-04-21 20:16:28 +00:00
|
|
|
func TestMigrateFeeMarket(t *testing.T) {
|
2022-04-22 15:58:55 +00:00
|
|
|
appMap, ctx := migrateToV17AndGetAppMap(t)
|
2022-04-21 20:16:28 +00:00
|
|
|
var genstate feemarkettypes.GenesisState
|
|
|
|
err := ctx.Codec.UnmarshalJSON(appMap[feemarkettypes.ModuleName], &genstate)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, genstate, *feemarkettypes.DefaultGenesisState())
|
|
|
|
}
|
|
|
|
|
2022-04-22 15:58:55 +00:00
|
|
|
func TestMigrateAuthz(t *testing.T) {
|
|
|
|
appMap, ctx := migrateToV17AndGetAppMap(t)
|
|
|
|
var genstate authz.GenesisState
|
|
|
|
err := ctx.Codec.UnmarshalJSON(appMap[authz.ModuleName], &genstate)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, genstate, authz.GenesisState{
|
|
|
|
Authorization: []authz.GrantAuthorization{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-04-22 16:22:20 +00:00
|
|
|
func TestMigrateBridge(t *testing.T) {
|
|
|
|
appMap, ctx := migrateToV17AndGetAppMap(t)
|
|
|
|
var genstate bridgetypes.GenesisState
|
|
|
|
err := ctx.Codec.UnmarshalJSON(appMap[bridgetypes.ModuleName], &genstate)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Len(t, genstate.ERC20BridgePairs, 0)
|
|
|
|
assert.Equal(t, genstate.NextWithdrawSequence, sdk.OneInt())
|
|
|
|
assert.Equal(t, genstate.Params, bridgetypes.Params{
|
|
|
|
BridgeEnabled: false,
|
|
|
|
EnabledERC20Tokens: bridgetypes.EnabledERC20Tokens{},
|
|
|
|
Relayer: sdk.AccAddress{},
|
|
|
|
EnabledConversionPairs: bridgetypes.ConversionPairs{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-04-22 23:30:09 +00:00
|
|
|
func TestMigrateIncentive(t *testing.T) {
|
|
|
|
appMap, ctx := migrateToV17AndGetAppMap(t)
|
|
|
|
var genstate incentivetypes.GenesisState
|
|
|
|
err := ctx.Codec.UnmarshalJSON(appMap[incentivetypes.ModuleName], &genstate)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, genstate.SavingsClaims, 0)
|
|
|
|
assert.Len(t, genstate.SavingsRewardState.AccumulationTimes, 0)
|
|
|
|
assert.Len(t, genstate.SavingsRewardState.MultiRewardIndexes, 0)
|
|
|
|
assert.Len(t, genstate.Params.SavingsRewardPeriods, 0)
|
|
|
|
}
|
|
|
|
|
2022-04-25 19:48:59 +00:00
|
|
|
func TestMigrateSavings(t *testing.T) {
|
|
|
|
appMap, ctx := migrateToV17AndGetAppMap(t)
|
|
|
|
var genstate savingstypes.GenesisState
|
|
|
|
err := ctx.Codec.UnmarshalJSON(appMap[savingstypes.ModuleName], &genstate)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, genstate.Deposits, 0)
|
|
|
|
assert.Equal(t, genstate.Params, savingstypes.Params{
|
|
|
|
SupportedDenoms: []string{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-04-22 15:58:55 +00:00
|
|
|
func migrateToV17AndGetAppMap(t *testing.T) (genutiltypes.AppMap, client.Context) {
|
2022-04-21 20:16:28 +00:00
|
|
|
genDoc, err := tmtypes.GenesisDocFromFile(filepath.Join("testdata", "genesis-v16.json"))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
ctx := newClientContext()
|
|
|
|
actualGenDoc, err := Migrate(genDoc, ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
var appMap genutiltypes.AppMap
|
|
|
|
err = tmjson.Unmarshal(actualGenDoc.AppState, &appMap)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
return appMap, ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
func getTestDataJSON(filename string) string {
|
|
|
|
file := filepath.Join("testdata", filename)
|
|
|
|
data, err := ioutil.ReadFile(file)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return string(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newClientContext() client.Context {
|
|
|
|
config := app.MakeEncodingConfig()
|
|
|
|
return client.Context{}.
|
|
|
|
WithCodec(config.Marshaler).
|
|
|
|
WithLegacyAmino(config.Amino).
|
|
|
|
WithInterfaceRegistry(config.InterfaceRegistry)
|
|
|
|
}
|