-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(revenue): Deprecate x/params usage in x/revenue (#1129)
* (refactor): Added migration to v2 and deprecation of x/params logic across the revenue module * added CHANGELOG entry * typo fix * Apply suggestions from code review Co-authored-by: Ramiro Carlucho <ramirocarlucho@gmail.com> * (fix): typo fix in import * (fix): organize imports * (fix): remove HTTP endpoint exposure * Apply suggestions from code review Co-authored-by: Tomas Guerra <54514587+GAtom22@users.noreply.github.com> * (fix): ran formatter * fix: applied changes from code review * tests: Added unit test for UpdateParams message Co-authored-by: Ramiro Carlucho <ramirocarlucho@gmail.com> Co-authored-by: Tomas Guerra <54514587+GAtom22@users.noreply.github.com>
- Loading branch information
1 parent
1d7e0b0
commit 37e6402
Showing
23 changed files
with
1,466 additions
and
81 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,26 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
v2 "github.com/evmos/evmos/v10/x/revenue/migrations/v2" | ||
"github.com/evmos/evmos/v10/x/revenue/types" | ||
) | ||
|
||
// Migrator is a struct for handling in-place store migrations. | ||
type Migrator struct { | ||
keeper Keeper | ||
legacySubspace types.Subspace | ||
} | ||
|
||
// NewMigrator returns a new Migrator. | ||
func NewMigrator(keeper Keeper, legacySubspace types.Subspace) Migrator { | ||
return Migrator{ | ||
keeper: keeper, | ||
legacySubspace: legacySubspace, | ||
} | ||
} | ||
|
||
// Migrate1to2 migrates the store from consensus version 1 to 2 | ||
func (m Migrator) Migrate1to2(ctx sdk.Context) error { | ||
return v2.MigrateStore(ctx, m.keeper.storeKey, m.legacySubspace, m.keeper.cdc) | ||
} |
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 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,37 @@ | ||
package v2 | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
v2types "github.com/evmos/evmos/v10/x/revenue/migrations/v2/types" | ||
"github.com/evmos/evmos/v10/x/revenue/types" | ||
) | ||
|
||
// MigrateStore migrates the x/revenue module state from the consensus version 1 to | ||
// version 2. Specifically, it takes the parameters that are currently stored | ||
// and managed by the Cosmos SDK params module and stores them directly into the x/evm module state. | ||
func MigrateStore( | ||
ctx sdk.Context, | ||
storeKey storetypes.StoreKey, | ||
legacySubspace types.Subspace, | ||
cdc codec.BinaryCodec, | ||
) error { | ||
store := ctx.KVStore(storeKey) | ||
var params v2types.Params | ||
|
||
legacySubspace.GetParamSetIfExists(ctx, ¶ms) | ||
|
||
if err := params.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
bz, err := cdc.Marshal(¶ms) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
store.Set(types.ParamsKey, bz) | ||
|
||
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,46 @@ | ||
package v2_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/evmos/ethermint/encoding" | ||
v2 "github.com/evmos/evmos/v10/x/revenue/migrations/v2" | ||
v2types "github.com/evmos/evmos/v10/x/revenue/migrations/v2/types" | ||
"github.com/evmos/evmos/v10/x/revenue/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/testutil" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/evmos/ethermint/app" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type mockSubspace struct { | ||
ps v2types.Params | ||
} | ||
|
||
func newMockSubspace(ps v2types.Params) mockSubspace { | ||
return mockSubspace{ps: ps} | ||
} | ||
|
||
func (ms mockSubspace) GetParamSetIfExists(ctx sdk.Context, ps types.LegacyParams) { | ||
*ps.(*v2types.Params) = ms.ps | ||
} | ||
|
||
func TestMigrate(t *testing.T) { | ||
encCfg := encoding.MakeConfig(app.ModuleBasics) | ||
cdc := encCfg.Codec | ||
|
||
storeKey := sdk.NewKVStoreKey(types.ModuleName) | ||
tKey := sdk.NewTransientStoreKey("transient_test") | ||
ctx := testutil.DefaultContext(storeKey, tKey) | ||
kvStore := ctx.KVStore(storeKey) | ||
|
||
legacySubspace := newMockSubspace(v2types.DefaultParams()) | ||
require.NoError(t, v2.MigrateStore(ctx, storeKey, legacySubspace, cdc)) | ||
|
||
paramsBz := kvStore.Get(v2types.ParamsKey) | ||
var params v2types.Params | ||
cdc.MustUnmarshal(paramsBz, ¶ms) | ||
|
||
require.Equal(t, params, legacySubspace.ps) | ||
} |
Oops, something went wrong.