-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
70 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package v2 | ||
|
||
const ( | ||
// ModuleName is the name of the module | ||
ModuleName = "gravity" | ||
) |
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,20 @@ | ||
package v2 | ||
|
||
import ( | ||
sdktypes "github.com/cosmos/cosmos-sdk/types" | ||
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
"github.com/peggyjv/gravity-bridge/module/v3/x/gravity/types" | ||
) | ||
|
||
func MigrateParamStore(ctx sdktypes.Context, subspace paramstypes.Subspace) error { | ||
if subspace.HasKeyTable() { | ||
subspace.Set(ctx, types.ParamStoreConfirmedOutgoingTxWindow, types.DefaultParams().ConfirmedOutgoingTxWindow) | ||
subspace.Set(ctx, types.ParamStoreEventVoteWindow, types.DefaultParams().EthereumEventVoteWindow) | ||
} else { | ||
subspace.WithKeyTable(types.ParamKeyTable()) | ||
subspace.Set(ctx, types.ParamStoreConfirmedOutgoingTxWindow, types.DefaultParams().ConfirmedOutgoingTxWindow) | ||
subspace.Set(ctx, types.ParamStoreEventVoteWindow, types.DefaultParams().EthereumEventVoteWindow) | ||
} | ||
|
||
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,33 @@ | ||
package v2_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
"github.com/cosmos/cosmos-sdk/testutil" | ||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
v2 "github.com/peggyjv/gravity-bridge/module/v3/x/gravity/migrations/v2" | ||
"github.com/peggyjv/gravity-bridge/module/v3/x/gravity/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestStoreMigration(t *testing.T) { | ||
gravityKey := storetypes.NewKVStoreKey(v2.ModuleName) | ||
tGravityKey := storetypes.NewTransientStoreKey("transient_test") | ||
ctx := testutil.DefaultContext(gravityKey, tGravityKey) | ||
aminoCodec := codec.NewLegacyAmino() | ||
paramstore := paramtypes.NewSubspace(nil, aminoCodec, gravityKey, tGravityKey, v2.ModuleName) | ||
|
||
// Check no params | ||
require.False(t, paramstore.Has(ctx, types.ParamStoreConfirmedOutgoingTxWindow)) | ||
require.False(t, paramstore.Has(ctx, types.ParamStoreEventVoteWindow)) | ||
|
||
// Run migrations. | ||
err := v2.MigrateParamStore(ctx, paramstore) | ||
require.NoError(t, err) | ||
|
||
// Make sure the new params are set. | ||
require.True(t, paramstore.Has(ctx, types.ParamStoreConfirmedOutgoingTxWindow)) | ||
require.True(t, paramstore.Has(ctx, types.ParamStoreEventVoteWindow)) | ||
} |
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