Skip to content

Commit

Permalink
fix(affiliates): Reject self referral in RegisterAffiliate (#2637)
Browse files Browse the repository at this point in the history
(cherry picked from commit 87a43cd)
  • Loading branch information
teddyding authored and mergify[bot] committed Dec 10, 2024
1 parent c0a8826 commit 7dd89be
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions protocol/x/affiliates/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 9 additions & 0 deletions protocol/x/affiliates/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions protocol/x/affiliates/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

0 comments on commit 7dd89be

Please sign in to comment.