This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(feemarket) - Depreacte usage of x/params in x/feemarket (#1509)
* (refactor): Added new MsgUpdateParams tx and generated new proto files * (refactor): Refactor for migration of x/params * (fix): Refactor to use single Params store key for easier more readable code * (fix): removed unused * (fix): add validation * (fix): fix linter * remove line * Added changes from code review * Apply changes from code review * (fix): Made ParamKey back to a string * Added CHANGELOG entry * Apply suggestions from code review Co-authored-by: Tomas Guerra <[email protected]> * (fix): remove HTTP endpoint exposure * Apply suggestions from code review Co-authored-by: MalteHerrmann <[email protected]> * fix: Apply changes from code review and run linter * Update x/feemarket/keeper/params.go Co-authored-by: Federico Kunze Küllmer <[email protected]> * Update x/feemarket/types/msg.go Co-authored-by: Federico Kunze Küllmer <[email protected]> * tests: added tests for msg_server and msg * tests: add failing test for migration * Update x/feemarket/keeper/params.go Co-authored-by: Tomas Guerra <[email protected]> Co-authored-by: MalteHerrmann <[email protected]> Co-authored-by: Federico Kunze Küllmer <[email protected]>
- Loading branch information
1 parent
8886ce3
commit 57ed355
Showing
24 changed files
with
2,082 additions
and
129 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
syntax = "proto3"; | ||
package ethermint.feemarket.v1; | ||
|
||
import "cosmos/msg/v1/msg.proto"; | ||
import "cosmos_proto/cosmos.proto"; | ||
import "ethermint/feemarket/v1/feemarket.proto"; | ||
import "gogoproto/gogo.proto"; | ||
|
||
option go_package = "github.com/evmos/ethermint/x/feemarket/types"; | ||
|
||
// Msg defines the erc20 Msg service. | ||
service Msg { | ||
// UpdateParams defined a governance operation for updating the x/feemarket module parameters. | ||
// The authority is hard-coded to the Cosmos SDK x/gov module account | ||
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); | ||
} | ||
|
||
// MsgUpdateParams defines a Msg for updating the x/feemarket module parameters. | ||
message MsgUpdateParams { | ||
option (cosmos.msg.v1.signer) = "authority"; | ||
// authority is the address of the governance account. | ||
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; | ||
// params defines the x/feemarket parameters to update. | ||
// NOTE: All parameters must be supplied. | ||
Params params = 2 [(gogoproto.nullable) = false]; | ||
} | ||
|
||
// MsgUpdateParamsResponse defines the response structure for executing a | ||
// MsgUpdateParams message. | ||
message MsgUpdateParamsResponse {} |
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 feemarket | ||
|
||
import ( | ||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
errortypes "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/evmos/ethermint/x/feemarket/types" | ||
) | ||
|
||
// NewHandler returns a handler for Ethermint type messages. | ||
func NewHandler(server types.MsgServer) sdk.Handler { | ||
return func(ctx sdk.Context, msg sdk.Msg) (result *sdk.Result, err error) { | ||
ctx = ctx.WithEventManager(sdk.NewEventManager()) | ||
|
||
switch msg := msg.(type) { | ||
case *types.MsgUpdateParams: | ||
// execute state transition | ||
res, err := server.UpdateParams(sdk.WrapSDKContext(ctx), msg) | ||
return sdk.WrapServiceResult(ctx, res, err) | ||
|
||
default: | ||
err := errorsmod.Wrapf(errortypes.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg) | ||
return nil, err | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1,42 @@ | ||
package keeper_test | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper" | ||
v4types "github.com/evmos/ethermint/x/feemarket/migrations/v4/types" | ||
"github.com/evmos/ethermint/x/feemarket/types" | ||
) | ||
|
||
type mockSubspace struct { | ||
ps v4types.Params | ||
} | ||
|
||
func newMockSubspace(ps v4types.Params) mockSubspace { | ||
return mockSubspace{ps: ps} | ||
} | ||
|
||
func (ms mockSubspace) GetParamSetIfExists(_ sdk.Context, ps types.LegacyParams) { | ||
*ps.(*v4types.Params) = ms.ps | ||
} | ||
|
||
func (suite *KeeperTestSuite) TestMigrations() { | ||
legacySubspace := newMockSubspace(v4types.DefaultParams()) | ||
migrator := feemarketkeeper.NewMigrator(suite.app.FeeMarketKeeper, legacySubspace) | ||
|
||
testCases := []struct { | ||
name string | ||
migrateFunc func(ctx sdk.Context) error | ||
}{ | ||
{ | ||
"Run Migrate3to4", | ||
migrator.Migrate3to4, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
suite.Run(tc.name, func() { | ||
err := tc.migrateFunc(suite.ctx) | ||
suite.Require().NoError(err) | ||
}) | ||
} | ||
} |
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,27 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
"github.com/evmos/ethermint/x/feemarket/types" | ||
) | ||
|
||
// UpdateParams implements the gRPC MsgServer interface. When an UpdateParams | ||
// proposal passes, it updates the module parameters. The update can only be | ||
// performed if the requested authority is the Cosmos SDK governance module | ||
// account. | ||
func (k *Keeper) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { | ||
if k.authority.String() != req.Authority { | ||
return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority.String(), req.Authority) | ||
} | ||
|
||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
if err := k.SetParams(ctx, req.Params); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &types.MsgUpdateParamsResponse{}, 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,40 @@ | ||
package keeper_test | ||
|
||
import ( | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
"github.com/evmos/ethermint/x/feemarket/types" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestUpdateParams() { | ||
testCases := []struct { | ||
name string | ||
request *types.MsgUpdateParams | ||
expectErr bool | ||
}{ | ||
{ | ||
name: "fail - invalid authority", | ||
request: &types.MsgUpdateParams{Authority: "foobar"}, | ||
expectErr: true, | ||
}, | ||
{ | ||
name: "pass - valid Update msg", | ||
request: &types.MsgUpdateParams{ | ||
Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), | ||
Params: types.DefaultParams(), | ||
}, | ||
expectErr: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
suite.Run("MsgUpdateParams", func() { | ||
_, err := suite.app.FeeMarketKeeper.UpdateParams(suite.ctx, tc.request) | ||
if tc.expectErr { | ||
suite.Require().Error(err) | ||
} else { | ||
suite.Require().NoError(err) | ||
} | ||
}) | ||
} | ||
} |
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.