Skip to content

Commit

Permalink
Reject malformed address
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyding committed Dec 12, 2024
1 parent 196dc84 commit ad4c75f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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, "user address is valid 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, "user address is valid bech32 address"),
},
} {
t.Run(name, func(t *testing.T) {
res, err := k.UserFeeTier(ctx, tc.req)
Expand Down

0 comments on commit ad4c75f

Please sign in to comment.