-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added upgrade handler for new token emission (#2176)
* added upgrade handler registration for new token emission * fix the migrator struct issue * add unit test cases for MigrateStore for ugov v2 * fix the golang lint * comment the new token emission upgrade handler
- Loading branch information
Showing
9 changed files
with
138 additions
and
20 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 was deleted.
Oops, something went wrong.
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,24 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
v2 "github.com/umee-network/umee/v5/x/ugov/migrations/v2" | ||
) | ||
|
||
// Migrator is a struct for handling in-place store migrations. | ||
type Migrator struct { | ||
kb Builder | ||
} | ||
|
||
// NewMigrator returns a new Migrator instance. | ||
func NewMigrator(kb Builder) Migrator { | ||
return Migrator{ | ||
kb: kb, | ||
} | ||
} | ||
|
||
// Migrate1to2 migrates from version 1 to 2. | ||
func (m Migrator) Migrate1to2(ctx sdk.Context) error { | ||
return v2.MigrateStore(ctx, m.kb.storeKey) | ||
} |
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,23 @@ | ||
package v2 | ||
|
||
import ( | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/umee-network/umee/v5/util/store" | ||
"github.com/umee-network/umee/v5/x/ugov" | ||
) | ||
|
||
// MigrateStore performs in-place store migrations from 1 to 2 | ||
func MigrateStore(ctx sdk.Context, key storetypes.StoreKey) error { | ||
kvStore := ctx.KVStore(key) | ||
|
||
ip := ugov.DefaultInflationParams() | ||
if err := store.SetValue(kvStore, ugov.KeyInflationParams, &ip, "inflation_params"); err != nil { | ||
return err | ||
} | ||
|
||
cycleEnd := ctx.BlockTime().Add(ip.InflationCycle) | ||
store.SetTimeMs(kvStore, ugov.KeyInflationCycleEnd, cycleEnd) | ||
|
||
return 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,44 @@ | ||
package v2_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
"gotest.tools/v3/assert" | ||
|
||
"github.com/umee-network/umee/v5/tests/tsdk" | ||
"github.com/umee-network/umee/v5/util/store" | ||
"github.com/umee-network/umee/v5/x/ugov" | ||
v2 "github.com/umee-network/umee/v5/x/ugov/migrations/v2" | ||
) | ||
|
||
func TestMigrateStore(t *testing.T) { | ||
storeKey := storetypes.NewKVStoreKey(ugov.ModuleName) | ||
sdkContext, _ := tsdk.NewCtx(t, []storetypes.StoreKey{storeKey}, []storetypes.StoreKey{}) | ||
kvStore := sdkContext.KVStore(storeKey) | ||
|
||
getInflationParams := func() *ugov.InflationParams { | ||
return store.GetValue[*ugov.InflationParams](kvStore, ugov.KeyInflationParams, "ip") | ||
} | ||
|
||
getInflationCycleEnd := func() (time.Time, bool) { | ||
return store.GetTimeMs(kvStore, ugov.KeyInflationCycleEnd) | ||
} | ||
|
||
// before migration | ||
_, ok := getInflationCycleEnd() | ||
assert.Equal(t, ok, false) | ||
ip := getInflationParams() | ||
assert.DeepEqual(t, 0, ip.Size()) | ||
|
||
// after migration | ||
err := v2.MigrateStore(sdkContext, storeKey) | ||
assert.NilError(t, err) | ||
ip = getInflationParams() | ||
assert.DeepEqual(t, ugov.DefaultInflationParams(), *ip) | ||
|
||
cycleEnd, ok := getInflationCycleEnd() | ||
assert.Equal(t, ok, true) | ||
assert.DeepEqual(t, sdkContext.BlockTime().Add(ip.InflationCycle), cycleEnd) | ||
} |
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