diff --git a/protocol/x/affiliates/keeper/keeper.go b/protocol/x/affiliates/keeper/keeper.go index 92554b8f1c..52cb1bfd3a 100644 --- a/protocol/x/affiliates/keeper/keeper.go +++ b/protocol/x/affiliates/keeper/keeper.go @@ -61,6 +61,12 @@ func (k Keeper) RegisterAffiliate( referee string, affiliateAddr string, ) error { + if referee == affiliateAddr { + return errorsmod.Wrapf( + types.ErrSelfReferral, "referee: %s, affiliate: %s", + referee, affiliateAddr, + ) + } if _, err := sdk.AccAddressFromBech32(referee); err != nil { return errorsmod.Wrapf(types.ErrInvalidAddress, "referee: %s", referee) } diff --git a/protocol/x/affiliates/keeper/keeper_test.go b/protocol/x/affiliates/keeper/keeper_test.go index 7a417cbdd6..5a889d1f9d 100644 --- a/protocol/x/affiliates/keeper/keeper_test.go +++ b/protocol/x/affiliates/keeper/keeper_test.go @@ -88,6 +88,15 @@ func TestRegisterAffiliate_GetReferredBy(t *testing.T) { // No setup needed for this test case }, }, + { + name: "Self referral", + referee: constants.AliceAccAddress.String(), + affiliate: constants.AliceAccAddress.String(), + expectError: types.ErrSelfReferral, + setup: func(t *testing.T, ctx sdk.Context, k *keeper.Keeper) { + // No setup needed for this test case + }, + }, } for _, tc := range tests { diff --git a/protocol/x/affiliates/types/errors.go b/protocol/x/affiliates/types/errors.go index ed8a2062d3..a60b522930 100644 --- a/protocol/x/affiliates/types/errors.go +++ b/protocol/x/affiliates/types/errors.go @@ -16,4 +16,5 @@ var ( ModuleName, 8, "Duplicate affiliate address for whitelist") ErrAffiliateTiersNotSet = errorsmod.Register(ModuleName, 9, "Affiliate tiers not set (affiliate program is not active)") + ErrSelfReferral = errorsmod.Register(ModuleName, 10, "Self referral not allowed") )