-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into adam/special3
- Loading branch information
Showing
16 changed files
with
220 additions
and
145 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
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
Oops, something went wrong.