From c5de1302f6020f898fc8f3a31a26601c075ad57a Mon Sep 17 00:00:00 2001 From: Levi Schoen Date: Fri, 22 Apr 2022 16:30:09 -0700 Subject: [PATCH] Add x/incentive module migrations (#1224) --- migrate/v0_17/kava.go | 9 +++++++++ migrate/v0_17/migrate_test.go | 14 +++++++++++++- migrate/v0_17/testdata/genesis-v17.json | 8 +++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/migrate/v0_17/kava.go b/migrate/v0_17/kava.go index 12949705..1d29ce14 100644 --- a/migrate/v0_17/kava.go +++ b/migrate/v0_17/kava.go @@ -17,6 +17,7 @@ import ( v016auction "github.com/kava-labs/kava/x/auction/legacy/v0_16" v017auction "github.com/kava-labs/kava/x/auction/legacy/v0_17" auctiontypes "github.com/kava-labs/kava/x/auction/types" + incentivetypes "github.com/kava-labs/kava/x/incentive/types" ) func migrateAppState(appState genutiltypes.AppMap, clientCtx client.Context) { @@ -74,4 +75,12 @@ func migrateAppState(appState genutiltypes.AppMap, clientCtx client.Context) { appState[auctiontypes.ModuleName] = encodedState } + + // x/incentive + if appState[incentivetypes.ModuleName] != nil { + var incentiveState incentivetypes.GenesisState + codec.MustUnmarshalJSON(appState[incentivetypes.ModuleName], &incentiveState) + + appState[incentivetypes.ModuleName] = codec.MustMarshalJSON(&incentiveState) + } } diff --git a/migrate/v0_17/migrate_test.go b/migrate/v0_17/migrate_test.go index ece41bef..4bf96698 100644 --- a/migrate/v0_17/migrate_test.go +++ b/migrate/v0_17/migrate_test.go @@ -20,6 +20,7 @@ import ( auctiontypes "github.com/kava-labs/kava/x/auction/types" evmutiltypes "github.com/kava-labs/kava/x/evmutil/types" + incentivetypes "github.com/kava-labs/kava/x/incentive/types" ) func TestMigrateGenesisDoc(t *testing.T) { @@ -59,7 +60,7 @@ func TestMigrateEvm(t *testing.T) { }) } -func TestMigrateXAuction(t *testing.T) { +func TestMigrateAuction(t *testing.T) { appMap, ctx := migrateToV17AndGetAppMap(t) var genstate auctiontypes.GenesisState err := ctx.Codec.UnmarshalJSON(appMap[auctiontypes.ModuleName], &genstate) @@ -101,6 +102,17 @@ func TestMigrateBridge(t *testing.T) { }) } +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) +} + func migrateToV17AndGetAppMap(t *testing.T) (genutiltypes.AppMap, client.Context) { genDoc, err := tmtypes.GenesisDocFromFile(filepath.Join("testdata", "genesis-v16.json")) assert.NoError(t, err) diff --git a/migrate/v0_17/testdata/genesis-v17.json b/migrate/v0_17/testdata/genesis-v17.json index 669eea14..6ad5966f 100644 --- a/migrate/v0_17/testdata/genesis-v17.json +++ b/migrate/v0_17/testdata/genesis-v17.json @@ -1745,7 +1745,8 @@ ] } ], - "claim_end": "2025-01-01T00:00:00Z" + "claim_end": "2025-01-01T00:00:00Z", + "savings_reward_periods": [] }, "usdx_reward_state": { "accumulation_times": [ @@ -1947,6 +1948,11 @@ ] } ], + "savings_claims": [], + "savings_reward_state": { + "accumulation_times": [], + "multi_reward_indexes": [] + }, "swap_claims": [ { "base_claim": {