Skip to content

Commit

Permalink
fix(feetiers): Reject malformed address in query (backport #2653) (#2655
Browse files Browse the repository at this point in the history
)

Co-authored-by: Teddy Ding <[email protected]>
  • Loading branch information
mergify[bot] and teddyding authored Dec 13, 2024
1 parent 62044d0 commit 34c8f71
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion protocol/x/feetiers/client/cli/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ func TestQueryPerpetualFeeParams(t *testing.T) {
func TestQueryUserFeeTier(t *testing.T) {
net, ctx := setupNetwork(t)

out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdQueryUserFeeTier(), []string{"alice"})
out, err := clitestutil.ExecTestCLICmd(
ctx,
cli.CmdQueryUserFeeTier(),
[]string{"dydx199tqg4wdlnu4qjlxchpd7seg454937hjrknju4"},
)

require.NoError(t, err)
var resp types.QueryUserFeeTierResponse
Expand Down
6 changes: 6 additions & 0 deletions protocol/x/feetiers/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package keeper
import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/dydxprotocol/v4-chain/protocol/lib"
"github.com/dydxprotocol/v4-chain/protocol/x/feetiers/types"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -42,6 +44,10 @@ func (k Keeper) UserFeeTier(
}

ctx := lib.UnwrapSDKContext(c, types.ModuleName)

if _, err := sdk.AccAddressFromBech32(req.User); err != nil {
return nil, status.Error(codes.InvalidArgument, "invalid bech32 address")
}
index, tier := k.getUserFeeTier(ctx, req.User)
return &types.QueryUserFeeTierResponse{
Index: index,
Expand Down
9 changes: 8 additions & 1 deletion protocol/x/feetiers/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestUserFeeTier(t *testing.T) {
}{
"Success": {
req: &types.QueryUserFeeTierRequest{
User: "alice",
User: "dydx199tqg4wdlnu4qjlxchpd7seg454937hjrknju4",
},
res: &types.QueryUserFeeTierResponse{
Index: 0,
Expand All @@ -78,6 +78,13 @@ func TestUserFeeTier(t *testing.T) {
res: nil,
err: status.Error(codes.InvalidArgument, "invalid request"),
},
"Malformed address": {
req: &types.QueryUserFeeTierRequest{
User: "alice",
},
res: nil,
err: status.Error(codes.InvalidArgument, "invalid bech32 address"),
},
} {
t.Run(name, func(t *testing.T) {
res, err := k.UserFeeTier(ctx, tc.req)
Expand Down

0 comments on commit 34c8f71

Please sign in to comment.