From eedbb0c8f034eb05e65589af95d727d3654b6cf8 Mon Sep 17 00:00:00 2001 From: Teddy Ding Date: Mon, 16 Dec 2024 10:31:11 -0500 Subject: [PATCH] fix(affiliates): Check address is valid in `ReferredBy` query [OTE-896] (#2567) (cherry picked from commit 6a1308136ec9bd9ac1f04beb3b60c843d5c84455) --- protocol/x/affiliates/keeper/grpc_query.go | 7 +++++++ protocol/x/affiliates/keeper/grpc_query_test.go | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/protocol/x/affiliates/keeper/grpc_query.go b/protocol/x/affiliates/keeper/grpc_query.go index 63b10dca48..84185382a8 100644 --- a/protocol/x/affiliates/keeper/grpc_query.go +++ b/protocol/x/affiliates/keeper/grpc_query.go @@ -59,6 +59,13 @@ func (k Keeper) ReferredBy(ctx context.Context, req *types.ReferredByRequest) (*types.ReferredByResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) + // Check req.Address is a valid bech32 address + _, err := sdk.AccAddressFromBech32(req.GetAddress()) + if err != nil { + return nil, errorsmod.Wrapf(types.ErrInvalidAddress, "address: %s, error: %s", + req.GetAddress(), err.Error()) + } + affiliateAddr, exists := k.GetReferredBy(sdkCtx, req.GetAddress()) if !exists { return &types.ReferredByResponse{}, nil diff --git a/protocol/x/affiliates/keeper/grpc_query_test.go b/protocol/x/affiliates/keeper/grpc_query_test.go index a19d76c3a9..23f0e35c93 100644 --- a/protocol/x/affiliates/keeper/grpc_query_test.go +++ b/protocol/x/affiliates/keeper/grpc_query_test.go @@ -190,6 +190,14 @@ func TestReferredBy(t *testing.T) { expected: nil, expectError: nil, }, + "Invalid bech32 address": { + req: &types.ReferredByRequest{ + Address: "Foo", + }, + setup: func(ctx sdk.Context, k keeper.Keeper) {}, + expected: nil, + expectError: types.ErrInvalidAddress, + }, } for name, tc := range testCases {